diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 4bfac7a..890bc1f 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -215,11 +215,6 @@ export class AppComponent implements OnInit{ gameModel.gamesystems = gamesystems gameModel.generateProductSystemContents() - const characterTemplateSystems = gameModel.getTemplateSystems(TemplateType.CHARACTER).map(templateSystem => templateSystem as SimpleTemplateGamesystem) - const characterRelationTemplateSystems = gameModel.getTemplateSystems(TemplateType.CHARACTER_RELATION).map(templateSystem => templateSystem as SimpleTemplateGamesystem) - const characterParser = new CharacterParser(characterTemplateSystems, characterRelationTemplateSystems, gameModel.scriptAccounts); - gameModel.characters = characterParser.parseCharacters(storedGameModel.storedCharacters) - const itemgroupParser = new ItemgroupParser(); itemgroupParser.parseItemgroups(storedGameModel.storedItemgroups); gameModel.itemgroups = itemgroupParser.getParsedTopItemgroups(); @@ -227,6 +222,13 @@ export class AppComponent implements OnInit{ const itemParser = new ItemParser(itemgroupParser.getParsedItemgroups()) itemParser.parseItems(storedGameModel.storedItems); + const characterTemplateSystems = gameModel.getTemplateSystems(TemplateType.CHARACTER).map(templateSystem => templateSystem as SimpleTemplateGamesystem) + const characterRelationTemplateSystems = gameModel.getTemplateSystems(TemplateType.CHARACTER_RELATION).map(templateSystem => templateSystem as SimpleTemplateGamesystem) + const characterParser = new CharacterParser(characterTemplateSystems, characterRelationTemplateSystems, gameModel.scriptAccounts, itemgroupParser.getCharacteristics(), itemgroupParser.getParsedItemgroups()); + gameModel.characters = characterParser.parseCharacters(storedGameModel.storedCharacters) + + + this.gameModel = gameModel; } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 152535a..7daa0e0 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -43,7 +43,7 @@ import { MatColumnDef, MatHeaderCell, MatHeaderCellDef, - MatHeaderRow, MatHeaderRowDef, MatRow, MatRowDef, + MatHeaderRow, MatHeaderRowDef, MatNoDataRow, MatRow, MatRowDef, MatTable } from "@angular/material/table"; import {MatCheckbox} from "@angular/material/checkbox"; @@ -91,6 +91,22 @@ import { import { InheritedItemCharacteristicEditorComponent } 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 { + InventorySlotCharacteristicEditorComponent +} from "./editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/inventory-slot-characteristic-editor.component"; +import {MatAutocomplete, MatAutocompleteTrigger} from "@angular/material/autocomplete"; +import { + CharacteristicSelectorComponent +} from "./editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/characteristic-selector/characteristic-selector.component"; +import { + RequieredInheritancesEditorComponent +} from "./editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-editor.component"; +import { + RequieredInheritancesCreatorComponent +} from "./editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-creator/requiered-inheritances-creator.component"; // AoT requires an exported function for factories const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new TranslateHttpLoader(http, './assets/i18n/', '.json'); @@ -120,7 +136,12 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl ItemGroupEditorComponent, ItemEditorComponent, ItemgroupInheritorComponent, - InheritedItemCharacteristicEditorComponent + InheritedItemCharacteristicEditorComponent, + InventorySlotEditorComponent, + InventorySlotCharacteristicEditorComponent, + CharacteristicSelectorComponent, + RequieredInheritancesEditorComponent, + RequieredInheritancesCreatorComponent ], imports: [ BrowserModule, @@ -184,7 +205,10 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl MatExpansionPanelTitle, MatCardTitle, MatExpansionPanelHeader, - MatExpansionPanelDescription + MatExpansionPanelDescription, + MatAutocomplete, + MatAutocompleteTrigger, + MatNoDataRow ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/editor/character-editor/character-editor.component.html b/src/app/editor/character-editor/character-editor.component.html index 959cad6..a8a7060 100644 --- a/src/app/editor/character-editor/character-editor.component.html +++ b/src/app/editor/character-editor/character-editor.component.html @@ -56,3 +56,13 @@ + + + + + Inventory-Slots + + + + + diff --git a/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/characteristic-selector/characteristic-selector.component.html b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/characteristic-selector/characteristic-selector.component.html new file mode 100644 index 0000000..dc87110 --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/characteristic-selector/characteristic-selector.component.html @@ -0,0 +1,12 @@ + + Item Characteristic + + + @for (option of filteredOptions | async; track option) { + {{option.characteristicName}} + } + + diff --git a/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/characteristic-selector/characteristic-selector.component.scss b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/characteristic-selector/characteristic-selector.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/characteristic-selector/characteristic-selector.component.spec.ts b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/characteristic-selector/characteristic-selector.component.spec.ts new file mode 100644 index 0000000..9735d95 --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/characteristic-selector/characteristic-selector.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CharacteristicSelectorComponent } from './characteristic-selector.component'; + +describe('CharacteristicSelectorComponent', () => { + let component: CharacteristicSelectorComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [CharacteristicSelectorComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(CharacteristicSelectorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/characteristic-selector/characteristic-selector.component.ts b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/characteristic-selector/characteristic-selector.component.ts new file mode 100644 index 0000000..a04c507 --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/characteristic-selector/characteristic-selector.component.ts @@ -0,0 +1,46 @@ +import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; +import {AsyncPipe} from "@angular/common"; +import {FormControl, FormsModule} from "@angular/forms"; +import {MatAutocomplete, MatOption} from "@angular/material/autocomplete"; +import {MatFormField, MatLabel} from "@angular/material/form-field"; +import {MatInput} from "@angular/material/input"; +import {map, Observable, startWith} from "rxjs"; +import {ItemGroupCharacteristic} from "../../../../../project/game-model/inventory/ItemgroupCharacteristic"; + +@Component({ + selector: 'app-characteristic-selector', + templateUrl: './characteristic-selector.component.html', + styleUrl: './characteristic-selector.component.scss' +}) +export class CharacteristicSelectorComponent implements OnInit{ + myControl = new FormControl(''); + @Input() options: ItemGroupCharacteristic[] = [] + @Input() selectedInput: ItemGroupCharacteristic | undefined + filteredOptions: Observable; + + @Output('onSelectOption') selectedOptionEmitter: EventEmitter = new EventEmitter(); + + constructor() { + this.filteredOptions = this.myControl.valueChanges.pipe( + startWith(''), + map(state => (state ? this._filterStates(state) : this.options.slice())), + ); + } + + ngOnInit() { + if(this.selectedInput != undefined) { + this.myControl.setValue(this.selectedInput.characteristicName); + } + } + + private _filterStates(value: any): ItemGroupCharacteristic[] { + const filterValue = value.toLowerCase(); + + return this.options.filter(state => state.characteristicName.toLowerCase().includes(filterValue)); + } + + onOptionSelected() { + const selectedOption = this.options.find(characteristic => characteristic.characteristicName.toLowerCase() === this.myControl.value!.toLowerCase()); + this.selectedOptionEmitter.emit(selectedOption!) + } +} diff --git a/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/inventory-slot-characteristic-editor.component.html b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/inventory-slot-characteristic-editor.component.html new file mode 100644 index 0000000..9a6486d --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/inventory-slot-characteristic-editor.component.html @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + +
Increasing Characteristic + {{slotCharacteristic.increasingCharacteristic.characteristicName}} + + + + Decreasing Characteristic + {{slotCharacteristic.increasingCharacteristic.characteristicName}} + + + + + + + + + +
diff --git a/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/inventory-slot-characteristic-editor.component.scss b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/inventory-slot-characteristic-editor.component.scss new file mode 100644 index 0000000..7b288e0 --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/inventory-slot-characteristic-editor.component.scss @@ -0,0 +1,9 @@ +.table { + width: 100%; +} + + +.mat-column-edit, .mat-column-delete { + width: 32px; + align-content: center; +} diff --git a/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/inventory-slot-characteristic-editor.component.spec.ts b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/inventory-slot-characteristic-editor.component.spec.ts new file mode 100644 index 0000000..f5ddc62 --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/inventory-slot-characteristic-editor.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { InventorySlotCharacteristicEditorComponent } from './inventory-slot-characteristic-editor.component'; + +describe('InventorySlotCharacteristicEditorComponent', () => { + let component: InventorySlotCharacteristicEditorComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [InventorySlotCharacteristicEditorComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(InventorySlotCharacteristicEditorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/inventory-slot-characteristic-editor.component.ts b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/inventory-slot-characteristic-editor.component.ts new file mode 100644 index 0000000..0d21b41 --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-characteristic-editor/inventory-slot-characteristic-editor.component.ts @@ -0,0 +1,72 @@ +import {Component, Input, OnInit} from '@angular/core'; +import {InventorySlot} from "../../../../project/game-model/inventory/intentory-slots/InventorySlot"; +import {ItemGroupCharacteristic} from "../../../../project/game-model/inventory/ItemgroupCharacteristic"; +import {ItemGroup} from "../../../../project/game-model/inventory/ItemGroup"; +import {MatTable, MatTableDataSource} from "@angular/material/table"; +import { + InventoryCharacteristic +} from "../../../../project/game-model/inventory/intentory-slots/InventoryCharacteristic"; +import {MatSnackBar} from "@angular/material/snack-bar"; + +@Component({ + selector: 'app-inventory-slot-characteristic-editor', + templateUrl: './inventory-slot-characteristic-editor.component.html', + styleUrl: './inventory-slot-characteristic-editor.component.scss' +}) +export class InventorySlotCharacteristicEditorComponent implements OnInit{ + + @Input() inventorySlot: InventorySlot | undefined + @Input() itemgroups: ItemGroup[] = [] + + availableCharacteristics: ItemGroupCharacteristic[] = [] + + datasource: MatTableDataSource = new MatTableDataSource(); + displayedColumns: string[] = ['increasing', 'decreasing', 'edit', 'delete'] + editedCharacteristic: InventoryCharacteristic | null = null; + + constructor(private snackbar: MatSnackBar) { + } + + ngOnInit() { + this.itemgroups.forEach(itemgroup => { + itemgroup.itemGroupCharacteristics.forEach(characteristic => { + if(!this.availableCharacteristics.includes(characteristic)) { + this.availableCharacteristics.push(characteristic) + } + }) + }) + this.datasource.data = this.inventorySlot!.slotCharacteristics; + } + + addInventorySlotCharacteristic() { + const slotCharacteristic = new InventoryCharacteristic(null, null); + this.inventorySlot!.addSlotCharacteristic(slotCharacteristic); + this.datasource.data = this.inventorySlot!.slotCharacteristics; + this.editedCharacteristic = slotCharacteristic; + } + + finishEditing() { + if(this.editedCharacteristic != null && this.editedCharacteristic.isValid()) { + this.editedCharacteristic = null; + } else if(this.editedCharacteristic != null) { + this.snackbar.open("Please select a valid increasing and decreasing Characterstic", "", {duration: 2000}); + } + } + + onSelectIncreasingCharacteristic(selectedCharacteristic: ItemGroupCharacteristic, slotCharacteristic: InventoryCharacteristic) { + slotCharacteristic.increasingCharacteristic = selectedCharacteristic; + } + + onSelectDecreasingCharacteristic(selectedCharacteristic: ItemGroupCharacteristic, slotCharacteristic: InventoryCharacteristic) { + slotCharacteristic.decreasingCharacteristic = selectedCharacteristic; + } + + editSlotCharacteristic(slotCharacteristic: InventoryCharacteristic) { + this.editedCharacteristic = slotCharacteristic; + } + + deleteSlotCharacteristic(slotCharacteristic: InventoryCharacteristic) { + this.inventorySlot!.slotCharacteristics = this.inventorySlot!.slotCharacteristics.filter(characteristic => characteristic !== slotCharacteristic); + this.datasource.data = this.inventorySlot!.slotCharacteristics; + } +} diff --git a/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-editor.component.html b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-editor.component.html new file mode 100644 index 0000000..ab9fc1f --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-editor.component.html @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Slot Name + + {{slot.slotName}} + + + Slot Name + + + Combinable + + done + close + + + + + + + + + + + + + + +
+ + + +
+
diff --git a/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-editor.component.scss b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-editor.component.scss new file mode 100644 index 0000000..f8ae030 --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-editor.component.scss @@ -0,0 +1,58 @@ +.panel-actions { + float: right; +} +.add-btn { + width: 100%; +} + +table { + width: 100%; +} + +tr.example-detail-row { + height: 0; +} + +tr.example-element-row:not(.example-expanded-row):hover { + background: #545456; +} + +tr.example-element-row:not(.example-expanded-row):active { + background: #4e5157; +} + +.example-element-row td { + border-bottom-width: 0; +} + +.example-element-detail { + overflow: hidden; +} + +.example-element-diagram { + min-width: 80px; + border: 2px solid black; + padding: 8px; + font-weight: lighter; + margin: 8px 0; + height: 104px; +} + +.example-element-symbol { + font-weight: bold; + font-size: 40px; + line-height: normal; +} + +.example-element-description { + padding: 16px; +} + +.example-element-description-attribution { + opacity: 0.5; +} + +.mat-column-edit, .mat-column-delete, .mat-column-expand { + width: 32px; + align-content: center; +} diff --git a/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-editor.component.spec.ts b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-editor.component.spec.ts new file mode 100644 index 0000000..8e5c454 --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-editor.component.spec.ts @@ -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; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [InventorySlotEditorComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(InventorySlotEditorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-editor.component.ts b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-editor.component.ts new file mode 100644 index 0000000..46c36bb --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/inventory-slot-editor.component.ts @@ -0,0 +1,57 @@ +import {Component, Input, OnInit} 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 {animate, state, style, transition, trigger} from "@angular/animations"; +import {MatTableDataSource} from "@angular/material/table"; + +@Component({ + selector: 'app-inventory-slot-editor', + templateUrl: './inventory-slot-editor.component.html', + styleUrl: './inventory-slot-editor.component.scss', + animations: [ + trigger('detailExpand', [ + state('collapsed,void', style({height: '0px', minHeight: '0'})), + state('expanded', style({height: '*'})), + transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')), + ]), + ], +}) +export class InventorySlotEditorComponent implements OnInit{ + + @Input() character: Character | undefined + @Input() itemgroups: ItemGroup[] = [] + displayedColumns: string[] = ['name','combinable', 'edit', 'delete'] + columnsToDisplayWithExpand = [...this.displayedColumns, 'expand']; + dataSource: MatTableDataSource = new MatTableDataSource(); + + expandedSlot: InventorySlot | null = null + editedSlot: InventorySlot | null = null + + constructor(private dialog: MatDialog) { + } + + ngOnInit() { + this.dataSource.data = this.character!.inventorySlots; + } + + addInventorySlot() { + this.editedSlot = new InventorySlot("New Inventory Slot"); + this.character!.addInventorySlot(this.editedSlot); + this.dataSource.data = this.character!.inventorySlots; + } + + editInventorySlot(inventorySlot: InventorySlot) { + this.editedSlot = inventorySlot + } + + deleteInventorySlot(inventorySlot: InventorySlot) { + this.character!.removeInventorySlot(inventorySlot); + this.dataSource.data = this.character!.inventorySlots; + } + + finishEditing() { + this.editedSlot = null; + } +} diff --git a/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-creator/requiered-inheritances-creator.component.html b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-creator/requiered-inheritances-creator.component.html new file mode 100644 index 0000000..191b7b9 --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-creator/requiered-inheritances-creator.component.html @@ -0,0 +1,13 @@ +

Add Itemgroup Requierement

+ + + Select Itemgroup as Requierement + + {{option.componentName}} + + + + + + + diff --git a/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-creator/requiered-inheritances-creator.component.scss b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-creator/requiered-inheritances-creator.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-creator/requiered-inheritances-creator.component.spec.ts b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-creator/requiered-inheritances-creator.component.spec.ts new file mode 100644 index 0000000..269a5ac --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-creator/requiered-inheritances-creator.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { RequieredInheritancesCreatorComponent } from './requiered-inheritances-creator.component'; + +describe('RequieredInheritancesCreatorComponent', () => { + let component: RequieredInheritancesCreatorComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [RequieredInheritancesCreatorComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(RequieredInheritancesCreatorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-creator/requiered-inheritances-creator.component.ts b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-creator/requiered-inheritances-creator.component.ts new file mode 100644 index 0000000..498d983 --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-creator/requiered-inheritances-creator.component.ts @@ -0,0 +1,28 @@ +import {Component, Inject} from '@angular/core'; +import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; +import {ItemGroup} from "../../../../../project/game-model/inventory/ItemGroup"; +import {FormControl, Validators} from "@angular/forms"; + +@Component({ + selector: 'app-requiered-inheritances-creator', + templateUrl: './requiered-inheritances-creator.component.html', + styleUrl: './requiered-inheritances-creator.component.scss' +}) +export class RequieredInheritancesCreatorComponent { + + selectorCtrl = new FormControl('', Validators.required) + + constructor(@Inject(MAT_DIALOG_DATA) public itemgroups: ItemGroup[], + private dialogRef: MatDialogRef) { + } + + cancel() { + this.dialogRef.close(); + } + + submit() { + if(this.selectorCtrl.value != undefined) { + this.dialogRef.close(this.selectorCtrl.value); + } + } +} diff --git a/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-editor.component.html b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-editor.component.html new file mode 100644 index 0000000..5b724d2 --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-editor.component.html @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + +
Itemgroup Name{{requieredInheritence.componentName}}Itemgroup Description{{requieredInheritence.componentDescription}} + + + +
No reqiered Inheritence: Items of all Itemgroups can be added
diff --git a/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-editor.component.scss b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-editor.component.scss new file mode 100644 index 0000000..d8646c5 --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-editor.component.scss @@ -0,0 +1,3 @@ +.mat-column-delete { + width: 32px; +} diff --git a/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-editor.component.spec.ts b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-editor.component.spec.ts new file mode 100644 index 0000000..f98066b --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-editor.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { RequieredInheritancesEditorComponent } from './requiered-inheritances-editor.component'; + +describe('RequieredInheritancesEditorComponent', () => { + let component: RequieredInheritancesEditorComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [RequieredInheritancesEditorComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(RequieredInheritancesEditorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-editor.component.ts b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-editor.component.ts new file mode 100644 index 0000000..ced9f17 --- /dev/null +++ b/src/app/editor/character-editor/inventory-slot-editor/requiered-inheritances-editor/requiered-inheritances-editor.component.ts @@ -0,0 +1,49 @@ +import {Component, Input, OnInit} from '@angular/core'; +import {InventorySlot} from "../../../../project/game-model/inventory/intentory-slots/InventorySlot"; +import {ItemGroup} from "../../../../project/game-model/inventory/ItemGroup"; +import {MatTableDataSource} from "@angular/material/table"; +import {MatDialog} from "@angular/material/dialog"; +import { + RequieredInheritancesCreatorComponent +} from "./requiered-inheritances-creator/requiered-inheritances-creator.component"; + +@Component({ + selector: 'app-requiered-inheritances-editor', + templateUrl: './requiered-inheritances-editor.component.html', + styleUrl: './requiered-inheritances-editor.component.scss' +}) +export class RequieredInheritancesEditorComponent implements OnInit{ + + @Input() inventorySlot: InventorySlot | undefined + @Input() itemgroups: ItemGroup[] = [] + + datasource: MatTableDataSource = new MatTableDataSource(); + displayedColumns: string[] = ['itemgroupName', 'itemgroupDescription', 'delete'] + + constructor(private dialog: MatDialog) { + } + + ngOnInit() { + this.datasource.data = this.inventorySlot!.requiredInheritances; + } + + addInheritance() { + const dialogRef = this.dialog.open(RequieredInheritancesCreatorComponent, { + data: this.itemgroups, + width: "400px" + }) + + dialogRef.afterClosed().subscribe(res => { + if(res != undefined) { + console.log("Added") + this.inventorySlot!.addRequieredInheritence(res); + this.datasource.data = this.inventorySlot!.requiredInheritances; + } + }) + } + + deleteRequieredInheritence(requieredInheritence: ItemGroup) { + this.inventorySlot!.removeRequieredInheritence(requieredInheritence) + this.datasource.data = this.inventorySlot!.requiredInheritances; + } +} diff --git a/src/app/project/game-model/characters/Character.ts b/src/app/project/game-model/characters/Character.ts index 51ec902..b787090 100644 --- a/src/app/project/game-model/characters/Character.ts +++ b/src/app/project/game-model/characters/Character.ts @@ -7,19 +7,41 @@ import {SimpleTemplateGamesystem} from "../templates/simpleGamesystem/SimpleTemp import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem"; import {ProductGamesystem} from "../gamesystems/ProductGamesystem"; import {CharacterRelation} from "./CharacterRelation"; +import {InventorySlot} from "../inventory/intentory-slots/InventorySlot"; +import {Tupel} from "../../../shared/Tupel"; export class Character extends ModelComponent implements TemplateElement { characterSpecificTemplateSystems: Gamesystem[] = [] - characterRelations: CharacterRelation[] = [] - characterRelationGamesystems: Gamesystem[] = [] + inventorySlots: InventorySlot[] = [] + combinableInventorySlots: Tupel[] = [] constructor(componentName: string, componentDescription: string) { 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) { + if(this.combinableInventorySlots.find(tupel => tupel.value00 === combinedSlot.value00 && tupel.value01 === combinedSlot.value01) != undefined) { + this.combinableInventorySlots.push(combinedSlot); + } + } + + removeCombinedInventorySlot(combinedSlot: Tupel) { + this.combinableInventorySlots = this.combinableInventorySlots.filter(slots => slots.value00 != combinedSlot.value00 && slots.value01 != combinedSlot.value01); + } + addCharacterSpecificSimpleTemplatesystem(gamesystem: Gamesystem, recursiveCall: boolean = false) { if(!this.isTemplateSystemCharacterSpecific(gamesystem.componentName)) { if(gamesystem instanceof SimpleTemplateGamesystem) { @@ -65,9 +87,6 @@ export class Character extends ModelComponent implements TemplateElement { this.addAsymetricCharacterRelationGamesystem(gamesystem.parentGamesystem, true) } - } else { - console.log("Was already added") - console.log(this) } } diff --git a/src/app/project/game-model/inventory/intentory-slots/InventoryCharacteristic.ts b/src/app/project/game-model/inventory/intentory-slots/InventoryCharacteristic.ts new file mode 100644 index 0000000..fbfb650 --- /dev/null +++ b/src/app/project/game-model/inventory/intentory-slots/InventoryCharacteristic.ts @@ -0,0 +1,16 @@ +import {ItemGroupCharacteristic} from "../ItemgroupCharacteristic"; + +export class InventoryCharacteristic { + increasingCharacteristic: ItemGroupCharacteristic | null + decreasingCharacteristic: ItemGroupCharacteristic | null + + + constructor(increasingCharacteristic: ItemGroupCharacteristic | null, decreasingCharacteristic: ItemGroupCharacteristic | null) { + this.increasingCharacteristic = increasingCharacteristic; + this.decreasingCharacteristic = decreasingCharacteristic; + } + + isValid() { + return this.increasingCharacteristic != null && this.decreasingCharacteristic != null; + } +} diff --git a/src/app/project/game-model/inventory/intentory-slots/InventorySlot.ts b/src/app/project/game-model/inventory/intentory-slots/InventorySlot.ts new file mode 100644 index 0000000..a588f11 --- /dev/null +++ b/src/app/project/game-model/inventory/intentory-slots/InventorySlot.ts @@ -0,0 +1,34 @@ +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 + combinable: boolean = false; + + + constructor(slotName: string) { + this.slotName = slotName; + } + + addSlotCharacteristic(slotCharacteristic: InventoryCharacteristic) { + const found = this.slotCharacteristics.find(characteristiic => characteristiic.increasingCharacteristic === slotCharacteristic.increasingCharacteristic + && characteristiic.decreasingCharacteristic === slotCharacteristic.decreasingCharacteristic) + if(found == undefined) { + this.slotCharacteristics.push(slotCharacteristic); + } + } + + addRequieredInheritence(itemgroup: ItemGroup) { + if(this.requiredInheritances.find(group => group.componentName === itemgroup.componentName) == undefined) { + this.requiredInheritances.push(itemgroup); + } + } + + removeRequieredInheritence(itemgroup: ItemGroup) { + this.requiredInheritances = this.requiredInheritances.filter(group => group.componentName !== itemgroup.componentName) + } +} diff --git a/src/app/project/parser/characterParser/CharacterParser.ts b/src/app/project/parser/characterParser/CharacterParser.ts index 6472cb1..f868942 100644 --- a/src/app/project/parser/characterParser/CharacterParser.ts +++ b/src/app/project/parser/characterParser/CharacterParser.ts @@ -7,8 +7,9 @@ import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {SimpleTemplateState} from "../../game-model/templates/simpleGamesystem/SimpleTemplateState"; import {SimpleTemplateTransition} from "../../game-model/templates/simpleGamesystem/SimpleTemplateTransition"; import {CharacterRelation} from "../../game-model/characters/CharacterRelation"; -import {load} from "@angular-devkit/build-angular/src/utils/server-rendering/esm-in-memory-loader/loader-hooks"; -import {Gamesystem} from "../../game-model/gamesystems/Gamesystem"; +import {InventorySlotParser} from "./InventorySlotParser"; +import {ItemGroupCharacteristic} from "../../game-model/inventory/ItemgroupCharacteristic"; +import {ItemGroup} from "../../game-model/inventory/ItemGroup"; export class CharacterParser { @@ -17,12 +18,14 @@ export class CharacterParser { characterRelationSpecificGamesystems: SimpleTemplateGamesystem[] scriptAccountConditionParser: ScriptAccountConditionParser scriptAccountActionParser: ScriptAccountActionParser + inventorySlotParser: InventorySlotParser - constructor(characterSpecificGamesystems: SimpleTemplateGamesystem[], characterRelationSpecificGamesystems: SimpleTemplateGamesystem[], scriptAccounts: ScriptAccount[]) { + constructor(characterSpecificGamesystems: SimpleTemplateGamesystem[], characterRelationSpecificGamesystems: SimpleTemplateGamesystem[], scriptAccounts: ScriptAccount[], characteristics: ItemGroupCharacteristic[], itemgroups: ItemGroup[]) { this.characterSpecificGamesystems = characterSpecificGamesystems; this.characterRelationSpecificGamesystems = characterRelationSpecificGamesystems; this.scriptAccountActionParser = new ScriptAccountActionParser(scriptAccounts); this.scriptAccountConditionParser = new ScriptAccountConditionParser(scriptAccounts) + this.inventorySlotParser = new InventorySlotParser(characteristics, itemgroups); } @@ -46,6 +49,8 @@ export class CharacterParser { const characterRelationGamesystems = this.parseCharacterSpecificGamesystems(character, characterData.characterRelationGamesystems, this.characterRelationSpecificGamesystems) characterRelationGamesystems.forEach(gamesystem => character.addAsymetricCharacterRelationGamesystem(gamesystem)) + + character.inventorySlots = this.inventorySlotParser.parseInventorySlots(characterData.inventorySlots); return character; } diff --git a/src/app/project/parser/characterParser/InventorySlotParser.ts b/src/app/project/parser/characterParser/InventorySlotParser.ts new file mode 100644 index 0000000..22b4041 --- /dev/null +++ b/src/app/project/parser/characterParser/InventorySlotParser.ts @@ -0,0 +1,66 @@ +import {ItemGroupCharacteristic} from "../../game-model/inventory/ItemgroupCharacteristic"; +import {ItemGroup} from "../../game-model/inventory/ItemGroup"; +import {InventorySlot} from "../../game-model/inventory/intentory-slots/InventorySlot"; +import {InventorySlotSerializer} from "../../serializer/InventorySlotSerializer"; +import {InventoryCharacteristic} from "../../game-model/inventory/intentory-slots/InventoryCharacteristic"; + +export class InventorySlotParser { + private parsedCharacteristics: ItemGroupCharacteristic[] + private parsedItemgroups: ItemGroup[] + + + constructor(parsedCharacteristics: ItemGroupCharacteristic[], parsedItemgroups: ItemGroup[]) { + this.parsedCharacteristics = parsedCharacteristics; + this.parsedItemgroups = parsedItemgroups; + } + + parseInventorySlots(inventorySlotData: any): InventorySlot[] { + const result: InventorySlot[] = [] + for(let i=0; i characteristic.characteristicName === characteristicName); + } + + private findReferencedItemgroup(groupName: string) { + return this.parsedItemgroups.find(group => group.componentName === groupName); + } +} diff --git a/src/app/project/parser/itemParser/ItemgroupParser.ts b/src/app/project/parser/itemParser/ItemgroupParser.ts index fb18e77..3da0cd2 100644 --- a/src/app/project/parser/itemParser/ItemgroupParser.ts +++ b/src/app/project/parser/itemParser/ItemgroupParser.ts @@ -9,6 +9,7 @@ export class ItemgroupParser { private parsedItemgroups: ItemGroup[] = [] private topParsedItemgroups: ItemGroup[] = [] + private parsedCharacteristics: ItemGroupCharacteristic[] = [] parseItemgroups(storeComponents: StoreComponent[]) { const topologicalSort = this.topologicalSort(storeComponents); @@ -81,6 +82,7 @@ export class ItemgroupParser { const characteristic = new ItemGroupCharacteristic(name, description, itemgroup); characteristic.itemgroup.addItemgroupCharacteristic(characteristic); + this.parsedCharacteristics.push(characteristic) return characteristic; } @@ -91,4 +93,8 @@ export class ItemgroupParser { getParsedItemgroups() { return this.parsedItemgroups; } + + getCharacteristics() { + return this.parsedCharacteristics; + } } diff --git a/src/app/project/serializer/CharacterSerializer.ts b/src/app/project/serializer/CharacterSerializer.ts index 56dcff2..e1021e2 100644 --- a/src/app/project/serializer/CharacterSerializer.ts +++ b/src/app/project/serializer/CharacterSerializer.ts @@ -4,6 +4,8 @@ import {SerializeConstants} from "./SerializeConstants"; import {ModelComponentType} from "../game-model/ModelComponentType"; import {SimpleTemplateGamesystem} from "../game-model/templates/simpleGamesystem/SimpleTemplateGamesystem"; import {Gamesystem} from "../game-model/gamesystems/Gamesystem"; +import {ItemGroup} from "../game-model/inventory/ItemGroup"; +import {InventorySlotSerializer} from "./InventorySlotSerializer"; export class CharacterSerializer { @@ -19,7 +21,6 @@ export class CharacterSerializer { const fileName = character.componentName const templateGamesystemBackup = character.characterSpecificTemplateSystems.concat(); character.characterSpecificTemplateSystems = character.characterSpecificTemplateSystems.filter(system => system instanceof SimpleTemplateGamesystem) - console.log("Templatesystem: ", character.characterSpecificTemplateSystems) const jsonString = JSON.stringify(character, (key, value) => { if(value instanceof Gamesystem) { return { @@ -29,14 +30,15 @@ export class CharacterSerializer { } } + if(key == 'inventorySlots') { + return InventorySlotSerializer.serializeInventorySlots(value) + } + if(key === 'scriptAccount') { return value.componentName } if(key === 'conditionMap' || key === 'actionMap' || key === 'initialMap') { - if(key === 'initialMap') { - console.log(value) - } if(value.get(character) == undefined) { return [] } @@ -54,6 +56,8 @@ export class CharacterSerializer { } }, SerializeConstants.JSON_INDENT) + console.log(jsonString) + character.characterSpecificTemplateSystems = templateGamesystemBackup return new StoreComponent(jsonString, fileName, ModelComponentType.CHARACTER); } diff --git a/src/app/project/serializer/InventorySlotSerializer.ts b/src/app/project/serializer/InventorySlotSerializer.ts new file mode 100644 index 0000000..739d260 --- /dev/null +++ b/src/app/project/serializer/InventorySlotSerializer.ts @@ -0,0 +1,24 @@ +import {InventorySlot} from "../game-model/inventory/intentory-slots/InventorySlot"; + +export class InventorySlotSerializer { + + private static ignoredKeys: string[] = [''] + + public static serializeInventorySlots(inventorySlots: InventorySlot[]) { + return inventorySlots.map(inventorySlot => { + return { + slotName: inventorySlot.slotName, + slotCharacteristics: inventorySlot.slotCharacteristics.map(slotCharacteristic => { + return { + increasingCharacteristic: slotCharacteristic.increasingCharacteristic!.characteristicName, + decreasingCharacteristic: slotCharacteristic.decreasingCharacteristic!.characteristicName + } + }), + requiredInheritances: inventorySlot.requiredInheritances.map(itemgroup => { + return itemgroup.componentName + }), + combinable: inventorySlot.combinable + } + }) + } +} diff --git a/testModel/characters/Astrid Hofferson.json b/testModel/characters/Astrid Hofferson.json index 64ad8a6..1c8abed 100644 --- a/testModel/characters/Astrid Hofferson.json +++ b/testModel/characters/Astrid Hofferson.json @@ -66,5 +66,7 @@ "generateIsolatedStates": true, "symmetric": true } - ] + ], + "inventorySlots": [], + "combinableInventorySlots": [] } \ No newline at end of file diff --git a/testModel/characters/Hicks Haddock.json b/testModel/characters/Hicks Haddock.json index bfb5c9c..b3f515d 100644 --- a/testModel/characters/Hicks Haddock.json +++ b/testModel/characters/Hicks Haddock.json @@ -66,5 +66,27 @@ "generateIsolatedStates": true, "symmetric": true } - ] + ], + "inventorySlots": [ + { + "slotName": "Linke Hand", + "slotCharacteristics": [ + { + "increasingCharacteristic": "Test0", + "decreasingCharacteristic": "Test0" + } + ], + "requiredInheritances": [ + "Clothing" + ], + "combinable": true + }, + { + "slotName": "Rechte Hand", + "slotCharacteristics": [], + "requiredInheritances": [], + "combinable": true + } + ], + "combinableInventorySlots": [] } \ No newline at end of file