From c413c457412b7804cf50b5f59ff22a9f69c0341f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 9 May 2024 18:25:27 +0200 Subject: [PATCH 1/9] Create New Itemgroups --- app/main.ts | 4 +- src/app/app.component.ts | 56 +++++++++++++++++-- .../utils/creator/ItemgroupCreator.ts | 36 ++++++++++++ .../utils/creator/ModelComponentCreator.ts | 18 ++++++ src/app/side-overviews/Overview.ts | 3 + .../item-overview/item-overview.component.ts | 32 ++++++++++- 6 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 src/app/project/game-model/utils/creator/ItemgroupCreator.ts create mode 100644 src/app/project/game-model/utils/creator/ModelComponentCreator.ts create mode 100644 src/app/side-overviews/Overview.ts diff --git a/app/main.ts b/app/main.ts index 30431c1..e1bbffd 100644 --- a/app/main.ts +++ b/app/main.ts @@ -104,13 +104,13 @@ function createWindow(): BrowserWindow { { label: "Abstract Itemgroup", click: () => { - win!.webContents.send('context-menu', "new-itemgroup_abstract") + win!.webContents.send('context-menu', "new-itemgroup-abstract") } }, { label: "Concrete Itemgroup", click: () => { - win!.webContents.send('context-menu', "new-itemgroup_concrete") + win!.webContents.send('context-menu', "new-itemgroup-concrete") } }, { diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 6a0240f..f82569a 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -25,11 +25,13 @@ import {CharacterOverviewComponent} from "./side-overviews/character-overview/ch import {CharacterSerializer} from "./project/serializer/CharacterSerializer"; import {CharacterParser} from "./project/parser/characterParser/CharacterParser"; import {TemplateType} from "./project/game-model/templates/TemplateType"; -import {TemplateTypeUtilities} from "./project/game-model/templates/TemplateTypeUtilities"; import {SimpleTemplateGamesystem} from "./project/game-model/templates/simpleGamesystem/SimpleTemplateGamesystem"; import {ItemSerializer} from "./project/serializer/ItemSerializer"; import {ItemgroupParser} from "./project/parser/itemParser/ItemgroupParser"; import {ItemParser} from "./project/parser/itemParser/ItemParser"; +import {ItemgroupCreator} from "./project/game-model/utils/creator/ItemgroupCreator"; +import {ItemOverviewComponent} from "./side-overviews/item-overview/item-overview.component"; +import {Overview} from "./side-overviews/Overview"; @Component({ selector: 'app-root', @@ -44,6 +46,7 @@ export class AppComponent implements OnInit{ @ViewChild('scriptAccountOverview') scriptAccountOverview: ScriptAccountOverviewComponent | undefined @ViewChild('gamesystemOverview') gamesystemOverview: GamescriptOverviewComponent | undefined @ViewChild('characterOverview') characterOverview: CharacterOverviewComponent | undefined + @ViewChild('itemOverview') itemOverview: ItemOverviewComponent | undefined gameModel: GameModel | undefined @@ -82,12 +85,34 @@ export class AppComponent implements OnInit{ } else if(message.startsWith("new")) { const splittedMessage = message.split("-"); const modelComponentType = ModelComponentTypeUtillities.fromString(splittedMessage[1]); - const templateType = TemplateTypeUtilities.fromString(splittedMessage[2]); - if(modelComponentType != undefined) { - this.onCreateModelComponent(modelComponentType, templateType); - } else { - console.log("[ERROR] [App-Component] Unknown Context-Menu Command!") + if(modelComponentType) { + let creationContext = ""; + if(splittedMessage.length > 2) { + creationContext = splittedMessage[2]; + } + + let componentCreator; + switch (modelComponentType) { + case ModelComponentType.ITEMGROUP: { + componentCreator = new ItemgroupCreator(creationContext, this.gameModel!, this.selectedModelComponent); + + } + } + + if(componentCreator) { + const createdModel = componentCreator.createModelComponent(); + this.openModelComponent(createdModel!) + + const openedOverview = this.openedOverview; + if(openedOverview) { + openedOverview.refresh() + } + + } else { + console.log("[ERROR] Unknown Creation Command: ", message) + } } + } } @@ -303,6 +328,25 @@ export class AppComponent implements OnInit{ } } + get selectedModelComponent(): ModelComponent | undefined { + switch (this.openContent) { + case ModelComponentType.GAMESYTEM: return this.gamesystemOverview!.getSelectedGamesystem(); + case ModelComponentType.CHARACTER: return this.characterOverview!.selectedCharacter; + case ModelComponentType.SCRIPTACCOUNT: return this.scriptAccountOverview!.selectedScriptAccount; + case ModelComponentType.ITEMGROUP: return this.itemOverview!.selectedModelComponent; + case ModelComponentType.ITEM: return this.itemOverview!.selectedModelComponent; + default: return undefined + } + } + + get openedOverview(): Overview | undefined { + if(this.openContent === ModelComponentType.ITEMGROUP || this.openContent === ModelComponentType.ITEM) { + return this.itemOverview; + } else { + return undefined; + } + } + protected readonly open = open; } diff --git a/src/app/project/game-model/utils/creator/ItemgroupCreator.ts b/src/app/project/game-model/utils/creator/ItemgroupCreator.ts new file mode 100644 index 0000000..924ee6a --- /dev/null +++ b/src/app/project/game-model/utils/creator/ItemgroupCreator.ts @@ -0,0 +1,36 @@ +import {ModelComponentCreator} from "./ModelComponentCreator"; +import {ModelComponent} from "../../ModelComponent"; +import {GameModel} from "../../GameModel"; +import {AbstractItemGroup} from "../../inventory/AbstractItemGroup"; +import {ModelComponentType} from "../../ModelComponentType"; +import {ConcreteItemGroup} from "../../inventory/ConcreteItemGroup"; + +export class ItemgroupCreator extends ModelComponentCreator { + + + + constructor(context: string, gameModel: GameModel, selectedComponent: ModelComponent | undefined) { + super(context, gameModel, selectedComponent); + } + + createModelComponent(): ModelComponent | undefined{ + let itemgroup; + if(this.context === 'abstract') { + itemgroup = new AbstractItemGroup("New Abstract Itemgroup", "", ModelComponentType.ITEMGROUP); + } else if(this.context === 'concrete') { + itemgroup = new ConcreteItemGroup("New Concrete Itemgroup", "", ModelComponentType.ITEMGROUP); + } else { + return undefined + } + + if(this.selectedComponent != null && this.selectedComponent instanceof AbstractItemGroup) { + this.selectedComponent.addChildItemgroup(itemgroup); + } else { + this.gameModel.itemgroups.push(itemgroup); + } + + return itemgroup; + } + + +} diff --git a/src/app/project/game-model/utils/creator/ModelComponentCreator.ts b/src/app/project/game-model/utils/creator/ModelComponentCreator.ts new file mode 100644 index 0000000..68a90e2 --- /dev/null +++ b/src/app/project/game-model/utils/creator/ModelComponentCreator.ts @@ -0,0 +1,18 @@ +import {ModelComponent} from "../../ModelComponent"; +import {GameModel} from "../../GameModel"; +import {Overview} from "../../../../side-overviews/Overview"; + +export abstract class ModelComponentCreator { + context: string; + gameModel: GameModel + selectedComponent: ModelComponent | undefined + + + protected constructor(context: string, gameModel: GameModel, selectedComponent: ModelComponent | undefined) { + this.context = context; + this.gameModel = gameModel; + this.selectedComponent = selectedComponent; + } + + abstract createModelComponent(): ModelComponent | undefined; +} diff --git a/src/app/side-overviews/Overview.ts b/src/app/side-overviews/Overview.ts new file mode 100644 index 0000000..88dd18f --- /dev/null +++ b/src/app/side-overviews/Overview.ts @@ -0,0 +1,3 @@ +export interface Overview { + refresh(): void +} diff --git a/src/app/side-overviews/item-overview/item-overview.component.ts b/src/app/side-overviews/item-overview/item-overview.component.ts index 3ae9aa0..a41020e 100644 --- a/src/app/side-overviews/item-overview/item-overview.component.ts +++ b/src/app/side-overviews/item-overview/item-overview.component.ts @@ -8,6 +8,7 @@ import {ModelComponent} from "../../project/game-model/ModelComponent"; import {ModelComponentType} from "../../project/game-model/ModelComponentType"; import {ItemGroup} from "../../project/game-model/inventory/ItemGroup"; import {Item} from "../../project/game-model/inventory/Item"; +import {Overview} from "../Overview"; interface FlatNode { expandable: boolean, @@ -21,7 +22,7 @@ interface FlatNode { templateUrl: './item-overview.component.html', styleUrl: './item-overview.component.scss' }) -export class ItemOverviewComponent implements OnInit{ +export class ItemOverviewComponent implements OnInit, Overview{ @Input() gameModel: GameModel | undefined @Output() openItemgroupEmitter: EventEmitter = new EventEmitter(); @@ -120,4 +121,33 @@ export class ItemOverviewComponent implements OnInit{ } return undefined; } + + get selectedModelComponent() { + if(this.selectedItem) { + if(this.selectedItem.type === ModelComponentType.ITEMGROUP) { + let groupQueue: ItemGroup[] = this.gameModel!.itemgroups.concat(); + while(groupQueue.length > 0) { + const currentGroup = groupQueue.shift()!; + + if(currentGroup.componentName === this.selectedItem.name) { + return currentGroup; + } + + if(currentGroup instanceof AbstractItemGroup) { + groupQueue = groupQueue.concat(currentGroup.children); + } + } + } else { + return this.searchItemByName(this.selectedItem!.name) + } + } else { + return undefined + } + } + + refresh(): void { + this.dataSource.data = this.gameModel!.itemgroups; + console.log("Opened Refreshed") + } + } -- 2.34.1 From 70904dae5ce10ce3cbab6e7bdc2b911035aea3a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 9 May 2024 18:35:12 +0200 Subject: [PATCH 2/9] Create New Items --- src/app/app.component.ts | 8 +++- src/app/project/game-model/GameModel.ts | 41 ------------------- .../game-model/utils/creator/ItemCreator.ts | 38 +++++++++++++++++ testModel/items/Inventory/Inventory.json | 2 +- 4 files changed, 45 insertions(+), 44 deletions(-) create mode 100644 src/app/project/game-model/utils/creator/ItemCreator.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index f82569a..f0b16be 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -32,6 +32,7 @@ import {ItemParser} from "./project/parser/itemParser/ItemParser"; import {ItemgroupCreator} from "./project/game-model/utils/creator/ItemgroupCreator"; import {ItemOverviewComponent} from "./side-overviews/item-overview/item-overview.component"; import {Overview} from "./side-overviews/Overview"; +import {ItemCreator} from "./project/game-model/utils/creator/ItemCreator"; @Component({ selector: 'app-root', @@ -95,12 +96,15 @@ export class AppComponent implements OnInit{ switch (modelComponentType) { case ModelComponentType.ITEMGROUP: { componentCreator = new ItemgroupCreator(creationContext, this.gameModel!, this.selectedModelComponent); - - } + } break + case ModelComponentType.ITEM: { + componentCreator = new ItemCreator(creationContext, this.gameModel!, this.selectedModelComponent); + } break } if(componentCreator) { const createdModel = componentCreator.createModelComponent(); + console.log(createdModel) this.openModelComponent(createdModel!) const openedOverview = this.openedOverview; diff --git a/src/app/project/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts index dde1cc3..22dc409 100644 --- a/src/app/project/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -30,47 +30,6 @@ export class GameModel { this.gameModelName = gameModelName; } - addAbstractItemgroup(groupName: string, parentgroup: AbstractItemGroup | undefined) { - //Ensure that Itemgroup does not exist - if(parentgroup == undefined) { - if(GameModel.findItemgroupByName(groupName, this.itemgroups) == undefined) { - const itemgroup = new AbstractItemGroup(groupName, "", ModelComponentType.ITEMGROUP) - this.itemgroups.push(itemgroup); - itemgroup.addItemgroupCharacteristic(new ItemGroupCharacteristic("Test0", "", itemgroup)); - } - } else { - if(GameModel.findItemgroupByName(groupName, parentgroup.children) == undefined) { - parentgroup.addChildItemgroup(new AbstractItemGroup(groupName, "", ModelComponentType.ITEMGROUP)); - } - } - } - - addConcreteItemgroup(groupName: string, parentgroup: AbstractItemGroup | undefined) { - //Ensure that Itemgroup does not exist - if(parentgroup == undefined) { - if(GameModel.findItemgroupByName(groupName, this.itemgroups) == undefined) { - this.itemgroups.push(new ConcreteItemGroup(groupName, "", ModelComponentType.ITEMGROUP)); - } - } else { - if(GameModel.findItemgroupByName(groupName, parentgroup.children) == undefined) { - parentgroup.addChildItemgroup(new ConcreteItemGroup(groupName, "", ModelComponentType.ITEMGROUP)); - } - } - } - - addItem(itemName: string, conceteItemgroupName: string) { - const itemgroup = GameModel.findItemgroupByName(conceteItemgroupName, this.itemgroups); - if(itemgroup instanceof ConcreteItemGroup) { - const itemgroups: ItemGroup[] = ItemgroupUtilities.findItemgroupPathToItemgroup(conceteItemgroupName, this.itemgroups); - - if(itemgroups.length > 0) { - const item = new Item(itemName, "", ModelComponentType.ITEM ) - itemgroup.addItem(item, itemgroups) - return item; - } - } - } - public static findItemgroupByName(name: string, itemgroups: ItemGroup[]) { const itemgroupQueue: ItemGroup[] = itemgroups.concat(); diff --git a/src/app/project/game-model/utils/creator/ItemCreator.ts b/src/app/project/game-model/utils/creator/ItemCreator.ts new file mode 100644 index 0000000..820d6de --- /dev/null +++ b/src/app/project/game-model/utils/creator/ItemCreator.ts @@ -0,0 +1,38 @@ +import {ModelComponentCreator} from "./ModelComponentCreator"; +import {GameModel} from "../../GameModel"; +import {ModelComponent} from "../../ModelComponent"; +import {Item} from "../../inventory/Item"; +import {ModelComponentType} from "../../ModelComponentType"; +import {ConcreteItemGroup} from "../../inventory/ConcreteItemGroup"; +import {ItemGroup} from "../../inventory/ItemGroup"; + +export class ItemCreator extends ModelComponentCreator { + + + constructor(context: string, gameModel: GameModel, selectedComponent: ModelComponent | undefined) { + super(context, gameModel, selectedComponent); + } + + createModelComponent(): ModelComponent | undefined { + if(this.selectedComponent != undefined && this.selectedComponent instanceof ConcreteItemGroup) { + const item = new Item("New Item", "", ModelComponentType.ITEM); + this.selectedComponent.addItem(item, this.getInheritedGroups(this.selectedComponent)) + return item; + } else { + console.log(this.selectedComponent) + return undefined + } + } + + private getInheritedGroups(baseGroup: ItemGroup): ItemGroup[] { + const itemgroups: ItemGroup[] = [] + let currentGroup: ItemGroup | undefined = baseGroup; + while(currentGroup != undefined) { + itemgroups.push(currentGroup); + currentGroup = currentGroup.parentGroup; + } + return itemgroups; + } + + +} diff --git a/testModel/items/Inventory/Inventory.json b/testModel/items/Inventory/Inventory.json index 27b2fe9..76568dd 100644 --- a/testModel/items/Inventory/Inventory.json +++ b/testModel/items/Inventory/Inventory.json @@ -7,5 +7,5 @@ "characteristicDescription": "" } ], - "itemgroupType": 1 + "itemgroupType": 0 } \ No newline at end of file -- 2.34.1 From 95a174cd4f82544fbbf0a8c9e72540110cdd7617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 9 May 2024 18:36:58 +0200 Subject: [PATCH 3/9] Remove logging statements --- src/app/app.component.ts | 1 - src/app/project/game-model/utils/creator/ItemCreator.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index f0b16be..04dc3d2 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -104,7 +104,6 @@ export class AppComponent implements OnInit{ if(componentCreator) { const createdModel = componentCreator.createModelComponent(); - console.log(createdModel) this.openModelComponent(createdModel!) const openedOverview = this.openedOverview; diff --git a/src/app/project/game-model/utils/creator/ItemCreator.ts b/src/app/project/game-model/utils/creator/ItemCreator.ts index 820d6de..bc58902 100644 --- a/src/app/project/game-model/utils/creator/ItemCreator.ts +++ b/src/app/project/game-model/utils/creator/ItemCreator.ts @@ -19,7 +19,6 @@ export class ItemCreator extends ModelComponentCreator { this.selectedComponent.addItem(item, this.getInheritedGroups(this.selectedComponent)) return item; } else { - console.log(this.selectedComponent) return undefined } } -- 2.34.1 From 92608125fb609b0da87c74f4aedb88568849e49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 9 May 2024 18:47:36 +0200 Subject: [PATCH 4/9] Refactor Creating New ScriptAccounts --- src/app/app.component.ts | 26 ++++--------------- src/app/project/game-model/GameModel.ts | 18 ++++--------- .../utils/creator/ScriptAccountCreator.ts | 22 ++++++++++++++++ 3 files changed, 32 insertions(+), 34 deletions(-) create mode 100644 src/app/project/game-model/utils/creator/ScriptAccountCreator.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 04dc3d2..650b6a5 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -33,6 +33,7 @@ import {ItemgroupCreator} from "./project/game-model/utils/creator/ItemgroupCrea import {ItemOverviewComponent} from "./side-overviews/item-overview/item-overview.component"; import {Overview} from "./side-overviews/Overview"; import {ItemCreator} from "./project/game-model/utils/creator/ItemCreator"; +import {ScriptAccountCreator} from "./project/game-model/utils/creator/ScriptAccountCreator"; @Component({ selector: 'app-root', @@ -86,7 +87,7 @@ export class AppComponent implements OnInit{ } else if(message.startsWith("new")) { const splittedMessage = message.split("-"); const modelComponentType = ModelComponentTypeUtillities.fromString(splittedMessage[1]); - if(modelComponentType) { + if(modelComponentType !== undefined) { let creationContext = ""; if(splittedMessage.length > 2) { creationContext = splittedMessage[2]; @@ -100,6 +101,9 @@ export class AppComponent implements OnInit{ case ModelComponentType.ITEM: { componentCreator = new ItemCreator(creationContext, this.gameModel!, this.selectedModelComponent); } break + case ModelComponentType.SCRIPTACCOUNT: { + componentCreator = new ScriptAccountCreator(creationContext, this.gameModel!, this.selectedModelComponent); + } break } if(componentCreator) { @@ -162,23 +166,6 @@ export class AppComponent implements OnInit{ }) } - private onCreateModelComponent(modelComponentType: ModelComponentType, templateType: TemplateType | undefined) { - switch (modelComponentType) { - case ModelComponentType.SCRIPTACCOUNT: this.onCreateNewScriptAccount(); break - case ModelComponentType.GAMESYTEM: this.onCreateNewGamesystem(templateType); break - case ModelComponentType.CHARACTER: this.onCreateNewCharacter(); break - } - } - - private onCreateNewScriptAccount() { - const createdScriptAccount = this.gameModel!.createScriptAccount("New ScriptAccount"); - if(createdScriptAccount != undefined) { - this.editor?.openGameModelComponent(createdScriptAccount); - } else { - console.log("[DEBUG] [App-Component] ScriptAccount could not be created (Name not unique)"); - } - } - private onCreateNewGamesystem(templateType: TemplateType | undefined) { let parentGamesystemName = undefined if(this.openContent != ModelComponentType.GAMESYTEM) { @@ -349,7 +336,4 @@ export class AppComponent implements OnInit{ return undefined; } } - - - protected readonly open = open; } diff --git a/src/app/project/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts index 22dc409..b10ffd6 100644 --- a/src/app/project/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -61,16 +61,12 @@ export class GameModel { } } - 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; - } + addScriptAccount(scriptAccount: ScriptAccount) { + if(!this.scriptAccounts.find(sA => sA.componentName === scriptAccount.componentName)) { + this.scriptAccounts.push(scriptAccount) + return true; } - return undefined; + return false; } createSimpleGamesystem(gamesystemName: string, templateType: TemplateType | undefined, pushToTop: boolean = true) { @@ -194,10 +190,6 @@ export class GameModel { } } - addScriptAccount(scriptAccount: ScriptAccount) { - this.scriptAccounts.push(scriptAccount); - } - generateProductSystemContents() { this.gamesystems.forEach(gamesystem => { if(gamesystem instanceof ProductGamesystem) { diff --git a/src/app/project/game-model/utils/creator/ScriptAccountCreator.ts b/src/app/project/game-model/utils/creator/ScriptAccountCreator.ts new file mode 100644 index 0000000..cee9fc4 --- /dev/null +++ b/src/app/project/game-model/utils/creator/ScriptAccountCreator.ts @@ -0,0 +1,22 @@ +import {ModelComponentCreator} from "./ModelComponentCreator"; +import {GameModel} from "../../GameModel"; +import {ModelComponent} from "../../ModelComponent"; +import {ScriptAccount} from "../../scriptAccounts/ScriptAccount"; + +export class ScriptAccountCreator extends ModelComponentCreator { + + constructor(context: string, gameModel: GameModel, selectedComponent: ModelComponent | undefined) { + super(context, gameModel, selectedComponent); + } + + createModelComponent(): ModelComponent | undefined { + const scriptAccount = new ScriptAccount("New ScriptAccount", ""); + if(this.gameModel.addScriptAccount(scriptAccount)) { + return scriptAccount; + } else { + return undefined; + } + } + + +} -- 2.34.1 From 7a650524f350d23021adabdc7df4916daa393e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 9 May 2024 18:52:27 +0200 Subject: [PATCH 5/9] Refactor Creating New Characters --- src/app/app.component.ts | 13 ++++------- src/app/project/game-model/GameModel.ts | 8 +++++++ .../utils/creator/CharacterCreator.ts | 22 +++++++++++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 src/app/project/game-model/utils/creator/CharacterCreator.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 650b6a5..790132e 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -34,6 +34,7 @@ import {ItemOverviewComponent} from "./side-overviews/item-overview/item-overvie import {Overview} from "./side-overviews/Overview"; import {ItemCreator} from "./project/game-model/utils/creator/ItemCreator"; import {ScriptAccountCreator} from "./project/game-model/utils/creator/ScriptAccountCreator"; +import {CharacterCreator} from "./project/game-model/utils/creator/CharacterCreator"; @Component({ selector: 'app-root', @@ -104,6 +105,9 @@ export class AppComponent implements OnInit{ case ModelComponentType.SCRIPTACCOUNT: { componentCreator = new ScriptAccountCreator(creationContext, this.gameModel!, this.selectedModelComponent); } break + case ModelComponentType.CHARACTER: { + componentCreator = new CharacterCreator(creationContext, this.gameModel!, this.selectedModelComponent); + } break } if(componentCreator) { @@ -188,15 +192,6 @@ export class AppComponent implements OnInit{ } } - private onCreateNewCharacter() { - const createdCharacter = this.gameModel!.createCharacter("New Character") - if(createdCharacter != undefined) { - this.editor?.openGameModelComponent(createdCharacter); - } else { - console.log("[DEBUG] [App-Component] ScriptAccount could not be created (Name not unique)"); - } - } - private getSelectedModelComponent(): ModelComponent | undefined { if(this.openContent == ModelComponentType.SCRIPTACCOUNT) { if(this.scriptAccountOverview != undefined) { diff --git a/src/app/project/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts index b10ffd6..2a34fc9 100644 --- a/src/app/project/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -232,4 +232,12 @@ export class GameModel { return result; } + + addCharacter(character: Character) { + if(this.characters.find(c => c.componentName === character.componentName) === undefined) { + this.characters.push(character) + return true; + } + return false; + } } diff --git a/src/app/project/game-model/utils/creator/CharacterCreator.ts b/src/app/project/game-model/utils/creator/CharacterCreator.ts new file mode 100644 index 0000000..03d19a6 --- /dev/null +++ b/src/app/project/game-model/utils/creator/CharacterCreator.ts @@ -0,0 +1,22 @@ +import {ModelComponentCreator} from "./ModelComponentCreator"; +import {GameModel} from "../../GameModel"; +import {ModelComponent} from "../../ModelComponent"; +import {Character} from "../../characters/Character"; + +export class CharacterCreator extends ModelComponentCreator{ + + + constructor(context: string, gameModel: GameModel, selectedComponent: ModelComponent | undefined) { + super(context, gameModel, selectedComponent); + } + + createModelComponent(): ModelComponent | undefined { + const character = new Character("New Character", ""); + if(this.gameModel.addCharacter(character)) { + return character; + } + return undefined; + } + + +} -- 2.34.1 From ae434f9005e5b0af33af6c6cfde795f02eaf9155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 9 May 2024 18:55:51 +0200 Subject: [PATCH 6/9] Remove unnessecary ScriptAccountTest.spec.ts --- .../scriptAccounts/ScriptAccountTest.spec.ts | 71 ------------------- 1 file changed, 71 deletions(-) delete mode 100644 e2e/game-model/scriptAccounts/ScriptAccountTest.spec.ts diff --git a/e2e/game-model/scriptAccounts/ScriptAccountTest.spec.ts b/e2e/game-model/scriptAccounts/ScriptAccountTest.spec.ts deleted file mode 100644 index 27aaed2..0000000 --- a/e2e/game-model/scriptAccounts/ScriptAccountTest.spec.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright'; -import { test, expect } from '@playwright/test'; -import * as PATH from 'path'; -import {GameModel} from "../../../src/app/project/game-model/GameModel"; -import {Gamesystem} from "../../src/app/project/game-model/gamesystems/Gamesystem"; -import {ScriptAccount} from "../../../src/app/project/game-model/scriptAccounts/ScriptAccount"; -import {ModelComponentType} from "../../../src/app/project/game-model/ModelComponentType"; - -test.describe('Test ScriptAccounts', () => { - - test("Test ScriptAccount Creation", async () => { - const scriptAccunt = new ScriptAccount("ScriptAccount", "Description"); - - expect(scriptAccunt.componentName).toEqual("ScriptAccount"); - expect(scriptAccunt.componentDescription).toEqual("Description"); - expect(scriptAccunt.type).toEqual(ModelComponentType.SCRIPTACCOUNT); - expect(scriptAccunt.minValue).toEqual(0); - expect(scriptAccunt.maxValue).toEqual(100); - }) - - test("Test Adding ScriptAccounts", async () => { - const gameModel: GameModel = new GameModel("GameModel"); - - let scriptAccount =gameModel.createScriptAccount("ScriptAccount"); - expect(scriptAccount).toBeDefined(); - expect(gameModel.scriptAccounts.length).toEqual(1); - expect(gameModel.scriptAccounts.includes(scriptAccount)).toBeTruthy(); - - //Test adding scriptAccount with already existing name - const scriptAccount2 = gameModel.createScriptAccount("ScriptAccount") - expect(scriptAccount2).toBeUndefined(); - expect(gameModel.scriptAccounts.length).toEqual(1); - - //Test for adding invalid names as scriptaccount names (null/undefined/empty) - let result = gameModel.createScriptAccount(null); - expect(result).toBeUndefined(); - expect(gameModel.scriptAccounts.length).toEqual(1); - result = gameModel.createScriptAccount(undefined); - expect(result).toBeUndefined(); - expect(gameModel.scriptAccounts.length).toEqual(1); - result = gameModel.createScriptAccount(""); - expect(result).toBeUndefined(); - expect(gameModel.scriptAccounts.length).toEqual(1); - }) - - test("test Removing ScriptAccounts", async () => { - const gameModel: GameModel = new GameModel("GameModel"); - let scriptAccount = new ScriptAccount("test", "") - - gameModel.removeScriptAccount(scriptAccount); - expect(gameModel.scriptAccounts.length).toEqual(0); - - scriptAccount = gameModel.createScriptAccount("ScriptAccount"); - gameModel.removeScriptAccount(scriptAccount); - expect(gameModel.scriptAccounts.length).toEqual(0); - - gameModel.removeScriptAccount(undefined); - expect(gameModel.scriptAccounts.length).toEqual(0); - - gameModel.removeScriptAccount(null); - expect(gameModel.scriptAccounts.length).toEqual(0); - - scriptAccount = gameModel.createScriptAccount(scriptAccount); - let scriptAccount2 = gameModel.createScriptAccount("ScriptAccount 2"); - - gameModel.removeScriptAccount(scriptAccount); - expect(gameModel.scriptAccounts.length).toEqual(1); - expect(gameModel.scriptAccounts.includes(scriptAccount2)).toBeTruthy(); - }) - -}); -- 2.34.1 From ccb53df8154a7151e7695531e405f1d826da4ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 9 May 2024 19:17:43 +0200 Subject: [PATCH 7/9] Refactor Gamesystem Creation --- src/app/app.component.ts | 5 ++ .../game-model/gamesystems/Gamesystem.ts | 1 - .../utils/creator/GamesystemCreator.ts | 46 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/app/project/game-model/utils/creator/GamesystemCreator.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 790132e..2ff3758 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -35,6 +35,7 @@ import {Overview} from "./side-overviews/Overview"; import {ItemCreator} from "./project/game-model/utils/creator/ItemCreator"; import {ScriptAccountCreator} from "./project/game-model/utils/creator/ScriptAccountCreator"; import {CharacterCreator} from "./project/game-model/utils/creator/CharacterCreator"; +import {GamesystemCreator} from "./project/game-model/utils/creator/GamesystemCreator"; @Component({ selector: 'app-root', @@ -108,6 +109,9 @@ export class AppComponent implements OnInit{ case ModelComponentType.CHARACTER: { componentCreator = new CharacterCreator(creationContext, this.gameModel!, this.selectedModelComponent); } break + case ModelComponentType.GAMESYTEM: { + componentCreator = new GamesystemCreator(creationContext, this.gameModel!, this.selectedModelComponent); + } break } if(componentCreator) { @@ -146,6 +150,7 @@ export class AppComponent implements OnInit{ } }break + } } diff --git a/src/app/project/game-model/gamesystems/Gamesystem.ts b/src/app/project/game-model/gamesystems/Gamesystem.ts index 981590a..e50cf3f 100644 --- a/src/app/project/game-model/gamesystems/Gamesystem.ts +++ b/src/app/project/game-model/gamesystems/Gamesystem.ts @@ -27,5 +27,4 @@ export abstract class Gamesystem extends ModelComponent{ this.transitions = updatedTransitions; return true; } - } diff --git a/src/app/project/game-model/utils/creator/GamesystemCreator.ts b/src/app/project/game-model/utils/creator/GamesystemCreator.ts new file mode 100644 index 0000000..f7a250f --- /dev/null +++ b/src/app/project/game-model/utils/creator/GamesystemCreator.ts @@ -0,0 +1,46 @@ +import {ModelComponentCreator} from "./ModelComponentCreator"; +import {GameModel} from "../../GameModel"; +import {ModelComponent} from "../../ModelComponent"; +import {TemplateTypeUtilities} from "../../templates/TemplateTypeUtilities"; +import {Gamesystem} from "../../gamesystems/Gamesystem"; +import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem"; +import {ProductGamesystem} from "../../gamesystems/ProductGamesystem"; +import {SimpleTemplateGamesystem} from "../../templates/simpleGamesystem/SimpleTemplateGamesystem"; +import {ProductTemplateCreator} from "../../templates/productGamesystem/ProductTemplateCreator"; + +export class GamesystemCreator extends ModelComponentCreator{ + + + constructor(context: string, gameModel: GameModel, selectedComponent: ModelComponent | undefined) { + super(context, gameModel, selectedComponent); + } + + createModelComponent(): ModelComponent | undefined { + const templateType = TemplateTypeUtilities.fromString(this.context); + let simpleGamesystem; + if(templateType == undefined) /**Aka normal**/{ + simpleGamesystem = new SimpleGamesystem("New Simple Gamesystem", ""); + } else { + simpleGamesystem = new SimpleTemplateGamesystem("New Simple Gamesystem", "", templateType) + } + + if(this.selectedComponent !== undefined && this.selectedComponent instanceof Gamesystem)/**Aka productGamesystem**/ { + let productParentsystem: ProductGamesystem; + if(this.selectedComponent instanceof SimpleTemplateGamesystem) { + productParentsystem = ProductTemplateCreator.constructTemplateFromSimpleGamesystem(this.selectedComponent, this.gameModel!, this.selectedComponent.templateType); + } else if(this.selectedComponent instanceof SimpleGamesystem) { + productParentsystem = ProductGamesystem.constructFromSimpleGamesystem(this.selectedComponent, this.gameModel); + } else { + productParentsystem = this.selectedComponent as ProductGamesystem; + } + + productParentsystem.addChildGamesystem(simpleGamesystem); + } else { + this.gameModel!.gamesystems.push(simpleGamesystem); + } + + return simpleGamesystem; + } + + +} -- 2.34.1 From 7ea5b3dd78069873787ad2cbdc1eb9552a91c99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sat, 11 May 2024 08:28:08 +0200 Subject: [PATCH 8/9] Refactor Gamesystem Creation and fix Hierarchy Construction --- src/app/app.component.ts | 29 ++-------- .../gamesystems/ProductGamesystem.ts | 10 ++-- .../utils/creator/GamesystemCreator.ts | 58 ++++++++++++++++--- .../character-overview.component.ts | 6 +- .../gamescript-overview.component.ts | 3 +- .../script-account-overview.component.ts | 7 ++- testModel/gamesystems/Parentgamesystem.json | 7 +++ 7 files changed, 79 insertions(+), 41 deletions(-) create mode 100644 testModel/gamesystems/Parentgamesystem.json diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 2ff3758..4bfac7a 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -175,27 +175,6 @@ export class AppComponent implements OnInit{ }) } - private onCreateNewGamesystem(templateType: TemplateType | undefined) { - let parentGamesystemName = undefined - if(this.openContent != ModelComponentType.GAMESYTEM) { - this.openGamesystemsOverview(); - } else { - parentGamesystemName = this.gamesystemOverview!.selectedGamesystemName; - } - - - 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); - } - } private getSelectedModelComponent(): ModelComponent | undefined { if(this.openContent == ModelComponentType.SCRIPTACCOUNT) { @@ -332,8 +311,12 @@ export class AppComponent implements OnInit{ get openedOverview(): Overview | undefined { if(this.openContent === ModelComponentType.ITEMGROUP || this.openContent === ModelComponentType.ITEM) { return this.itemOverview; - } else { - return undefined; + } else if(this.openContent === ModelComponentType.SCRIPTACCOUNT) { + return this.scriptAccountOverview; + } else if(this.openContent === ModelComponentType.CHARACTER) { + return this.characterOverview; + } else if(this.openContent === ModelComponentType.GAMESYTEM) { + return this.gamesystemOverview; } } } diff --git a/src/app/project/game-model/gamesystems/ProductGamesystem.ts b/src/app/project/game-model/gamesystems/ProductGamesystem.ts index 2b77cdc..eb2dc3e 100644 --- a/src/app/project/game-model/gamesystems/ProductGamesystem.ts +++ b/src/app/project/game-model/gamesystems/ProductGamesystem.ts @@ -32,14 +32,12 @@ export class ProductGamesystem extends Gamesystem, producttemplateType: TemplateType | undefined): ProductGamesystem | undefined { + if(!(simpleGamesystem instanceof ProductTemplateSystem) && producttemplateType != undefined) { + console.log("Wierd, Debug") + return ProductTemplateCreator.convertProductToTemplate(simpleGamesystem as ProductGamesystem, this.gameModel, producttemplateType); + } + + if(simpleGamesystem instanceof ProductGamesystem) { + console.log("Wierder Debug") + return simpleGamesystem; + } + + let productGamesystem: ProductGamesystem + if(producttemplateType != undefined) { + productGamesystem = new ProductTemplateSystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription, producttemplateType); + } else { + productGamesystem = new ProductGamesystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription); + } + + this.constructGamesystemHierarchy(productGamesystem, simpleGamesystem as SimpleGamesystem) + return productGamesystem; + } + + private constructGamesystemHierarchy(productGamesystem: ProductGamesystem, simpleGamesystem: SimpleGamesystem) { + const simpleParentGamesystem = simpleGamesystem.parentGamesystem; + + if(simpleGamesystem.states.length > 0) { + simpleGamesystem.componentName += "(Child)"; + if(simpleParentGamesystem == undefined) { + this.gameModel.removeGamesystem(simpleGamesystem); + productGamesystem.addChildGamesystem(simpleGamesystem); + this.gameModel.addGamesystem(productGamesystem); + } else { + simpleParentGamesystem.removeChildGamesystem(simpleGamesystem); + productGamesystem.addChildGamesystem(simpleGamesystem); + simpleParentGamesystem.addChildGamesystem(productGamesystem); + } + } else { + if(simpleParentGamesystem == undefined) { + this.gameModel.removeGamesystem(simpleGamesystem); + this.gameModel.addGamesystem(productGamesystem); + } else { + simpleParentGamesystem.removeChildGamesystem(simpleGamesystem); + simpleParentGamesystem.addChildGamesystem(productGamesystem); + } + } + } } diff --git a/src/app/side-overviews/character-overview/character-overview.component.ts b/src/app/side-overviews/character-overview/character-overview.component.ts index c182485..50ad56a 100644 --- a/src/app/side-overviews/character-overview/character-overview.component.ts +++ b/src/app/side-overviews/character-overview/character-overview.component.ts @@ -5,13 +5,17 @@ import {MatIcon} from "@angular/material/icon"; import {NgClass, NgForOf} from "@angular/common"; import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccount"; import {Character} from "../../project/game-model/characters/Character"; +import {Overview} from "../Overview"; @Component({ selector: 'app-character-overview', templateUrl: './character-overview.component.html', styleUrl: './character-overview.component.scss' }) -export class CharacterOverviewComponent { +export class CharacterOverviewComponent implements Overview{ + refresh(): void { + //Nothing to-do + } @Input() gameModel: GameModel | undefined @Output("onOpenCharacterEditor") openCharacterEmitter: EventEmitter = new EventEmitter(); diff --git a/src/app/side-overviews/gamescript-overview/gamescript-overview.component.ts b/src/app/side-overviews/gamescript-overview/gamescript-overview.component.ts index 3194a5f..4c6fe9c 100644 --- a/src/app/side-overviews/gamescript-overview/gamescript-overview.component.ts +++ b/src/app/side-overviews/gamescript-overview/gamescript-overview.component.ts @@ -8,6 +8,7 @@ import {State} from "../../project/game-model/gamesystems/states/State"; import {Transition} from "../../project/game-model/gamesystems/transitions/Transition"; import {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem"; import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem"; +import {Overview} from "../Overview"; interface FlatNode { @@ -20,7 +21,7 @@ interface FlatNode { templateUrl: './gamescript-overview.component.html', styleUrl: './gamescript-overview.component.scss' }) -export class GamescriptOverviewComponent implements OnInit { +export class GamescriptOverviewComponent implements OnInit, Overview { @Input('gameModel') gameModel: GameModel | undefined @Output('openGamesystemEditor') openGamesystemEmitter : EventEmitter, Transition>> = new EventEmitter, Transition>>(); diff --git a/src/app/side-overviews/script-account-overview/script-account-overview.component.ts b/src/app/side-overviews/script-account-overview/script-account-overview.component.ts index 3643289..fce194e 100644 --- a/src/app/side-overviews/script-account-overview/script-account-overview.component.ts +++ b/src/app/side-overviews/script-account-overview/script-account-overview.component.ts @@ -2,13 +2,14 @@ import {Component, EventEmitter, Input, NgZone, Output} from '@angular/core'; import {ElectronService} from "../../core/services"; import {GameModel} from "../../project/game-model/GameModel"; import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccount"; +import {Overview} from "../Overview"; @Component({ selector: 'app-script-account-overview', templateUrl: './script-account-overview.component.html', styleUrl: './script-account-overview.component.css' }) -export class ScriptAccountOverviewComponent { +export class ScriptAccountOverviewComponent implements Overview{ @Input("gameModel") gameModel: GameModel | undefined @Output("onOpenScriptAccount") openScriptAccountEmitter: EventEmitter = new EventEmitter(); @@ -17,6 +18,10 @@ export class ScriptAccountOverviewComponent { constructor() { } + refresh(): void { + //Nothing to do + } + onOpenScriptAccount(scriptAccount: ScriptAccount) { console.log("onOpenScriptAccount (overview)") this.openScriptAccountEmitter.emit(scriptAccount); diff --git a/testModel/gamesystems/Parentgamesystem.json b/testModel/gamesystems/Parentgamesystem.json new file mode 100644 index 0000000..75902da --- /dev/null +++ b/testModel/gamesystems/Parentgamesystem.json @@ -0,0 +1,7 @@ +{ + "componentName": "Parentgamesystem", + "componentDescription": "", + "states": [], + "transitions": [], + "generateIsolatedStates": false +} \ No newline at end of file -- 2.34.1 From cbe5fe0ef0e6a53dc729e26ae59d91a3ec07a189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sat, 11 May 2024 08:32:42 +0200 Subject: [PATCH 9/9] Remove GamesystemCreationTest --- .../gamesystems/CreateGamesystem.spec.ts | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 e2e/game-model/gamesystems/CreateGamesystem.spec.ts diff --git a/e2e/game-model/gamesystems/CreateGamesystem.spec.ts b/e2e/game-model/gamesystems/CreateGamesystem.spec.ts deleted file mode 100644 index fffea92..0000000 --- a/e2e/game-model/gamesystems/CreateGamesystem.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { test, expect } from '@playwright/test'; -import {GamesystemTrainer} from "./GamesystemTrainer"; -import {ProductGamesystem} from "../../../src/app/project/game-model/gamesystems/ProductGamesystem"; -test.describe('Test Create Gamesystems', () => { - - test('Test creating gamesystem with invalid name', async => { - const gameModel = GamesystemTrainer.givenEmptyGameModel(); - let result = gameModel.createGamesystem(undefined, undefined); - expect(result).toBeUndefined(); - - result = gameModel.createGamesystem(null, undefined); - expect(result).toBeUndefined(); - }) - - test("Test creating gamesystem with valid name but without parent", async => { - const gameModel = GamesystemTrainer.givenEmptyGameModel(); - let result = gameModel.createGamesystem(GamesystemTrainer.SIMPLEGAMESYSTEMNAME, undefined); - expect(result).toBeDefined(); - expect(gameModel.gamesystems.length).toEqual(1); - expect(gameModel.findGamesystem(GamesystemTrainer.SIMPLEGAMESYSTEMNAME)).toBeDefined(); - }) - - test("Test creating Gamesystem with valid name but with Product Parent", async => { - const gameModel = GamesystemTrainer.givenGameModelWithProductGamesytemOnTopLayer(); - let result = gameModel.createGamesystem(GamesystemTrainer.SIMPLEGAMESYSTEM_LEAF_LEFT, GamesystemTrainer.TOP_PRODUCT_GAMESYSTEM_NAME); - expect(result).toBeDefined(); - expect(result.parentGamesystem!.componentName).toEqual(GamesystemTrainer.TOP_PRODUCT_GAMESYSTEM_NAME); - expect(result.parentGamesystem!.innerGamesystems.length).toEqual(3); - expect(result.parentGamesystem!.innerGamesystems.includes(result)).toBeTruthy(); - }) - - test("Test creating Gamesystem with valid name but with Simple Parent", async() => { - const gameModel = GamesystemTrainer.givenGameModelWithSimpleGamesystemOnTopLayer(); - let result = gameModel.createGamesystem(GamesystemTrainer.SIMPLEGAMESYSTEM_LEAF_LEFT, GamesystemTrainer.SIMPLEGAMESYSTEMNAME); - expect(result).toBeDefined(); - expect(gameModel.gamesystems.length).toEqual(1); - expect(gameModel.gamesystems[0]).toBeInstanceOf(ProductGamesystem); - expect(gameModel.gamesystems[0]).toEqual(result.parentGamesystem); - expect((gameModel.gamesystems[0] as ProductGamesystem).innerGamesystems.length).toEqual(1); - expect((gameModel.gamesystems[0] as ProductGamesystem).innerGamesystems.includes(result)).toBeTruthy(); - }) - - -}); -- 2.34.1