inventory-items-2 #44

Closed
sebastian wants to merge 32 commits from inventory-items-2 into inventory
7 changed files with 86 additions and 17 deletions
Showing only changes of commit db0bd14ea8 - Show all commits

View File

@ -4,7 +4,7 @@
</mat-card-header> </mat-card-header>
<mat-card-content> <mat-card-content>
<mat-accordion> <mat-accordion>
<mat-expansion-panel *ngFor="let itemgroup of item!.inheritedGroups"> <mat-expansion-panel *ngFor="let itemgroup of manuallyAndHierarchyItemgroups">
<mat-expansion-panel-header> <mat-expansion-panel-header>
<mat-panel-title>{{itemgroup.componentName}}</mat-panel-title> <mat-panel-title>{{itemgroup.componentName}}</mat-panel-title>
<mat-panel-description>{{itemgroup.componentDescription}}</mat-panel-description> <mat-panel-description>{{itemgroup.componentDescription}}</mat-panel-description>

View File

@ -17,29 +17,33 @@ export class ItemEditorComponent {
@Input() gameModel: GameModel | undefined; @Input() gameModel: GameModel | undefined;
constructor(private dialog: MatDialog) { constructor(private dialog: MatDialog) {
} }
onAddNewInheritedItemgroup() { onAddNewInheritedItemgroup() {
const itemgroups = this.item!.manuallyInheritedGroups.concat(this.item!.hierarchyInheritedGroups);
const dialogRef = this.dialog.open(ItemgroupInheritorComponent, { 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" width: "400px"
}) })
dialogRef.afterClosed().subscribe(res => { dialogRef.afterClosed().subscribe(res => {
if(res != undefined) { if(res != undefined) {
this.item!.inheritedGroups.push(res); this.item!.addInheritedGroup(res);
} }
}) })
} }
deleteInheritedItemgroup(itemgroup: ItemGroup) { deleteInheritedItemgroup(itemgroup: ItemGroup) {
this.item!.inheritedGroups = this.item!.inheritedGroups.filter(group => group.componentName !== itemgroup.componentName); this.item!.deleteInheritedGroup(itemgroup);
} }
get automaticallyInheritedItemgroups() { get automaticallyInheritedItemgroups() {
return ItemgroupUtilities.findItemgroupPathToItem(this.item!.componentName, this.gameModel!.itemgroups); return ItemgroupUtilities.findItemgroupPathToItem(this.item!.componentName, this.gameModel!.itemgroups);
} }
get manuallyAndHierarchyItemgroups() {
return this.item!.hierarchyInheritedGroups.concat(this.item!.manuallyInheritedGroups);
}
} }

View File

@ -38,7 +38,8 @@ export class ItemGroupEditorComponent implements OnInit{
addItemgroupCharacteristic() { addItemgroupCharacteristic() {
const itemgroupCharacteristic = new ItemGroupCharacteristic("", "", this.itemgroup!); const itemgroupCharacteristic = new ItemGroupCharacteristic("", "", this.itemgroup!);
this.itemgroup!.itemGroupCharacteristics.push(itemgroupCharacteristic); this.itemgroup!.addItemgroupCharacteristic(itemgroupCharacteristic);
this.itemQualityDatasource.data = this.itemgroup!.itemGroupCharacteristics; this.itemQualityDatasource.data = this.itemgroup!.itemGroupCharacteristics;
this.editedCharacteristic = itemgroupCharacteristic; this.editedCharacteristic = itemgroupCharacteristic;
} }

View File

@ -1,4 +1,5 @@
import {ItemGroup} from "./ItemGroup"; import {ItemGroup} from "./ItemGroup";
import {ItemGroupCharacteristic} from "./ItemgroupCharacteristic";
export class AbstractItemGroup extends ItemGroup { export class AbstractItemGroup extends ItemGroup {
@ -8,4 +9,10 @@ export class AbstractItemGroup extends ItemGroup {
this.children.push(itemGroup) this.children.push(itemGroup)
itemGroup.parentGroup = this; itemGroup.parentGroup = this;
} }
protected addCharacteristicValue(characteristic: ItemGroupCharacteristic): void {
//Do Nothing
}
} }

View File

