Introduce Symetric and Asymetric Template Relation Systems #40

Merged
sebastian merged 23 commits from assymetric-template-relation-systems into template-systems 2024-04-19 20:04:54 +02:00
4 changed files with 62 additions and 27 deletions
Showing only changes of commit 448ff5bd1b - Show all commits

View File

@ -46,11 +46,15 @@ export class Character extends ModelComponent implements TemplateElement {
if(gamesystem instanceof SimpleTemplateGamesystem) {
this.characterRelationGamesystems.push(gamesystem);
gamesystem.addTemplateElement(this);
console.log("Should have been added")
console.log(this.characterRelationGamesystems)
this.characterRelations.forEach(characterRelation => {
characterRelation.addCharacterRelationSystem(gamesystem)
})
} else if(gamesystem instanceof ProductTemplateSystem) {
this.characterRelationGamesystems.push(gamesystem);
gamesystem.addTemplateElement(this);
this.characterRelations.forEach(characterRelation => {
characterRelation.addCharacterRelationSystem(gamesystem)
})
if(!recursiveCall) {
gamesystem.innerGamesystems.forEach(innerGamesystem => this.addAsymetricCharacterRelationGamesystem(innerGamesystem, true))

View File

@ -1,14 +1,32 @@
import {TemplateElement} from "../templates/TemplateElement";
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{
firstCharacter: Character
secondCharacter: Character
characterRelationGamesystems: ProductTemplateSystem[] = []
constructor(firstCharacter: Character, secondCharacter: Character) {
this.firstCharacter = firstCharacter;
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
}
}

View File

@ -59,12 +59,12 @@ export class ProductSystemGenerator {
if(startingState != undefined) {
const endingState_right = this.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
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);
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);
@ -79,7 +79,7 @@ export class ProductSystemGenerator {
const endingState = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, generatedProductStates);
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);
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;
}
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);
transition.scriptAccountActions = [... this.getTransitionActions(usedTransition)];
transition.scriptAccountConditions = [... this.getTransitionConditions(usedTransition)];
transition.scriptAccountActions = [... this.getTransitionActions(usedTransition, leftSystem)];
transition.scriptAccountConditions = [... this.getTransitionConditions(usedTransition, leftSystem)];
if(generatedTransitions.find(generatedTransition => generatedTransition.startingState.equals(startingState) && generatedTransition.endingState.equals(endingState)) == undefined) {
generatedTransitions.push(transition)
@ -119,13 +119,13 @@ export class ProductSystemGenerator {
}
protected generateBinaryProductTransitionMulti(startingState: ProductState, endingState: ProductState, leftTransition: Transition<any>, rightTransition: Transition<any>, generatedTransitions: ProductTransition[]) {
const leftConditions = this.getTransitionConditions(leftTransition)
const rightConditions = this.getTransitionConditions(rightTransition)
const leftConditions = this.getTransitionConditions(leftTransition, true)
const rightConditions = this.getTransitionConditions(rightTransition, false)
if(!this.contradictCombinedConditions(leftConditions, rightConditions)) {
const transition = new ProductTransition(startingState, endingState)
transition.scriptAccountActions = this.generateCombinedActions(this.getTransitionActions(leftTransition), this.getTransitionActions(rightTransition));
transition.scriptAccountConditions = this.generateCombinedConditions(this.getTransitionConditions(leftTransition), this.getTransitionConditions(rightTransition));
transition.scriptAccountActions = this.generateCombinedActions(this.getTransitionActions(leftTransition, true), this.getTransitionActions(rightTransition, false));
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) {
generatedTransitions.push(transition)
@ -134,8 +134,8 @@ export class ProductSystemGenerator {
}
protected generateBinaryProductState(leftState: State<any>, rightState: State<any>, generatedStates: ProductState[]): ProductState | undefined {
const leftConditions = this.getStateConditions(leftState)
const rightConditions = this.getStateConditions(rightState)
const leftConditions = this.getStateConditions(leftState, true)
const rightConditions = this.getStateConditions(rightState, false)
const combinedStateConditions: ScriptAccountCondition[] = leftConditions.concat(rightConditions)
for(let i=0; i<combinedStateConditions.length; i++) {
@ -231,15 +231,15 @@ export class ProductSystemGenerator {
return false;
}
protected getTransitionConditions(transition: Transition<any>) {
protected getTransitionConditions(transition: Transition<any>, leftSystem: boolean) {
return transition.scriptAccountConditions;
}
protected getTransitionActions(transition: Transition<any>) {
protected getTransitionActions(transition: Transition<any>, leftSystem: boolean) {
return transition.scriptAccountActions;
}
protected getStateConditions(state: State<any>) {
protected getStateConditions(state: State<any>, leftSystem: boolean) {
return state.conditions;
}

View File

@ -10,6 +10,8 @@ import {SimpleTemplateTransition} from "../../templates/simpleGamesystem/SimpleT
import {state, transition} from "@angular/animations";
import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition";
import {SimpleTemplateState} from "../../templates/simpleGamesystem/SimpleTemplateState";
import {Character} from "../../characters/Character";
import {CharacterRelation} from "../../characters/CharacterRelation";
export class TemplateProductSystemGenerator extends ProductSystemGenerator {
@ -27,16 +29,18 @@ export class TemplateProductSystemGenerator extends ProductSystemGenerator {
productTemplateSystem.stateMap.set(this.templateElement, generationResult.states)
}
protected getTransitionConditions(transition: Transition<any>) {
if(transition instanceof SimpleTemplateTransition) {
return transition.conditionMap.get(this.templateElement)!
} else {
return transition.scriptAccountConditions;
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>) {
if(transition instanceof SimpleTemplateTransition) {
protected getTransitionActions(transition: Transition<any>, leftSystem: boolean) {
const templateElement = this.determineTemplateElement(leftSystem)!;
if(transition instanceof SimpleTemplateTransition && transition.actionMap.has(templateElement)) {
return transition.actionMap.get(this.templateElement)!
} else {
return transition.scriptAccountActions;
@ -44,11 +48,20 @@ export class TemplateProductSystemGenerator extends ProductSystemGenerator {
}
protected getStateConditions(state: State<any>): ScriptAccountCondition[] {
if(state instanceof SimpleTemplateState) {
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(this.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;
}
}
}