issue-15 #21

Merged
sebastian merged 60 commits from issue-15 into main 2024-03-22 08:46:49 +01:00
2 changed files with 44 additions and 4 deletions
Showing only changes of commit 6d14328b9f - Show all commits

View File

@ -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<jsonObject.transitions.length; i++) {
const startingStateLabel = jsonObject.transitions[i].startingState;
@ -50,8 +51,39 @@ export class SimpleGamesystemParser {
const startingState = states.find(state => state.stateLabel === startingStateLabel);
const endingState = states.find(state => state.stateLabel === endingStateLabel);
const actions: ScriptAccountAction[] = []
for(let j=0; j<jsonObject.transitions[i].scriptAccountActions.length; j++) {
const scriptAccountName = jsonObject.transitions[i].scriptAccountActions[j].scriptAccount
const referencedScriptAccount = scriptAccounts.find(scriptAccount => 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<jsonObject.transitions[i].scriptAccountConditions.length; j++) {
const scriptAccountName = jsonObject.transitions[i].scriptAccountConditions[j].scriptAccount
const referencedScriptAccount = scriptAccounts.find(scriptAccount => 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)
}

View File

@ -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"
}