Parse and Load ProductTemplateSystem
All checks were successful
E2E Testing / test (push) Successful in 1m33s

This commit is contained in:
Sebastian Böckelmann 2024-04-13 06:43:54 +02:00
parent 69c820581a
commit a2645e1324
7 changed files with 67 additions and 24 deletions

View File

@ -7,6 +7,7 @@ import {SimpleGamesystem} from "./gamesystems/SimpleGamesystem";
import {Character} from "./characters/Character";
import {TemplateType} from "./TemplateType";
import {SimpleTemplateGamesystem} from "./gamesystems/SimpleTemplateGamesystem";
import {ProductTemplateSystem} from "./gamesystems/ProductTemplateSystem";
export class GameModel {
@ -58,10 +59,19 @@ export class GameModel {
if(parentGamesystemName != undefined) {
const parentGamesystem = this.findGamesystem(parentGamesystemName);
if(parentGamesystem instanceof SimpleGamesystem) {
const parentProductGamesystem = ProductGamesystem.constructFromSimpleGamesystem(parentGamesystem, this);
parentProductGamesystem.addChildGamesystem(simpleGamesystem);
simpleGamesystem.parentGamesystem = parentProductGamesystem;
if(parentGamesystem instanceof SimpleGamesystem || parentGamesystem instanceof SimpleTemplateGamesystem) {
if(parentGamesystem.templateType == TemplateType.NORMAL) {
const parentProductGamesystem = new ProductGamesystem(parentGamesystem.componentName, parentGamesystem.componentDescription);
parentProductGamesystem.constructFromSimpleGamesystem(parentGamesystem, this);
parentProductGamesystem.addChildGamesystem(simpleGamesystem);
simpleGamesystem.parentGamesystem = parentProductGamesystem;
} else {
const parentProductTemplateGamesystem = new ProductTemplateSystem<Character>(parentGamesystem.componentName, parentGamesystem.componentDescription, TemplateType.CHARACTER);
parentProductTemplateGamesystem.constructFromSimpleGamesystem(parentGamesystem, this);
parentProductTemplateGamesystem.addChildGamesystem(simpleGamesystem);
simpleGamesystem.parentGamesystem = parentProductTemplateGamesystem;
}
} else {
const productParentGamesystem = parentGamesystem as ProductGamesystem;
productParentGamesystem.addChildGamesystem(simpleGamesystem);

View File

@ -6,38 +6,39 @@ import {Transition} from "./transitions/Transition";
import {SimpleState} from "./states/SimpleState";
import {SimpleGamesystem} from "./SimpleGamesystem";
import {GameModel} from "../GameModel";
import {ScriptAccountCondition} from "./conditions/ScriptAccountCondition";
import {ScriptAccountAction} from "./actions/ScriptAccountAction";
import {ProductGamesystemGenerator} from "./productSystemGenerator/ProductGamesystemGenerator";
import {TemplateType} from "../TemplateType";
import {ProductTemplateSystem} from "./ProductTemplateSystem";
import {Character} from "../characters/Character";
export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> {
innerGamesystems: Gamesystem<State<any>, Transition<any>>[] = [];
productGamesystemGenerator: ProductGamesystemGenerator = new ProductGamesystemGenerator(this);
static constructFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel) {
const productGamesystem = new ProductGamesystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription);
const parentGamesystem = simpleGamesystem.parentGamesystem;
constructFromSimpleGamesystem(referenceSystem: SimpleGamesystem, gameModel: GameModel) {
if(simpleGamesystem.states.length > 0) {
simpleGamesystem.componentName += "(Child)";
productGamesystem.addChildGamesystem(simpleGamesystem);
simpleGamesystem.parentGamesystem = productGamesystem
const parentGamesystem = referenceSystem.parentGamesystem;
if(referenceSystem.states.length > 0) {
referenceSystem.componentName += "(Child)";
this.addChildGamesystem(referenceSystem);
referenceSystem.parentGamesystem = this
}
if(parentGamesystem != undefined) {
parentGamesystem.removeChildGamesystem(simpleGamesystem);
parentGamesystem.addChildGamesystem(productGamesystem);
productGamesystem.parentGamesystem = parentGamesystem
parentGamesystem.removeChildGamesystem(referenceSystem);
parentGamesystem.addChildGamesystem(this);
this.parentGamesystem = parentGamesystem
} else {
gameModel.removeGamesystem(simpleGamesystem);
gameModel.addGamesystem(productGamesystem);
gameModel.removeGamesystem(referenceSystem);
gameModel.addGamesystem(this);
}
return productGamesystem;
}
createState(innerStates: State<any>[]): ProductState | undefined {
if(innerStates.length == this.innerGamesystems.length && this.findProductStateByInnerStates(innerStates)== undefined) {
const productState = new ProductState(innerStates);

View File

@ -4,12 +4,21 @@ import {ProductTransition} from "./transitions/ProductTransition";
import {Gamesystem} from "./Gamesystem";
import {ProductTemplateGamesystemGenerator} from "./productSystemGenerator/ProductTemplateGamesystemGenerator";
import {ProductGamesystemGenerator} from "./productSystemGenerator/ProductGamesystemGenerator";
import {SimpleGamesystem} from "./SimpleGamesystem";
import {GameModel} from "../GameModel";
import {TemplateType} from "../TemplateType";
export class ProductTemplateSystem<ReferenceTemplate> extends ProductGamesystem {
stateMap: Map<ReferenceTemplate, ProductState[]> = new Map<ReferenceTemplate, ProductState[]>();
transitionMap: Map<ReferenceTemplate, ProductTransition[]> = new Map<ReferenceTemplate, ProductTransition[]>();
constructor(gamesystemName: string, gamesystemDescription: string, templateType: TemplateType) {
super(gamesystemName, gamesystemDescription);
this.templateType = templateType
}
generateFromChildsystems() {
const productSystemGenerator = new ProductGamesystemGenerator(this);
productSystemGenerator.generateFromChildsystems();
@ -19,6 +28,4 @@ export class ProductTemplateSystem<ReferenceTemplate> extends ProductGamesystem
const productSystemGenerator = new ProductTemplateGamesystemGenerator(this, referenceTemplate);
productSystemGenerator.generateFromChildsystems()
}
}

View File

@ -9,6 +9,7 @@ import {TransitionParser} from "./TransitionParser";
import {TemplateType} from "../../game-model/TemplateType";
import {SimpleTemplateGamesystem} from "../../game-model/gamesystems/SimpleTemplateGamesystem";
import {Character} from "../../game-model/characters/Character";
import {ProductTemplateSystem} from "../../game-model/gamesystems/ProductTemplateSystem";
export class GamesystemParser {
@ -61,7 +62,13 @@ export class GamesystemParser {
}
parseProductGamesystem(gamesystemData: any) {
const productGamesystem = new ProductGamesystem(gamesystemData.componentName, gamesystemData.componentDescription);
let productGamesystem: ProductGamesystem | ProductTemplateSystem<any>
if(gamesystemData.templateType == TemplateType.CHARACTER) {
productGamesystem = new ProductTemplateSystem(gamesystemData.componentName, gamesystemData.componentDescription, TemplateType.CHARACTER)
} else {
productGamesystem = new ProductGamesystem(gamesystemData.componentName, gamesystemData.componentDescription);
}
const childsystemNames: string[] = []
for(let i=0; i<gamesystemData.childsystems.length; i++) {
childsystemNames.push(gamesystemData.childsystems[i].componentName)

View File

@ -63,7 +63,8 @@ export class GamesystemSerializer {
const jsonString = {
'componentName': productGamesystem.componentName,
'componentDescription': productGamesystem.componentDescription,
'childsystems': innerGamesystemJsonArray
'childsystems': innerGamesystemJsonArray,
"templateType": productGamesystem.templateType
}
const storedProductsystem = new StoreComponent(JSON.stringify(jsonString, null, SerializeConstants.JSON_INDENT), fileName, ModelComponentType.GAMESYTEM)

View File

@ -0,0 +1,7 @@
{
"componentName": "New Gamesystem 1",
"componentDescription": "",
"states": [],
"transitions": [],
"templateType": 1
}

View File

@ -0,0 +1,10 @@
{
"componentName": "ProductTemplate",
"componentDescription": "",
"childsystems": [
{
"componentName": "New Gamesystem 1"
}
],
"templateType": 1
}