Load States and Transition as Templates in Templatesystems
All checks were successful
E2E Testing / test (push) Successful in 1m33s

This commit is contained in:
Sebastian Böckelmann 2024-04-14 08:44:26 +02:00
parent 877d90171f
commit 26ea30da13
4 changed files with 26 additions and 14 deletions

View File

@ -114,8 +114,6 @@ export class ProductSystemGenerator {
if(generatedTransitions.find(generatedTransition => generatedTransition.startingState.equals(startingState) && generatedTransition.endingState.equals(endingState)) == undefined) {
generatedTransitions.push(transition)
} else {
console.log(transition)
}
}
@ -130,8 +128,6 @@ export class ProductSystemGenerator {
if(generatedTransitions.find(generatedTransition => generatedTransition.startingState.equals(startingState) && generatedTransition.endingState.equals(endingState)) == undefined) {
generatedTransitions.push(transition)
} else {
console.log(transition)
}
}
}

View File

@ -50,10 +50,10 @@ export class GamesystemParser {
const stateParser = new StateParser(this.scriptAccounts);
simpleGamesystem.states = stateParser.parseStates(gamesystemData.states)
simpleGamesystem.states = stateParser.parseStates(gamesystemData.states, gamesystemData.templateType)
const transitionParser = new TransitionParser(simpleGamesystem.states, this.scriptAccounts)
simpleGamesystem.transitions = transitionParser.parseTransitions(gamesystemData.transitions)
simpleGamesystem.transitions = transitionParser.parseTransitions(gamesystemData.transitions, gamesystemData.templateType)
return simpleGamesystem

View File

@ -2,6 +2,8 @@ import {SimpleState} from "../../game-model/gamesystems/states/SimpleState";
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {ScriptAccountCondition} from "../../game-model/gamesystems/conditions/ScriptAccountCondition";
import {ScriptAccountConditionParser} from "./ScriptAccountConditionParser";
import {TemplateType} from "../../game-model/templates/TemplateType";
import {SimpleTemplateState} from "../../game-model/templates/simpleGamesystem/SimpleTemplateState";
export class StateParser {
@ -12,23 +14,28 @@ export class StateParser {
this.conditionParser = new ScriptAccountConditionParser(scriptAccounts)
}
public parseStates(stateData: any): SimpleState[] {
public parseStates(stateData: any, templateType: TemplateType | undefined): SimpleState[] {
const parsedStates: SimpleState[] = []
for(let i=0; i<stateData.length; i++) {
parsedStates.push(this.parseState(stateData[i]))
parsedStates.push(this.parseState(stateData[i], templateType))
}
return parsedStates;
}
private parseState(stateData: any): SimpleState {
private parseState(stateData: any, templateType: TemplateType | undefined): SimpleState {
const initial = stateData.initial
const stateLabel = stateData.stateLabel
const stateDescription = stateData.stateDescription
const conditions = this.conditionParser.parseStoredConditions(stateData.conditions)
const simpleState = new SimpleState(stateLabel, stateDescription);
let simpleState;
if(templateType == undefined) {
simpleState = new SimpleState(stateLabel, stateDescription)
} else {
simpleState = new SimpleTemplateState(stateLabel, stateDescription)
}
simpleState.initial = initial;
simpleState.conditions = conditions;

View File

@ -3,6 +3,8 @@ import {ScriptAccountConditionParser} from "./ScriptAccountConditionParser";
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {SimpleTransition} from "../../game-model/gamesystems/transitions/SimpleTransition";
import {ScriptAccountActionParser} from "./ScriptAccountActionParser";
import {TemplateType} from "../../game-model/templates/TemplateType";
import {SimpleTemplateTransition} from "../../game-model/templates/simpleGamesystem/SimpleTemplateTransition";
export class TransitionParser {
@ -18,10 +20,10 @@ export class TransitionParser {
this.actionParser = new ScriptAccountActionParser(scriptAccounts)
}
public parseTransitions(transitionData: any): SimpleTransition[] {
public parseTransitions(transitionData: any, templateType: TemplateType | undefined): SimpleTransition[] {
const transitions: SimpleTransition[] = []
for(let i=0; i<transitionData.length; i++) {
const parsedTransition = this.parseSingleTransition(transitionData[i]);
const parsedTransition = this.parseSingleTransition(transitionData[i], templateType);
if(parsedTransition != undefined) {
transitions.push(parsedTransition)
}
@ -29,7 +31,7 @@ export class TransitionParser {
return transitions
}
private parseSingleTransition(transitionData: any): SimpleTransition | undefined{
private parseSingleTransition(transitionData: any, templateType: TemplateType | undefined): SimpleTransition | undefined{
const startingState = this.findStateByLabel(transitionData.startingState)
const endingState = this.findStateByLabel(transitionData.endingState);
@ -37,7 +39,14 @@ export class TransitionParser {
return undefined
}
const simpleTransition = new SimpleTransition(startingState, endingState)
let simpleTransition;
if(templateType == undefined) {
simpleTransition = new SimpleTransition(startingState, endingState)
} else {
simpleTransition = new SimpleTemplateTransition(startingState, endingState)
}
simpleTransition.scriptAccountConditions = this.conditionParser.parseStoredConditions(transitionData.scriptAccountConditions)
simpleTransition.scriptAccountActions = this.actionParser.parseActions(transitionData.scriptAccountActions);