From db0bd14ea885940a0ba286c4c78b529596d066fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 9 May 2024 07:04:19 +0200 Subject: [PATCH] Initialize Itemgroup Characteristic Values --- .../item-editor/item-editor.component.html | 2 +- .../item-editor/item-editor.component.ts | 12 ++++-- .../item-group-editor.component.ts | 3 +- .../game-model/inventory/AbstractItemGroup.ts | 7 +++ .../game-model/inventory/ConcreteItemGroup.ts | 11 ++++- src/app/project/game-model/inventory/Item.ts | 43 ++++++++++++++----- .../project/game-model/inventory/ItemGroup.ts | 25 +++++++++++ 7 files changed, 86 insertions(+), 17 deletions(-) diff --git a/src/app/editor/items/item-editor/item-editor.component.html b/src/app/editor/items/item-editor/item-editor.component.html index c15b565..8ff7a5d 100644 --- a/src/app/editor/items/item-editor/item-editor.component.html +++ b/src/app/editor/items/item-editor/item-editor.component.html @@ -4,7 +4,7 @@ - + {{itemgroup.componentName}} {{itemgroup.componentDescription}} diff --git a/src/app/editor/items/item-editor/item-editor.component.ts b/src/app/editor/items/item-editor/item-editor.component.ts index d259cb1..05a673d 100644 --- a/src/app/editor/items/item-editor/item-editor.component.ts +++ b/src/app/editor/items/item-editor/item-editor.component.ts @@ -17,29 +17,33 @@ export class ItemEditorComponent { @Input() gameModel: GameModel | undefined; - constructor(private dialog: MatDialog) { } onAddNewInheritedItemgroup() { + const itemgroups = this.item!.manuallyInheritedGroups.concat(this.item!.hierarchyInheritedGroups); const dialogRef = this.dialog.open(ItemgroupInheritorComponent, { - data: this.gameModel!.itemgroupsAsList.filter(group => !this.item!.inheritedGroups.includes(group)), + data: this.gameModel!.itemgroupsAsList.filter(group => !itemgroups.includes(group)), width: "400px" }) dialogRef.afterClosed().subscribe(res => { if(res != undefined) { - this.item!.inheritedGroups.push(res); + this.item!.addInheritedGroup(res); } }) } deleteInheritedItemgroup(itemgroup: ItemGroup) { - this.item!.inheritedGroups = this.item!.inheritedGroups.filter(group => group.componentName !== itemgroup.componentName); + this.item!.deleteInheritedGroup(itemgroup); } get automaticallyInheritedItemgroups() { return ItemgroupUtilities.findItemgroupPathToItem(this.item!.componentName, this.gameModel!.itemgroups); } + + get manuallyAndHierarchyItemgroups() { + return this.item!.hierarchyInheritedGroups.concat(this.item!.manuallyInheritedGroups); + } } diff --git a/src/app/editor/items/item-group-editor/item-group-editor.component.ts b/src/app/editor/items/item-group-editor/item-group-editor.component.ts index c47c0aa..2436e71 100644 --- a/src/app/editor/items/item-group-editor/item-group-editor.component.ts +++ b/src/app/editor/items/item-group-editor/item-group-editor.component.ts @@ -38,7 +38,8 @@ export class ItemGroupEditorComponent implements OnInit{ addItemgroupCharacteristic() { const itemgroupCharacteristic = new ItemGroupCharacteristic("", "", this.itemgroup!); - this.itemgroup!.itemGroupCharacteristics.push(itemgroupCharacteristic); + this.itemgroup!.addItemgroupCharacteristic(itemgroupCharacteristic); + this.itemQualityDatasource.data = this.itemgroup!.itemGroupCharacteristics; this.editedCharacteristic = itemgroupCharacteristic; } diff --git a/src/app/project/game-model/inventory/AbstractItemGroup.ts b/src/app/project/game-model/inventory/AbstractItemGroup.ts index e1b058a..5141f5a 100644 --- a/src/app/project/game-model/inventory/AbstractItemGroup.ts +++ b/src/app/project/game-model/inventory/AbstractItemGroup.ts @@ -1,4 +1,5 @@ import {ItemGroup} from "./ItemGroup"; +import {ItemGroupCharacteristic} from "./ItemgroupCharacteristic"; export class AbstractItemGroup extends ItemGroup { @@ -8,4 +9,10 @@ export class AbstractItemGroup extends ItemGroup { this.children.push(itemGroup) itemGroup.parentGroup = this; } + + protected addCharacteristicValue(characteristic: ItemGroupCharacteristic): void { + //Do Nothing + } + + } diff --git a/src/app/project/game-model/inventory/ConcreteItemGroup.ts b/src/app/project/game-model/inventory/ConcreteItemGroup.ts index 605108c..21e6682 100644 --- a/src/app/project/game-model/inventory/ConcreteItemGroup.ts +++ b/src/app/project/game-model/inventory/ConcreteItemGroup.ts @@ -1,5 +1,6 @@ import {ItemGroup} from "./ItemGroup"; import {Item} from "./Item"; +import {ItemGroupCharacteristic} from "./ItemgroupCharacteristic"; export class ConcreteItemGroup extends ItemGroup { @@ -8,7 +9,7 @@ export class ConcreteItemGroup extends ItemGroup { addItem(item: Item, parentItemgroups: ItemGroup[]) { if(this.findItemByName(item.componentName) == undefined) { parentItemgroups.forEach(itemgroup => { - item.inheritedGroups.push(itemgroup); + item.addInheritedHierarchyGroup(itemgroup); }) this.items.push(item); } @@ -17,4 +18,12 @@ export class ConcreteItemGroup extends ItemGroup { findItemByName(itemName: string) { return this.items.find(item => item.componentName === itemName); } + + protected addCharacteristicValue(characteristic: ItemGroupCharacteristic): void { + this.items.forEach(item => { + item.addCharacteristic(characteristic); + }) + } + + } diff --git a/src/app/project/game-model/inventory/Item.ts b/src/app/project/game-model/inventory/Item.ts index 6241ca9..bbe2140 100644 --- a/src/app/project/game-model/inventory/Item.ts +++ b/src/app/project/game-model/inventory/Item.ts @@ -5,17 +5,21 @@ import {ItemGroupCharacteristic} from "./ItemgroupCharacteristic"; export class Item extends ModelComponent { - inheritedGroups: ItemGroup[] = [] + + manuallyInheritedGroups: ItemGroup[] = [] + hierarchyInheritedGroups: ItemGroup[] = [] itemCharacteristicValues: ItemgroupCharacteristicValue[] = [] initializeItemCharacteristics() { - this.inheritedGroups.forEach(itemGroup => { - itemGroup.itemGroupCharacteristics.forEach(characteristic => { - const characteristicValue = new ItemgroupCharacteristicValue(characteristic, 0); - if(!this.isValueInitialized(characteristic)) { - this.itemCharacteristicValues.push(characteristicValue); - } - }) + const inheritedGroups = this.manuallyInheritedGroups.concat(this.hierarchyInheritedGroups); + inheritedGroups.forEach(itemGroup => { + this.initializeItemCharacteristicsOfItemgroup(itemGroup); + }) + } + + initializeItemCharacteristicsOfItemgroup(itemGroup: ItemGroup) { + itemGroup.itemGroupCharacteristics.forEach(characteristic => { + this.addCharacteristic(characteristic); }) } @@ -25,11 +29,30 @@ export class Item extends ModelComponent { addInheritedGroup(itemgroup: ItemGroup) { if(this.findItemgroupByName(itemgroup.componentName) == undefined) { - this.inheritedGroups.push(itemgroup); + this.manuallyInheritedGroups.push(itemgroup); + this.initializeItemCharacteristicsOfItemgroup(itemgroup); } } findItemgroupByName(groupName: string) { - return this.inheritedGroups.find(group => group.componentName === groupName); + const itemgroups = this.hierarchyInheritedGroups.concat(this.manuallyInheritedGroups); + return itemgroups.find(group => group.componentName === groupName); + } + + addCharacteristic(characteristic: ItemGroupCharacteristic) { + const characteristicValue = new ItemgroupCharacteristicValue(characteristic, 0); + if(!this.isValueInitialized(characteristic)) { + this.itemCharacteristicValues.push(characteristicValue); + } + } + + deleteInheritedGroup(itemgroup: ItemGroup) { + this.manuallyInheritedGroups = this.manuallyInheritedGroups.filter(manually => manually.componentName !== itemgroup.componentName); + } + + addInheritedHierarchyGroup(itemgroup: ItemGroup) { + this.hierarchyInheritedGroups.push(itemgroup); + this.initializeItemCharacteristicsOfItemgroup(itemgroup); + } } diff --git a/src/app/project/game-model/inventory/ItemGroup.ts b/src/app/project/game-model/inventory/ItemGroup.ts index 9205238..3096e7b 100644 --- a/src/app/project/game-model/inventory/ItemGroup.ts +++ b/src/app/project/game-model/inventory/ItemGroup.ts @@ -1,10 +1,35 @@ import {ModelComponent} from "../ModelComponent"; import {ItemGroupCharacteristic} from "./ItemgroupCharacteristic"; import {AbstractItemGroup} from "./AbstractItemGroup"; +import {Item} from "./Item"; export abstract class ItemGroup extends ModelComponent { itemGroupCharacteristics: ItemGroupCharacteristic[] = [] parentGroup: AbstractItemGroup | undefined + manuallyInheritedItems: Item[] = [] + + addItemgroupCharacteristic(itemgroupCharacteristic: ItemGroupCharacteristic) { + this.itemGroupCharacteristics.push(itemgroupCharacteristic); + this.addCharacteristicValueForManuallyItems(itemgroupCharacteristic); + this.addCharacteristicValue(itemgroupCharacteristic); + } + + protected abstract addCharacteristicValue(characteristic: ItemGroupCharacteristic): void; + + private addCharacteristicValueForManuallyItems(characteristic: ItemGroupCharacteristic) { + this.manuallyInheritedItems.forEach(item => { + item.addCharacteristic(characteristic); + }) + } + + inheritManualItem(item: Item) { + if(this.manuallyInheritedItems.find(inheritedItems => inheritedItems.componentName === item.componentName) == undefined) { + this.manuallyInheritedItems.push(item); + item.addInheritedGroup(this); + } + } + + }