Introduce Symetric and Asymetric Template Relation Systems #40
@ -46,11 +46,15 @@ export class Character extends ModelComponent implements TemplateElement {
|
|||||||
if(gamesystem instanceof SimpleTemplateGamesystem) {
|
if(gamesystem instanceof SimpleTemplateGamesystem) {
|
||||||
this.characterRelationGamesystems.push(gamesystem);
|
this.characterRelationGamesystems.push(gamesystem);
|
||||||
gamesystem.addTemplateElement(this);
|
gamesystem.addTemplateElement(this);
|
||||||
console.log("Should have been added")
|
this.characterRelations.forEach(characterRelation => {
|
||||||
console.log(this.characterRelationGamesystems)
|
characterRelation.addCharacterRelationSystem(gamesystem)
|
||||||
|
})
|
||||||
} else if(gamesystem instanceof ProductTemplateSystem) {
|
} else if(gamesystem instanceof ProductTemplateSystem) {
|
||||||
this.characterRelationGamesystems.push(gamesystem);
|
this.characterRelationGamesystems.push(gamesystem);
|
||||||
gamesystem.addTemplateElement(this);
|
gamesystem.addTemplateElement(this);
|
||||||
|
this.characterRelations.forEach(characterRelation => {
|
||||||
|
characterRelation.addCharacterRelationSystem(gamesystem)
|
||||||
|
})
|
||||||
|
|
||||||
if(!recursiveCall) {
|
if(!recursiveCall) {
|
||||||
gamesystem.innerGamesystems.forEach(innerGamesystem => this.addAsymetricCharacterRelationGamesystem(innerGamesystem, true))
|
gamesystem.innerGamesystems.forEach(innerGamesystem => this.addAsymetricCharacterRelationGamesystem(innerGamesystem, true))
|
||||||
|
@ -1,14 +1,32 @@
|
|||||||
import {TemplateElement} from "../templates/TemplateElement";
|
import {TemplateElement} from "../templates/TemplateElement";
|
||||||
import {Character} from "./Character";
|
import {Character} from "./Character";
|
||||||
|
import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem";
|
||||||
|
import {Gamesystem} from "../gamesystems/Gamesystem";
|
||||||
|
import {SimpleTemplateGamesystem} from "../templates/simpleGamesystem/SimpleTemplateGamesystem";
|
||||||
|
import {TemplateType} from "../templates/TemplateType";
|
||||||
|
|
||||||
export class CharacterRelation implements TemplateElement{
|
export class CharacterRelation implements TemplateElement{
|
||||||
|
|
||||||
firstCharacter: Character
|
firstCharacter: Character
|
||||||
secondCharacter: Character
|
secondCharacter: Character
|
||||||
|
|
||||||
|
characterRelationGamesystems: ProductTemplateSystem[] = []
|
||||||
|
|
||||||
constructor(firstCharacter: Character, secondCharacter: Character) {
|
constructor(firstCharacter: Character, secondCharacter: Character) {
|
||||||
this.firstCharacter = firstCharacter;
|
this.firstCharacter = firstCharacter;
|
||||||
this.secondCharacter = secondCharacter;
|
this.secondCharacter = secondCharacter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addCharacterRelationSystem(gamesystem: Gamesystem<any, any>) {
|
||||||
|
if((gamesystem instanceof SimpleTemplateGamesystem || gamesystem instanceof ProductTemplateSystem) && this.isGamesystemCharacterRelationSpecific(gamesystem.componentName)) {
|
||||||
|
const templateGamesystem = new ProductTemplateSystem(gamesystem.componentName, gamesystem.componentDescription, TemplateType.CHARACTER_RELATION);
|
||||||
|
templateGamesystem.addChildGamesystem(gamesystem);
|
||||||
|
templateGamesystem.addChildGamesystem(gamesystem);
|
||||||
|
this.characterRelationGamesystems.push(templateGamesystem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private isGamesystemCharacterRelationSpecific(gamesystemName: string) {
|
||||||
|
return this.characterRelationGamesystems.find(gamesystem => gamesystem.componentName === gamesystemName) != undefined
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,12 +59,12 @@ export class ProductSystemGenerator {
|
|||||||
if(startingState != undefined) {
|
if(startingState != undefined) {
|
||||||
const endingState_right = this.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
|
const endingState_right = this.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
|
||||||
if(endingState_right != undefined) {
|
if(endingState_right != undefined) {
|
||||||
this.generateBinaryProductTransition(startingState, endingState_right, rightState.outgoingTransitions[j], generatedProductTransitions);
|
this.generateBinaryProductTransition(startingState, endingState_right, rightState.outgoingTransitions[j], generatedProductTransitions, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const endingState_left = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, generatedProductStates);
|
const endingState_left = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, generatedProductStates);
|
||||||
if(endingState_left != undefined) {
|
if(endingState_left != undefined) {
|
||||||
this.generateBinaryProductTransition(startingState, endingState_left, leftState.outgoingTransitions[i], generatedProductTransitions)
|
this.generateBinaryProductTransition(startingState, endingState_left, leftState.outgoingTransitions[i], generatedProductTransitions, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const endingState_left_right = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
|
const endingState_left_right = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
|
||||||
@ -79,7 +79,7 @@ export class ProductSystemGenerator {
|
|||||||
const endingState = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, generatedProductStates);
|
const endingState = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, generatedProductStates);
|
||||||
|
|
||||||
if(startingState != undefined && endingState != undefined) {
|
if(startingState != undefined && endingState != undefined) {
|
||||||
this.generateBinaryProductTransition(startingState, endingState, leftState.outgoingTransitions[i], generatedProductTransitions)
|
this.generateBinaryProductTransition(startingState, endingState, leftState.outgoingTransitions[i], generatedProductTransitions, true)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ export class ProductSystemGenerator {
|
|||||||
const endingState = this.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
|
const endingState = this.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
|
||||||
|
|
||||||
if(startingState != undefined && endingState != undefined) {
|
if(startingState != undefined && endingState != undefined) {
|
||||||
this.generateBinaryProductTransition(startingState, endingState, rightState.outgoingTransitions[j], generatedProductTransitions);
|
this.generateBinaryProductTransition(startingState, endingState, rightState.outgoingTransitions[j], generatedProductTransitions, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,10 +108,10 @@ export class ProductSystemGenerator {
|
|||||||
this.productGamesystem.transitions = generationResult.transitions;
|
this.productGamesystem.transitions = generationResult.transitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected generateBinaryProductTransition(startingState: ProductState, endingState: ProductState, usedTransition: Transition<any>, generatedTransitions: ProductTransition[]) {
|
protected generateBinaryProductTransition(startingState: ProductState, endingState: ProductState, usedTransition: Transition<any>, generatedTransitions: ProductTransition[], leftSystem: boolean) {
|
||||||
const transition = new ProductTransition(startingState, endingState);
|
const transition = new ProductTransition(startingState, endingState);
|
||||||
transition.scriptAccountActions = [... this.getTransitionActions(usedTransition)];
|
transition.scriptAccountActions = [... this.getTransitionActions(usedTransition, leftSystem)];
|
||||||
transition.scriptAccountConditions = [... this.getTransitionConditions(usedTransition)];
|
transition.scriptAccountConditions = [... this.getTransitionConditions(usedTransition, leftSystem)];
|
||||||
|
|
||||||
if(generatedTransitions.find(generatedTransition => generatedTransition.startingState.equals(startingState) && generatedTransition.endingState.equals(endingState)) == undefined) {
|
if(generatedTransitions.find(generatedTransition => generatedTransition.startingState.equals(startingState) && generatedTransition.endingState.equals(endingState)) == undefined) {
|
||||||
generatedTransitions.push(transition)
|
generatedTransitions.push(transition)
|
||||||
@ -119,13 +119,13 @@ export class ProductSystemGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected generateBinaryProductTransitionMulti(startingState: ProductState, endingState: ProductState, leftTransition: Transition<any>, rightTransition: Transition<any>, generatedTransitions: ProductTransition[]) {
|
protected generateBinaryProductTransitionMulti(startingState: ProductState, endingState: ProductState, leftTransition: Transition<any>, rightTransition: Transition<any>, generatedTransitions: ProductTransition[]) {
|
||||||
const leftConditions = this.getTransitionConditions(leftTransition)
|
const leftConditions = this.getTransitionConditions(leftTransition, true)
|
||||||
const rightConditions = this.getTransitionConditions(rightTransition)
|
const rightConditions = this.getTransitionConditions(rightTransition, false)
|
||||||
|
|
||||||
if(!this.contradictCombinedConditions(leftConditions, rightConditions)) {
|
if(!this.contradictCombinedConditions(leftConditions, rightConditions)) {
|
||||||
const transition = new ProductTransition(startingState, endingState)
|
const transition = new ProductTransition(startingState, endingState)
|
||||||
transition.scriptAccountActions = this.generateCombinedActions(this.getTransitionActions(leftTransition), this.getTransitionActions(rightTransition));
|
transition.scriptAccountActions = this.generateCombinedActions(this.getTransitionActions(leftTransition, true), this.getTransitionActions(rightTransition, false));
|
||||||
transition.scriptAccountConditions = this.generateCombinedConditions(this.getTransitionConditions(leftTransition), this.getTransitionConditions(rightTransition));
|
transition.scriptAccountConditions = this.generateCombinedConditions(this.getTransitionConditions(leftTransition, true), this.getTransitionConditions(rightTransition, false));
|
||||||
|
|
||||||
if(generatedTransitions.find(generatedTransition => generatedTransition.startingState.equals(startingState) && generatedTransition.endingState.equals(endingState)) == undefined) {
|
if(generatedTransitions.find(generatedTransition => generatedTransition.startingState.equals(startingState) && generatedTransition.endingState.equals(endingState)) == undefined) {
|
||||||
generatedTransitions.push(transition)
|
generatedTransitions.push(transition)
|
||||||
@ -134,8 +134,8 @@ export class ProductSystemGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected generateBinaryProductState(leftState: State<any>, rightState: State<any>, generatedStates: ProductState[]): ProductState | undefined {
|
protected generateBinaryProductState(leftState: State<any>, rightState: State<any>, generatedStates: ProductState[]): ProductState | undefined {
|
||||||
const leftConditions = this.getStateConditions(leftState)
|
const leftConditions = this.getStateConditions(leftState, true)
|
||||||
const rightConditions = this.getStateConditions(rightState)
|
const rightConditions = this.getStateConditions(rightState, false)
|
||||||
|
|
||||||
const combinedStateConditions: ScriptAccountCondition[] = leftConditions.concat(rightConditions)
|
const combinedStateConditions: ScriptAccountCondition[] = leftConditions.concat(rightConditions)
|
||||||
for(let i=0; i<combinedStateConditions.length; i++) {
|
for(let i=0; i<combinedStateConditions.length; i++) {
|
||||||
@ -231,15 +231,15 @@ export class ProductSystemGenerator {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getTransitionConditions(transition: Transition<any>) {
|
protected getTransitionConditions(transition: Transition<any>, leftSystem: boolean) {
|
||||||
return transition.scriptAccountConditions;
|
return transition.scriptAccountConditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getTransitionActions(transition: Transition<any>) {
|
protected getTransitionActions(transition: Transition<any>, leftSystem: boolean) {
|
||||||
return transition.scriptAccountActions;
|
return transition.scriptAccountActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getStateConditions(state: State<any>) {
|
protected getStateConditions(state: State<any>, leftSystem: boolean) {
|
||||||
return state.conditions;
|
return state.conditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ import {SimpleTemplateTransition} from "../../templates/simpleGamesystem/SimpleT
|
|||||||
import {state, transition} from "@angular/animations";
|
import {state, transition} from "@angular/animations";
|
||||||
import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition";
|
import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition";
|
||||||
import {SimpleTemplateState} from "../../templates/simpleGamesystem/SimpleTemplateState";
|
import {SimpleTemplateState} from "../../templates/simpleGamesystem/SimpleTemplateState";
|
||||||
|
import {Character} from "../../characters/Character";
|
||||||
|
import {CharacterRelation} from "../../characters/CharacterRelation";
|
||||||
|
|
||||||
export class TemplateProductSystemGenerator extends ProductSystemGenerator {
|
export class TemplateProductSystemGenerator extends ProductSystemGenerator {
|
||||||
|
|
||||||
@ -27,16 +29,18 @@ export class TemplateProductSystemGenerator extends ProductSystemGenerator {
|
|||||||
productTemplateSystem.stateMap.set(this.templateElement, generationResult.states)
|
productTemplateSystem.stateMap.set(this.templateElement, generationResult.states)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getTransitionConditions(transition: Transition<any>) {
|
protected getTransitionConditions(transition: Transition<any>, leftSystem: boolean) {
|
||||||
if(transition instanceof SimpleTemplateTransition) {
|
const templateElement = this.determineTemplateElement(leftSystem)!;
|
||||||
return transition.conditionMap.get(this.templateElement)!
|
if(transition instanceof SimpleTemplateTransition && transition.conditionMap.has(templateElement)) {
|
||||||
} else {
|
return transition.conditionMap.get(templateElement)!
|
||||||
return transition.scriptAccountConditions;
|
|
||||||
}
|
}
|
||||||
|
return transition.scriptAccountConditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getTransitionActions(transition: Transition<any>) {
|
protected getTransitionActions(transition: Transition<any>, leftSystem: boolean) {
|
||||||
if(transition instanceof SimpleTemplateTransition) {
|
const templateElement = this.determineTemplateElement(leftSystem)!;
|
||||||
|
|
||||||
|
if(transition instanceof SimpleTemplateTransition && transition.actionMap.has(templateElement)) {
|
||||||
return transition.actionMap.get(this.templateElement)!
|
return transition.actionMap.get(this.templateElement)!
|
||||||
} else {
|
} else {
|
||||||
return transition.scriptAccountActions;
|
return transition.scriptAccountActions;
|
||||||
@ -44,11 +48,20 @@ export class TemplateProductSystemGenerator extends ProductSystemGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected getStateConditions(state: State<any>): ScriptAccountCondition[] {
|
protected getStateConditions(state: State<any>, leftSystem: boolean): ScriptAccountCondition[] {
|
||||||
if(state instanceof SimpleTemplateState) {
|
const templateElement = this.determineTemplateElement(leftSystem)!
|
||||||
|
if(state instanceof SimpleTemplateState && state.conditionMap.has(templateElement)) {
|
||||||
return state.conditionMap.get(this.templateElement)!
|
return state.conditionMap.get(this.templateElement)!
|
||||||
} else {
|
} else {
|
||||||
return state.conditions
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user