diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 1927ff2..6b962e0 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -157,8 +157,13 @@ export class AppComponent implements OnInit{ } - //const createdGamesystem = this.gameModel!.createGamesystem("New Gamesystem", parentGamesystemName, templateType); - const createdGamesystem = this.gameModel!.createSimpleGamesystem("New Gamesystem", templateType) + let createdGamesystem; + if(parentGamesystemName == undefined) { + createdGamesystem = this.gameModel?.createSimpleGamesystem("New Gamesystem", templateType); + } else { + createdGamesystem = this.gameModel!.createSimpleGamesystemWithParent("New Gamesystem", parentGamesystemName, templateType) + } + if(createdGamesystem != undefined) { this.gamesystemOverview!.refresh(); this.editor?.openGameModelComponent(createdGamesystem); diff --git a/src/app/project/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts index a50286f..b59445a 100644 --- a/src/app/project/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -8,6 +8,8 @@ import {Character} from "./characters/Character"; import {ModelComponentType} from "./ModelComponentType"; import {TemplateType} from "./templates/TemplateType"; import {SimpleTemplateGamesystem} from "./templates/simpleGamesystem/SimpleTemplateGamesystem"; +import {ProductTemplateSystem} from "./templates/productGamesystem/ProductTemplateSystem"; +import {ProductTemplateCreator} from "./templates/productGamesystem/ProductTemplateCreator"; export class GameModel { gameModelName: string @@ -47,7 +49,7 @@ export class GameModel { return undefined; } - createSimpleGamesystem(gamesystemName: string, templateType: TemplateType | undefined) { + createSimpleGamesystem(gamesystemName: string, templateType: TemplateType | undefined, pushToTop: boolean = true) { if(gamesystemName != undefined && this.findGamesystem(gamesystemName) == undefined) { let simpleGamesystem: SimpleGamesystem @@ -57,12 +59,48 @@ export class GameModel { simpleGamesystem = new SimpleTemplateGamesystem(gamesystemName, "", templateType) } - this.gamesystems.push(simpleGamesystem) + if(pushToTop) { + this.gamesystems.push(simpleGamesystem) + } return simpleGamesystem; } return undefined; } + createSimpleGamesystemWithParent(gamesystemName: string, parentGamesystemName: string, templateType: TemplateType | undefined) { + const simpleGamesystem = this.createSimpleGamesystem(gamesystemName, templateType, false)!; + + const parentGamesystem = this.findGamesystem(parentGamesystemName) + if(parentGamesystem == undefined) {return undefined} + + let parentProductGamesystem: ProductGamesystem; + if(parentGamesystem instanceof SimpleTemplateGamesystem) { + parentProductGamesystem = ProductTemplateCreator.constructTemplateFromSimpleGamesystem(parentGamesystem, this, templateType!) + } else if(parentGamesystem instanceof SimpleGamesystem) { + if(simpleGamesystem instanceof SimpleTemplateGamesystem) { + parentProductGamesystem = ProductTemplateCreator.constructTemplateFromSimpleGamesystem(parentGamesystem, this, templateType!) + } else { + console.log("Test") + parentProductGamesystem = ProductGamesystem.constructFromSimpleGamesystem(parentGamesystem, this); + console.log(this.gamesystems) + } + } else { + if(simpleGamesystem instanceof SimpleTemplateGamesystem) { + parentProductGamesystem = ProductTemplateCreator.convertProductToTemplate(parentGamesystem as ProductGamesystem, this, templateType!) + } else { + parentProductGamesystem = parentGamesystem as ProductGamesystem + } + + } + + parentProductGamesystem.addChildGamesystem(simpleGamesystem); + simpleGamesystem.parentGamesystem = parentProductGamesystem; + + return simpleGamesystem; + } + + + createGamesystem(gamesystemName: string, parentGamesystemName: string | undefined, templateType: TemplateType | undefined) { if(gamesystemName != undefined && this.findGamesystem(gamesystemName) == undefined) { const simpleGamesystem = new SimpleGamesystem(gamesystemName, ""); @@ -140,7 +178,9 @@ export class GameModel { while(gamesystemQueue.length > 0) { const currentGamesystem = gamesystemQueue.shift()!; - if(currentGamesystem instanceof SimpleTemplateGamesystem && currentGamesystem.templateType === templateType) { + if(currentGamesystem instanceof SimpleTemplateGamesystem && currentGamesystem.templateType === templateType) { + requestedTemplates.push(currentGamesystem) + } else if(currentGamesystem instanceof ProductTemplateSystem && currentGamesystem.templateType === templateType) { requestedTemplates.push(currentGamesystem) } diff --git a/src/app/project/game-model/gamesystems/ProductGamesystem.ts b/src/app/project/game-model/gamesystems/ProductGamesystem.ts index e3e2daf..a7d380f 100644 --- a/src/app/project/game-model/gamesystems/ProductGamesystem.ts +++ b/src/app/project/game-model/gamesystems/ProductGamesystem.ts @@ -9,6 +9,8 @@ import {GameModel} from "../GameModel"; import {ScriptAccountCondition} from "./conditions/ScriptAccountCondition"; import {ScriptAccountAction} from "./actions/ScriptAccountAction"; import {ProductSystemGenerator} from "./productSystemGenerator/ProductSystemGenerator"; +import {TemplateType} from "../templates/TemplateType"; +import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem"; export class ProductGamesystem extends Gamesystem { @@ -16,25 +18,28 @@ export class ProductGamesystem extends Gamesystem 0) { simpleGamesystem.componentName += "(Child)"; - productGamesystem.addChildGamesystem(simpleGamesystem); - simpleGamesystem.parentGamesystem = productGamesystem + this.addChildGamesystem(simpleGamesystem); + simpleGamesystem.parentGamesystem = this } if(parentGamesystem != undefined) { parentGamesystem.removeChildGamesystem(simpleGamesystem); - parentGamesystem.addChildGamesystem(productGamesystem); - productGamesystem.parentGamesystem = parentGamesystem + parentGamesystem.addChildGamesystem(this); + this.parentGamesystem = parentGamesystem } else { gameModel.removeGamesystem(simpleGamesystem); - gameModel.addGamesystem(productGamesystem); + gameModel.addGamesystem(this); } - - return productGamesystem; } createState(innerStates: State[]): ProductState | undefined { diff --git a/src/app/project/game-model/templates/productGamesystem/ProductTemplateCreator.ts b/src/app/project/game-model/templates/productGamesystem/ProductTemplateCreator.ts new file mode 100644 index 0000000..1befc41 --- /dev/null +++ b/src/app/project/game-model/templates/productGamesystem/ProductTemplateCreator.ts @@ -0,0 +1,30 @@ +import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem"; +import {GameModel} from "../../GameModel"; +import {TemplateType} from "../TemplateType"; +import {ProductTemplateSystem} from "./ProductTemplateSystem"; +import {ProductGamesystem} from "../../gamesystems/ProductGamesystem"; + +export class ProductTemplateCreator { + static constructTemplateFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel, templateType: TemplateType) { + const productGamesystem = new ProductTemplateSystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription, templateType); + productGamesystem.constructHierarchyFromSimpleGamesystem(simpleGamesystem, gameModel); + return productGamesystem; + } + + static convertProductToTemplate(productGamesystem: ProductGamesystem, gameModel: GameModel, templateType: TemplateType) { + const productTemplate = new ProductTemplateSystem(productGamesystem.componentName, productGamesystem.componentDescription, templateType); + productTemplate.states = productGamesystem.states + productTemplate.transitions = productGamesystem.transitions + productTemplate.innerGamesystems = productGamesystem.innerGamesystems; + productGamesystem.innerGamesystems.forEach(innerGamesystem => innerGamesystem.parentGamesystem = productTemplate); + + if(productGamesystem.parentGamesystem == undefined) { + gameModel.removeGamesystem(productGamesystem) + gameModel.gamesystems.push(productTemplate) + } else { + productTemplate.parentGamesystem = productGamesystem.parentGamesystem; + productGamesystem.parentGamesystem.addChildGamesystem(productTemplate); + } + return productTemplate; + } +} diff --git a/src/app/project/game-model/templates/productGamesystem/ProductTemplateSystem.ts b/src/app/project/game-model/templates/productGamesystem/ProductTemplateSystem.ts index f4a2b4b..6db77cc 100644 --- a/src/app/project/game-model/templates/productGamesystem/ProductTemplateSystem.ts +++ b/src/app/project/game-model/templates/productGamesystem/ProductTemplateSystem.ts @@ -3,15 +3,24 @@ import {TemplateGamesystem} from "../TemplateGamesystem"; import {TemplateElement} from "../TemplateElement"; import {ProductState} from "../../gamesystems/states/ProductState"; import {ProductTransition} from "../../gamesystems/transitions/ProductTransition"; +import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem"; +import {GameModel} from "../../GameModel"; +import {TemplateType} from "../TemplateType"; export class ProductTemplateSystem extends ProductGamesystem implements TemplateGamesystem{ stateMap: Map = new Map(); transitionMap: Map = new Map() + templateType: TemplateType - addTemplateElement(templateElement: TemplateElement): void { + + constructor(gamesystemName: string, gamesystemDescription: string, templateType: TemplateType) { + super(gamesystemName, gamesystemDescription); + this.templateType = templateType; } + addTemplateElement(templateElement: TemplateElement): void { + } }