Load ScriptAccountActions
All checks were successful
E2E Testing / test (push) Successful in 1m39s

This commit is contained in:
Sebastian Böckelmann 2024-03-22 08:34:54 +01:00
parent 679cb70487
commit 2416e226fc
4 changed files with 78 additions and 12 deletions

View File

@ -0,0 +1,36 @@
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {ScriptAccountCondition} from "../../game-model/gamesystems/conditions/ScriptAccountCondition";
import {ScriptAccountAction} from "../../game-model/gamesystems/actions/ScriptAccountAction";
export class ScriptAccountActionParser {
private scriptAccounts: ScriptAccount[]
constructor(scriptAccounts: ScriptAccount[]) {
this.scriptAccounts = scriptAccounts;
}
parseActions(actionData: any) {
const actions: ScriptAccountAction[] = []
for(let i=0; i<actionData.length; i++) {
const parsedCondition = this.parseSingleAction(actionData[i]);
if(parsedCondition != undefined) {
actions.push(parsedCondition)
}
}
return actions
}
private parseSingleAction(actionData: any) {
const referencedScriptAccount = this.findScriptAccountByName(actionData.scriptAccount);
if(referencedScriptAccount != undefined) {
return new ScriptAccountAction(referencedScriptAccount, actionData.changingValue);
} else {
return undefined;
}
}
private findScriptAccountByName(scriptAccountName: string) {
return this.scriptAccounts.find(scriptAccount => scriptAccount.componentName === scriptAccountName);
}
}

View File

@ -2,17 +2,20 @@ import {SimpleState} from "../../game-model/gamesystems/states/SimpleState";
import {ScriptAccountConditionParser} from "./ScriptAccountConditionParser"; import {ScriptAccountConditionParser} from "./ScriptAccountConditionParser";
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {SimpleTransition} from "../../game-model/gamesystems/transitions/SimpleTransition"; import {SimpleTransition} from "../../game-model/gamesystems/transitions/SimpleTransition";
import {ScriptAccountActionParser} from "./ScriptAccountActionParser";
export class TransitionParser { export class TransitionParser {
private states: SimpleState[] private states: SimpleState[]
private conditionParser: ScriptAccountConditionParser private conditionParser: ScriptAccountConditionParser
private actionParser: ScriptAccountActionParser
constructor(states: SimpleState[], scriptAccounts: ScriptAccount[]) { constructor(states: SimpleState[], scriptAccounts: ScriptAccount[]) {
this.states = states; this.states = states;
this.conditionParser = new ScriptAccountConditionParser(scriptAccounts); this.conditionParser = new ScriptAccountConditionParser(scriptAccounts);
this.actionParser = new ScriptAccountActionParser(scriptAccounts)
} }
public parseTransitions(transitionData: any): SimpleTransition[] { public parseTransitions(transitionData: any): SimpleTransition[] {
@ -36,6 +39,7 @@ export class TransitionParser {
const simpleTransition = new SimpleTransition(startingState, endingState) const simpleTransition = new SimpleTransition(startingState, endingState)
simpleTransition.scriptAccountConditions = this.conditionParser.parseStoredConditions(transitionData.scriptAccountConditions) simpleTransition.scriptAccountConditions = this.conditionParser.parseStoredConditions(transitionData.scriptAccountConditions)
simpleTransition.scriptAccountActions = this.actionParser.parseActions(transitionData.scriptAccountActions);
return simpleTransition; return simpleTransition;
} }

View File

@ -0,0 +1,37 @@
{
"componentName": "Testsystem",
"componentDescription": "",
"states": [
{
"initial": false,
"conditions": [],
"stateLabel": "A",
"stateDescription": ""
},
{
"initial": false,
"conditions": [],
"stateLabel": "B",
"stateDescription": ""
}
],
"transitions": [
{
"scriptAccountActions": [
{
"changingValue": 5,
"scriptAccount": "New ScriptAccount"
}
],
"scriptAccountConditions": [
{
"scriptAccount": "Temperature",
"minValue": 0,
"maxValue": "10"
}
],
"startingState": "A",
"endingState": "B"
}
]
}

View File

@ -1,12 +1 @@
{ {"componentName":"Weathersystem","componentDescription":"Ein Wettersystem, dass sich aus normalem Wetter (Sonne, Regen, Wolke, Schnee, Sturm etc.) und zusätzlich den Jahreszeiten (Frühling, Sommer, Herbst, Winter, etc.) zusammensetzt.","childsystems":[{"componentName":"Season"},{"componentName":"Weather"}]}
"componentName": "Weathersystem",
"componentDescription": "Ein Wettersystem, dass sich aus normalem Wetter (Sonne, Regen, Wolke, Schnee, Sturm etc.) und zusätzlich den Jahreszeiten (Frühling, Sommer, Herbst, Winter, etc.) zusammensetzt.",
"childsystems": [
{
"componentName": "Season"
},
{
"componentName": "Weather"
}
]
}