inventory-items-2 #44

Closed
sebastian wants to merge 32 commits from inventory-items-2 into inventory
9 changed files with 130 additions and 6 deletions
Showing only changes of commit 7ee8db2a37 - Show all commits

View File

@ -72,7 +72,7 @@ import {CharacterOverviewComponent} from "./side-overviews/character-overview/ch
import {CharacterEditorComponent} from "./editor/character-editor/character-editor.component"; import {CharacterEditorComponent} from "./editor/character-editor/character-editor.component";
import { import {
MatAccordion, MatAccordion,
MatExpansionPanel, MatExpansionPanel, MatExpansionPanelDescription,
MatExpansionPanelHeader, MatExpansionPanelHeader,
MatExpansionPanelTitle MatExpansionPanelTitle
} from "@angular/material/expansion"; } from "@angular/material/expansion";
@ -85,7 +85,9 @@ import {
import {ItemOverviewComponent} from "./side-overviews/item-overview/item-overview.component"; import {ItemOverviewComponent} from "./side-overviews/item-overview/item-overview.component";
import {ItemGroupEditorComponent} from "./editor/items/item-group-editor/item-group-editor.component"; import {ItemGroupEditorComponent} from "./editor/items/item-group-editor/item-group-editor.component";
import {ItemEditorComponent} from "./editor/items/item-editor/item-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 // AoT requires an exported function for factories
const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new TranslateHttpLoader(http, './assets/i18n/', '.json'); const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new TranslateHttpLoader(http, './assets/i18n/', '.json');
@ -113,7 +115,8 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl
StateInitialCellComponent, StateInitialCellComponent,
ItemOverviewComponent, ItemOverviewComponent,
ItemGroupEditorComponent, ItemGroupEditorComponent,
ItemEditorComponent ItemEditorComponent,
ItemgroupInheritorComponent
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
@ -176,7 +179,8 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl
MatExpansionPanel, MatExpansionPanel,
MatExpansionPanelTitle, MatExpansionPanelTitle,
MatCardTitle, MatCardTitle,
MatExpansionPanelHeader MatExpansionPanelHeader,
MatExpansionPanelDescription
], ],
providers: [], providers: [],
bootstrap: [AppComponent] bootstrap: [AppComponent]

View File

@ -21,6 +21,6 @@
</app-character-editor> </app-character-editor>
<app-item-group-editor *ngIf="modelComponent.type === ModelComponentType.ITEMGROUP" [itemgroup]="convertModelComponentToItemGroup(modelComponent)"></app-item-group-editor> <app-item-group-editor *ngIf="modelComponent.type === ModelComponentType.ITEMGROUP" [itemgroup]="convertModelComponentToItemGroup(modelComponent)"></app-item-group-editor>
<app-item-editor *ngIf="modelComponent.type === ModelComponentType.ITEM" [item]="convertModelComponentToItem(modelComponent)"></app-item-editor> <app-item-editor *ngIf="modelComponent.type === ModelComponentType.ITEM" [item]="convertModelComponentToItem(modelComponent)" [gameModel]="gameModel!"></app-item-editor>
</mat-tab> </mat-tab>
</mat-tab-group> </mat-tab-group>

View File

@ -1 +1,20 @@
<p>item-editor works!</p> <mat-card>
<mat-card-header>
<mat-card-title>Inherited Itemgroups</mat-card-title>
</mat-card-header>
<mat-card-content>
<mat-accordion>
<mat-expansion-panel *ngFor="let itemgroup of item!.inheritedGroups">
<mat-expansion-panel-header>
<mat-panel-title>{{itemgroup.componentName}}</mat-panel-title>
<mat-panel-description>{{itemgroup.componentDescription}}</mat-panel-description>
</mat-expansion-panel-header>
</mat-expansion-panel>
</mat-accordion>
<div>
</div>
<button mat-stroked-button style="width: 100%" (click)="onAddNewInheritedItemgroup()">Add Itemgroup</button>
</mat-card-content>
</mat-card>

View File

@ -1,5 +1,9 @@
import {Component, Input} from '@angular/core'; import {Component, Input} from '@angular/core';
import {Item} from "../../../project/game-model/inventory/Item"; 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({ @Component({
selector: 'app-item-editor', selector: 'app-item-editor',
@ -9,4 +13,25 @@ import {Item} from "../../../project/game-model/inventory/Item";
export class ItemEditorComponent { export class ItemEditorComponent {
@Input() item: Item | undefined @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);
}
})
}
} }

View File

@ -0,0 +1,13 @@
<h1 mat-dialog-title>Inherit Itemgroup</h1>
<mat-dialog-content>
<mat-form-field appearance="outline" style="width: 100%;">
<mat-label>Select Itemgroup</mat-label>
<mat-select [(ngModel)]="selectedItemgroup">
<mat-option *ngFor="let itemgroup of availableItemgroups" [value]="itemgroup">{{itemgroup.componentName}}</mat-option>
</mat-select>
</mat-form-field>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-stroked-button (click)="cancel()">Cancel</button>
<button mat-raised-button color="primary" (click)="submit()">Confim</button>
</mat-dialog-actions>

View File

@ -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<ItemgroupInheritorComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ItemgroupInheritorComponent]
})
.compileComponents();
fixture = TestBed.createComponent(ItemgroupInheritorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -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<ItemgroupInheritorComponent>,
@Inject(MAT_DIALOG_DATA) public availableItemgroups: ItemGroup[]) {
}
cancel() {
this.dialogRef.close()
}
submit() {
this.dialogRef.close(this.selectedItemgroup);
}
}

View File

@ -263,4 +263,19 @@ export class GameModel {
return requestedTemplates; 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;
}
} }