issue-15 #21

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

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