diff --git a/src/app/project/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts index 295b6bb..86a2003 100644 --- a/src/app/project/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -11,6 +11,11 @@ import {SimpleTemplateGamesystem} from "./templates/simpleGamesystem/SimpleTempl import {ProductTemplateSystem} from "./templates/productGamesystem/ProductTemplateSystem"; import {ProductTemplateCreator} from "./templates/productGamesystem/ProductTemplateCreator"; import {CharacterRelation} from "./characters/CharacterRelation"; +import {ItemGroup} from "./inventory/ItemGroup"; +import {AbstractItemGroup} from "./inventory/AbstractItemGroup"; +import {GameModelLoader} from "../../../../app/storage/loader/GameModelLoader"; +import {ConcreteItemGroup} from "./inventory/ConcreteItemGroup"; +import {Item} from "./inventory/Item"; export class GameModel { gameModelName: string @@ -18,9 +23,63 @@ export class GameModel { gamesystems: Gamesystem[] = []; scriptAccounts: ScriptAccount[] = []; characters: Character[] = [] + itemgroups: ItemGroup[] = [] constructor(gameModelName: string) { this.gameModelName = gameModelName; + + this.addAbstractItemgroup("Clothing", undefined); + this.addAbstractItemgroup("Inventory", undefined); + this.addConcreteItemgroup("Oberteil", GameModel.findItemgroupByName("Clothing", this.itemgroups)! as AbstractItemGroup); + this.addConcreteItemgroup("Hose", GameModel.findItemgroupByName("Clothing", this.itemgroups)! as AbstractItemGroup); + } + + addAbstractItemgroup(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 AbstractItemGroup(groupName, "", ModelComponentType.ITEMGROUP)); + } + } else { + if(GameModel.findItemgroupByName(groupName, parentgroup.children) == undefined) { + parentgroup.addChildItemgroup(new AbstractItemGroup(groupName, "", ModelComponentType.ITEMGROUP)); + } + } + } + + addConcreteItemgroup(groupName: string, parentgroup: AbstractItemGroup) { + //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) { + itemgroup.addItem(new Item(itemName, "", ModelComponentType.ITEM )) + } + } + + private static findItemgroupByName(name: string, itemgroups: ItemGroup[]) { + const itemgroupQueue: ItemGroup[] = itemgroups.concat(); + while(itemgroupQueue.length > 0 ) { + const currentItemgroup = itemgroupQueue.shift()!; + + if(currentItemgroup.componentName === name) { + return currentItemgroup; + } + + if(currentItemgroup instanceof AbstractItemGroup) { + currentItemgroup.children.forEach(itemgroup => itemgroupQueue.push(itemgroup)); + } + } } addGamesystem(gamesystem: Gamesystem) { diff --git a/src/app/project/game-model/ModelComponentType.ts b/src/app/project/game-model/ModelComponentType.ts index 14eaf8b..ffef110 100644 --- a/src/app/project/game-model/ModelComponentType.ts +++ b/src/app/project/game-model/ModelComponentType.ts @@ -1,6 +1,8 @@ export enum ModelComponentType { SCRIPTACCOUNT, GAMESYTEM, - CHARACTER + CHARACTER, + ITEMGROUP, + ITEM } diff --git a/src/app/project/game-model/inventory/AbstractItemGroup.ts b/src/app/project/game-model/inventory/AbstractItemGroup.ts new file mode 100644 index 0000000..9cb8a32 --- /dev/null +++ b/src/app/project/game-model/inventory/AbstractItemGroup.ts @@ -0,0 +1,10 @@ +import {ItemGroup} from "./ItemGroup"; + +export class AbstractItemGroup extends ItemGroup { + + children: ItemGroup[] = []; + + addChildItemgroup(itemGroup: ItemGroup) { + this.children.push(itemGroup) + } +} diff --git a/src/app/project/game-model/inventory/ConcreteItemGroup.ts b/src/app/project/game-model/inventory/ConcreteItemGroup.ts new file mode 100644 index 0000000..3dad098 --- /dev/null +++ b/src/app/project/game-model/inventory/ConcreteItemGroup.ts @@ -0,0 +1,17 @@ +import {ItemGroup} from "./ItemGroup"; +import {Item} from "./Item"; + +export class ConcreteItemGroup extends ItemGroup { + + items: Item[] = []; + + addItem(item: Item) { + if(this.findItemByName(item.componentName) == undefined) { + this.items.push(item); + } + } + + findItemByName(itemName: string) { + return this.items.find(item => item.componentName === itemName); + } +} diff --git a/src/app/project/game-model/inventory/Item.ts b/src/app/project/game-model/inventory/Item.ts new file mode 100644 index 0000000..179aa18 --- /dev/null +++ b/src/app/project/game-model/inventory/Item.ts @@ -0,0 +1,7 @@ +import {ModelComponent} from "../ModelComponent"; +import {ItemGroup} from "./ItemGroup"; + +export class Item extends ModelComponent { + + inheritedGroups: ItemGroup[] = [] +} diff --git a/src/app/project/game-model/inventory/ItemGroup.ts b/src/app/project/game-model/inventory/ItemGroup.ts new file mode 100644 index 0000000..ab21f62 --- /dev/null +++ b/src/app/project/game-model/inventory/ItemGroup.ts @@ -0,0 +1,7 @@ +import {ModelComponent} from "../ModelComponent"; +import {ItemQuality} from "./ItemQuality"; + +export abstract class ItemGroup extends ModelComponent { + + requiredItemQualities: ItemQuality[] = [] +} diff --git a/src/app/project/game-model/inventory/ItemQuality.ts b/src/app/project/game-model/inventory/ItemQuality.ts new file mode 100644 index 0000000..fa6abe1 --- /dev/null +++ b/src/app/project/game-model/inventory/ItemQuality.ts @@ -0,0 +1,10 @@ +export class ItemQuality { + + key: string + value: number + + constructor(key: string, value: number) { + this.key = key; + this.value = value; + } +}