template-systems #41

Merged
sebastian merged 30 commits from template-systems into main 2024-04-19 21:10:01 +02:00
10 changed files with 77 additions and 4 deletions
Showing only changes of commit 3e3b03d722 - Show all commits

View File

@ -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-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()" <app-product-gamesystem-editor *ngIf="!isSimpleGamesystem()" [templateElement]="templateElement" [gamesystem]="convertGamesystemToProductGamesystem()"
(onOpenGamesystemEditor)="onOpenGamesystemEditor($event)"></app-product-gamesystem-editor> (onOpenGamesystemEditor)="onOpenGamesystemEditor($event)"></app-product-gamesystem-editor>

View File

@ -6,6 +6,8 @@ import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccou
import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem"; import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem";
import {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem"; import {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem";
import {TemplateElement} from "../../project/game-model/templates/TemplateElement"; 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({ @Component({
selector: 'app-gamesystem-editor', selector: 'app-gamesystem-editor',
@ -42,4 +44,19 @@ export class GamesystemEditorComponent implements OnInit{
onOpenGamesystemEditor(gamesystem: SimpleGamesystem) { onOpenGamesystemEditor(gamesystem: SimpleGamesystem) {
this.openGamesystemEmitter.emit(gamesystem); 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
}
}
} }

View File

@ -21,6 +21,7 @@ export class CharacterRelation implements TemplateElement{
addCharacterRelationSystem(gamesystem: Gamesystem<any, any>) { addCharacterRelationSystem(gamesystem: Gamesystem<any, any>) {
if((gamesystem instanceof SimpleTemplateGamesystem || gamesystem instanceof ProductTemplateSystem) && !this.isGamesystemCharacterRelationSpecific(gamesystem.componentName)) { if((gamesystem instanceof SimpleTemplateGamesystem || gamesystem instanceof ProductTemplateSystem) && !this.isGamesystemCharacterRelationSpecific(gamesystem.componentName)) {
const templateGamesystem = new ProductTemplateSystem(gamesystem.componentName, gamesystem.componentDescription, TemplateType.CHARACTER_RELATION); const templateGamesystem = new ProductTemplateSystem(gamesystem.componentName, gamesystem.componentDescription, TemplateType.CHARACTER_RELATION);
templateGamesystem.symmetric = gamesystem.symmetric
templateGamesystem.addChildGamesystem(gamesystem); templateGamesystem.addChildGamesystem(gamesystem);
templateGamesystem.addChildGamesystem(gamesystem); templateGamesystem.addChildGamesystem(gamesystem);
this.characterRelationGamesystems.push(templateGamesystem); this.characterRelationGamesystems.push(templateGamesystem);

View File

@ -9,6 +9,7 @@ import {Gamesystem} from "../Gamesystem";
import {ProductGenerationData} from "./ProductGenerationData"; import {ProductGenerationData} from "./ProductGenerationData";
import {ProductTransition} from "../transitions/ProductTransition"; import {ProductTransition} from "../transitions/ProductTransition";
import {SimpleTemplateTransition} from "../../templates/simpleGamesystem/SimpleTemplateTransition"; import {SimpleTemplateTransition} from "../../templates/simpleGamesystem/SimpleTemplateTransition";
import {ProductTemplateSystem} from "../../templates/productGamesystem/ProductTemplateSystem";
export class ProductSystemGenerator { export class ProductSystemGenerator {
productGamesystem: ProductGamesystem productGamesystem: ProductGamesystem
@ -106,6 +107,8 @@ export class ProductSystemGenerator {
protected assignGeneratedStatesAndTransitions(generationResult: ProductGeneratorResult): void { protected assignGeneratedStatesAndTransitions(generationResult: ProductGeneratorResult): void {
this.productGamesystem.states = generationResult.states; this.productGamesystem.states = generationResult.states;
this.productGamesystem.transitions = generationResult.transitions; this.productGamesystem.transitions = generationResult.transitions;
console.log("General ", generationResult.transitions.length)
} }
protected generateBinaryProductTransition(startingState: ProductState, endingState: ProductState, usedTransition: Transition<any>, generatedTransitions: ProductTransition[], leftSystem: boolean) { protected generateBinaryProductTransition(startingState: ProductState, endingState: ProductState, usedTransition: Transition<any>, generatedTransitions: ProductTransition[], leftSystem: boolean) {

View File

@ -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);
}
}

View File

@ -12,6 +12,7 @@ import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition";
import {SimpleTemplateState} from "../../templates/simpleGamesystem/SimpleTemplateState"; import {SimpleTemplateState} from "../../templates/simpleGamesystem/SimpleTemplateState";
import {Character} from "../../characters/Character"; import {Character} from "../../characters/Character";
import {CharacterRelation} from "../../characters/CharacterRelation"; import {CharacterRelation} from "../../characters/CharacterRelation";
import {ProductGenerationData} from "./ProductGenerationData";
export class TemplateProductSystemGenerator extends ProductSystemGenerator { export class TemplateProductSystemGenerator extends ProductSystemGenerator {
@ -28,7 +29,8 @@ export class TemplateProductSystemGenerator extends ProductSystemGenerator {
productTemplateSystem.transitionMap.set(this.templateElement, generationResult.transitions) productTemplateSystem.transitionMap.set(this.templateElement, generationResult.transitions)
productTemplateSystem.stateMap.set(this.templateElement, generationResult.states) 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) { protected getTransitionConditions(transition: Transition<any>, leftSystem: boolean) {

View File

@ -7,12 +7,16 @@ import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem";
import {GameModel} from "../../GameModel"; import {GameModel} from "../../GameModel";
import {TemplateType} from "../TemplateType"; import {TemplateType} from "../TemplateType";
import {TemplateProductSystemGenerator} from "../../gamesystems/productSystemGenerator/TemplateProductSystemGenerator"; import {TemplateProductSystemGenerator} from "../../gamesystems/productSystemGenerator/TemplateProductSystemGenerator";
import {
SymmetricProductTemplateGenerator
} from "../../gamesystems/productSystemGenerator/SymmetricProductTemplateGenerator";
export class ProductTemplateSystem extends ProductGamesystem implements TemplateGamesystem{ export class ProductTemplateSystem extends ProductGamesystem implements TemplateGamesystem{
stateMap: Map<TemplateElement, ProductState[]> = new Map(); stateMap: Map<TemplateElement, ProductState[]> = new Map();
transitionMap: Map<TemplateElement, ProductTransition[]> = new Map<TemplateElement, ProductTransition[]>() transitionMap: Map<TemplateElement, ProductTransition[]> = new Map<TemplateElement, ProductTransition[]>()
templateType: TemplateType templateType: TemplateType
symmetric: boolean = false
constructor(gamesystemName: string, gamesystemDescription: string, templateType: TemplateType) { constructor(gamesystemName: string, gamesystemDescription: string, templateType: TemplateType) {
@ -21,8 +25,14 @@ export class ProductTemplateSystem extends ProductGamesystem implements Template
} }
addTemplateElement(templateElement: TemplateElement): void { addTemplateElement(templateElement: TemplateElement): void {
if(this.symmetric) {
const symmetricGenerator = new SymmetricProductTemplateGenerator(this, templateElement);
symmetricGenerator.generateFromChildsystems()
} else {
const productTemplateGenerator = new TemplateProductSystemGenerator(this, templateElement); const productTemplateGenerator = new TemplateProductSystemGenerator(this, templateElement);
productTemplateGenerator.generateFromChildsystems() productTemplateGenerator.generateFromChildsystems()
} }
} }
}

View File

@ -10,6 +10,7 @@ import {TemplateType} from "../TemplateType";
export class SimpleTemplateGamesystem extends SimpleGamesystem implements TemplateGamesystem { export class SimpleTemplateGamesystem extends SimpleGamesystem implements TemplateGamesystem {
templateType: TemplateType templateType: TemplateType
symmetric: boolean = true
constructor(gamesystemName: string, gamesystemDescription: string, templateType: TemplateType) { constructor(gamesystemName: string, gamesystemDescription: string, templateType: TemplateType) {
super(gamesystemName, gamesystemDescription); super(gamesystemName, gamesystemDescription);

View File

@ -44,7 +44,8 @@
"conditionMap": [], "conditionMap": [],
"actionMap": [] "actionMap": []
} }
] ],
"symmetric": true
} }
] ]
} }

View File

@ -47,5 +47,6 @@
"endingState": "Feind" "endingState": "Feind"
} }
], ],
"symmetric": true,
"templateType": 1 "templateType": 1
} }