From 7ee8db2a379cab258532456d6c94f59059d3b69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Tue, 7 May 2024 08:58:56 +0200 Subject: [PATCH] Let Items Inherit new Itemgroups --- src/app/app.module.ts | 12 ++++++--- src/app/editor/editor.component.html | 2 +- .../item-editor/item-editor.component.html | 21 +++++++++++++++- .../item-editor/item-editor.component.ts | 25 +++++++++++++++++++ .../itemgroup-inheritor.component.html | 13 ++++++++++ .../itemgroup-inheritor.component.scss | 0 .../itemgroup-inheritor.component.spec.ts | 23 +++++++++++++++++ .../itemgroup-inheritor.component.ts | 25 +++++++++++++++++++ src/app/project/game-model/GameModel.ts | 15 +++++++++++ 9 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.html create mode 100644 src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.scss create mode 100644 src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.spec.ts create mode 100644 src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d66da66..23968d5 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -72,7 +72,7 @@ import {CharacterOverviewComponent} from "./side-overviews/character-overview/ch import {CharacterEditorComponent} from "./editor/character-editor/character-editor.component"; import { MatAccordion, - MatExpansionPanel, + MatExpansionPanel, MatExpansionPanelDescription, MatExpansionPanelHeader, MatExpansionPanelTitle } from "@angular/material/expansion"; @@ -85,7 +85,9 @@ import { import {ItemOverviewComponent} from "./side-overviews/item-overview/item-overview.component"; import {ItemGroupEditorComponent} from "./editor/items/item-group-editor/item-group-editor.component"; import {ItemEditorComponent} from "./editor/items/item-editor/item-editor.component"; - +import { + ItemgroupInheritorComponent +} from "./editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component"; // AoT requires an exported function for factories const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new TranslateHttpLoader(http, './assets/i18n/', '.json'); @@ -113,7 +115,8 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl StateInitialCellComponent, ItemOverviewComponent, ItemGroupEditorComponent, - ItemEditorComponent + ItemEditorComponent, + ItemgroupInheritorComponent ], imports: [ BrowserModule, @@ -176,7 +179,8 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl MatExpansionPanel, MatExpansionPanelTitle, MatCardTitle, - MatExpansionPanelHeader + MatExpansionPanelHeader, + MatExpansionPanelDescription ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/editor/editor.component.html b/src/app/editor/editor.component.html index 90d41ee..ae86488 100644 --- a/src/app/editor/editor.component.html +++ b/src/app/editor/editor.component.html @@ -21,6 +21,6 @@ - + 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 75719cb..003ee47 100644 --- a/src/app/editor/items/item-editor/item-editor.component.html +++ b/src/app/editor/items/item-editor/item-editor.component.html @@ -1 +1,20 @@ -

item-editor works!

+ + + Inherited Itemgroups + + + + + + {{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 f360f3a..1ea90ce 100644 --- a/src/app/editor/items/item-editor/item-editor.component.ts +++ b/src/app/editor/items/item-editor/item-editor.component.ts @@ -1,5 +1,9 @@ import {Component, Input} from '@angular/core'; import {Item} from "../../../project/game-model/inventory/Item"; +import {ItemGroup} from "../../../project/game-model/inventory/ItemGroup"; +import {GameModel} from "../../../project/game-model/GameModel"; +import {MatDialog} from "@angular/material/dialog"; +import {ItemgroupInheritorComponent} from "./itemgroup-inheritor/itemgroup-inheritor.component"; @Component({ selector: 'app-item-editor', @@ -9,4 +13,25 @@ import {Item} from "../../../project/game-model/inventory/Item"; export class ItemEditorComponent { @Input() item: Item | undefined + @Input() gameModel: GameModel | undefined; + + constructor(private dialog: MatDialog) { + + } + + onAddNewInheritedItemgroup() { + const dialogRef = this.dialog.open(ItemgroupInheritorComponent, { + data: this.gameModel!.itemgroupsAsList.filter(group => !this.item!.inheritedGroups.includes(group)), + width: "400px" + }) + + dialogRef.afterClosed().subscribe(res => { + if(res != undefined) { + this.item!.inheritedGroups.push(res); + } + }) + } + + + } diff --git a/src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.html b/src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.html new file mode 100644 index 0000000..dc0ed23 --- /dev/null +++ b/src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.html @@ -0,0 +1,13 @@ +

Inherit Itemgroup

+ + + Select Itemgroup + + {{itemgroup.componentName}} + + + + + + + diff --git a/src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.scss b/src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.spec.ts b/src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.spec.ts new file mode 100644 index 0000000..3bdf452 --- /dev/null +++ b/src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ItemgroupInheritorComponent } from './itemgroup-inheritor.component'; + +describe('ItemgroupInheritorComponent', () => { + let component: ItemgroupInheritorComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ItemgroupInheritorComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(ItemgroupInheritorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.ts b/src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.ts new file mode 100644 index 0000000..c71a02e --- /dev/null +++ b/src/app/editor/items/item-editor/itemgroup-inheritor/itemgroup-inheritor.component.ts @@ -0,0 +1,25 @@ +import {Component, Inject} from '@angular/core'; +import {MAT_DIALOG_DATA, MatDialogRef, MatDialogTitle} from "@angular/material/dialog"; +import {ItemGroup} from "../../../../project/game-model/inventory/ItemGroup"; + +@Component({ + selector: 'app-itemgroup-inheritor', + templateUrl: './itemgroup-inheritor.component.html', + styleUrl: './itemgroup-inheritor.component.scss' +}) +export class ItemgroupInheritorComponent { + + selectedItemgroup: ItemGroup | undefined + + constructor(private dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public availableItemgroups: ItemGroup[]) { + } + + cancel() { + this.dialogRef.close() + } + + submit() { + this.dialogRef.close(this.selectedItemgroup); + } +} diff --git a/src/app/project/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts index d438107..27d8af5 100644 --- a/src/app/project/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -263,4 +263,19 @@ export class GameModel { return requestedTemplates; } + + get itemgroupsAsList() { + let itemgroupQueue: ItemGroup[] = this.itemgroups.concat(); + const result: ItemGroup[] = [] + while(itemgroupQueue.length > 0) { + const currentGroup = itemgroupQueue.shift()!; + + if(currentGroup instanceof AbstractItemGroup) { + itemgroupQueue = itemgroupQueue.concat(currentGroup.children); + } + result.push(currentGroup); + } + + return result; + } }