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 {Character} from "./characters/Character";
|
||||||
import {TemplateType} from "./TemplateType";
|
import {TemplateType} from "./TemplateType";
|
||||||
import {SimpleTemplateGamesystem} from "./gamesystems/SimpleTemplateGamesystem";
|
import {SimpleTemplateGamesystem} from "./gamesystems/SimpleTemplateGamesystem";
|
||||||
|
import {ProductTemplateSystem} from "./gamesystems/ProductTemplateSystem";
|
||||||
|
|
||||||
export class GameModel {
|
export class GameModel {
|
||||||
|
|
||||||
@ -58,10 +59,19 @@ export class GameModel {
|
|||||||
|
|
||||||
if(parentGamesystemName != undefined) {
|
if(parentGamesystemName != undefined) {
|
||||||
const parentGamesystem = this.findGamesystem(parentGamesystemName);
|
const parentGamesystem = this.findGamesystem(parentGamesystemName);
|
||||||
if(parentGamesystem instanceof SimpleGamesystem) {
|
if(parentGamesystem instanceof SimpleGamesystem || parentGamesystem instanceof SimpleTemplateGamesystem) {
|
||||||
const parentProductGamesystem = ProductGamesystem.constructFromSimpleGamesystem(parentGamesystem, this);
|
if(parentGamesystem.templateType == TemplateType.NORMAL) {
|
||||||
|
const parentProductGamesystem = new ProductGamesystem(parentGamesystem.componentName, parentGamesystem.componentDescription);
|
||||||
|
parentProductGamesystem.constructFromSimpleGamesystem(parentGamesystem, this);
|
||||||
parentProductGamesystem.addChildGamesystem(simpleGamesystem);
|
parentProductGamesystem.addChildGamesystem(simpleGamesystem);
|
||||||
simpleGamesystem.parentGamesystem = parentProductGamesystem;
|
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 {
|
} else {
|
||||||
const productParentGamesystem = parentGamesystem as ProductGamesystem;
|
const productParentGamesystem = parentGamesystem as ProductGamesystem;
|
||||||
productParentGamesystem.addChildGamesystem(simpleGamesystem);
|
productParentGamesystem.addChildGamesystem(simpleGamesystem);
|
||||||
|
@ -6,37 +6,38 @@ import {Transition} from "./transitions/Transition";
|
|||||||
import {SimpleState} from "./states/SimpleState";
|
import {SimpleState} from "./states/SimpleState";
|
||||||
import {SimpleGamesystem} from "./SimpleGamesystem";
|
import {SimpleGamesystem} from "./SimpleGamesystem";
|
||||||
import {GameModel} from "../GameModel";
|
import {GameModel} from "../GameModel";
|
||||||
import {ScriptAccountCondition} from "./conditions/ScriptAccountCondition";
|
|
||||||
import {ScriptAccountAction} from "./actions/ScriptAccountAction";
|
|
||||||
import {ProductGamesystemGenerator} from "./productSystemGenerator/ProductGamesystemGenerator";
|
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> {
|
export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> {
|
||||||
|
|
||||||
innerGamesystems: Gamesystem<State<any>, Transition<any>>[] = [];
|
innerGamesystems: Gamesystem<State<any>, Transition<any>>[] = [];
|
||||||
productGamesystemGenerator: ProductGamesystemGenerator = new ProductGamesystemGenerator(this);
|
productGamesystemGenerator: ProductGamesystemGenerator = new ProductGamesystemGenerator(this);
|
||||||
|
|
||||||
static constructFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel) {
|
constructFromSimpleGamesystem(referenceSystem: SimpleGamesystem, gameModel: GameModel) {
|
||||||
const productGamesystem = new ProductGamesystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription);
|
|
||||||
const parentGamesystem = simpleGamesystem.parentGamesystem;
|
|
||||||
|
|
||||||
if(simpleGamesystem.states.length > 0) {
|
const parentGamesystem = referenceSystem.parentGamesystem;
|
||||||
simpleGamesystem.componentName += "(Child)";
|
|
||||||
productGamesystem.addChildGamesystem(simpleGamesystem);
|
if(referenceSystem.states.length > 0) {
|
||||||
simpleGamesystem.parentGamesystem = productGamesystem
|
referenceSystem.componentName += "(Child)";
|
||||||
|
this.addChildGamesystem(referenceSystem);
|
||||||
|
referenceSystem.parentGamesystem = this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(parentGamesystem != undefined) {
|
if(parentGamesystem != undefined) {
|
||||||
parentGamesystem.removeChildGamesystem(simpleGamesystem);
|
parentGamesystem.removeChildGamesystem(referenceSystem);
|
||||||
parentGamesystem.addChildGamesystem(productGamesystem);
|
parentGamesystem.addChildGamesystem(this);
|
||||||
productGamesystem.parentGamesystem = parentGamesystem
|
this.parentGamesystem = parentGamesystem
|
||||||
} else {
|
} else {
|
||||||
gameModel.removeGamesystem(simpleGamesystem);
|
gameModel.removeGamesystem(referenceSystem);
|
||||||
gameModel.addGamesystem(productGamesystem);
|
gameModel.addGamesystem(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return productGamesystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
createState(innerStates: State<any>[]): ProductState | undefined {
|
createState(innerStates: State<any>[]): ProductState | undefined {
|
||||||
if(innerStates.length == this.innerGamesystems.length && this.findProductStateByInnerStates(innerStates)== 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 {Gamesystem} from "./Gamesystem";
|
||||||
import {ProductTemplateGamesystemGenerator} from "./productSystemGenerator/ProductTemplateGamesystemGenerator";
|
import {ProductTemplateGamesystemGenerator} from "./productSystemGenerator/ProductTemplateGamesystemGenerator";
|
||||||
import {ProductGamesystemGenerator} from "./productSystemGenerator/ProductGamesystemGenerator";
|
import {ProductGamesystemGenerator} from "./productSystemGenerator/ProductGamesystemGenerator";
|
||||||
|
import {SimpleGamesystem} from "./SimpleGamesystem";
|
||||||
|
import {GameModel} from "../GameModel";
|
||||||
|
import {TemplateType} from "../TemplateType";
|
||||||
|
|
||||||
export class ProductTemplateSystem<ReferenceTemplate> extends ProductGamesystem {
|
export class ProductTemplateSystem<ReferenceTemplate> extends ProductGamesystem {
|
||||||
|
|
||||||
stateMap: Map<ReferenceTemplate, ProductState[]> = new Map<ReferenceTemplate, ProductState[]>();
|
stateMap: Map<ReferenceTemplate, ProductState[]> = new Map<ReferenceTemplate, ProductState[]>();
|
||||||
transitionMap: Map<ReferenceTemplate, ProductTransition[]> = new Map<ReferenceTemplate, ProductTransition[]>();
|
transitionMap: Map<ReferenceTemplate, ProductTransition[]> = new Map<ReferenceTemplate, ProductTransition[]>();
|
||||||
|
|
||||||
|
|
||||||
|
constructor(gamesystemName: string, gamesystemDescription: string, templateType: TemplateType) {
|
||||||
|
super(gamesystemName, gamesystemDescription);
|
||||||
|
this.templateType = templateType
|
||||||
|
}
|
||||||
|
|
||||||
generateFromChildsystems() {
|
generateFromChildsystems() {
|
||||||
const productSystemGenerator = new ProductGamesystemGenerator(this);
|
const productSystemGenerator = new ProductGamesystemGenerator(this);
|
||||||
productSystemGenerator.generateFromChildsystems();
|
productSystemGenerator.generateFromChildsystems();
|
||||||
@ -19,6 +28,4 @@ export class ProductTemplateSystem<ReferenceTemplate> extends ProductGamesystem
|
|||||||
const productSystemGenerator = new ProductTemplateGamesystemGenerator(this, referenceTemplate);
|
const productSystemGenerator = new ProductTemplateGamesystemGenerator(this, referenceTemplate);
|
||||||
productSystemGenerator.generateFromChildsystems()
|
productSystemGenerator.generateFromChildsystems()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import {TransitionParser} from "./TransitionParser";
|
|||||||
import {TemplateType} from "../../game-model/TemplateType";
|
import {TemplateType} from "../../game-model/TemplateType";
|
||||||
import {SimpleTemplateGamesystem} from "../../game-model/gamesystems/SimpleTemplateGamesystem";
|
import {SimpleTemplateGamesystem} from "../../game-model/gamesystems/SimpleTemplateGamesystem";
|
||||||
import {Character} from "../../game-model/characters/Character";
|
import {Character} from "../../game-model/characters/Character";
|
||||||
|
import {ProductTemplateSystem} from "../../game-model/gamesystems/ProductTemplateSystem";
|
||||||
|
|
||||||
export class GamesystemParser {
|
export class GamesystemParser {
|
||||||
|
|
||||||
@ -61,7 +62,13 @@ export class GamesystemParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parseProductGamesystem(gamesystemData: any) {
|
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[] = []
|
const childsystemNames: string[] = []
|
||||||
for(let i=0; i<gamesystemData.childsystems.length; i++) {
|
for(let i=0; i<gamesystemData.childsystems.length; i++) {
|
||||||
childsystemNames.push(gamesystemData.childsystems[i].componentName)
|
childsystemNames.push(gamesystemData.childsystems[i].componentName)
|
||||||
|
@ -63,7 +63,8 @@ export class GamesystemSerializer {
|
|||||||
const jsonString = {
|
const jsonString = {
|
||||||
'componentName': productGamesystem.componentName,
|
'componentName': productGamesystem.componentName,
|
||||||
'componentDescription': productGamesystem.componentDescription,
|
'componentDescription': productGamesystem.componentDescription,
|
||||||
'childsystems': innerGamesystemJsonArray
|
'childsystems': innerGamesystemJsonArray,
|
||||||
|
"templateType": productGamesystem.templateType
|
||||||
}
|
}
|
||||||
|
|
||||||
const storedProductsystem = new StoreComponent(JSON.stringify(jsonString, null, SerializeConstants.JSON_INDENT), fileName, ModelComponentType.GAMESYTEM)
|
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