Parse and Load ProductTemplateSystem
All checks were successful
E2E Testing / test (push) Successful in 1m33s
All checks were successful
E2E Testing / test (push) Successful in 1m33s
This commit is contained in:
parent
69c820581a
commit
a2645e1324
@ -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);
|
||||
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);
|
||||
|
@ -6,37 +6,38 @@ 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) {
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"componentName": "New Gamesystem 1",
|
||||
"componentDescription": "",
|
||||
"states": [],
|
||||
"transitions": [],
|
||||
"templateType": 1
|
||||
}
|
10
testModel/gamesystems/ProductTemplate/ProductTemplate.json
Normal file
10
testModel/gamesystems/ProductTemplate/ProductTemplate.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"componentName": "ProductTemplate",
|
||||
"componentDescription": "",
|
||||
"childsystems": [
|
||||
{
|
||||
"componentName": "New Gamesystem 1"
|
||||
}
|
||||
],
|
||||
"templateType": 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user