diff --git a/src/app/game-model/fs/parser/SimpleGamesystemParser.ts b/src/app/game-model/fs/parser/SimpleGamesystemParser.ts index 34b88ea..505d879 100644 --- a/src/app/game-model/fs/parser/SimpleGamesystemParser.ts +++ b/src/app/game-model/fs/parser/SimpleGamesystemParser.ts @@ -3,6 +3,7 @@ import {SimpleState} from "../../gamesystems/states/SimpleState"; import {SimpleTransition} from "../../gamesystems/transitions/SimpleTransition"; import {ScriptAccount} from "../../scriptAccounts/ScriptAccount"; import {ScriptAccountCondition} from "../../gamesystems/conditions/ScriptAccountCondition"; +import {ScriptAccountAction} from "../../gamesystems/actions/ScriptAccountAction"; export class SimpleGamesystemParser { @@ -10,7 +11,7 @@ export class SimpleGamesystemParser { const gamesystemName = jsonObject.componentName; const gamesystemDescription = jsonObject.componentDescription; const simpleStates = SimpleGamesystemParser.parseSimpleStates(jsonObject, scriptAccounts) - const simpleTransitions = SimpleGamesystemParser.parseSimpleTransitions(jsonObject, simpleStates); + const simpleTransitions = SimpleGamesystemParser.parseSimpleTransitions(jsonObject, simpleStates, scriptAccounts); const gamesystem = new SimpleGamesystem(gamesystemName, gamesystemDescription); gamesystem.states = simpleStates; @@ -41,7 +42,7 @@ export class SimpleGamesystemParser { - static parseSimpleTransitions(jsonObject: any, states: SimpleState[]): SimpleTransition[] { + static parseSimpleTransitions(jsonObject: any, states: SimpleState[], scriptAccounts: ScriptAccount[]): SimpleTransition[] { const transitions: SimpleTransition[] = []; for(let i=0; i state.stateLabel === startingStateLabel); const endingState = states.find(state => state.stateLabel === endingStateLabel); + const actions: ScriptAccountAction[] = [] + for(let j=0; j scriptAccount.componentName === scriptAccountName) + + if(referencedScriptAccount != undefined) { + const scriptAccountAction = new ScriptAccountAction(referencedScriptAccount!, jsonObject.transitions[i].scriptAccountActions[j].changingValue) + actions.push(scriptAccountAction) + } + } + + const conditions: ScriptAccountCondition[] = []; + for(let j=0; j scriptAccount.componentName === scriptAccountName) + + if(referencedScriptAccount != undefined) { + const minValue = jsonObject.transitions[i].scriptAccountConditions[j].minValue + const maxValue = jsonObject.transitions[i].scriptAccountConditions[j].maxValue + + const scriptAccountCondition = + ScriptAccountCondition.constructScriptAccountCondition(referencedScriptAccount, minValue, maxValue) + + conditions.push(scriptAccountCondition!) + } + } + if(startingState != undefined && endingState != undefined) { - transitions.push(new SimpleTransition(startingState, endingState)); + const simpleTransition = new SimpleTransition(startingState, endingState); + simpleTransition.scriptAccountActions = actions; + simpleTransition.scriptAccountConditions = conditions; + + transitions.push(simpleTransition); } else { console.error("Starting or Ending State are not defined!", startingState, endingState) } diff --git a/testModel/gamesystems/Weather.json b/testModel/gamesystems/Weather.json index e6baf79..c7f2531 100644 --- a/testModel/gamesystems/Weather.json +++ b/testModel/gamesystems/Weather.json @@ -6,6 +6,7 @@ "initial": false, "conditions": [ { + "scriptAccount": "Temperature", "minValue": 0, "maxValue": "50" } @@ -17,6 +18,7 @@ "initial": false, "conditions": [ { + "scriptAccount": "Temperature", "minValue": "50", "maxValue": "75" } @@ -33,7 +35,13 @@ "scriptAccount": "Temperature" } ], - "scriptAccountConditions": [], + "scriptAccountConditions": [ + { + "scriptAccount": "Temperature", + "minValue": 0, + "maxValue": "10" + } + ], "startingState": "Sonnig", "endingState": "Wolkig" }