diff --git a/src/app/project/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts index ac0859e..8abe35b 100644 --- a/src/app/project/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -7,6 +7,7 @@ import {SimpleGamesystem} from "./gamesystems/SimpleGamesystem"; import {Character} from "./characters/Character"; import {TemplateType} from "./TemplateType"; import {SimpleTemplateGamesystem} from "./gamesystems/SimpleTemplateGamesystem"; +import {ProductTemplateSystem} from "./gamesystems/ProductTemplateSystem"; export class GameModel { @@ -58,10 +59,19 @@ export class GameModel { if(parentGamesystemName != undefined) { const parentGamesystem = this.findGamesystem(parentGamesystemName); - if(parentGamesystem instanceof SimpleGamesystem) { - const parentProductGamesystem = ProductGamesystem.constructFromSimpleGamesystem(parentGamesystem, this); - parentProductGamesystem.addChildGamesystem(simpleGamesystem); - simpleGamesystem.parentGamesystem = parentProductGamesystem; + if(parentGamesystem instanceof SimpleGamesystem || parentGamesystem instanceof SimpleTemplateGamesystem) { + if(parentGamesystem.templateType == TemplateType.NORMAL) { + const parentProductGamesystem = new ProductGamesystem(parentGamesystem.componentName, parentGamesystem.componentDescription); + parentProductGamesystem.constructFromSimpleGamesystem(parentGamesystem, this); + parentProductGamesystem.addChildGamesystem(simpleGamesystem); + simpleGamesystem.parentGamesystem = parentProductGamesystem; + } else { + const parentProductTemplateGamesystem = new ProductTemplateSystem(parentGamesystem.componentName, parentGamesystem.componentDescription, TemplateType.CHARACTER); + parentProductTemplateGamesystem.constructFromSimpleGamesystem(parentGamesystem, this); + parentProductTemplateGamesystem.addChildGamesystem(simpleGamesystem); + simpleGamesystem.parentGamesystem = parentProductTemplateGamesystem; + } + } else { const productParentGamesystem = parentGamesystem as ProductGamesystem; productParentGamesystem.addChildGamesystem(simpleGamesystem); diff --git a/src/app/project/game-model/gamesystems/ProductGamesystem.ts b/src/app/project/game-model/gamesystems/ProductGamesystem.ts index 791cbce..2923a03 100644 --- a/src/app/project/game-model/gamesystems/ProductGamesystem.ts +++ b/src/app/project/game-model/gamesystems/ProductGamesystem.ts @@ -6,38 +6,39 @@ import {Transition} from "./transitions/Transition"; import {SimpleState} from "./states/SimpleState"; import {SimpleGamesystem} from "./SimpleGamesystem"; import {GameModel} from "../GameModel"; -import {ScriptAccountCondition} from "./conditions/ScriptAccountCondition"; -import {ScriptAccountAction} from "./actions/ScriptAccountAction"; import {ProductGamesystemGenerator} from "./productSystemGenerator/ProductGamesystemGenerator"; +import {TemplateType} from "../TemplateType"; +import {ProductTemplateSystem} from "./ProductTemplateSystem"; +import {Character} from "../characters/Character"; export class ProductGamesystem extends Gamesystem { innerGamesystems: Gamesystem, Transition>[] = []; productGamesystemGenerator: ProductGamesystemGenerator = new ProductGamesystemGenerator(this); - static constructFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel) { - const productGamesystem = new ProductGamesystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription); - const parentGamesystem = simpleGamesystem.parentGamesystem; + constructFromSimpleGamesystem(referenceSystem: SimpleGamesystem, gameModel: GameModel) { - if(simpleGamesystem.states.length > 0) { - simpleGamesystem.componentName += "(Child)"; - productGamesystem.addChildGamesystem(simpleGamesystem); - simpleGamesystem.parentGamesystem = productGamesystem + const parentGamesystem = referenceSystem.parentGamesystem; + + if(referenceSystem.states.length > 0) { + referenceSystem.componentName += "(Child)"; + this.addChildGamesystem(referenceSystem); + referenceSystem.parentGamesystem = this } if(parentGamesystem != undefined) { - parentGamesystem.removeChildGamesystem(simpleGamesystem); - parentGamesystem.addChildGamesystem(productGamesystem); - productGamesystem.parentGamesystem = parentGamesystem + parentGamesystem.removeChildGamesystem(referenceSystem); + parentGamesystem.addChildGamesystem(this); + this.parentGamesystem = parentGamesystem } else { - gameModel.removeGamesystem(simpleGamesystem); - gameModel.addGamesystem(productGamesystem); + gameModel.removeGamesystem(referenceSystem); + gameModel.addGamesystem(this); } - - return productGamesystem; } + + createState(innerStates: State[]): ProductState | undefined { if(innerStates.length == this.innerGamesystems.length && this.findProductStateByInnerStates(innerStates)== undefined) { const productState = new ProductState(innerStates); diff --git a/src/app/project/game-model/gamesystems/ProductTemplateSystem.ts b/src/app/project/game-model/gamesystems/ProductTemplateSystem.ts index 2442643..70a727a 100644 --- a/src/app/project/game-model/gamesystems/ProductTemplateSystem.ts +++ b/src/app/project/game-model/gamesystems/ProductTemplateSystem.ts @@ -4,12 +4,21 @@ import {ProductTransition} from "./transitions/ProductTransition"; import {Gamesystem} from "./Gamesystem"; import {ProductTemplateGamesystemGenerator} from "./productSystemGenerator/ProductTemplateGamesystemGenerator"; import {ProductGamesystemGenerator} from "./productSystemGenerator/ProductGamesystemGenerator"; +import {SimpleGamesystem} from "./SimpleGamesystem"; +import {GameModel} from "../GameModel"; +import {TemplateType} from "../TemplateType"; export class ProductTemplateSystem extends ProductGamesystem { stateMap: Map = new Map(); transitionMap: Map = new Map(); + + constructor(gamesystemName: string, gamesystemDescription: string, templateType: TemplateType) { + super(gamesystemName, gamesystemDescription); + this.templateType = templateType + } + generateFromChildsystems() { const productSystemGenerator = new ProductGamesystemGenerator(this); productSystemGenerator.generateFromChildsystems(); @@ -19,6 +28,4 @@ export class ProductTemplateSystem extends ProductGamesystem const productSystemGenerator = new ProductTemplateGamesystemGenerator(this, referenceTemplate); productSystemGenerator.generateFromChildsystems() } - - } diff --git a/src/app/project/parser/gamesystemParser/GamesystemParser.ts b/src/app/project/parser/gamesystemParser/GamesystemParser.ts index 2ae86a3..97a099d 100644 --- a/src/app/project/parser/gamesystemParser/GamesystemParser.ts +++ b/src/app/project/parser/gamesystemParser/GamesystemParser.ts @@ -9,6 +9,7 @@ import {TransitionParser} from "./TransitionParser"; import {TemplateType} from "../../game-model/TemplateType"; import {SimpleTemplateGamesystem} from "../../game-model/gamesystems/SimpleTemplateGamesystem"; import {Character} from "../../game-model/characters/Character"; +import {ProductTemplateSystem} from "../../game-model/gamesystems/ProductTemplateSystem"; export class GamesystemParser { @@ -61,7 +62,13 @@ export class GamesystemParser { } parseProductGamesystem(gamesystemData: any) { - const productGamesystem = new ProductGamesystem(gamesystemData.componentName, gamesystemData.componentDescription); + let productGamesystem: ProductGamesystem | ProductTemplateSystem + if(gamesystemData.templateType == TemplateType.CHARACTER) { + productGamesystem = new ProductTemplateSystem(gamesystemData.componentName, gamesystemData.componentDescription, TemplateType.CHARACTER) + } else { + productGamesystem = new ProductGamesystem(gamesystemData.componentName, gamesystemData.componentDescription); + } + const childsystemNames: string[] = [] for(let i=0; i