diff --git a/src/app/project/game-model/gamesystems/ProductGamesystem.ts b/src/app/project/game-model/gamesystems/ProductGamesystem.ts index 3984e2d..791cbce 100644 --- a/src/app/project/game-model/gamesystems/ProductGamesystem.ts +++ b/src/app/project/game-model/gamesystems/ProductGamesystem.ts @@ -68,7 +68,6 @@ export class ProductGamesystem extends Gamesystem extends ProductGamesystem{ +export class ProductTemplateSystem extends ProductGamesystem { stateMap: Map = new Map(); transitionMap: Map = new Map(); + generateFromChildsystems() { + const productSystemGenerator = new ProductGamesystemGenerator(this); + productSystemGenerator.generateFromChildsystems(); + } + generateTemplateFromChildsystems(referenceTemplate: ReferenceTemplate) { + const productSystemGenerator = new ProductTemplateGamesystemGenerator(this, referenceTemplate); + productSystemGenerator.generateFromChildsystems() + } } diff --git a/src/app/project/game-model/gamesystems/productSystemGenerator/ProductTemplateGamesystemGenerator.ts b/src/app/project/game-model/gamesystems/productSystemGenerator/ProductTemplateGamesystemGenerator.ts index e98b031..058455f 100644 --- a/src/app/project/game-model/gamesystems/productSystemGenerator/ProductTemplateGamesystemGenerator.ts +++ b/src/app/project/game-model/gamesystems/productSystemGenerator/ProductTemplateGamesystemGenerator.ts @@ -4,20 +4,145 @@ import {ProductState} from "../states/ProductState"; import {Transition} from "../transitions/Transition"; import {ProductTransition} from "../transitions/ProductTransition"; import {ProductGeneratorResult} from "./ProductGeneratorResult"; +import {ProductGamesystem} from "../ProductGamesystem"; +import {ProductTemplateSystem} from "../ProductTemplateSystem"; +import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition"; +import {SimpleTemplateState} from "../states/SimpleTemplateState"; +import {SimpleTemplateTransition} from "../transitions/SimpleTemplateTransition"; +import {ScriptAccountAction} from "../actions/ScriptAccountAction"; -export class ProductTemplateGamesystemGenerator extends AbstractProductGamesystemGenerator{ +export class ProductTemplateGamesystemGenerator extends AbstractProductGamesystemGenerator{ + + templateReference: TemplateReference + + + constructor(productGamesystem: ProductGamesystem, templateReference: TemplateReference) { + super(productGamesystem); + this.templateReference = templateReference; + } protected assignGeneratedStatesAndTransitions(generationResult: ProductGeneratorResult): void { + const templateGamesystem = this.productGamesystem as ProductTemplateSystem + + templateGamesystem.stateMap.set(this.templateReference, generationResult.states) + templateGamesystem.transitionMap.set(this.templateReference, generationResult.transitions); } - protected generateBinaryProductState(leftState: State, rightState: State, generadedStates: ProductState[]): ProductState | undefined { - return undefined; + protected generateBinaryProductState(leftState: State, rightState: State, generatedStates: ProductState[]): ProductState | undefined { + const combinedStateConditions: ScriptAccountCondition[] = this.getCombinedStateConditions(leftState, rightState) + for(let i=0; i[] = leftState.getInnerStates().concat(rightState.getInnerStates()) + let binaryProductState: ProductState | undefined = this.findGeneratedProductState(innerStates, generatedStates); + if(binaryProductState == undefined) { + binaryProductState = new ProductState(innerStates); + generatedStates.push(binaryProductState) + } + + binaryProductState.determineInitialProperty() + binaryProductState.conditions = combinedStateConditions; + + return binaryProductState; } - protected generateBinaryProductTransition(leftState: State, rightState: State, usedTransition: Transition, generatedTransitions: ProductTransition[]): void { + private getCombinedStateConditions(leftState: State, rightState: State) { + let combinedConditions: ScriptAccountCondition[] = [] + if(leftState instanceof SimpleTemplateState && leftState.conditionMap.has(this.templateReference)) { + combinedConditions = leftState.conditionMap.get(this.templateReference)!; + } else { + combinedConditions = leftState.conditions; + } + + if(rightState instanceof SimpleTemplateState && rightState.conditionMap.has(this.templateReference)) { + combinedConditions = combinedConditions.concat(rightState.conditionMap.get(this.templateReference)!) + } else { + combinedConditions = combinedConditions.concat(rightState.conditions) + } + return combinedConditions; } - protected generateBinaryProductTransitionMulti(leftState: State, rightState: State, leftTransition: Transition, rightTransition: Transition, generatedTransitions: ProductTransition[]): void { + protected generateBinaryProductTransition(startingState: ProductState, endingState: ProductState, usedTransition: Transition, generatedTransitions: ProductTransition[]): void { + const transition = new ProductTransition(startingState, endingState); + + if(usedTransition instanceof SimpleTemplateTransition && usedTransition.conditionMap.has(this.templateReference)) { + transition.scriptAccountConditions = [... usedTransition.conditionMap.get(this.templateReference)!] + } else { + transition.scriptAccountConditions = [... usedTransition.scriptAccountConditions]; + } + + if(usedTransition instanceof SimpleTemplateTransition && usedTransition.actionMap.has(this.templateReference)) { + transition.scriptAccountActions = [... usedTransition.actionMap.get(this.templateReference)!] + } else { + transition.scriptAccountActions = [... usedTransition.scriptAccountActions]; + } + + + + if(generatedTransitions.find(generatedTransition => generatedTransition.startingState.equals(startingState) && generatedTransition.endingState.equals(endingState)) == undefined) { + generatedTransitions.push(transition) + } + } + + protected generateBinaryProductTransitionMulti(startingState: ProductState, endingState: ProductState, leftTransition: Transition, rightTransition: Transition, generatedTransitions: ProductTransition[]): void { + let leftConditions: ScriptAccountCondition[] = []; + if(leftTransition instanceof SimpleTemplateTransition && leftTransition.conditionMap.has(this.templateReference)) { + leftConditions = leftTransition.conditionMap.get(this.templateReference)! + } else { + leftConditions = leftTransition.scriptAccountConditions + } + + let rightConditions: ScriptAccountCondition[] = []; + if(rightTransition instanceof SimpleTemplateTransition && rightTransition.conditionMap.has(this.templateReference)) { + rightConditions = rightTransition.conditionMap.get(this.templateReference)! + } else { + rightConditions = rightTransition.scriptAccountConditions; + } + + + if(!this.contradictCombinedConditions(leftConditions, rightConditions)) { + const transition = new ProductTransition(startingState, endingState) + + let leftActions: ScriptAccountAction[] = [] + let rightActions: ScriptAccountAction[] = [] + if(leftTransition instanceof SimpleTemplateTransition && leftTransition.actionMap.has(this.templateReference)) { + leftActions = leftTransition.actionMap.get(this.templateReference)! + } else { + leftActions = leftTransition.scriptAccountActions; + } + + if(rightTransition instanceof SimpleTemplateTransition && rightTransition.actionMap.has(this.templateReference)) { + rightActions = rightTransition.actionMap.get(this.templateReference)! + } else { + rightActions = rightTransition.scriptAccountActions + } + + + transition.scriptAccountActions = this.generateCombinedActions(leftActions, rightActions); + + let leftConditions: ScriptAccountCondition[] = [] + let rightConditions: ScriptAccountCondition[] = [] + if(leftTransition instanceof SimpleTemplateTransition && leftTransition.conditionMap.has(this.templateReference)) { + leftConditions = leftTransition.conditionMap.get(this.templateReference)! + } else { + leftConditions = leftTransition.scriptAccountConditions; + } + + if(rightTransition instanceof SimpleTemplateTransition && rightTransition.conditionMap.has(this.templateReference)) { + rightConditions = rightTransition.conditionMap.get(this.templateReference)! + } else { + rightConditions = rightTransition.scriptAccountConditions + } + + transition.scriptAccountConditions = this.generateCombinedConditions(leftConditions, rightConditions); + + generatedTransitions.push(transition) + } }