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