Visualize InventorySlots and Create them
All checks were successful
E2E Testing / test (push) Successful in 1m39s

This commit is contained in:
Sebastian Böckelmann 2024-05-11 09:28:29 +02:00
parent 6912b4cc28
commit 82dd597d6d
13 changed files with 207 additions and 6 deletions

View File

@ -91,6 +91,12 @@ import {
import { import {
InheritedItemCharacteristicEditorComponent InheritedItemCharacteristicEditorComponent
} from "./editor/items/item-editor/inherited-item-characteristic-editor/inherited-item-characteristic-editor.component"; } from "./editor/items/item-editor/inherited-item-characteristic-editor/inherited-item-characteristic-editor.component";
import {
InventorySlotEditorComponent
} from "./editor/character-editor/inventory-slot-editor/inventory-slot-editor.component";
import {
InventorySlotCreatorComponent
} from "./editor/character-editor/inventory-slot-editor/inventory-slot-creator/inventory-slot-creator.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');
@ -120,7 +126,9 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl
ItemGroupEditorComponent, ItemGroupEditorComponent,
ItemEditorComponent, ItemEditorComponent,
ItemgroupInheritorComponent, ItemgroupInheritorComponent,
InheritedItemCharacteristicEditorComponent InheritedItemCharacteristicEditorComponent,
InventorySlotEditorComponent,
InventorySlotCreatorComponent
], ],
imports: [ imports: [
BrowserModule, BrowserModule,

View File

@ -56,3 +56,13 @@
</mat-accordion> </mat-accordion>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>
<mat-card>
<mat-card-header>
<mat-card-title>Inventory-Slots</mat-card-title>
</mat-card-header>
<mat-card-content>
<app-inventory-slot-editor [character]="character" [itemgroups]="gameModel!.itemgroupsAsList"></app-inventory-slot-editor>
</mat-card-content>
</mat-card>

View File

@ -0,0 +1,11 @@
<h1 mat-dialog-title>Create Inventory Slot</h1>
<mat-dialog-content>
<mat-form-field appearance="outline" class="long-form">
<mat-label>Slot-Name</mat-label>
<input matInput [formControl]="slotNameCtrl">
</mat-form-field>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-raised-button (click)="cancel()">Cancel</button>
<button mat-raised-button [disabled]="slotNameCtrl.invalid" (click)="submit()">Submit</button>
</mat-dialog-actions>

View File

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { InventorySlotCreatorComponent } from './inventory-slot-creator.component';
describe('InventorySlotCreatorComponent', () => {
let component: InventorySlotCreatorComponent;
let fixture: ComponentFixture<InventorySlotCreatorComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [InventorySlotCreatorComponent]
})
.compileComponents();
fixture = TestBed.createComponent(InventorySlotCreatorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,27 @@
import {Component, Inject} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
import {InventorySlot} from "../../../../project/game-model/inventory/intentory-slots/InventorySlot";
import {FormControl, Validators} from "@angular/forms";
@Component({
selector: 'app-inventory-slot-creator',
templateUrl: './inventory-slot-creator.component.html',
styleUrl: './inventory-slot-creator.component.scss'
})
export class InventorySlotCreatorComponent {
slotNameCtrl = new FormControl('', [Validators.required]);
constructor(private dialogRef: MatDialogRef<InventorySlotCreatorComponent>,
@Inject(MAT_DIALOG_DATA) public data: InventorySlot | undefined) {
}
submit() {
this.dialogRef.close(new InventorySlot(this.slotNameCtrl.value!))
}
cancel() {
this.dialogRef.close()
}
}

View File

@ -0,0 +1,12 @@
<mat-accordion>
<mat-expansion-panel *ngFor="let slot of character!.inventorySlots">
<mat-expansion-panel-header>
<mat-panel-title>{{slot.slotName}}</mat-panel-title>
</mat-expansion-panel-header>
<div class="panel-actions">
<button mat-raised-button color="primary">Edit</button>
<button mat-raised-button color="warn">Delete</button>
</div>
</mat-expansion-panel>
<button mat-stroked-button class="add-btn" (click)="addInventorySlot()">Add Inventory-Slot</button>
</mat-accordion>

View File

@ -0,0 +1,6 @@
.panel-actions {
float: right;
}
.add-btn {
width: 100%;
}

View File

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { InventorySlotEditorComponent } from './inventory-slot-editor.component';
describe('InventorySlotEditorComponent', () => {
let component: InventorySlotEditorComponent;
let fixture: ComponentFixture<InventorySlotEditorComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [InventorySlotEditorComponent]
})
.compileComponents();
fixture = TestBed.createComponent(InventorySlotEditorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,32 @@
import {Component, Input} from '@angular/core';
import {Character} from "../../../project/game-model/characters/Character";
import {ItemGroup} from "../../../project/game-model/inventory/ItemGroup";
import {InventorySlot} from "../../../project/game-model/inventory/intentory-slots/InventorySlot";
import {MatDialog} from "@angular/material/dialog";
import {InventorySlotCreatorComponent} from "./inventory-slot-creator/inventory-slot-creator.component";
@Component({
selector: 'app-inventory-slot-editor',
templateUrl: './inventory-slot-editor.component.html',
styleUrl: './inventory-slot-editor.component.scss'
})
export class InventorySlotEditorComponent {
@Input() character: Character | undefined
@Input() itemgroups: ItemGroup[] = []
constructor(private dialog: MatDialog) {
}
addInventorySlot() {
const dialogRef = this.dialog.open(InventorySlotCreatorComponent, {
minWidth: "400px"
})
dialogRef.afterClosed().subscribe(res => {
if(res != undefined) {
this.character!.inventorySlots.push(res)
}
})
}
}

View File

@ -7,19 +7,41 @@ import {SimpleTemplateGamesystem} from "../templates/simpleGamesystem/SimpleTemp
import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem"; import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem";
import {ProductGamesystem} from "../gamesystems/ProductGamesystem"; import {ProductGamesystem} from "../gamesystems/ProductGamesystem";
import {CharacterRelation} from "./CharacterRelation"; import {CharacterRelation} from "./CharacterRelation";
import {InventorySlot} from "../inventory/intentory-slots/InventorySlot";
import {Tupel} from "../../../shared/Tupel";
export class Character extends ModelComponent implements TemplateElement { export class Character extends ModelComponent implements TemplateElement {
characterSpecificTemplateSystems: Gamesystem<any, any>[] = [] characterSpecificTemplateSystems: Gamesystem<any, any>[] = []
characterRelations: CharacterRelation[] = [] characterRelations: CharacterRelation[] = []
characterRelationGamesystems: Gamesystem<any, any>[] = [] characterRelationGamesystems: Gamesystem<any, any>[] = []
inventorySlots: InventorySlot[] = []
combinableInventorySlots: Tupel<InventorySlot, InventorySlot>[] = []
constructor(componentName: string, componentDescription: string) { constructor(componentName: string, componentDescription: string) {
super(componentName, componentDescription, ModelComponentType.CHARACTER); super(componentName, componentDescription, ModelComponentType.CHARACTER);
} }
addInventorySlot(inventorySlot: InventorySlot) {
if(this.inventorySlots.find(slot => slot.slotName === inventorySlot.slotName) == undefined) {
this.inventorySlots.push(inventorySlot);
}
}
removeInventorySlot(removedInventorySlot: InventorySlot) {
this.inventorySlots = this.inventorySlots.filter(slot => removedInventorySlot.slotName !== slot.slotName);
}
addCombinedInventorySlot(combinedSlot: Tupel<InventorySlot, InventorySlot>) {
if(this.combinableInventorySlots.find(tupel => tupel.value00 === combinedSlot.value00 && tupel.value01 === combinedSlot.value01) != undefined) {
this.combinableInventorySlots.push(combinedSlot);
}
}
removeCombinedInventorySlot(combinedSlot: Tupel<InventorySlot, InventorySlot>) {
this.combinableInventorySlots = this.combinableInventorySlots.filter(slots => slots.value00 != combinedSlot.value00 && slots.value01 != combinedSlot.value01);
}
addCharacterSpecificSimpleTemplatesystem(gamesystem: Gamesystem<any, any>, recursiveCall: boolean = false) { addCharacterSpecificSimpleTemplatesystem(gamesystem: Gamesystem<any, any>, recursiveCall: boolean = false) {
if(!this.isTemplateSystemCharacterSpecific(gamesystem.componentName)) { if(!this.isTemplateSystemCharacterSpecific(gamesystem.componentName)) {
if(gamesystem instanceof SimpleTemplateGamesystem) { if(gamesystem instanceof SimpleTemplateGamesystem) {
@ -65,9 +87,6 @@ export class Character extends ModelComponent implements TemplateElement {
this.addAsymetricCharacterRelationGamesystem(gamesystem.parentGamesystem, true) this.addAsymetricCharacterRelationGamesystem(gamesystem.parentGamesystem, true)
} }
} else {
console.log("Was already added")
console.log(this)
} }
} }

View File

@ -0,0 +1,14 @@
import {ItemGroupCharacteristic} from "../ItemgroupCharacteristic";
export class InventoryCharacteristic {
increasingCharacteristic: ItemGroupCharacteristic
decreasingCharacteristic: ItemGroupCharacteristic
constructor(increasingCharacteristic: ItemGroupCharacteristic, decreasingCharacteristic: ItemGroupCharacteristic) {
this.increasingCharacteristic = increasingCharacteristic;
this.decreasingCharacteristic = decreasingCharacteristic;
}
}

View File

@ -0,0 +1,16 @@
import {ItemGroupCharacteristic} from "../ItemgroupCharacteristic";
import {InventoryCharacteristic} from "./InventoryCharacteristic";
import {ItemGroup} from "../ItemGroup";
export class InventorySlot {
slotName: string
slotCharacteristics: InventoryCharacteristic[] = []
requiredInheritances: ItemGroup[] = [] //if empty: non reqierements
constructor(slotName: string) {
this.slotName = slotName;
}
}