import {State} from "../states/State"; import {ScriptAccountAction} from "../actions/ScriptAccountAction"; import {ScriptAccount} from "../../scriptAccounts/ScriptAccount"; import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition"; export abstract class Transition> { startingState: S endingState: S scriptAccountActions: ScriptAccountAction[] = []; scriptAccountConditions: ScriptAccountCondition[] = []; constructor(startingState: S, endingState: S) { this.startingState = startingState; this.endingState = endingState; this.startingState.addOutgoingTransition(this); this.endingState.addIncomingTransition(this); } addScriptAccountAction(scriptAccountAction: ScriptAccountAction) { if(scriptAccountAction != undefined) { const searchedScriptAccount = this.findScriptAccountActionByScriptAccount(scriptAccountAction.scriptAccount); if(searchedScriptAccount == undefined) { this.scriptAccountActions.push(scriptAccountAction) } else { searchedScriptAccount.changingValue += scriptAccountAction.changingValue; } } } removeScriptAccountAction(scriptAccount: ScriptAccount) { if(scriptAccount != undefined) { this.scriptAccountActions = this.scriptAccountActions.filter(sA => sA.scriptAccount.componentName !== scriptAccount.componentName); } } findScriptAccountActionByScriptAccount(scriptAccount: ScriptAccount) { return this.scriptAccountActions.find(sA => sA.scriptAccount.componentName === scriptAccount.componentName); } addScriptAccountCondition(scriptAccountCondition: ScriptAccountCondition) { const existingScriptAccountCondition = this.findScriptAccountConditionByScriptAccount(scriptAccountCondition.scriptAccount); if(existingScriptAccountCondition != undefined) { if(!existingScriptAccountCondition.isContradicting(scriptAccountCondition)) { existingScriptAccountCondition.extendCondition(scriptAccountCondition) } } else { this.scriptAccountConditions.push(scriptAccountCondition); } } removeScriptAccountCondition(scriptAccount: ScriptAccount) { this.scriptAccountConditions = this.scriptAccountConditions.filter(condition => condition.scriptAccount !== scriptAccount); } findScriptAccountConditionByScriptAccount(scriptAccount: ScriptAccount): ScriptAccountCondition | undefined { return this.scriptAccountConditions.find(condition => condition.scriptAccount === scriptAccount); } }