From 64786efce05d18b97c8a6cb522b123afccaa93c8 Mon Sep 17 00:00:00 2001 From: Sebastian Boeckelmann Date: Sat, 15 Jun 2024 14:44:20 +0200 Subject: [PATCH] Implement InventoryActions for Interactions --- src/app/app.module.ts | 4 +- ...haracter-interaction-editor.component.html | 4 +- .../item-action-editor.component.html | 65 +++++++++++ .../item-action-editor.component.scss | 3 + .../item-action-editor.component.spec.ts | 23 ++++ .../item-action-editor.component.ts | 109 ++++++++++++++++++ .../game-model/interactions/Interaction.ts | 4 + .../interactions/actions/InventoryAction.ts | 13 +++ .../actions/InventoryItemAction.ts | 17 ++- .../actions/InventoryItemgroupAction.ts | 19 +++ 10 files changed, 252 insertions(+), 9 deletions(-) create mode 100644 src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.html create mode 100644 src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.scss create mode 100644 src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.spec.ts create mode 100644 src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.ts create mode 100644 src/app/project/game-model/interactions/actions/InventoryAction.ts create mode 100644 src/app/project/game-model/interactions/actions/InventoryItemgroupAction.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 219130c..097fd05 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -119,6 +119,7 @@ import { import { ItemSelectorComponent } from "./editor/interaction-editor/conditions/item-condition-editor/item-selector/item-selector.component"; +import {ItemActionEditorComponent} from "./editor/interaction-editor/item-action-editor/item-action-editor.component"; // AoT requires an exported function for factories const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new TranslateHttpLoader(http, './assets/i18n/', '.json'); @@ -157,7 +158,8 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl CharacterInteractionEditorComponent, GamesystemConditionEditorComponent, ItemConditionEditorComponent, - ItemSelectorComponent + ItemSelectorComponent, + ItemActionEditorComponent ], imports: [ BrowserModule, diff --git a/src/app/editor/character-editor/character-interaction-editor/character-interaction-editor.component.html b/src/app/editor/character-editor/character-interaction-editor/character-interaction-editor.component.html index 76c23bf..122f207 100644 --- a/src/app/editor/character-editor/character-interaction-editor/character-interaction-editor.component.html +++ b/src/app/editor/character-editor/character-interaction-editor/character-interaction-editor.component.html @@ -129,10 +129,10 @@ > - + - +

Gamesystem Actions

diff --git a/src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.html b/src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.html new file mode 100644 index 0000000..57ed58c --- /dev/null +++ b/src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.html @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + +
{{group? 'Itemgroup':'Item'}} + @if(group) { + @if(action == editedAction) { + + Itemgroup + + {{itemgroup.componentName}} + + + } @else { +

+ {{actionAsItemgroupAction(action)!.itemgroup!.componentName}} +

+ } + } @else { + @if(action == editedAction) { + + } @else { +

+ {{actionAsItemAction(action)!.item!.componentName}} +

+ } + } +
Min + @if(action == editedAction) { + + Min Value + + + } @else { + {{action.valueChange}} + } + + + + + + + +
diff --git a/src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.scss b/src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.scss new file mode 100644 index 0000000..906202f --- /dev/null +++ b/src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.scss @@ -0,0 +1,3 @@ +.mat-column-edit, .mat-column-delete { + width: 32px; +} diff --git a/src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.spec.ts b/src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.spec.ts new file mode 100644 index 0000000..8b5fd9b --- /dev/null +++ b/src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ItemActionEditorComponent } from './item-action-editor.component'; + +describe('ItemActionEditorComponent', () => { + let component: ItemActionEditorComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ItemActionEditorComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(ItemActionEditorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.ts b/src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.ts new file mode 100644 index 0000000..5f84241 --- /dev/null +++ b/src/app/editor/interaction-editor/item-action-editor/item-action-editor.component.ts @@ -0,0 +1,109 @@ +import {Component, Input} from '@angular/core'; +import { + MatCell, + MatCellDef, + MatColumnDef, + MatHeaderCell, + MatHeaderRow, + MatHeaderRowDef, + MatRow, MatRowDef, MatTable, MatTableDataSource +} from "@angular/material/table"; +import {MatFormField, MatLabel} from "@angular/material/form-field"; +import {MatIcon} from "@angular/material/icon"; +import {MatIconButton} from "@angular/material/button"; +import {MatInput} from "@angular/material/input"; +import {MatOption} from "@angular/material/autocomplete"; +import {MatSelect} from "@angular/material/select"; +import {NgForOf, NgIf} from "@angular/common"; +import {ReactiveFormsModule} from "@angular/forms"; +import {AbstractInteraction} from "../../../project/game-model/interactions/AbstractInteraction"; +import {GameModel} from "../../../project/game-model/GameModel"; +import {InventoryCondition} from "../../../project/game-model/interactions/condition/InventoryCondition"; +import { + InventoryItemgroupCondition +} from "../../../project/game-model/interactions/condition/InventoryItemgroupCondition"; +import {CharacterDependency} from "../../../project/game-model/interactions/CharacterDependency"; +import {InventoryItemCondition} from "../../../project/game-model/interactions/condition/InventoryItemCondition"; +import {Item} from "../../../project/game-model/inventory/Item"; +import {Interaction} from "../../../project/game-model/interactions/Interaction"; +import {InventoryAction} from "../../../project/game-model/interactions/actions/InventoryAction"; +import {InventoryItemGroupAction} from "../../../project/game-model/interactions/actions/InventoryItemgroupAction"; +import {InventoryItemAction} from "../../../project/game-model/interactions/actions/InventoryItemAction"; + +@Component({ + selector: 'app-item-action-editor', + templateUrl: './item-action-editor.component.html', + styleUrl: './item-action-editor.component.scss' +}) +export class ItemActionEditorComponent { + + @Input() interaction: Interaction | undefined + @Input() gameModel: GameModel | undefined + @Input() group: boolean = false; + + actionDatasource: MatTableDataSource = new MatTableDataSource(); + displayedColumns: string[] = ["item", "delta", "edit", "delete"]; + editedAction: InventoryAction | undefined + addedAction: InventoryAction | undefined + + ngOnInit() { + this.actionDatasource.data = this.interaction!.inventoryActions; + } + + addAction() { + if(this.group) { + this.addedAction = new InventoryItemGroupAction(CharacterDependency.NONE, 0, undefined); + } else { + this.addedAction = new InventoryItemAction(CharacterDependency.NONE, 0, undefined); + } + + this.editedAction = this.addedAction; + + const displayedColumns = this.actionDatasource.data; + displayedColumns.push(this.addedAction); + this.actionDatasource.data = displayedColumns; + } + + editAction(action: InventoryAction) { + this.editedAction = action; + } + + finishEditing() { + if(this.editedAction == undefined) { + return; + } + + if(this.editedAction.validate()) { + if(this.addedAction != undefined) { + this.interaction!.addAction(this.addedAction); + this.addedAction = undefined; + } + this.editedAction = undefined; + } + } + + deleteAction(deletedAction: InventoryAction) { + this.interaction!.removeAction(deletedAction); + this.actionDatasource.data = this.actionDatasource.data.filter(action => action !== deletedAction); + } + + actionAsItemAction(action: InventoryAction) { + if(action instanceof InventoryItemAction) { + return action; + } else { + return undefined; + } + } + + actionAsItemgroupAction(action: InventoryAction) { + if(action instanceof InventoryItemGroupAction) { + return action; + } else { + return undefined; + } + } + + onSelectedItemChange(action: InventoryItemAction, item: Item) { + (action as InventoryItemAction).item = item; + } +} diff --git a/src/app/project/game-model/interactions/Interaction.ts b/src/app/project/game-model/interactions/Interaction.ts index cd89c73..84eec3e 100644 --- a/src/app/project/game-model/interactions/Interaction.ts +++ b/src/app/project/game-model/interactions/Interaction.ts @@ -5,6 +5,7 @@ import {AbstractInteraction} from "./AbstractInteraction"; import {ScriptAccountCondition} from "../gamesystems/conditions/ScriptAccountCondition"; import {ScriptAccountAction} from "../gamesystems/actions/ScriptAccountAction"; import {InventoryCondition} from "./condition/InventoryCondition"; +import {InventoryItemAction} from "./actions/InventoryItemAction"; export class Interaction extends AbstractInteraction{ @@ -41,6 +42,9 @@ export class Interaction extends AbstractInteraction{ return this.actions.filter(condition => condition instanceof ScriptAccountAction).map(condition => condition as ScriptAccountAction) } + get inventoryActions(): InventoryItemAction[] { + return this.actions.filter(action => action instanceof InventoryItemAction).map(action => action as InventoryItemAction); + } addAction(action: Action) { this.actions.push(action); diff --git a/src/app/project/game-model/interactions/actions/InventoryAction.ts b/src/app/project/game-model/interactions/actions/InventoryAction.ts new file mode 100644 index 0000000..b13e6d7 --- /dev/null +++ b/src/app/project/game-model/interactions/actions/InventoryAction.ts @@ -0,0 +1,13 @@ +import {Action} from "./Action"; +import {CharacterDependency} from "../CharacterDependency"; + +export abstract class InventoryAction extends Action { + valueChange: number; + + protected constructor(characterDependency: CharacterDependency, valueChange: number) { + super(characterDependency); + this.valueChange = valueChange; + } + + public abstract validate(): boolean; +} diff --git a/src/app/project/game-model/interactions/actions/InventoryItemAction.ts b/src/app/project/game-model/interactions/actions/InventoryItemAction.ts index 29b5d8f..6fde8eb 100644 --- a/src/app/project/game-model/interactions/actions/InventoryItemAction.ts +++ b/src/app/project/game-model/interactions/actions/InventoryItemAction.ts @@ -1,15 +1,20 @@ import {Action} from "./Action"; import {Item} from "../../inventory/Item"; import {CharacterDependency} from "../CharacterDependency"; +import {InventoryAction} from "./InventoryAction"; -export class InventoryItemAction extends Action { +export class InventoryItemAction extends InventoryAction { - item: Item - valueChange: number + item: Item | undefined - constructor(characterDependency: CharacterDependency, item: Item, valueChange: number) { - super(characterDependency); + + constructor(characterDependency: CharacterDependency, valueChange: number, item: Item | undefined) { + super(characterDependency, valueChange); this.item = item; - this.valueChange = valueChange; } + + validate(): boolean { + return this.item != undefined; + } + } diff --git a/src/app/project/game-model/interactions/actions/InventoryItemgroupAction.ts b/src/app/project/game-model/interactions/actions/InventoryItemgroupAction.ts new file mode 100644 index 0000000..0371351 --- /dev/null +++ b/src/app/project/game-model/interactions/actions/InventoryItemgroupAction.ts @@ -0,0 +1,19 @@ +import {Action} from "./Action"; +import {ItemGroup} from "../../inventory/ItemGroup"; +import {CharacterDependency} from "../CharacterDependency"; +import {InventoryAction} from "./InventoryAction"; + +export class InventoryItemGroupAction extends InventoryAction{ + itemgroup: ItemGroup | undefined + + + constructor(characterDependency: CharacterDependency, valueChange: number, itemgroup: ItemGroup | undefined) { + super(characterDependency, valueChange); + this.itemgroup = itemgroup; + } + + validate(): boolean { + return this.itemgroup != undefined; + } + +}