From 61e3e9039593b148c56da3341ec64cedd11a5b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 11 Apr 2024 13:56:13 +0200 Subject: [PATCH] Consider TemplateType of Gamesystems to load and store --- .../game-model/gamesystems/Gamesystem.ts | 5 +++++ .../gamesystems/SimpleTemplateGamesystem.ts | 4 ---- .../gamesystemParser/GamesystemParser.ts | 11 +++++++++- .../serializer/GamesystemSerializer.ts | 5 +++-- testModel/characters/Astrid Hofferson.json | 3 ++- testModel/characters/Hicks Haddock.json | 3 ++- testModel/gamesystems/Characterstimmung.json | 20 +++++++++++++++++++ testModel/gamesystems/Testsystem.json | 3 ++- .../gamesystems/Weathersystem/Season.json | 3 ++- .../gamesystems/Weathersystem/Weather.json | 3 ++- 10 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 testModel/gamesystems/Characterstimmung.json diff --git a/src/app/project/game-model/gamesystems/Gamesystem.ts b/src/app/project/game-model/gamesystems/Gamesystem.ts index 2e94174..e41d1a0 100644 --- a/src/app/project/game-model/gamesystems/Gamesystem.ts +++ b/src/app/project/game-model/gamesystems/Gamesystem.ts @@ -2,12 +2,17 @@ import {SimpleGamesystem} from "./SimpleGamesystem"; import {ProductGamesystem} from "./ProductGamesystem"; import {ModelComponent} from "../ModelComponent"; import {ModelComponentType} from "../ModelComponentType"; +import {TemplateType} from "../TemplateType"; export abstract class Gamesystem extends ModelComponent{ states: S[] = []; transitions: T[] = []; parentGamesystem: ProductGamesystem | undefined + + templateType: TemplateType = TemplateType.NORMAL + + constructor(gamesystemName: string, gamesystemDescription: string) { super(gamesystemName, gamesystemDescription, ModelComponentType.GAMESYTEM); } diff --git a/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts b/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts index 6eabd03..022a703 100644 --- a/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts +++ b/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts @@ -1,14 +1,10 @@ -import {SimpleGamesystem} from "./SimpleGamesystem"; import {SimpleTemplateState} from "./states/SimpleTemplateState"; import {Gamesystem} from "./Gamesystem"; -import {SimpleTransition} from "./transitions/SimpleTransition"; import {SimpleState} from "./states/SimpleState"; import {SimpleTemplateTransition} from "./transitions/SimpleTemplateTransition"; import {TemplateType} from "../TemplateType"; -import {state} from "@angular/animations"; export class SimpleTemplateGamesystem extends Gamesystem, SimpleTemplateTransition> { - createState(label: string, description: string): SimpleState | undefined { if(label == null) { return undefined; diff --git a/src/app/project/parser/gamesystemParser/GamesystemParser.ts b/src/app/project/parser/gamesystemParser/GamesystemParser.ts index e085bba..959c3dc 100644 --- a/src/app/project/parser/gamesystemParser/GamesystemParser.ts +++ b/src/app/project/parser/gamesystemParser/GamesystemParser.ts @@ -6,6 +6,9 @@ import {SimpleGamesystem} from "../../game-model/gamesystems/SimpleGamesystem"; import {StateParser} from "./StateParser"; import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {TransitionParser} from "./TransitionParser"; +import {TemplateType} from "../../game-model/TemplateType"; +import {SimpleTemplateGamesystem} from "../../game-model/gamesystems/SimpleTemplateGamesystem"; +import {Character} from "../../game-model/characters/Character"; export class GamesystemParser { @@ -40,13 +43,19 @@ export class GamesystemParser { } parseSimpleGamesystem(gamesystemData: any): SimpleGamesystem { - const simpleGamesystem = new SimpleGamesystem(gamesystemData.componentName, gamesystemData.componentDescription) + const templateType = gamesystemData.templateType + let simpleGamesystem = new SimpleGamesystem(gamesystemData.componentName, gamesystemData.componentDescription) + if(templateType == TemplateType.CHARACTER) { + simpleGamesystem = new SimpleTemplateGamesystem(gamesystemData.componentName, gamesystemData.componentDescription) + } const stateParser = new StateParser(this.scriptAccounts); simpleGamesystem.states = stateParser.parseStates(gamesystemData.states) const transitionParser = new TransitionParser(simpleGamesystem.states, this.scriptAccounts) simpleGamesystem.transitions = transitionParser.parseTransitions(gamesystemData.transitions) + + return simpleGamesystem } diff --git a/src/app/project/serializer/GamesystemSerializer.ts b/src/app/project/serializer/GamesystemSerializer.ts index 8ffcafc..717da47 100644 --- a/src/app/project/serializer/GamesystemSerializer.ts +++ b/src/app/project/serializer/GamesystemSerializer.ts @@ -4,10 +4,11 @@ import {SimpleGamesystem} from "../game-model/gamesystems/SimpleGamesystem"; import {ProductGamesystem} from "../game-model/gamesystems/ProductGamesystem"; import {SerializeConstants} from "./SerializeConstants"; import {ModelComponentType} from "../game-model/ModelComponentType"; +import {SimpleTemplateGamesystem} from "../game-model/gamesystems/SimpleTemplateGamesystem"; export class GamesystemSerializer { - private static IGNORED_SIMPLE_ATTRIBUTES = ["parentGamesystem", 'incomingTransitions', "outgoingTransitions", "unsaved", "type"] + private static IGNORED_SIMPLE_ATTRIBUTES = ["parentGamesystem", 'incomingTransitions', "outgoingTransitions", "unsaved", "type", "conditionMap"] public static serializeGamesystems(gamesystems: Gamesystem[]): StoreComponent[] { let storedGamesystems: StoreComponent[] = [] @@ -16,7 +17,7 @@ export class GamesystemSerializer { } private static serializeSingleGamesystem(gamesystem: Gamesystem): StoreComponent[] { - if(gamesystem instanceof SimpleGamesystem) { + if(gamesystem instanceof SimpleGamesystem || gamesystem instanceof SimpleTemplateGamesystem) { console.log("Simple Gamesystem") return [this.serializeSimpleGamesystem(gamesystem as SimpleGamesystem)] } else { diff --git a/testModel/characters/Astrid Hofferson.json b/testModel/characters/Astrid Hofferson.json index 0678c2b..c0c32fc 100644 --- a/testModel/characters/Astrid Hofferson.json +++ b/testModel/characters/Astrid Hofferson.json @@ -1,4 +1,5 @@ { "componentName": "Astrid Hofferson", - "componentDescription": "" + "componentDescription": "", + "characterSpecificGamesystems": [] } \ No newline at end of file diff --git a/testModel/characters/Hicks Haddock.json b/testModel/characters/Hicks Haddock.json index 1e611d7..e11ab14 100644 --- a/testModel/characters/Hicks Haddock.json +++ b/testModel/characters/Hicks Haddock.json @@ -1,4 +1,5 @@ { "componentName": "Hicks Haddock", - "componentDescription": "" + "componentDescription": "", + "characterSpecificGamesystems": [] } \ No newline at end of file diff --git a/testModel/gamesystems/Characterstimmung.json b/testModel/gamesystems/Characterstimmung.json new file mode 100644 index 0000000..fe49734 --- /dev/null +++ b/testModel/gamesystems/Characterstimmung.json @@ -0,0 +1,20 @@ +{ + "componentName": "Characterstimmung", + "componentDescription": "", + "states": [ + { + "initial": true, + "conditions": [], + "stateLabel": "Fröhlich", + "stateDescription": "" + }, + { + "initial": false, + "conditions": [], + "stateLabel": "Wütend", + "stateDescription": "" + } + ], + "transitions": [], + "templateType": 1 +} \ No newline at end of file diff --git a/testModel/gamesystems/Testsystem.json b/testModel/gamesystems/Testsystem.json index 654df19..9c53926 100644 --- a/testModel/gamesystems/Testsystem.json +++ b/testModel/gamesystems/Testsystem.json @@ -33,5 +33,6 @@ "startingState": "A", "endingState": "B" } - ] + ], + "templateType": 0 } \ No newline at end of file diff --git a/testModel/gamesystems/Weathersystem/Season.json b/testModel/gamesystems/Weathersystem/Season.json index a815ccb..246c9ab 100644 --- a/testModel/gamesystems/Weathersystem/Season.json +++ b/testModel/gamesystems/Weathersystem/Season.json @@ -76,5 +76,6 @@ "startingState": "Winter", "endingState": "Frühling" } - ] + ], + "templateType": 0 } \ No newline at end of file diff --git a/testModel/gamesystems/Weathersystem/Weather.json b/testModel/gamesystems/Weathersystem/Weather.json index b9de825..4a0388d 100644 --- a/testModel/gamesystems/Weathersystem/Weather.json +++ b/testModel/gamesystems/Weathersystem/Weather.json @@ -76,5 +76,6 @@ "startingState": "Schnee", "endingState": "Wolke" } - ] + ], + "templateType": 0 } \ No newline at end of file