From eaaac9ec7a2028024ca58470774aac6d754f2961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sun, 14 Apr 2024 10:09:30 +0200 Subject: [PATCH 1/8] Implement basic ProductTemplateSystem --- .../productGamesystem/ProductTemplateSystem.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/app/project/game-model/templates/productGamesystem/ProductTemplateSystem.ts diff --git a/src/app/project/game-model/templates/productGamesystem/ProductTemplateSystem.ts b/src/app/project/game-model/templates/productGamesystem/ProductTemplateSystem.ts new file mode 100644 index 0000000..f4a2b4b --- /dev/null +++ b/src/app/project/game-model/templates/productGamesystem/ProductTemplateSystem.ts @@ -0,0 +1,17 @@ +import {ProductGamesystem} from "../../gamesystems/ProductGamesystem"; +import {TemplateGamesystem} from "../TemplateGamesystem"; +import {TemplateElement} from "../TemplateElement"; +import {ProductState} from "../../gamesystems/states/ProductState"; +import {ProductTransition} from "../../gamesystems/transitions/ProductTransition"; + +export class ProductTemplateSystem extends ProductGamesystem implements TemplateGamesystem{ + + stateMap: Map = new Map(); + transitionMap: Map = new Map() + + addTemplateElement(templateElement: TemplateElement): void { + } + + + +} From 151531f970b5ca3b02a33c76bec4b0e97ca7b7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sun, 14 Apr 2024 11:14:04 +0200 Subject: [PATCH 2/8] Create ProductTemplatesystems --- src/app/app.component.ts | 9 +++- src/app/project/game-model/GameModel.ts | 46 +++++++++++++++++-- .../gamesystems/ProductGamesystem.ts | 19 +++++--- .../ProductTemplateCreator.ts | 30 ++++++++++++ .../ProductTemplateSystem.ts | 11 ++++- 5 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 src/app/project/game-model/templates/productGamesystem/ProductTemplateCreator.ts 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 { + } } From 21d324d3b241c6f11653f3413231050e12e9ddfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sun, 14 Apr 2024 11:18:23 +0200 Subject: [PATCH 3/8] Persist TemplateType of ProductTemplateSystems --- .../serializer/GamesystemSerializer.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/app/project/serializer/GamesystemSerializer.ts b/src/app/project/serializer/GamesystemSerializer.ts index 311ce30..41ebcf3 100644 --- a/src/app/project/serializer/GamesystemSerializer.ts +++ b/src/app/project/serializer/GamesystemSerializer.ts @@ -4,6 +4,7 @@ import {SimpleGamesystem} from "../game-model/gamesystems/SimpleGamesystem"; import {ProductGamesystem} from "../game-model/gamesystems/ProductGamesystem"; import {SerializeConstants} from "./SerializeConstants"; import {ModelComponentType} from "../game-model/ModelComponentType"; +import {ProductTemplateSystem} from "../game-model/templates/productGamesystem/ProductTemplateSystem"; export class GamesystemSerializer { @@ -59,12 +60,24 @@ export class GamesystemSerializer { storedChildsystems.forEach(storedChildsystem => storedGamesystems.push(storedChildsystem)) }) - const jsonString = { - 'componentName': productGamesystem.componentName, - 'componentDescription': productGamesystem.componentDescription, - 'childsystems': innerGamesystemJsonArray + let jsonString; + if(productGamesystem instanceof ProductTemplateSystem) { + jsonString = { + 'componentName': productGamesystem.componentName, + 'componentDescription': productGamesystem.componentDescription, + 'childsystems': innerGamesystemJsonArray, + 'templateType': productGamesystem.templateType + } + } else { + jsonString = { + 'componentName': productGamesystem.componentName, + 'componentDescription': productGamesystem.componentDescription, + 'childsystems': innerGamesystemJsonArray, + } } + + const storedProductsystem = new StoreComponent(JSON.stringify(jsonString, null, SerializeConstants.JSON_INDENT), fileName, ModelComponentType.GAMESYTEM) storedGamesystems.push(storedProductsystem) From 10a32df8591d7291347b43fc6edf92864d42a77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sun, 14 Apr 2024 11:20:36 +0200 Subject: [PATCH 4/8] Load Templatetype of ProductTemplateGamesystems --- .../parser/gamesystemParser/GamesystemParser.ts | 9 ++++++++- testModel/gamesystems/Producttest/Letters.json | 7 +++++++ testModel/gamesystems/Producttest/Numbers.json | 6 ++++++ testModel/gamesystems/Producttest/Producttest.json | 13 +++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 testModel/gamesystems/Producttest/Letters.json create mode 100644 testModel/gamesystems/Producttest/Numbers.json create mode 100644 testModel/gamesystems/Producttest/Producttest.json diff --git a/src/app/project/parser/gamesystemParser/GamesystemParser.ts b/src/app/project/parser/gamesystemParser/GamesystemParser.ts index 564d4ce..0e4ce93 100644 --- a/src/app/project/parser/gamesystemParser/GamesystemParser.ts +++ b/src/app/project/parser/gamesystemParser/GamesystemParser.ts @@ -7,6 +7,7 @@ import {StateParser} from "./StateParser"; import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {TransitionParser} from "./TransitionParser"; import {SimpleTemplateGamesystem} from "../../game-model/templates/simpleGamesystem/SimpleTemplateGamesystem"; +import {ProductTemplateSystem} from "../../game-model/templates/productGamesystem/ProductTemplateSystem"; export class GamesystemParser { @@ -60,7 +61,13 @@ export class GamesystemParser { } parseProductGamesystem(gamesystemData: any) { - const productGamesystem = new ProductGamesystem(gamesystemData.componentName, gamesystemData.componentDescription); + let productGamesystem; + if(gamesystemData.templateType == undefined) { + productGamesystem = new ProductGamesystem(gamesystemData.componentName, gamesystemData.componentDescription); + } else { + productGamesystem = new ProductTemplateSystem(gamesystemData.componentName, gamesystemData.componentDescription, gamesystemData.templateType) + } + const childsystemNames: string[] = [] for(let i=0; i Date: Sun, 14 Apr 2024 11:35:24 +0200 Subject: [PATCH 5/8] Add related Templatesystem as specified Gamesystems --- .../project/game-model/characters/Character.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/app/project/game-model/characters/Character.ts b/src/app/project/game-model/characters/Character.ts index 8f2fe49..a35e773 100644 --- a/src/app/project/game-model/characters/Character.ts +++ b/src/app/project/game-model/characters/Character.ts @@ -4,6 +4,8 @@ import {TemplateElement} from "../templates/TemplateElement"; import {TemplateGamesystem} from "../templates/TemplateGamesystem"; import {Gamesystem} from "../gamesystems/Gamesystem"; import {SimpleTemplateGamesystem} from "../templates/simpleGamesystem/SimpleTemplateGamesystem"; +import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem"; +import {ProductGamesystem} from "../gamesystems/ProductGamesystem"; export class Character extends ModelComponent implements TemplateElement { @@ -13,10 +15,20 @@ export class Character extends ModelComponent implements TemplateElement { super(componentName, componentDescription, ModelComponentType.CHARACTER); } - addCharacterSpecificSimpleTemplatesystem(gamesystem: SimpleTemplateGamesystem) { + addCharacterSpecificSimpleTemplatesystem(gamesystem: Gamesystem) { if(!this.isTemplateSystemCharacterSpecific(gamesystem.componentName)) { - this.characterSpecificTemplateSystems.push(gamesystem) - gamesystem.addTemplateElement(this) + if(gamesystem instanceof SimpleTemplateGamesystem) { + this.characterSpecificTemplateSystems.push(gamesystem) + gamesystem.addTemplateElement(this) + } else if(gamesystem instanceof ProductTemplateSystem) { + this.characterSpecificTemplateSystems.push(gamesystem) + gamesystem.addTemplateElement(this) + gamesystem.innerGamesystems.forEach(innerGamesystem => this.addCharacterSpecificSimpleTemplatesystem(innerGamesystem)) + } + + if(gamesystem.parentGamesystem != undefined) { + this.addCharacterSpecificSimpleTemplatesystem(gamesystem.parentGamesystem) + } } } From bf5403814ad17e1b9e7a947cada63fdc9377ed56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sun, 14 Apr 2024 11:36:30 +0200 Subject: [PATCH 6/8] Exclude SiblingTemplates to be automatically specified --- src/app/project/game-model/characters/Character.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/project/game-model/characters/Character.ts b/src/app/project/game-model/characters/Character.ts index a35e773..e4161ab 100644 --- a/src/app/project/game-model/characters/Character.ts +++ b/src/app/project/game-model/characters/Character.ts @@ -23,7 +23,6 @@ export class Character extends ModelComponent implements TemplateElement { } else if(gamesystem instanceof ProductTemplateSystem) { this.characterSpecificTemplateSystems.push(gamesystem) gamesystem.addTemplateElement(this) - gamesystem.innerGamesystems.forEach(innerGamesystem => this.addCharacterSpecificSimpleTemplatesystem(innerGamesystem)) } if(gamesystem.parentGamesystem != undefined) { From 4d4efa49c9d4268b172bfc2dd833d92303fa14dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sun, 14 Apr 2024 11:39:39 +0200 Subject: [PATCH 7/8] Exclude SiblingTemplates to be automatically specified only by recursive call --- src/app/project/game-model/characters/Character.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/project/game-model/characters/Character.ts b/src/app/project/game-model/characters/Character.ts index e4161ab..4d9bf6c 100644 --- a/src/app/project/game-model/characters/Character.ts +++ b/src/app/project/game-model/characters/Character.ts @@ -15,7 +15,7 @@ export class Character extends ModelComponent implements TemplateElement { super(componentName, componentDescription, ModelComponentType.CHARACTER); } - addCharacterSpecificSimpleTemplatesystem(gamesystem: Gamesystem) { + addCharacterSpecificSimpleTemplatesystem(gamesystem: Gamesystem, recursiveCall: boolean = false) { if(!this.isTemplateSystemCharacterSpecific(gamesystem.componentName)) { if(gamesystem instanceof SimpleTemplateGamesystem) { this.characterSpecificTemplateSystems.push(gamesystem) @@ -23,10 +23,15 @@ export class Character extends ModelComponent implements TemplateElement { } else if(gamesystem instanceof ProductTemplateSystem) { this.characterSpecificTemplateSystems.push(gamesystem) gamesystem.addTemplateElement(this) + + if(!recursiveCall) { + gamesystem.innerGamesystems.forEach(innerGamesystem => this.addCharacterSpecificSimpleTemplatesystem(innerGamesystem, true)) + } + } if(gamesystem.parentGamesystem != undefined) { - this.addCharacterSpecificSimpleTemplatesystem(gamesystem.parentGamesystem) + this.addCharacterSpecificSimpleTemplatesystem(gamesystem.parentGamesystem, true) } } } From 6496bd52c5222fad3676c8a05c87e9c61a15458d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sun, 14 Apr 2024 11:42:45 +0200 Subject: [PATCH 8/8] Persist and Load Characterspecified ProductTemplateSystems --- src/app/project/serializer/CharacterSerializer.ts | 2 +- testModel/characters/Astrid Hofferson.json | 8 +++++++- testModel/characters/Hicks Haddock.json | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/project/serializer/CharacterSerializer.ts b/src/app/project/serializer/CharacterSerializer.ts index 210052e..bc0d21e 100644 --- a/src/app/project/serializer/CharacterSerializer.ts +++ b/src/app/project/serializer/CharacterSerializer.ts @@ -51,7 +51,7 @@ export class CharacterSerializer { } }, SerializeConstants.JSON_INDENT) - + character.characterSpecificTemplateSystems = templateGamesystemBackup return new StoreComponent(jsonString, fileName, ModelComponentType.CHARACTER); } } diff --git a/testModel/characters/Astrid Hofferson.json b/testModel/characters/Astrid Hofferson.json index 9437d7c..468452a 100644 --- a/testModel/characters/Astrid Hofferson.json +++ b/testModel/characters/Astrid Hofferson.json @@ -1,5 +1,11 @@ { "componentName": "Astrid Hofferson", "componentDescription": "", - "characterSpecificTemplateSystems": [] + "characterSpecificTemplateSystems": [ + { + "componentName": "Letters", + "states": [], + "transitions": [] + } + ] } \ No newline at end of file diff --git a/testModel/characters/Hicks Haddock.json b/testModel/characters/Hicks Haddock.json index 0ff4204..571f2e5 100644 --- a/testModel/characters/Hicks Haddock.json +++ b/testModel/characters/Hicks Haddock.json @@ -34,6 +34,11 @@ "actionMap": [] } ] + }, + { + "componentName": "Letters", + "states": [], + "transitions": [] } ] } \ No newline at end of file