Introduce Symetric and Asymetric Template Relation Systems #40
@ -1,3 +1,6 @@
 | 
			
		||||
<div *ngIf="isGamesystemTemplate()">
 | 
			
		||||
  <mat-checkbox [(ngModel)]="convertGamesystemToTemplate(gamesystem)!.symmetric">Gamesystem is symmetric template</mat-checkbox>
 | 
			
		||||
</div>
 | 
			
		||||
<app-simple-gamesystem-editor *ngIf="isSimpleGamesystem()"  [templateElement]="templateElement" [simpleGamesystem]="convertGamesystemToSimpleGamesystem()" [scriptAccunts]="scriptAccounts"></app-simple-gamesystem-editor>
 | 
			
		||||
<app-product-gamesystem-editor *ngIf="!isSimpleGamesystem()"  [templateElement]="templateElement" [gamesystem]="convertGamesystemToProductGamesystem()"
 | 
			
		||||
                               (onOpenGamesystemEditor)="onOpenGamesystemEditor($event)"></app-product-gamesystem-editor>
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,8 @@ import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccou
 | 
			
		||||
import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem";
 | 
			
		||||
import {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem";
 | 
			
		||||
import {TemplateElement} from "../../project/game-model/templates/TemplateElement";
 | 
			
		||||
import {SimpleTemplateGamesystem} from "../../project/game-model/templates/simpleGamesystem/SimpleTemplateGamesystem";
 | 
			
		||||
import {ProductTemplateSystem} from "../../project/game-model/templates/productGamesystem/ProductTemplateSystem";
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'app-gamesystem-editor',
 | 
			
		||||
@ -42,4 +44,19 @@ export class GamesystemEditorComponent implements OnInit{
 | 
			
		||||
  onOpenGamesystemEditor(gamesystem: SimpleGamesystem) {
 | 
			
		||||
    this.openGamesystemEmitter.emit(gamesystem);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  isGamesystemTemplate() {
 | 
			
		||||
    return this.gamesystem instanceof SimpleTemplateGamesystem || this.gamesystem instanceof ProductTemplateSystem;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  convertGamesystemToTemplate(gamesystem: Gamesystem<State<any>, Transition<any>> | undefined) {
 | 
			
		||||
    if(gamesystem instanceof SimpleTemplateGamesystem) {
 | 
			
		||||
      return gamesystem as SimpleTemplateGamesystem;
 | 
			
		||||
    } else if(gamesystem instanceof ProductTemplateSystem) {
 | 
			
		||||
      return gamesystem as ProductTemplateSystem
 | 
			
		||||
    } else {
 | 
			
		||||
      return undefined
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,6 +21,7 @@ export class CharacterRelation implements TemplateElement{
 | 
			
		||||
  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.symmetric = gamesystem.symmetric
 | 
			
		||||
       templateGamesystem.addChildGamesystem(gamesystem);
 | 
			
		||||
       templateGamesystem.addChildGamesystem(gamesystem);
 | 
			
		||||
       this.characterRelationGamesystems.push(templateGamesystem);
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@ import {Gamesystem} from "../Gamesystem";
 | 
			
		||||
import {ProductGenerationData} from "./ProductGenerationData";
 | 
			
		||||
import {ProductTransition} from "../transitions/ProductTransition";
 | 
			
		||||
import {SimpleTemplateTransition} from "../../templates/simpleGamesystem/SimpleTemplateTransition";
 | 
			
		||||
import {ProductTemplateSystem} from "../../templates/productGamesystem/ProductTemplateSystem";
 | 
			
		||||
 | 
			
		||||
export class ProductSystemGenerator {
 | 
			
		||||
  productGamesystem: ProductGamesystem
 | 
			
		||||
@ -106,6 +107,8 @@ export class ProductSystemGenerator {
 | 
			
		||||
  protected assignGeneratedStatesAndTransitions(generationResult: ProductGeneratorResult): void {
 | 
			
		||||
    this.productGamesystem.states = generationResult.states;
 | 
			
		||||
    this.productGamesystem.transitions = generationResult.transitions;
 | 
			
		||||
 | 
			
		||||
    console.log("General ", generationResult.transitions.length)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected generateBinaryProductTransition(startingState: ProductState, endingState: ProductState, usedTransition: Transition<any>, generatedTransitions: ProductTransition[], leftSystem: boolean) {
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,34 @@
 | 
			
		||||
import {TemplateProductSystemGenerator} from "./TemplateProductSystemGenerator";
 | 
			
		||||
import {ProductGenerationData} from "./ProductGenerationData";
 | 
			
		||||
import {ProductGeneratorResult} from "./ProductGeneratorResult";
 | 
			
		||||
import {ProductState} from "../states/ProductState";
 | 
			
		||||
import {ProductTransition} from "../transitions/ProductTransition";
 | 
			
		||||
import {ProductTemplateSystem} from "../../templates/productGamesystem/ProductTemplateSystem";
 | 
			
		||||
 | 
			
		||||
export class SymmetricProductTemplateGenerator extends TemplateProductSystemGenerator {
 | 
			
		||||
  protected generateFromBinaryChildsystems(leftSystemData: ProductGenerationData, rightSystemData: ProductGenerationData): ProductGeneratorResult {
 | 
			
		||||
    const generatedProductStates: ProductState[] = []
 | 
			
		||||
    const generatedProductTransitions: ProductTransition[] = []
 | 
			
		||||
 | 
			
		||||
    leftSystemData.states.forEach(leftState => {
 | 
			
		||||
      rightSystemData.states.forEach(rightState => {
 | 
			
		||||
        if(leftState.equals(rightState)) {
 | 
			
		||||
          for(let i=0; i<leftState.outgoingTransitions.length; i++) {
 | 
			
		||||
            for(let j=0; j<rightState.outgoingTransitions.length; j++) {
 | 
			
		||||
              const startingState = this.generateBinaryProductState(leftState, rightState, generatedProductStates);
 | 
			
		||||
              if(startingState != undefined && leftState.outgoingTransitions[i].endingState.equals(rightState.outgoingTransitions[j].endingState)) {
 | 
			
		||||
                const endingState_left_right = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
 | 
			
		||||
                if(endingState_left_right != undefined) {
 | 
			
		||||
                  this.generateBinaryProductTransitionMulti(startingState, endingState_left_right, leftState.outgoingTransitions[i], rightState.outgoingTransitions[j], generatedProductTransitions);
 | 
			
		||||
                }
 | 
			
		||||
              }
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    return new ProductGeneratorResult(generatedProductStates, generatedProductTransitions);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -12,6 +12,7 @@ import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition";
 | 
			
		||||
import {SimpleTemplateState} from "../../templates/simpleGamesystem/SimpleTemplateState";
 | 
			
		||||
import {Character} from "../../characters/Character";
 | 
			
		||||
import {CharacterRelation} from "../../characters/CharacterRelation";
 | 
			
		||||
import {ProductGenerationData} from "./ProductGenerationData";
 | 
			
		||||
 | 
			
		||||
export class TemplateProductSystemGenerator extends ProductSystemGenerator {
 | 
			
		||||
 | 
			
		||||
@ -28,7 +29,8 @@ export class TemplateProductSystemGenerator extends ProductSystemGenerator {
 | 
			
		||||
    productTemplateSystem.transitionMap.set(this.templateElement, generationResult.transitions)
 | 
			
		||||
    productTemplateSystem.stateMap.set(this.templateElement, generationResult.states)
 | 
			
		||||
 | 
			
		||||
    console.log("Test")
 | 
			
		||||
    console.log("Symmetric", (this.productGamesystem as ProductTemplateSystem).symmetric)
 | 
			
		||||
    console.log("Template: ", generationResult.transitions.length)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected getTransitionConditions(transition: Transition<any>, leftSystem: boolean) {
 | 
			
		||||
 | 
			
		||||
@ -7,12 +7,16 @@ import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem";
 | 
			
		||||
import {GameModel} from "../../GameModel";
 | 
			
		||||
import {TemplateType} from "../TemplateType";
 | 
			
		||||
import {TemplateProductSystemGenerator} from "../../gamesystems/productSystemGenerator/TemplateProductSystemGenerator";
 | 
			
		||||
import {
 | 
			
		||||
  SymmetricProductTemplateGenerator
 | 
			
		||||
} from "../../gamesystems/productSystemGenerator/SymmetricProductTemplateGenerator";
 | 
			
		||||
 | 
			
		||||
export class ProductTemplateSystem extends ProductGamesystem implements TemplateGamesystem{
 | 
			
		||||
 | 
			
		||||
  stateMap: Map<TemplateElement, ProductState[]> = new Map();
 | 
			
		||||
  transitionMap: Map<TemplateElement, ProductTransition[]> = new Map<TemplateElement, ProductTransition[]>()
 | 
			
		||||
  templateType: TemplateType
 | 
			
		||||
  symmetric: boolean = false
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  constructor(gamesystemName: string, gamesystemDescription: string, templateType: TemplateType) {
 | 
			
		||||
@ -21,8 +25,14 @@ export class ProductTemplateSystem extends ProductGamesystem implements Template
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  addTemplateElement(templateElement: TemplateElement): void {
 | 
			
		||||
    if(this.symmetric) {
 | 
			
		||||
      const symmetricGenerator = new SymmetricProductTemplateGenerator(this, templateElement);
 | 
			
		||||
      symmetricGenerator.generateFromChildsystems()
 | 
			
		||||
    } else {
 | 
			
		||||
      const productTemplateGenerator = new TemplateProductSystemGenerator(this, templateElement);
 | 
			
		||||
      productTemplateGenerator.generateFromChildsystems()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -10,6 +10,7 @@ import {TemplateType} from "../TemplateType";
 | 
			
		||||
export class SimpleTemplateGamesystem extends SimpleGamesystem implements TemplateGamesystem {
 | 
			
		||||
 | 
			
		||||
  templateType: TemplateType
 | 
			
		||||
  symmetric: boolean = true
 | 
			
		||||
 | 
			
		||||
  constructor(gamesystemName: string, gamesystemDescription: string, templateType: TemplateType) {
 | 
			
		||||
    super(gamesystemName, gamesystemDescription);
 | 
			
		||||
 | 
			
		||||
@ -44,7 +44,8 @@
 | 
			
		||||
                    "conditionMap": [],
 | 
			
		||||
                    "actionMap": []
 | 
			
		||||
                }
 | 
			
		||||
            ]
 | 
			
		||||
            ],
 | 
			
		||||
            "symmetric": true
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
@ -47,5 +47,6 @@
 | 
			
		||||
            "endingState": "Feind"
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    "symmetric": true,
 | 
			
		||||
    "templateType": 1
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user