diff --git a/src/app/editor/gamesystem-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.ts b/src/app/editor/gamesystem-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.ts index 2801dc2..e8ddc69 100644 --- a/src/app/editor/gamesystem-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.ts +++ b/src/app/editor/gamesystem-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.ts @@ -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 {ScriptAccount} from "../../../project/game-model/scriptAccounts/ScriptAccount"; import {Transition} from "../../../project/game-model/gamesystems/transitions/Transition"; @@ -7,6 +7,7 @@ import {TemplateElement} from "../../../project/game-model/templates/TemplateEle import { SimpleTemplateTransition } from "../../../project/game-model/templates/simpleGamesystem/SimpleTemplateTransition"; +import {ScriptAccountCondition} from "../../../project/game-model/gamesystems/conditions/ScriptAccountCondition"; @Component({ selector: 'app-scriptaccount-action-editor', @@ -14,10 +15,11 @@ import { styleUrl: './scriptaccount-action-editor.component.scss' }) export class ScriptaccountActionEditorComponent implements OnInit{ - @Input() transition: Transition | undefined @Input() scriptAccounts: ScriptAccount[] = [] @Input() enableEditing: boolean = false; - @Input() templateElement: TemplateElement | undefined + @Input() actions: ScriptAccountAction[] = [] + @Output() onAddAction: EventEmitter = new EventEmitter(); + @Output() onRemoveAction: EventEmitter = new EventEmitter(); dataSource: MatTableDataSource = new MatTableDataSource(); displayedColumns: string[] = ['scriptAccount', "valueChange", 'edit', 'delete']; @@ -26,7 +28,7 @@ export class ScriptaccountActionEditorComponent implements OnInit{ addedAction: ScriptAccountAction | undefined ngOnInit() { - this.dataSource.data = this.getDisplayedActions() + this.dataSource.data = this.actions @@ -48,42 +50,15 @@ export class ScriptaccountActionEditorComponent implements OnInit{ finishEditing() { if(this.addedAction != undefined && this.addedAction.scriptAccount.componentName !== '') { - if(this.templateElement != undefined && this.transition instanceof SimpleTemplateTransition) { - 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.onAddAction.emit(this.addedAction); this.addedAction = 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) { - if(this.templateElement != undefined && this.transition instanceof SimpleTemplateTransition && this.transition.actionMap.has(this.templateElement!)) { - const updatedAction = this.transition.actionMap.get(this.templateElement)!.filter(currentAction => - currentAction.scriptAccount !== action.scriptAccount) - this.transition.actionMap.set(this.templateElement!, updatedAction) - } else { - this.transition!.removeScriptAccountAction(action.scriptAccount) - } - - this.dataSource.data = this.getDisplayedActions() + deleteAction(deletedAction: ScriptAccountAction) { + this.dataSource.data = this.dataSource.data.filter(action => action !== deletedAction); + this.onRemoveAction.emit(deletedAction); } } diff --git a/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.html b/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.html index 7a57e18..ca299fe 100644 --- a/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.html +++ b/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.html @@ -42,7 +42,8 @@ [@detailExpand]="element == expandedElement ? 'expanded' : 'collapsed'">
- +
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 []; + } + } }