diff --git a/src/app/project/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts index 27d8af5..a96ad25 100644 --- a/src/app/project/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -15,6 +15,7 @@ import {ItemGroup} from "./inventory/ItemGroup"; import {AbstractItemGroup} from "./inventory/AbstractItemGroup"; import {ConcreteItemGroup} from "./inventory/ConcreteItemGroup"; import {Item} from "./inventory/Item"; +import {ItemgroupUtilities} from "./utils/ItemgroupUtilities"; export class GameModel { gameModelName: string @@ -65,10 +66,15 @@ export class GameModel { addItem(itemName: string, conceteItemgroupName: string) { const itemgroup = GameModel.findItemgroupByName(conceteItemgroupName, this.itemgroups); if(itemgroup instanceof ConcreteItemGroup) { - itemgroup.addItem(new Item(itemName, "", ModelComponentType.ITEM )) + const itemgroups: ItemGroup[] = ItemgroupUtilities.findItemgroupPathToItemgroup(conceteItemgroupName, this.itemgroups); + + if(itemgroups.length > 0) { + itemgroup.addItem(new Item(itemName, "", ModelComponentType.ITEM ), itemgroups) + } } } + public static findItemgroupByName(name: string, itemgroups: ItemGroup[]) { const itemgroupQueue: ItemGroup[] = itemgroups.concat(); while(itemgroupQueue.length > 0 ) { diff --git a/src/app/project/game-model/inventory/ConcreteItemGroup.ts b/src/app/project/game-model/inventory/ConcreteItemGroup.ts index 478721c..605108c 100644 --- a/src/app/project/game-model/inventory/ConcreteItemGroup.ts +++ b/src/app/project/game-model/inventory/ConcreteItemGroup.ts @@ -5,9 +5,11 @@ export class ConcreteItemGroup extends ItemGroup { items: Item[] = []; - addItem(item: Item) { + addItem(item: Item, parentItemgroups: ItemGroup[]) { if(this.findItemByName(item.componentName) == undefined) { - item.addInheritedGroup(this); + parentItemgroups.forEach(itemgroup => { + item.inheritedGroups.push(itemgroup); + }) this.items.push(item); } } diff --git a/src/app/project/game-model/utils/ItemgroupUtilities.ts b/src/app/project/game-model/utils/ItemgroupUtilities.ts new file mode 100644 index 0000000..cbd7745 --- /dev/null +++ b/src/app/project/game-model/utils/ItemgroupUtilities.ts @@ -0,0 +1,37 @@ +import {GameModel} from "../GameModel"; +import {ItemGroup} from "../inventory/ItemGroup"; +import {AbstractItemGroup} from "../inventory/AbstractItemGroup"; + +export class ItemgroupUtilities { + + public static findItemgroupPathToItemgroup(searchedItemgroupName: string, itemgroups: ItemGroup[]): ItemGroup[] { + for(let i=0; i 0) { + return found_path; + } + } + return []; + } + + private static findItemgroupPathToItemgroupRecursive(root: ItemGroup, searchedItemgroupName: string, path: ItemGroup[]): ItemGroup[] { + path.push(root); + + if(root.componentName === searchedItemgroupName) { + return path; + } + + if(root instanceof AbstractItemGroup) { + for(let i=0; i 0) { + return found_path; + } + } + return []; + } else { + return []; + } + } + +}