Parse Transitions (& TransitionConditions)
Some checks failed
E2E Testing / test (push) Failing after 1m29s

This commit is contained in:
Sebastian Böckelmann 2024-03-20 15:33:34 +01:00
parent 542515db6e
commit 4f4122fd6d
4 changed files with 63 additions and 12 deletions

View File

@ -5,17 +5,18 @@ import {ProductGamesystem} from "../../game-model/gamesystems/ProductGamesystem"
import {SimpleGamesystem} from "../../game-model/gamesystems/SimpleGamesystem"; import {SimpleGamesystem} from "../../game-model/gamesystems/SimpleGamesystem";
import {StateParser} from "./StateParser"; import {StateParser} from "./StateParser";
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {TransitionParser} from "./TransitionParser";
export class GamesystemParser { export class GamesystemParser {
parsedParentGamesystems: ParsedParentGamesystems[] = [] private parsedParentGamesystems: ParsedParentGamesystems[] = []
parsedGamesystems: Gamesystem<any, any>[] = [] private parsedGamesystems: Gamesystem<any, any>[] = []
private stateParser: StateParser private scriptAccounts: ScriptAccount[]
constructor(scriptAccounts: ScriptAccount[]) { constructor(scriptAccounts: ScriptAccount[]) {
this.stateParser = new StateParser(scriptAccounts) this.scriptAccounts = scriptAccounts;
} }
@ -40,8 +41,12 @@ export class GamesystemParser {
parseSimpleGamesystem(gamesystemData: any): SimpleGamesystem { parseSimpleGamesystem(gamesystemData: any): SimpleGamesystem {
const simpleGamesystem = new SimpleGamesystem(gamesystemData.componentName, gamesystemData.componentDescription) const simpleGamesystem = new SimpleGamesystem(gamesystemData.componentName, gamesystemData.componentDescription)
const states = this.stateParser.parseStates(gamesystemData)
simpleGamesystem.states = states const stateParser = new StateParser(this.scriptAccounts);
simpleGamesystem.states = stateParser.parseStates(gamesystemData.states)
const transitionParser = new TransitionParser(simpleGamesystem.states, this.scriptAccounts)
simpleGamesystem.transitions = transitionParser.parseTransitions(gamesystemData.transitions)
return simpleGamesystem return simpleGamesystem
} }

View File

@ -4,7 +4,7 @@ import {max, min} from "rxjs";
export class ScriptAccountConditionParser { export class ScriptAccountConditionParser {
scriptAccounts: ScriptAccount[] private scriptAccounts: ScriptAccount[]
constructor(scriptAccounts: ScriptAccount[]) { constructor(scriptAccounts: ScriptAccount[]) {
@ -22,7 +22,7 @@ export class ScriptAccountConditionParser {
return conditions return conditions
} }
parseSingleCondition(conditionData: any): ScriptAccountCondition | undefined{ private parseSingleCondition(conditionData: any): ScriptAccountCondition | undefined{
const referencedScriptAccount = this.findScriptAccountByName(conditionData.scriptAccount); const referencedScriptAccount = this.findScriptAccountByName(conditionData.scriptAccount);
if(referencedScriptAccount != undefined) { if(referencedScriptAccount != undefined) {
const minValue = conditionData.minValue; const minValue = conditionData.minValue;
@ -33,7 +33,7 @@ export class ScriptAccountConditionParser {
} }
} }
findScriptAccountByName(scriptAccountName: string) { private findScriptAccountByName(scriptAccountName: string) {
return this.scriptAccounts.find(scriptAccount => scriptAccount.componentName === scriptAccountName); return this.scriptAccounts.find(scriptAccount => scriptAccount.componentName === scriptAccountName);
} }
} }

View File

@ -12,10 +12,10 @@ export class StateParser {
this.conditionParser = new ScriptAccountConditionParser(scriptAccounts) this.conditionParser = new ScriptAccountConditionParser(scriptAccounts)
} }
public parseStates(gamesystemData: any): SimpleState[] { public parseStates(stateData: any): SimpleState[] {
const parsedStates: SimpleState[] = [] const parsedStates: SimpleState[] = []
for(let i=0; i<gamesystemData.states.length; i++) { for(let i=0; i<stateData.length; i++) {
parsedStates.push(this.parseState(gamesystemData.states[i])) parsedStates.push(this.parseState(stateData[i]))
} }
return parsedStates; return parsedStates;

View File

@ -0,0 +1,46 @@
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";
export class TransitionParser {
private states: SimpleState[]
private conditionParser: ScriptAccountConditionParser
constructor(states: SimpleState[], scriptAccounts: ScriptAccount[]) {
this.states = states;
this.conditionParser = new ScriptAccountConditionParser(scriptAccounts);
}
public parseTransitions(transitionData: any): SimpleTransition[] {
const transitions: SimpleTransition[] = []
for(let i=0; i<transitionData.length; i++) {
const parsedTransition = this.parseSingleTransition(transitionData[i]);
if(parsedTransition != undefined) {
transitions.push(parsedTransition)
}
}
return transitions
}
private parseSingleTransition(transitionData: any): SimpleTransition | undefined{
const startingState = this.findStateByLabel(transitionData.startingState)
const endingState = this.findStateByLabel(transitionData.endingState);
if(startingState == undefined || endingState == undefined) {
return undefined
}
const simpleTransition = new SimpleTransition(startingState, endingState)
simpleTransition.scriptAccountConditions = this.conditionParser.parseStoredConditions(transitionData.scriptAccountConditions)
return simpleTransition;
}
private findStateByLabel(stateLabel: string) {
return this.states.find(state => state.stateLabel === stateLabel);
}
}