Provide interaction to GamesystemConditionEditor
All checks were successful
E2E Testing / test (push) Successful in 1m20s

This commit is contained in:
sebastian 2024-06-02 17:23:29 +02:00
parent 1ffc5c1ecf
commit 8c4d2ad5ca
3 changed files with 25 additions and 15 deletions

View File

@ -107,7 +107,7 @@
<p>Inventory Conditions</p> <p>Inventory Conditions</p>
</mat-tab> </mat-tab>
<mat-tab label="Gamesystem Conditions"> <mat-tab label="Gamesystem Conditions">
<app-gamesystem-condition-editor [gamesystemConditions]="element.gamesystemConditions" [gamesystems]="gameModel!.gamesystemsAsList" <app-gamesystem-condition-editor [intgeraction]="element" [gamesystems]="gameModel!.gamesystemsAsList"
></app-gamesystem-condition-editor> ></app-gamesystem-condition-editor>
</mat-tab> </mat-tab>
</mat-tab-group> </mat-tab-group>

View File

@ -1,9 +1,10 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; import {Component, Input, OnInit} from '@angular/core';
import {GamesystemCondition} from "../../../../project/game-model/interactions/condition/GamesystemCondition"; import {GamesystemCondition} from "../../../../project/game-model/interactions/condition/GamesystemCondition";
import {MatSnackBar} from "@angular/material/snack-bar"; import {MatSnackBar} from "@angular/material/snack-bar";
import {MatTableDataSource} from "@angular/material/table"; import {MatTableDataSource} from "@angular/material/table";
import {CharacterDependency} from "../../../../project/game-model/interactions/CharacterDependency"; import {CharacterDependency} from "../../../../project/game-model/interactions/CharacterDependency";
import {Gamesystem} from "../../../../project/game-model/gamesystems/Gamesystem"; import {Gamesystem} from "../../../../project/game-model/gamesystems/Gamesystem";
import {AbstractInteraction} from "../../../../project/game-model/interactions/AbstractInteraction";
@Component({ @Component({
selector: 'app-gamesystem-condition-editor', selector: 'app-gamesystem-condition-editor',
@ -12,10 +13,8 @@ import {Gamesystem} from "../../../../project/game-model/gamesystems/Gamesystem"
}) })
export class GamesystemConditionEditorComponent implements OnInit{ export class GamesystemConditionEditorComponent implements OnInit{
@Input() gamesystemConditions: GamesystemCondition[] = [] @Input() intgeraction: AbstractInteraction | undefined
@Input() gamesystems: Gamesystem<any, any>[] = [] @Input() gamesystems: Gamesystem<any, any>[] = []
@Output("onConditionUpdate") gamesytemConditionChangeEmitter: EventEmitter<GamesystemCondition> = new EventEmitter();
@Output("onConditionDelete") gamesystemConditionDeleteEmitter: EventEmitter<GamesystemCondition> = new EventEmitter();
editedCondition: GamesystemCondition | undefined editedCondition: GamesystemCondition | undefined
addedCondition: GamesystemCondition | undefined addedCondition: GamesystemCondition | undefined
@ -26,7 +25,7 @@ export class GamesystemConditionEditorComponent implements OnInit{
} }
ngOnInit() { ngOnInit() {
this.datasource.data = this.gamesystemConditions; this.datasource.data = this.intgeraction!.gamesystemConditions
} }
editCondition(condition: GamesystemCondition) { editCondition(condition: GamesystemCondition) {
@ -40,7 +39,7 @@ export class GamesystemConditionEditorComponent implements OnInit{
if(this.editedCondition!.validate()) { if(this.editedCondition!.validate()) {
if(this.editedCondition === this.addedCondition) { if(this.editedCondition === this.addedCondition) {
this.gamesytemConditionChangeEmitter.emit(this.editedCondition); this.intgeraction!.addConditon(this.addedCondition);
this.addedCondition = undefined this.addedCondition = undefined
} }
this.editedCondition = undefined; this.editedCondition = undefined;
@ -49,19 +48,21 @@ export class GamesystemConditionEditorComponent implements OnInit{
} }
} }
deleteCondition(condition: GamesystemCondition) { deleteCondition(deletedCondition: GamesystemCondition) {
this.gamesystemConditions = this.gamesystemConditions.filter(c => c !== condition); this.intgeraction!.removeCondition(deletedCondition);
this.datasource.data = this.gamesystemConditions; this.datasource.data = this.datasource.data.filter(condition => condition !== deletedCondition);
this.gamesystemConditionDeleteEmitter.emit(condition);
} }
addCondition() { addCondition() {
const condition = new GamesystemCondition(CharacterDependency.NONE, undefined, undefined); const condition = new GamesystemCondition(CharacterDependency.NONE, undefined, undefined);
this.gamesystemConditions.push(condition); const displayedConditions = this.datasource.data;
displayedConditions.push(condition);
this.editedCondition = condition; this.editedCondition = condition;
this.addedCondition = condition; this.addedCondition = condition;
this.datasource.data = this.gamesystemConditions; this.datasource.data = displayedConditions;
} }
protected readonly CharacterDependency = CharacterDependency; protected readonly CharacterDependency = CharacterDependency;

View File

@ -5,6 +5,7 @@ import {InventoryCondition} from "./condition/InventoryCondition";
import {GamesystemCondition} from "./condition/GamesystemCondition"; import {GamesystemCondition} from "./condition/GamesystemCondition";
export abstract class AbstractInteraction { export abstract class AbstractInteraction {
sourceCharacter: Character sourceCharacter: Character
targetCharacter: Character | undefined targetCharacter: Character | undefined
@ -30,7 +31,15 @@ export abstract class AbstractInteraction {
return this.conditions.filter(condition => condition instanceof InventoryCondition) return this.conditions.filter(condition => condition instanceof InventoryCondition)
} }
get gamesystemConditions() { get gamesystemConditions(): GamesystemCondition[] {
return this.conditions.filter(condition => condition instanceof GamesystemCondition) return this.conditions.filter(condition => condition instanceof GamesystemCondition).map(condition => condition as GamesystemCondition)
}
addConditon(addedCondition: Condition) {
this.conditions.push(addedCondition);
}
removeCondition(removedCondition: Condition) {
this.conditions = this.conditions.filter(condition => condition !== removedCondition);
} }
} }