Implement ProductGeneration for Templates
All checks were successful
E2E Testing / test (push) Successful in 1m30s
All checks were successful
E2E Testing / test (push) Successful in 1m30s
This commit is contained in:
parent
9d565aad35
commit
30eed285aa
@ -68,7 +68,6 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
|
|||||||
}
|
}
|
||||||
|
|
||||||
generateFromChildsystems() {
|
generateFromChildsystems() {
|
||||||
console.log("Debug msg")
|
|
||||||
this.productGamesystemGenerator.generateFromChildsystems()
|
this.productGamesystemGenerator.generateFromChildsystems()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,13 +2,23 @@ import {ProductGamesystem} from "./ProductGamesystem";
|
|||||||
import {ProductState} from "./states/ProductState";
|
import {ProductState} from "./states/ProductState";
|
||||||
import {ProductTransition} from "./transitions/ProductTransition";
|
import {ProductTransition} from "./transitions/ProductTransition";
|
||||||
import {Gamesystem} from "./Gamesystem";
|
import {Gamesystem} from "./Gamesystem";
|
||||||
|
import {ProductTemplateGamesystemGenerator} from "./productSystemGenerator/ProductTemplateGamesystemGenerator";
|
||||||
|
import {ProductGamesystemGenerator} from "./productSystemGenerator/ProductGamesystemGenerator";
|
||||||
|
|
||||||
export class ProductTemplateSystem<ReferenceTemplate> extends ProductGamesystem{
|
export class ProductTemplateSystem<ReferenceTemplate> extends ProductGamesystem {
|
||||||
|
|
||||||
stateMap: Map<ReferenceTemplate, ProductState[]> = new Map<ReferenceTemplate, ProductState[]>();
|
stateMap: Map<ReferenceTemplate, ProductState[]> = new Map<ReferenceTemplate, ProductState[]>();
|
||||||
transitionMap: Map<ReferenceTemplate, ProductTransition[]> = new Map<ReferenceTemplate, ProductTransition[]>();
|
transitionMap: Map<ReferenceTemplate, ProductTransition[]> = new Map<ReferenceTemplate, ProductTransition[]>();
|
||||||
|
|
||||||
|
generateFromChildsystems() {
|
||||||
|
const productSystemGenerator = new ProductGamesystemGenerator(this);
|
||||||
|
productSystemGenerator.generateFromChildsystems();
|
||||||
|
}
|
||||||
|
|
||||||
|
generateTemplateFromChildsystems(referenceTemplate: ReferenceTemplate) {
|
||||||
|
const productSystemGenerator = new ProductTemplateGamesystemGenerator(this, referenceTemplate);
|
||||||
|
productSystemGenerator.generateFromChildsystems()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,20 +4,145 @@ import {ProductState} from "../states/ProductState";
|
|||||||
import {Transition} from "../transitions/Transition";
|
import {Transition} from "../transitions/Transition";
|
||||||
import {ProductTransition} from "../transitions/ProductTransition";
|
import {ProductTransition} from "../transitions/ProductTransition";
|
||||||
import {ProductGeneratorResult} from "./ProductGeneratorResult";
|
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<TemplateReference> extends AbstractProductGamesystemGenerator{
|
||||||
|
|
||||||
|
templateReference: TemplateReference
|
||||||
|
|
||||||
|
|
||||||
|
constructor(productGamesystem: ProductGamesystem, templateReference: TemplateReference) {
|
||||||
|
super(productGamesystem);
|
||||||
|
this.templateReference = templateReference;
|
||||||
|
}
|
||||||
|
|
||||||
protected assignGeneratedStatesAndTransitions(generationResult: ProductGeneratorResult): void {
|
protected assignGeneratedStatesAndTransitions(generationResult: ProductGeneratorResult): void {
|
||||||
|
const templateGamesystem = this.productGamesystem as ProductTemplateSystem<TemplateReference>
|
||||||
|
|
||||||
|
templateGamesystem.stateMap.set(this.templateReference, generationResult.states)
|
||||||
|
templateGamesystem.transitionMap.set(this.templateReference, generationResult.transitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected generateBinaryProductState(leftState: State<any>, rightState: State<any>, generadedStates: ProductState[]): ProductState | undefined {
|
protected generateBinaryProductState(leftState: State<any>, rightState: State<any>, generatedStates: ProductState[]): ProductState | undefined {
|
||||||
return undefined;
|
const combinedStateConditions: ScriptAccountCondition[] = this.getCombinedStateConditions(leftState, rightState)
|
||||||
|
for(let i=0; i<combinedStateConditions.length; i++) {
|
||||||
|
for(let j=0; j<combinedStateConditions.length; j++) {
|
||||||
|
if(combinedStateConditions[i].isContradicting(combinedStateConditions[j])) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const innerStates: State<any>[] = 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<any>, rightState: State<any>, usedTransition: Transition<any>, generatedTransitions: ProductTransition[]): void {
|
private getCombinedStateConditions(leftState: State<any>, rightState: State<any>) {
|
||||||
|
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<any>, rightState: State<any>, leftTransition: Transition<any>, rightTransition: Transition<any>, generatedTransitions: ProductTransition[]): void {
|
protected generateBinaryProductTransition(startingState: ProductState, endingState: ProductState, usedTransition: Transition<any>, 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<any>, rightTransition: Transition<any>, 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user