template-systems #41

Merged
sebastian merged 30 commits from template-systems into main 2024-04-19 21:10:01 +02:00
3 changed files with 61 additions and 1 deletions
Showing only changes of commit ee970db716 - Show all commits

View File

@ -31,7 +31,7 @@ export class IsolatedProductStateGenerator extends ProductSystemGenerator {
this.productGamesystem.states = generationResult.states; this.productGamesystem.states = generationResult.states;
} }
generateBinaryIsolatedProductStates(leftSystemData: ProductGenerationData, rightSystemData: ProductGenerationData): ProductGeneratorResult { protected generateBinaryIsolatedProductStates(leftSystemData: ProductGenerationData, rightSystemData: ProductGenerationData): ProductGeneratorResult {
const generatedProductStates: ProductState[] = [] const generatedProductStates: ProductState[] = []
leftSystemData.states.forEach(leftState => { leftSystemData.states.forEach(leftState => {
if(leftState.outgoingTransitions.length == 0 && leftState.incomingTransitions.length == 0) { if(leftState.outgoingTransitions.length == 0 && leftState.incomingTransitions.length == 0) {

View File

@ -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<any>, 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<any>, 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<any>, 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;
}
}
}

View File

@ -10,6 +10,7 @@ import {TemplateProductSystemGenerator} from "../../gamesystems/productSystemGen
import { import {
SymmetricProductTemplateGenerator SymmetricProductTemplateGenerator
} from "../../gamesystems/productSystemGenerator/SymmetricProductTemplateGenerator"; } from "../../gamesystems/productSystemGenerator/SymmetricProductTemplateGenerator";
import {IsolatedTemplateStateGenerator} from "../../gamesystems/productSystemGenerator/IsolatedTemplateStateGenerator";
export class ProductTemplateSystem extends ProductGamesystem implements TemplateGamesystem{ export class ProductTemplateSystem extends ProductGamesystem implements TemplateGamesystem{
@ -33,6 +34,8 @@ export class ProductTemplateSystem extends ProductGamesystem implements Template
productTemplateGenerator.generateFromChildsystems() productTemplateGenerator.generateFromChildsystems()
} }
const isolatedTemplateStateGenerator = new IsolatedTemplateStateGenerator(this, templateElement);
isolatedTemplateStateGenerator.generateIsolatedProductStates();
} }
} }