product-template-systems #33

Merged
sebastian merged 8 commits from product-template-systems into template-systems 2024-04-14 11:45:39 +02:00
14 changed files with 201 additions and 22 deletions

View File

@ -157,8 +157,13 @@ export class AppComponent implements OnInit{
} }
//const createdGamesystem = this.gameModel!.createGamesystem("New Gamesystem", parentGamesystemName, templateType); let createdGamesystem;
const createdGamesystem = this.gameModel!.createSimpleGamesystem("New Gamesystem", templateType) if(parentGamesystemName == undefined) {
createdGamesystem = this.gameModel?.createSimpleGamesystem("New Gamesystem", templateType);
} else {
createdGamesystem = this.gameModel!.createSimpleGamesystemWithParent("New Gamesystem", parentGamesystemName, templateType)
}
if(createdGamesystem != undefined) { if(createdGamesystem != undefined) {
this.gamesystemOverview!.refresh(); this.gamesystemOverview!.refresh();
this.editor?.openGameModelComponent(createdGamesystem); this.editor?.openGameModelComponent(createdGamesystem);

View File

@ -8,6 +8,8 @@ import {Character} from "./characters/Character";
import {ModelComponentType} from "./ModelComponentType"; import {ModelComponentType} from "./ModelComponentType";
import {TemplateType} from "./templates/TemplateType"; import {TemplateType} from "./templates/TemplateType";
import {SimpleTemplateGamesystem} from "./templates/simpleGamesystem/SimpleTemplateGamesystem"; import {SimpleTemplateGamesystem} from "./templates/simpleGamesystem/SimpleTemplateGamesystem";
import {ProductTemplateSystem} from "./templates/productGamesystem/ProductTemplateSystem";
import {ProductTemplateCreator} from "./templates/productGamesystem/ProductTemplateCreator";
export class GameModel { export class GameModel {
gameModelName: string gameModelName: string
@ -47,7 +49,7 @@ export class GameModel {
return undefined; return undefined;
} }
createSimpleGamesystem(gamesystemName: string, templateType: TemplateType | undefined) { createSimpleGamesystem(gamesystemName: string, templateType: TemplateType | undefined, pushToTop: boolean = true) {
if(gamesystemName != undefined && this.findGamesystem(gamesystemName) == undefined) { if(gamesystemName != undefined && this.findGamesystem(gamesystemName) == undefined) {
let simpleGamesystem: SimpleGamesystem let simpleGamesystem: SimpleGamesystem
@ -57,12 +59,48 @@ export class GameModel {
simpleGamesystem = new SimpleTemplateGamesystem(gamesystemName, "", templateType) simpleGamesystem = new SimpleTemplateGamesystem(gamesystemName, "", templateType)
} }
this.gamesystems.push(simpleGamesystem) if(pushToTop) {
this.gamesystems.push(simpleGamesystem)
}
return simpleGamesystem; return simpleGamesystem;
} }
return undefined; return undefined;
} }
createSimpleGamesystemWithParent(gamesystemName: string, parentGamesystemName: string, templateType: TemplateType | undefined) {
const simpleGamesystem = this.createSimpleGamesystem(gamesystemName, templateType, false)!;
const parentGamesystem = this.findGamesystem(parentGamesystemName)
if(parentGamesystem == undefined) {return undefined}
let parentProductGamesystem: ProductGamesystem;
if(parentGamesystem instanceof SimpleTemplateGamesystem) {
parentProductGamesystem = ProductTemplateCreator.constructTemplateFromSimpleGamesystem(parentGamesystem, this, templateType!)
} else if(parentGamesystem instanceof SimpleGamesystem) {
if(simpleGamesystem instanceof SimpleTemplateGamesystem) {
parentProductGamesystem = ProductTemplateCreator.constructTemplateFromSimpleGamesystem(parentGamesystem, this, templateType!)
} else {
console.log("Test")
parentProductGamesystem = ProductGamesystem.constructFromSimpleGamesystem(parentGamesystem, this);
console.log(this.gamesystems)
}
} else {
if(simpleGamesystem instanceof SimpleTemplateGamesystem) {
parentProductGamesystem = ProductTemplateCreator.convertProductToTemplate(parentGamesystem as ProductGamesystem, this, templateType!)
} else {
parentProductGamesystem = parentGamesystem as ProductGamesystem
}
}
parentProductGamesystem.addChildGamesystem(simpleGamesystem);
simpleGamesystem.parentGamesystem = parentProductGamesystem;
return simpleGamesystem;
}
createGamesystem(gamesystemName: string, parentGamesystemName: string | undefined, templateType: TemplateType | undefined) { createGamesystem(gamesystemName: string, parentGamesystemName: string | undefined, templateType: TemplateType | undefined) {
if(gamesystemName != undefined && this.findGamesystem(gamesystemName) == undefined) { if(gamesystemName != undefined && this.findGamesystem(gamesystemName) == undefined) {
const simpleGamesystem = new SimpleGamesystem(gamesystemName, ""); const simpleGamesystem = new SimpleGamesystem(gamesystemName, "");
@ -140,7 +178,9 @@ export class GameModel {
while(gamesystemQueue.length > 0) { while(gamesystemQueue.length > 0) {
const currentGamesystem = gamesystemQueue.shift()!; const currentGamesystem = gamesystemQueue.shift()!;
if(currentGamesystem instanceof SimpleTemplateGamesystem && currentGamesystem.templateType === templateType) { if(currentGamesystem instanceof SimpleTemplateGamesystem && currentGamesystem.templateType === templateType) {
requestedTemplates.push(currentGamesystem)
} else if(currentGamesystem instanceof ProductTemplateSystem && currentGamesystem.templateType === templateType) {
requestedTemplates.push(currentGamesystem) requestedTemplates.push(currentGamesystem)
} }

View File

@ -4,6 +4,8 @@ import {TemplateElement} from "../templates/TemplateElement";
import {TemplateGamesystem} from "../templates/TemplateGamesystem"; import {TemplateGamesystem} from "../templates/TemplateGamesystem";
import {Gamesystem} from "../gamesystems/Gamesystem"; import {Gamesystem} from "../gamesystems/Gamesystem";
import {SimpleTemplateGamesystem} from "../templates/simpleGamesystem/SimpleTemplateGamesystem"; import {SimpleTemplateGamesystem} from "../templates/simpleGamesystem/SimpleTemplateGamesystem";
import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem";
import {ProductGamesystem} from "../gamesystems/ProductGamesystem";
export class Character extends ModelComponent implements TemplateElement { export class Character extends ModelComponent implements TemplateElement {
@ -13,10 +15,24 @@ export class Character extends ModelComponent implements TemplateElement {
super(componentName, componentDescription, ModelComponentType.CHARACTER); super(componentName, componentDescription, ModelComponentType.CHARACTER);
} }
addCharacterSpecificSimpleTemplatesystem(gamesystem: SimpleTemplateGamesystem) { addCharacterSpecificSimpleTemplatesystem(gamesystem: Gamesystem<any, any>, recursiveCall: boolean = false) {
if(!this.isTemplateSystemCharacterSpecific(gamesystem.componentName)) { if(!this.isTemplateSystemCharacterSpecific(gamesystem.componentName)) {
this.characterSpecificTemplateSystems.push(gamesystem) if(gamesystem instanceof SimpleTemplateGamesystem) {
gamesystem.addTemplateElement(this) this.characterSpecificTemplateSystems.push(gamesystem)
gamesystem.addTemplateElement(this)
} else if(gamesystem instanceof ProductTemplateSystem) {
this.characterSpecificTemplateSystems.push(gamesystem)
gamesystem.addTemplateElement(this)
if(!recursiveCall) {
gamesystem.innerGamesystems.forEach(innerGamesystem => this.addCharacterSpecificSimpleTemplatesystem(innerGamesystem, true))
}
}
if(gamesystem.parentGamesystem != undefined) {
this.addCharacterSpecificSimpleTemplatesystem(gamesystem.parentGamesystem, true)
}
} }
} }

View File

@ -9,6 +9,8 @@ import {GameModel} from "../GameModel";
import {ScriptAccountCondition} from "./conditions/ScriptAccountCondition"; import {ScriptAccountCondition} from "./conditions/ScriptAccountCondition";
import {ScriptAccountAction} from "./actions/ScriptAccountAction"; import {ScriptAccountAction} from "./actions/ScriptAccountAction";
import {ProductSystemGenerator} from "./productSystemGenerator/ProductSystemGenerator"; import {ProductSystemGenerator} from "./productSystemGenerator/ProductSystemGenerator";
import {TemplateType} from "../templates/TemplateType";
import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem";
export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> { export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> {
@ -16,25 +18,28 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
static constructFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel) { static constructFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel) {
const productGamesystem = new ProductGamesystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription); const productGamesystem = new ProductGamesystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription);
productGamesystem.constructHierarchyFromSimpleGamesystem(simpleGamesystem, gameModel);
return productGamesystem;
}
constructHierarchyFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel) {
const parentGamesystem = simpleGamesystem.parentGamesystem; const parentGamesystem = simpleGamesystem.parentGamesystem;
if(simpleGamesystem.states.length > 0) { if(simpleGamesystem.states.length > 0) {
simpleGamesystem.componentName += "(Child)"; simpleGamesystem.componentName += "(Child)";
productGamesystem.addChildGamesystem(simpleGamesystem); this.addChildGamesystem(simpleGamesystem);
simpleGamesystem.parentGamesystem = productGamesystem simpleGamesystem.parentGamesystem = this
} }
if(parentGamesystem != undefined) { if(parentGamesystem != undefined) {
parentGamesystem.removeChildGamesystem(simpleGamesystem); parentGamesystem.removeChildGamesystem(simpleGamesystem);
parentGamesystem.addChildGamesystem(productGamesystem); parentGamesystem.addChildGamesystem(this);
productGamesystem.parentGamesystem = parentGamesystem this.parentGamesystem = parentGamesystem
} else { } else {
gameModel.removeGamesystem(simpleGamesystem); gameModel.removeGamesystem(simpleGamesystem);
gameModel.addGamesystem(productGamesystem); gameModel.addGamesystem(this);
} }
return productGamesystem;
} }
createState(innerStates: State<any>[]): ProductState | undefined { createState(innerStates: State<any>[]): ProductState | undefined {

View File

@ -0,0 +1,30 @@
import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem";
import {GameModel} from "../../GameModel";
import {TemplateType} from "../TemplateType";
import {ProductTemplateSystem} from "./ProductTemplateSystem";
import {ProductGamesystem} from "../../gamesystems/ProductGamesystem";
export class ProductTemplateCreator {
static constructTemplateFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel, templateType: TemplateType) {
const productGamesystem = new ProductTemplateSystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription, templateType);
productGamesystem.constructHierarchyFromSimpleGamesystem(simpleGamesystem, gameModel);
return productGamesystem;
}
static convertProductToTemplate(productGamesystem: ProductGamesystem, gameModel: GameModel, templateType: TemplateType) {
const productTemplate = new ProductTemplateSystem(productGamesystem.componentName, productGamesystem.componentDescription, templateType);
productTemplate.states = productGamesystem.states
productTemplate.transitions = productGamesystem.transitions
productTemplate.innerGamesystems = productGamesystem.innerGamesystems;
productGamesystem.innerGamesystems.forEach(innerGamesystem => innerGamesystem.parentGamesystem = productTemplate);
if(productGamesystem.parentGamesystem == undefined) {
gameModel.removeGamesystem(productGamesystem)
gameModel.gamesystems.push(productTemplate)
} else {
productTemplate.parentGamesystem = productGamesystem.parentGamesystem;
productGamesystem.parentGamesystem.addChildGamesystem(productTemplate);
}
return productTemplate;
}
}

View File

@ -0,0 +1,26 @@
import {ProductGamesystem} from "../../gamesystems/ProductGamesystem";
import {TemplateGamesystem} from "../TemplateGamesystem";
import {TemplateElement} from "../TemplateElement";
import {ProductState} from "../../gamesystems/states/ProductState";
import {ProductTransition} from "../../gamesystems/transitions/ProductTransition";
import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem";
import {GameModel} from "../../GameModel";
import {TemplateType} from "../TemplateType";
export class ProductTemplateSystem extends ProductGamesystem implements TemplateGamesystem{
stateMap: Map<TemplateElement, ProductState[]> = new Map();
transitionMap: Map<TemplateElement, ProductTransition[]> = new Map<TemplateElement, ProductTransition[]>()
templateType: TemplateType
constructor(gamesystemName: string, gamesystemDescription: string, templateType: TemplateType) {
super(gamesystemName, gamesystemDescription);
this.templateType = templateType;
}
addTemplateElement(templateElement: TemplateElement): void {
}
}

View File

@ -7,6 +7,7 @@ import {StateParser} from "./StateParser";
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {TransitionParser} from "./TransitionParser"; import {TransitionParser} from "./TransitionParser";
import {SimpleTemplateGamesystem} from "../../game-model/templates/simpleGamesystem/SimpleTemplateGamesystem"; import {SimpleTemplateGamesystem} from "../../game-model/templates/simpleGamesystem/SimpleTemplateGamesystem";
import {ProductTemplateSystem} from "../../game-model/templates/productGamesystem/ProductTemplateSystem";
export class GamesystemParser { export class GamesystemParser {
@ -60,7 +61,13 @@ export class GamesystemParser {
} }
parseProductGamesystem(gamesystemData: any) { parseProductGamesystem(gamesystemData: any) {
const productGamesystem = new ProductGamesystem(gamesystemData.componentName, gamesystemData.componentDescription); let productGamesystem;
if(gamesystemData.templateType == undefined) {
productGamesystem = new ProductGamesystem(gamesystemData.componentName, gamesystemData.componentDescription);
} else {
productGamesystem = new ProductTemplateSystem(gamesystemData.componentName, gamesystemData.componentDescription, gamesystemData.templateType)
}
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)

View File

@ -51,7 +51,7 @@ export class CharacterSerializer {
} }
}, SerializeConstants.JSON_INDENT) }, SerializeConstants.JSON_INDENT)
character.characterSpecificTemplateSystems = templateGamesystemBackup
return new StoreComponent(jsonString, fileName, ModelComponentType.CHARACTER); return new StoreComponent(jsonString, fileName, ModelComponentType.CHARACTER);
} }
} }

