main #48

Closed
sebastian wants to merge 44 commits from main into inventory
3 changed files with 37 additions and 2 deletions
Showing only changes of commit 6b93bf1dc5 - Show all commits

View File

@ -11,7 +11,7 @@
</mat-expansion-panel-header> </mat-expansion-panel-header>
<div class="panel-actions"> <div class="panel-actions">
<button mat-raised-button color="warn" (click)="deleteInheritedItemgroup(itemgroup)">Delete</button> <button mat-raised-button color="warn" [disabled]="automaticallyInheritedItemgroups.includes(itemgroup)" (click)="deleteInheritedItemgroup(itemgroup)">Delete</button>
</div> </div>
</mat-expansion-panel> </mat-expansion-panel>
</mat-accordion> </mat-accordion>

View File

@ -4,6 +4,7 @@ import {ItemGroup} from "../../../project/game-model/inventory/ItemGroup";
import {GameModel} from "../../../project/game-model/GameModel"; import {GameModel} from "../../../project/game-model/GameModel";
import {MatDialog} from "@angular/material/dialog"; import {MatDialog} from "@angular/material/dialog";
import {ItemgroupInheritorComponent} from "./itemgroup-inheritor/itemgroup-inheritor.component"; import {ItemgroupInheritorComponent} from "./itemgroup-inheritor/itemgroup-inheritor.component";
import {ItemgroupUtilities} from "../../../project/game-model/utils/ItemgroupUtilities";
@Component({ @Component({
selector: 'app-item-editor', selector: 'app-item-editor',
@ -35,4 +36,8 @@ export class ItemEditorComponent {
deleteInheritedItemgroup(itemgroup: ItemGroup) { deleteInheritedItemgroup(itemgroup: ItemGroup) {
this.item!.inheritedGroups = this.item!.inheritedGroups.filter(group => group.componentName !== itemgroup.componentName); this.item!.inheritedGroups = this.item!.inheritedGroups.filter(group => group.componentName !== itemgroup.componentName);
} }
get automaticallyInheritedItemgroups() {
return ItemgroupUtilities.findItemgroupPathToItem(this.item!.componentName, this.gameModel!.itemgroups);
}
} }

View File

@ -1,9 +1,20 @@
import {GameModel} from "../GameModel"; import {GameModel} from "../GameModel";
import {ItemGroup} from "../inventory/ItemGroup"; import {ItemGroup} from "../inventory/ItemGroup";
import {AbstractItemGroup} from "../inventory/AbstractItemGroup"; import {AbstractItemGroup} from "../inventory/AbstractItemGroup";
import {ConcreteItemGroup} from "../inventory/ConcreteItemGroup";
export class ItemgroupUtilities { export class ItemgroupUtilities {
public static findItemgroupPathToItem(searchedItemName: string, itemgroups: ItemGroup[]): ItemGroup[] {
for(let i=0; i<itemgroups.length; i++) {
const found_path = this.findItemgroupPathToItemRecursive(itemgroups[i], searchedItemName, []);
if(found_path.length > 0) {
return found_path;
}
}
return [];
}
public static findItemgroupPathToItemgroup(searchedItemgroupName: string, itemgroups: ItemGroup[]): ItemGroup[] { public static findItemgroupPathToItemgroup(searchedItemgroupName: string, itemgroups: ItemGroup[]): ItemGroup[] {
for(let i=0; i<itemgroups.length; i++) { for(let i=0; i<itemgroups.length; i++) {
const found_path = this.findItemgroupPathToItemgroupRecursive(itemgroups[i], searchedItemgroupName, []); const found_path = this.findItemgroupPathToItemgroupRecursive(itemgroups[i], searchedItemgroupName, []);
@ -34,4 +45,23 @@ export class ItemgroupUtilities {
} }
} }
private static findItemgroupPathToItemRecursive(root: ItemGroup, searchedItemName: string, path: ItemGroup[]): ItemGroup[] {
path.push(root);
if(root instanceof ConcreteItemGroup) {
const searchedItem = root.items.find(item => item.componentName === searchedItemName)
if(searchedItem != undefined) {
return path;
}
} else if(root instanceof AbstractItemGroup) {
for(let i=0; i<root.children.length; i++) {
const found_path = this.findItemgroupPathToItemRecursive(root.children[i], searchedItemName, path.concat());
if(found_path.length > 0) {
return found_path;
}
}
}
return [];
}
} }