import {Gamesystem} from "./gamesystems/Gamesystem"; import {ScriptAccount} from "./scriptAccounts/ScriptAccount"; import {Transition} from "./gamesystems/transitions/Transition"; import {State} from "./gamesystems/states/State"; import {ProductGamesystem} from "./gamesystems/ProductGamesystem"; import {SimpleGamesystem} from "./gamesystems/SimpleGamesystem"; import {Character} from "./characters/Character"; import {ModelComponentType} from "./ModelComponentType"; export class GameModel { gameModelName: string gamesystems: Gamesystem[] = []; scriptAccounts: ScriptAccount[] = []; characters: Character[] = [] constructor(gameModelName: string) { this.gameModelName = gameModelName; this.characters.push(new Character("Astrid Hofferson", "", ModelComponentType.CHARACTER)) this.characters.push(new Character("Hicks Haddock", "", ModelComponentType.CHARACTER)) } addGamesystem(gamesystem: Gamesystem) { if(this.findGamesystem(gamesystem.componentName) == undefined) { this.gamesystems.push(gamesystem); } } removeGamesystem(gamesystem : Gamesystem) { if(gamesystem.parentGamesystem == undefined) { this.gamesystems = this.gamesystems.filter(g => g !== gamesystem); } else { (gamesystem.parentGamesystem as ProductGamesystem).removeChildGamesystem(gamesystem); } } createScriptAccount(scriptAccountName: string) { if(scriptAccountName != undefined && scriptAccountName.length > 0) { const scriptAccount = new ScriptAccount(scriptAccountName, ""); const searchedScriptAccount = this.scriptAccounts.find(s => s.componentName === scriptAccount.componentName); if(searchedScriptAccount == undefined) { this.scriptAccounts.push(scriptAccount); return scriptAccount; } } return undefined; } createGamesystem(gamesystemName: string, parentGamesystemName: string | undefined) { if(gamesystemName != undefined && this.findGamesystem(gamesystemName) == undefined) { const simpleGamesystem = new SimpleGamesystem(gamesystemName, ""); if(parentGamesystemName != undefined) { const parentGamesystem = this.findGamesystem(parentGamesystemName); if(parentGamesystem instanceof SimpleGamesystem) { const parentProductGamesystem = ProductGamesystem.constructFromSimpleGamesystem(parentGamesystem, this); parentProductGamesystem.addChildGamesystem(simpleGamesystem); simpleGamesystem.parentGamesystem = parentProductGamesystem; } else { const productParentGamesystem = parentGamesystem as ProductGamesystem; productParentGamesystem.addChildGamesystem(simpleGamesystem); simpleGamesystem.parentGamesystem = productParentGamesystem; } } else { this.gamesystems.push(simpleGamesystem); } return simpleGamesystem; } } removeScriptAccount(scriptAccount: ScriptAccount) { if(scriptAccount != undefined) { this.scriptAccounts = this.scriptAccounts.filter(s => s != scriptAccount); } } findGamesystem(gamesystemName: string) { const gamesystemQueue : Gamesystem, Transition>[] = []; this.gamesystems.forEach(gamesystem => gamesystemQueue.push(gamesystem)); while(gamesystemQueue.length > 0) { const currentGamesystem = gamesystemQueue.shift()!; if(currentGamesystem.componentName == gamesystemName) { return currentGamesystem; } else if(currentGamesystem instanceof ProductGamesystem) { const currentProductGamesystem = currentGamesystem as ProductGamesystem; currentProductGamesystem.innerGamesystems.forEach(gamesystem => gamesystemQueue.push(gamesystem)); } } } addScriptAccount(scriptAccount: ScriptAccount) { this.scriptAccounts.push(scriptAccount); } generateProductSystemContents() { this.gamesystems.forEach(gamesystem => { if(gamesystem instanceof ProductGamesystem) { gamesystem.generateFromChildsystems(); } }) } }