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

View File

@ -5,6 +5,7 @@ import {InventoryCondition} from "./condition/InventoryCondition";
import {GamesystemCondition} from "./condition/GamesystemCondition";
export abstract class AbstractInteraction {
sourceCharacter: Character
targetCharacter: Character | undefined
@ -30,7 +31,15 @@ export abstract class AbstractInteraction {
return this.conditions.filter(condition => condition instanceof InventoryCondition)
}
get gamesystemConditions() {
return this.conditions.filter(condition => condition instanceof GamesystemCondition)
get gamesystemConditions(): 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);
}
}