refactor-scriptaccount-action-editor #52
@ -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<any> | undefined
|
||||
@Input() scriptAccounts: ScriptAccount[] = []
|
||||
@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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,8 @@
|
||||
[@detailExpand]="element == expandedElement ? 'expanded' : 'collapsed'">
|
||||
<div class="condition-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 class="condition-container">
|
||||
<app-scriptaccount-condition-editor [conditions]="getDisplayedConditions(element)" [scriptAccounts]="scriptAccounts" [enableEditiong]="true"
|
||||
|
@ -12,6 +12,7 @@ import {TemplateElement} from "../../../../project/game-model/templates/Template
|
||||
import {
|
||||
SimpleTemplateTransition
|
||||
} from "../../../../project/game-model/templates/simpleGamesystem/SimpleTemplateTransition";
|
||||
import {ScriptAccountAction} from "../../../../project/game-model/gamesystems/actions/ScriptAccountAction";
|
||||
@Component({
|
||||
selector: 'app-simple-transition-editor',
|
||||
templateUrl: './simple-transition-editor.component.html',
|
||||
@ -102,7 +103,6 @@ export class SimpleTransitionEditorComponent implements OnInit {
|
||||
} else {
|
||||
transition.addScriptAccountCondition(condition);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
deleteCondition(trasition: SimpleTransition, condition: ScriptAccountCondition) {
|
||||
@ -126,4 +126,32 @@ export class SimpleTransitionEditorComponent implements OnInit {
|
||||
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 [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user