UNPKG

cbt-game-generator

Version:

Configuration generator for CBT animation apps

140 lines (129 loc) 4.97 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.TypesGenerator = void 0; const fs = __importStar(require("fs")); const path = __importStar(require("path")); class TypesGenerator { constructor(gamePath, gameName, numberOfVariants) { this.gamePath = gamePath; this.gameName = gameName; this.numberOfVariants = numberOfVariants; this.typesDir = path.join(this.gamePath, 'types'); } generate() { fs.mkdirSync(this.typesDir, { recursive: true }); this.generateConfiguration(); this.generateTagTypes(); } generateConfiguration() { const configContent = `import { EGames } from "../../../../shared/constants/Games"; import { EGameLevel, EReinforcements, } from "../../../../shared/constants/gameStates"; import { ICommonConfiguration } from "../../../../shared/types/commonConfiguration"; import { ISources } from "../../../../shared/types/resources"; import { E${this.gameName}Targets } from "../constants/targets"; import { E${this.gameName}, E${this.gameName}Variants, } from "../constants/variantsConfig"; import { T${this.gameName}Tags } from "./tagTypes"; export interface IVariantsMapping extends Record<E${this.gameName}, T${this.gameName}Tags> { ${Array.from({ length: this.numberOfVariants }, (_, i) => ` [E${this.gameName}Variants.V${i + 1}]: E${this.gameName}Targets;`).join('\n')} } export interface I${this.gameName}<Variant extends E${this.gameName}Variants> extends ICommonConfiguration<EGames.${this.gameName}, Variant> { segments: ISegments; } export interface ISegments { speechInteractionDuration?: number; speechSecondInteractionDuration?: number; actions: ISegmentActions[]; } export interface ISegmentActions { target: E${this.gameName}Targets; backgroundDisplay: IDisplayObjects; display: IDisplayObjects; showVisualCue: boolean; lottieAudio: IAudioPrompt; changeLanguage?: boolean; [EGameLevel.INTRO]: IGameLevelCommon; [EGameLevel.INTRO_REPEAT]: IGameLevelCommon; [EGameLevel.INTERACTION]: IGameLevelCommon; [EGameLevel.INTRO_2]: IGameLevelCommon; [EGameLevel.INTERACTION_2]: IGameLevelCommon; [EGameLevel.INTRO_3]: IGameLevelCommon; [EGameLevel.INTERACTION_3]: IGameLevelCommon; [EGameLevel.REINFORCEMENT]: IReinforcement; } export interface IDisplay { mainDisplay: IDisplayObjects[]; clueDisplay: IDisplayObjects[]; lottieDisplay: IDisplayObjects[]; } export interface IGameLevelCommon { audio?: IAudioPrompt[]; video?: IAudioPrompt[]; showPulse: boolean; } export interface IDisplayObjects { id: ISources["id"]; } export interface IAudioPrompt { id: ISources["id"]; delay?: number; } interface IReinforcement { [EReinforcements.SUCCESS]: IGameLevelCommon; [EReinforcements.PARTIAL_SUCCESS]: IGameLevelCommon; [EReinforcements.FAILURE]: IGameLevelCommon; showPulse?: boolean; }`; fs.writeFileSync(path.join(this.typesDir, 'configuration.ts'), configContent); } generateTagTypes() { const tagTypesContent = `import { E${this.gameName}Targets } from "../constants/targets"; import { E${this.gameName}Variants } from "../constants/variantsConfig"; import { I${this.gameName} } from "./configuration"; export type T${this.gameName}Tags = E${this.gameName}Targets; export type T${this.gameName} = ${Array.from({ length: this.numberOfVariants }, (_, i) => ` | I${this.gameName}<E${this.gameName}Variants.V${i + 1}>`).join('\n')};`; fs.writeFileSync(path.join(this.typesDir, 'tagTypes.ts'), tagTypesContent); } } exports.TypesGenerator = TypesGenerator;