View File

@ -4,6 +4,7 @@ import {SimpleGamesystem} from "../game-model/gamesystems/SimpleGamesystem";
import {ProductGamesystem} from "../game-model/gamesystems/ProductGamesystem"; import {ProductGamesystem} from "../game-model/gamesystems/ProductGamesystem";
import {SerializeConstants} from "./SerializeConstants"; import {SerializeConstants} from "./SerializeConstants";
import {ModelComponentType} from "../game-model/ModelComponentType"; import {ModelComponentType} from "../game-model/ModelComponentType";
import {ProductTemplateSystem} from "../game-model/templates/productGamesystem/ProductTemplateSystem";
export class GamesystemSerializer { export class GamesystemSerializer {
@ -59,12 +60,24 @@ export class GamesystemSerializer {
storedChildsystems.forEach(storedChildsystem => storedGamesystems.push(storedChildsystem)) storedChildsystems.forEach(storedChildsystem => storedGamesystems.push(storedChildsystem))
}) })
const jsonString = { let jsonString;
'componentName': productGamesystem.componentName, if(productGamesystem instanceof ProductTemplateSystem) {
'componentDescription': productGamesystem.componentDescription, jsonString = {
'childsystems': innerGamesystemJsonArray 'componentName': productGamesystem.componentName,
'componentDescription': productGamesystem.componentDescription,
'childsystems': innerGamesystemJsonArray,
'templateType': productGamesystem.templateType
}
} else {
jsonString = {
'componentName': productGamesystem.componentName,
'componentDescription': productGamesystem.componentDescription,
'childsystems': innerGamesystemJsonArray,
}
} }
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)
storedGamesystems.push(storedProductsystem) storedGamesystems.push(storedProductsystem)

View File

@ -1,5 +1,11 @@
{ {
"componentName": "Astrid Hofferson", "componentName": "Astrid Hofferson",
"componentDescription": "", "componentDescription": "",
"characterSpecificTemplateSystems": [] "characterSpecificTemplateSystems": [
{
"componentName": "Letters",
"states": [],
"transitions": []
}
]
} }

View File

@ -34,6 +34,11 @@
"actionMap": [] "actionMap": []
} }
] ]
},
{
"componentName": "Letters",
"states": [],
"transitions": []
} }
] ]
} }

View File

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

View File

@ -0,0 +1,6 @@
{
"componentName": "Numbers",
"componentDescription": "",
"states": [],
"transitions": []
}

View File

@ -0,0 +1,13 @@
{
"componentName": "Producttest",
"componentDescription": "",
"childsystems": [
{
"componentName": "Letters"
},
{
"componentName": "Numbers"
}
],
"templateType": 0
}