refactor-scriptaccount-action-editor #52

Merged
sebastian merged 4 commits from refactor-scriptaccount-action-editor into character-interactions 2024-06-15 14:04:53 +02:00
3 changed files with 41 additions and 37 deletions
Showing only changes of commit e8e3c83b45 - Show all commits

View File

@ -1,4 +1,4 @@
import {Component, Input, OnInit} from '@angular/core'; import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {MatTableDataSource} from "@angular/material/table"; import {MatTableDataSource} from "@angular/material/table";
import {ScriptAccount} from "../../../project/game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "../../../project/game-model/scriptAccounts/ScriptAccount";
import {Transition} from "../../../project/game-model/gamesystems/transitions/Transition"; import {Transition} from "../../../project/game-model/gamesystems/transitions/Transition";
@ -7,6 +7,7 @@ import {TemplateElement} from "../../../project/game-model/templates/TemplateEle
import { import {
SimpleTemplateTransition SimpleTemplateTransition
} from "../../../project/game-model/templates/simpleGamesystem/SimpleTemplateTransition"; } from "../../../project/game-model/templates/simpleGamesystem/SimpleTemplateTransition";
import {ScriptAccountCondition} from "../../../project/game-model/gamesystems/conditions/ScriptAccountCondition";
@Component({ @Component({
selector: 'app-scriptaccount-action-editor', selector: 'app-scriptaccount-action-editor',
@ -14,10 +15,11 @@ import {
styleUrl: './scriptaccount-action-editor.component.scss' styleUrl: './scriptaccount-action-editor.component.scss'
}) })
export class ScriptaccountActionEditorComponent implements OnInit{ export class ScriptaccountActionEditorComponent implements OnInit{
@Input() transition: Transition<any> | undefined
@Input() scriptAccounts: ScriptAccount[] = [] @Input() scriptAccounts: ScriptAccount[] = []
@Input() enableEditing: boolean = false; @Input() enableEditing: boolean = false;
@Input() templateElement: TemplateElement | undefined @Input() actions: ScriptAccountAction[] = []
@Output() onAddAction: EventEmitter<ScriptAccountAction> = new EventEmitter<ScriptAccountAction>();
@Output() onRemoveAction: EventEmitter<ScriptAccountAction> = new EventEmitter<ScriptAccountAction>();
dataSource: MatTableDataSource<ScriptAccountAction> = new MatTableDataSource(); dataSource: MatTableDataSource<ScriptAccountAction> = new MatTableDataSource();
displayedColumns: string[] = ['scriptAccount', "valueChange", 'edit', 'delete']; displayedColumns: string[] = ['scriptAccount', "valueChange", 'edit', 'delete'];
@ -26,7 +28,7 @@ export class ScriptaccountActionEditorComponent implements OnInit{
addedAction: ScriptAccountAction | undefined addedAction: ScriptAccountAction | undefined
ngOnInit() { ngOnInit() {
this.dataSource.data = this.getDisplayedActions() this.dataSource.data = this.actions
@ -48,42 +50,15 @@ export class ScriptaccountActionEditorComponent implements OnInit{
finishEditing() { finishEditing() {
if(this.addedAction != undefined && this.addedAction.scriptAccount.componentName !== '') { if(this.addedAction != undefined && this.addedAction.scriptAccount.componentName !== '') {
if(this.templateElement != undefined && this.transition instanceof SimpleTemplateTransition) { this.onAddAction.emit(this.addedAction);
if(this.transition.actionMap.has(this.templateElement!)) {
this.transition.actionMap.get(this.templateElement!)!.push(this.addedAction)
} else {
this.transition.actionMap.set(this.templateElement!, [this.addedAction])
}
} else {
this.transition?.addScriptAccountAction(this.addedAction)
}
this.dataSource.data = this.getDisplayedActions();
this.addedAction = undefined; this.addedAction = undefined;
} }
this.editedAction = undefined; this.editedAction = undefined;
} }
getDisplayedActions(): ScriptAccountAction[] {
if(this.templateElement == undefined) {
return this.transition!.scriptAccountActions.map(action => action);
} else if(this.transition instanceof SimpleTemplateTransition) {
return this.transition!.actionMap.get(this.templateElement)!
} else {
return []
}
}
deleteAction(action: ScriptAccountAction) { deleteAction(deletedAction: ScriptAccountAction) {
if(this.templateElement != undefined && this.transition instanceof SimpleTemplateTransition && this.transition.actionMap.has(this.templateElement!)) { this.dataSource.data = this.dataSource.data.filter(action => action !== deletedAction);
const updatedAction = this.transition.actionMap.get(this.templateElement)!.filter(currentAction => this.onRemoveAction.emit(deletedAction);
currentAction.scriptAccount !== action.scriptAccount)
this.transition.actionMap.set(this.templateElement!, updatedAction)
} else {
this.transition!.removeScriptAccountAction(action.scriptAccount)
}
this.dataSource.data = this.getDisplayedActions()
} }
} }

View File

@ -42,7 +42,8 @@
[@detailExpand]="element == expandedElement ? 'expanded' : 'collapsed'"> [@detailExpand]="element == expandedElement ? 'expanded' : 'collapsed'">
<div class="condition-action-container"> <div class="condition-action-container">
<div class="action-container"> <div class="action-container">
<app-scriptaccount-action-editor [templateElement]="templateElement" [transition]="element" [scriptAccounts]="scriptAccounts" [enableEditing]="true"></app-scriptaccount-action-editor> <app-scriptaccount-action-editor [actions]="getDisplayedActions(element)" [scriptAccounts]="scriptAccounts" [enableEditing]="true"
(onAddAction)="onAddAction(element, $event)" (onRemoveAction)="onDeleteAction(element, $event)"></app-scriptaccount-action-editor>
</div> </div>
<div class="condition-container"> <div class="condition-container">
<app-scriptaccount-condition-editor [conditions]="getDisplayedConditions(element)" [scriptAccounts]="scriptAccounts" [enableEditiong]="true" <app-scriptaccount-condition-editor [conditions]="getDisplayedConditions(element)" [scriptAccounts]="scriptAccounts" [enableEditiong]="true"

View File

@ -12,6 +12,7 @@ import {TemplateElement} from "../../../../project/game-model/templates/Template
import { import {
SimpleTemplateTransition SimpleTemplateTransition
} from "../../../../project/game-model/templates/simpleGamesystem/SimpleTemplateTransition"; } from "../../../../project/game-model/templates/simpleGamesystem/SimpleTemplateTransition";
import {ScriptAccountAction} from "../../../../project/game-model/gamesystems/actions/ScriptAccountAction";
@Component({ @Component({
selector: 'app-simple-transition-editor', selector: 'app-simple-transition-editor',
templateUrl: './simple-transition-editor.component.html', templateUrl: './simple-transition-editor.component.html',
@ -102,7 +103,6 @@ export class SimpleTransitionEditorComponent implements OnInit {
} else { } else {
transition.addScriptAccountCondition(condition); transition.addScriptAccountCondition(condition);
} }
} }
deleteCondition(trasition: SimpleTransition, condition: ScriptAccountCondition) { deleteCondition(trasition: SimpleTransition, condition: ScriptAccountCondition) {
@ -126,4 +126,32 @@ export class SimpleTransitionEditorComponent implements OnInit {
return []; return [];
} }
} }
onAddAction(transition: SimpleTransition, action: ScriptAccountAction) {
if(this.templateElement != undefined && transition instanceof SimpleTemplateTransition) {
transition.actionMap.get(this.templateElement)!.push(action)
} else {
transition.addScriptAccountAction(action);
}
}
onDeleteAction(transition: SimpleTransition, action: ScriptAccountAction) {
if(this.templateElement != undefined && transition instanceof SimpleTemplateTransition) {
let updatedActions = transition.actionMap.get(this.templateElement)!
updatedActions = updatedActions.filter(currentAction => action.scriptAccount !== currentAction.scriptAccount);
transition.actionMap.set(this.templateElement, updatedActions);
} else {
transition.removeScriptAccountAction(action.scriptAccount);
}
}
getDisplayedActions(transition: SimpleTransition) {
if(this.templateElement == undefined) {
return transition.scriptAccountActions
} else if(transition instanceof SimpleTemplateTransition) {
return transition.actionMap.get(this.templateElement)!
} else {
return [];
}
}
} }