@ -1,5 +1,6 @@
import {ItemGroup} from "./ItemGroup"; import {ItemGroup} from "./ItemGroup";
import {Item} from "./Item"; import {Item} from "./Item";
import {ItemGroupCharacteristic} from "./ItemgroupCharacteristic";
export class ConcreteItemGroup extends ItemGroup { export class ConcreteItemGroup extends ItemGroup {
@ -8,7 +9,7 @@ export class ConcreteItemGroup extends ItemGroup {
addItem(item: Item, parentItemgroups: ItemGroup[]) { addItem(item: Item, parentItemgroups: ItemGroup[]) {
if(this.findItemByName(item.componentName) == undefined) { if(this.findItemByName(item.componentName) == undefined) {
parentItemgroups.forEach(itemgroup => { parentItemgroups.forEach(itemgroup => {
item.inheritedGroups.push(itemgroup); item.addInheritedHierarchyGroup(itemgroup);
}) })
this.items.push(item); this.items.push(item);
} }
@ -17,4 +18,12 @@ export class ConcreteItemGroup extends ItemGroup {
findItemByName(itemName: string) { findItemByName(itemName: string) {
return this.items.find(item => item.componentName === itemName); return this.items.find(item => item.componentName === itemName);
} }
protected addCharacteristicValue(characteristic: ItemGroupCharacteristic): void {
this.items.forEach(item => {
item.addCharacteristic(characteristic);
})
}
} }

View File

@ -5,17 +5,21 @@ import {ItemGroupCharacteristic} from "./ItemgroupCharacteristic";
export class Item extends ModelComponent { export class Item extends ModelComponent {
inheritedGroups: ItemGroup[] = []
manuallyInheritedGroups: ItemGroup[] = []
hierarchyInheritedGroups: ItemGroup[] = []
itemCharacteristicValues: ItemgroupCharacteristicValue[] = [] itemCharacteristicValues: ItemgroupCharacteristicValue[] = []
initializeItemCharacteristics() { initializeItemCharacteristics() {
this.inheritedGroups.forEach(itemGroup => { const inheritedGroups = this.manuallyInheritedGroups.concat(this.hierarchyInheritedGroups);
itemGroup.itemGroupCharacteristics.forEach(characteristic => { inheritedGroups.forEach(itemGroup => {
const characteristicValue = new ItemgroupCharacteristicValue(characteristic, 0); this.initializeItemCharacteristicsOfItemgroup(itemGroup);
if(!this.isValueInitialized(characteristic)) { })
this.itemCharacteristicValues.push(characteristicValue); }
}
}) initializeItemCharacteristicsOfItemgroup(itemGroup: ItemGroup) {
itemGroup.itemGroupCharacteristics.forEach(characteristic => {
this.addCharacteristic(characteristic);
}) })
} }
@ -25,11 +29,30 @@ export class Item extends ModelComponent {
addInheritedGroup(itemgroup: ItemGroup) { addInheritedGroup(itemgroup: ItemGroup) {
if(this.findItemgroupByName(itemgroup.componentName) == undefined) { if(this.findItemgroupByName(itemgroup.componentName) == undefined) {
this.inheritedGroups.push(itemgroup); this.manuallyInheritedGroups.push(itemgroup);
this.initializeItemCharacteristicsOfItemgroup(itemgroup);
} }
} }
findItemgroupByName(groupName: string) { 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);
} }
} }

View File

@ -1,10 +1,35 @@
import {ModelComponent} from "../ModelComponent"; import {ModelComponent} from "../ModelComponent";
import {ItemGroupCharacteristic} from "./ItemgroupCharacteristic"; import {ItemGroupCharacteristic} from "./ItemgroupCharacteristic";
import {AbstractItemGroup} from "./AbstractItemGroup"; import {AbstractItemGroup} from "./AbstractItemGroup";
import {Item} from "./Item";
export abstract class ItemGroup extends ModelComponent { export abstract class ItemGroup extends ModelComponent {
itemGroupCharacteristics: ItemGroupCharacteristic[] = [] itemGroupCharacteristics: ItemGroupCharacteristic[] = []
parentGroup: AbstractItemGroup | undefined 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);
}
}
} }