From ee970db7164c5b3c2987f84d8d8b05359a2a772d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Fri, 19 Apr 2024 17:45:58 +0200 Subject: [PATCH] Generate isolated template States --- .../IsolatedProductStateGenerator.ts | 2 +- .../IsolatedTemplateStateGenerator.ts | 57 +++++++++++++++++++ .../ProductTemplateSystem.ts | 3 + 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/app/project/game-model/gamesystems/productSystemGenerator/IsolatedTemplateStateGenerator.ts diff --git a/src/app/project/game-model/gamesystems/productSystemGenerator/IsolatedProductStateGenerator.ts b/src/app/project/game-model/gamesystems/productSystemGenerator/IsolatedProductStateGenerator.ts index 99b8919..3577424 100644 --- a/src/app/project/game-model/gamesystems/productSystemGenerator/IsolatedProductStateGenerator.ts +++ b/src/app/project/game-model/gamesystems/productSystemGenerator/IsolatedProductStateGenerator.ts @@ -31,7 +31,7 @@ export class IsolatedProductStateGenerator extends ProductSystemGenerator { this.productGamesystem.states = generationResult.states; } - generateBinaryIsolatedProductStates(leftSystemData: ProductGenerationData, rightSystemData: ProductGenerationData): ProductGeneratorResult { + protected generateBinaryIsolatedProductStates(leftSystemData: ProductGenerationData, rightSystemData: ProductGenerationData): ProductGeneratorResult { const generatedProductStates: ProductState[] = [] leftSystemData.states.forEach(leftState => { if(leftState.outgoingTransitions.length == 0 && leftState.incomingTransitions.length == 0) { diff --git a/src/app/project/game-model/gamesystems/productSystemGenerator/IsolatedTemplateStateGenerator.ts b/src/app/project/game-model/gamesystems/productSystemGenerator/IsolatedTemplateStateGenerator.ts new file mode 100644 index 0000000..b9244a4 --- /dev/null +++ b/src/app/project/game-model/gamesystems/productSystemGenerator/IsolatedTemplateStateGenerator.ts @@ -0,0 +1,57 @@ +import {IsolatedProductStateGenerator} from "./IsolatedProductStateGenerator"; +import {Transition} from "../transitions/Transition"; +import {SimpleTemplateTransition} from "../../templates/simpleGamesystem/SimpleTemplateTransition"; +import {State} from "../states/State"; +import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition"; +import {SimpleTemplateState} from "../../templates/simpleGamesystem/SimpleTemplateState"; +import {Character} from "../../characters/Character"; +import {CharacterRelation} from "../../characters/CharacterRelation"; +import {TemplateElement} from "../../templates/TemplateElement"; +import {ProductTemplateSystem} from "../../templates/productGamesystem/ProductTemplateSystem"; + +export class IsolatedTemplateStateGenerator extends IsolatedProductStateGenerator { + templateElement: TemplateElement + + constructor(productGamesystem: ProductTemplateSystem, templateElement: TemplateElement) { + super(productGamesystem); + this.templateElement = templateElement; + } + + + + protected getTransitionConditions(transition: Transition, leftSystem: boolean) { + const templateElement = this.determineTemplateElement(leftSystem)!; + if(transition instanceof SimpleTemplateTransition && transition.conditionMap.has(templateElement)) { + return transition.conditionMap.get(templateElement)! + } + return transition.scriptAccountConditions; + } + + protected getTransitionActions(transition: Transition, leftSystem: boolean) { + const templateElement = this.determineTemplateElement(leftSystem)!; + + if(transition instanceof SimpleTemplateTransition && transition.actionMap.has(templateElement)) { + return transition.actionMap.get(templateElement)! + } else { + return transition.scriptAccountActions; + } + } + + + protected getStateConditions(state: State, leftSystem: boolean): ScriptAccountCondition[] { + const templateElement = this.determineTemplateElement(leftSystem)! + if(state instanceof SimpleTemplateState && state.conditionMap.has(templateElement)) { + return state.conditionMap.get(templateElement)! + } else { + return state.conditions + } + } + + private determineTemplateElement(leftSystem: boolean) { + if(this.templateElement instanceof Character) { + return this.templateElement; + } else if(this.templateElement instanceof CharacterRelation) { + return leftSystem ? this.templateElement.firstCharacter : this.templateElement.secondCharacter; + } + } +} diff --git a/src/app/project/game-model/templates/productGamesystem/ProductTemplateSystem.ts b/src/app/project/game-model/templates/productGamesystem/ProductTemplateSystem.ts index 4193ecd..1e5a9da 100644 --- a/src/app/project/game-model/templates/productGamesystem/ProductTemplateSystem.ts +++ b/src/app/project/game-model/templates/productGamesystem/ProductTemplateSystem.ts @@ -10,6 +10,7 @@ import {TemplateProductSystemGenerator} from "../../gamesystems/productSystemGen import { SymmetricProductTemplateGenerator } from "../../gamesystems/productSystemGenerator/SymmetricProductTemplateGenerator"; +import {IsolatedTemplateStateGenerator} from "../../gamesystems/productSystemGenerator/IsolatedTemplateStateGenerator"; export class ProductTemplateSystem extends ProductGamesystem implements TemplateGamesystem{ @@ -33,6 +34,8 @@ export class ProductTemplateSystem extends ProductGamesystem implements Template productTemplateGenerator.generateFromChildsystems() } + const isolatedTemplateStateGenerator = new IsolatedTemplateStateGenerator(this, templateElement); + isolatedTemplateStateGenerator.generateIsolatedProductStates(); } }