From 010adc913652c99a33488c3c366251b3fa18ec3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 11 Apr 2024 10:50:05 +0200 Subject: [PATCH 01/10] Alternative Implementation of Templatesystems --- .../gamesystems/SimpleTemplateGamesystem.ts | 54 +++++++++++++++++++ .../gamesystems/states/SimpleTemplateState.ts | 8 +++ .../transitions/SimpleTemplateTransition.ts | 9 ++++ 3 files changed, 71 insertions(+) create mode 100644 src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts create mode 100644 src/app/project/game-model/gamesystems/states/SimpleTemplateState.ts create mode 100644 src/app/project/game-model/gamesystems/transitions/SimpleTemplateTransition.ts diff --git a/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts b/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts new file mode 100644 index 0000000..39863fe --- /dev/null +++ b/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts @@ -0,0 +1,54 @@ +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"; + +export class SimpleTemplateGamesystem extends Gamesystem, SimpleTemplateTransition> { + + createState(label: string, description: string): SimpleState | undefined { + if(label == null) { + return undefined; + } + + if(description == null) { + description = ""; + } + + const state = new SimpleTemplateState(label, description); + if(this.states.find(s => s.stateLabel == label) == undefined) { + this.states.push(state); + return state; + } else { + return undefined + } + } + + createTransition(startingState: SimpleTemplateState, endingState: SimpleTemplateState): SimpleTemplateTransition | undefined { + if((startingState == null || endingState == null) || startingState === endingState) { + return undefined; + } + + const transition = new SimpleTemplateTransition(startingState, endingState); + if(this.transitions.find(t => t.startingState === startingState && t.endingState === endingState) == undefined) { + this.transitions.push(transition) + return transition; + } else { + startingState.removeOutgoingTransition(transition); + endingState.removeIncomingTransition(transition); + return undefined + } + } + + removeState(state: SimpleTemplateState): boolean { + const updatedStates = this.states.filter(s => s !== state); + const updated = updatedStates.length != this.states.length; + this.states = updatedStates; + + this.transitions = this.transitions.filter(t => t.startingState !== state && t.endingState !== state); + + return updated; + } + +} diff --git a/src/app/project/game-model/gamesystems/states/SimpleTemplateState.ts b/src/app/project/game-model/gamesystems/states/SimpleTemplateState.ts new file mode 100644 index 0000000..f10055c --- /dev/null +++ b/src/app/project/game-model/gamesystems/states/SimpleTemplateState.ts @@ -0,0 +1,8 @@ +import {SimpleState} from "./SimpleState"; +import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition"; + +export class SimpleTemplateState extends SimpleState { + + conditionMap: Map = new Map() + +} diff --git a/src/app/project/game-model/gamesystems/transitions/SimpleTemplateTransition.ts b/src/app/project/game-model/gamesystems/transitions/SimpleTemplateTransition.ts new file mode 100644 index 0000000..72d267a --- /dev/null +++ b/src/app/project/game-model/gamesystems/transitions/SimpleTemplateTransition.ts @@ -0,0 +1,9 @@ +import {SimpleTransition} from "./SimpleTransition"; +import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition"; +import {ScriptAccountAction} from "../actions/ScriptAccountAction"; + +export class SimpleTemplateTransition extends SimpleTransition { + + conditions: Map = new Map(); + actions: Map = new Map(); +} From 312a684a17748887bf57220164d3b0dad3c751d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 11 Apr 2024 13:28:09 +0200 Subject: [PATCH 02/10] Create Characterspecific Systems and open their editor correctly --- app/main.ts | 17 ++++++++++++++--- src/app/app.component.ts | 17 ++++++++++++----- .../gamesystem-editor.component.ts | 5 +++-- .../simple-gamesystem-editor.component.ts | 11 ++++++++--- src/app/project/game-model/GameModel.ts | 12 +++++++++--- src/app/project/game-model/TemplateType.ts | 3 +++ .../project/game-model/TemplateTypeUtilities.ts | 11 +++++++++++ .../gamesystems/SimpleTemplateGamesystem.ts | 1 + 8 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 src/app/project/game-model/TemplateType.ts create mode 100644 src/app/project/game-model/TemplateTypeUtilities.ts diff --git a/app/main.ts b/app/main.ts index 45b1f1a..13f4633 100644 --- a/app/main.ts +++ b/app/main.ts @@ -64,9 +64,20 @@ function createWindow(): BrowserWindow { submenu: [ { label: "Gamesystem", - click: () => { - win!.webContents.send('context-menu', "new-gamesystem"); - } + submenu: [ + { + label: "Normal", + click: () => { + win!.webContents.send('context-menu', "new-gamesystem-normal"); + } + }, + { + label: "Characterspecific", + click: () => { + win!.webContents.send('context-menu', "new-gamesystem-character"); + } + } + ] }, { label: "ScriptAccount", diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 41f2835..b0c7035 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -24,6 +24,8 @@ import {Character} from "./project/game-model/characters/Character"; import {CharacterOverviewComponent} from "./side-overviews/character-overview/character-overview.component"; import {CharacterSerializer} from "./project/serializer/CharacterSerializer"; import {CharacterParser} from "./project/parser/characterParser/CharacterParser"; +import {TemplateType} from "./project/game-model/TemplateType"; +import {TemplateTypeUtilities} from "./project/game-model/TemplateTypeUtilities"; @Component({ selector: 'app-root', @@ -76,8 +78,13 @@ export class AppComponent implements OnInit{ } else if(message.startsWith("new")) { const splittedMessage = message.split("-"); const modelComponentType = ModelComponentTypeUtillities.fromString(splittedMessage[1]); + let templateType: TemplateType = TemplateType.NORMAL + if(splittedMessage.length > 2) { + templateType = TemplateTypeUtilities.fromString(splittedMessage[2]); + } + if(modelComponentType != undefined) { - this.onCreateModelComponent(modelComponentType); + this.onCreateModelComponent(modelComponentType, templateType); } else { console.log("[ERROR] [App-Component] Unknown Context-Menu Command!") } @@ -127,10 +134,10 @@ export class AppComponent implements OnInit{ }) } - private onCreateModelComponent(modelComponentType: ModelComponentType) { + private onCreateModelComponent(modelComponentType: ModelComponentType, templateType: TemplateType) { switch (modelComponentType) { case ModelComponentType.SCRIPTACCOUNT: this.onCreateNewScriptAccount(); break - case ModelComponentType.GAMESYTEM: this.onCreateNewGamesystem(); break + case ModelComponentType.GAMESYTEM: this.onCreateNewGamesystem(templateType); break case ModelComponentType.CHARACTER: this.onCreateNewCharacter(); break } } @@ -144,7 +151,7 @@ export class AppComponent implements OnInit{ } } - private onCreateNewGamesystem() { + private onCreateNewGamesystem(templateType: TemplateType) { let parentGamesystemName = undefined if(this.openContent != ModelComponentType.GAMESYTEM) { this.openGamesystemsOverview(); @@ -153,7 +160,7 @@ export class AppComponent implements OnInit{ } - const createdGamesystem = this.gameModel!.createGamesystem("New Gamesystem", parentGamesystemName); + const createdGamesystem = this.gameModel!.createGamesystem("New Gamesystem "+ templateType, parentGamesystemName, templateType); if(createdGamesystem != undefined) { this.gamesystemOverview!.refresh(); this.editor?.openGameModelComponent(createdGamesystem); diff --git a/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts b/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts index f14dda3..de5ef89 100644 --- a/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts +++ b/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts @@ -5,6 +5,7 @@ import { Transition } from '../../project/game-model/gamesystems/transitions/Tra import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccount"; import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem"; import {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem"; +import {SimpleTemplateGamesystem} from "../../project/game-model/gamesystems/SimpleTemplateGamesystem"; @Component({ selector: 'app-gamesystem-editor', @@ -22,11 +23,11 @@ export class GamesystemEditorComponent implements OnInit{ } isSimpleGamesystem() { - return this.gamesystem instanceof SimpleGamesystem; + return this.gamesystem instanceof SimpleGamesystem || this.gamesystem instanceof SimpleTemplateGamesystem; } convertGamesystemToSimpleGamesystem() { - if(this.gamesystem instanceof SimpleGamesystem) { + if(!(this.gamesystem instanceof ProductGamesystem)) { return this.gamesystem as SimpleGamesystem; } } diff --git a/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.ts b/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.ts index 36af424..abebbb8 100644 --- a/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.ts +++ b/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.ts @@ -1,17 +1,22 @@ -import {Component, Input} from '@angular/core'; +import {Component, Input, OnInit} from '@angular/core'; import {MatTableDataSource} from "@angular/material/table"; import {SimpleGamesystem} from "../../../project/game-model/gamesystems/SimpleGamesystem"; import {ScriptAccount} from "../../../project/game-model/scriptAccounts/ScriptAccount"; +import {SimpleTemplateGamesystem} from "../../../project/game-model/gamesystems/SimpleTemplateGamesystem"; @Component({ selector: 'app-simple-gamesystem-editor', templateUrl: './simple-gamesystem-editor.component.html', styleUrl: './simple-gamesystem-editor.component.scss' }) -export class SimpleGamesystemEditorComponent { +export class SimpleGamesystemEditorComponent implements OnInit{ - @Input() simpleGamesystem: SimpleGamesystem | undefined + @Input() simpleGamesystem: SimpleGamesystem | SimpleTemplateGamesystem | undefined @Input() scriptAccunts: ScriptAccount[] = [] + ngOnInit(): void { + console.log("SimpleGamesystem: ", this.simpleGamesystem) + } + } diff --git a/src/app/project/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts index 8497737..dab8a83 100644 --- a/src/app/project/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -5,7 +5,8 @@ import {State} from "./gamesystems/states/State"; import {ProductGamesystem} from "./gamesystems/ProductGamesystem"; import {SimpleGamesystem} from "./gamesystems/SimpleGamesystem"; import {Character} from "./characters/Character"; -import {ModelComponentType} from "./ModelComponentType"; +import {TemplateType} from "./TemplateType"; +import {SimpleTemplateGamesystem} from "./gamesystems/SimpleTemplateGamesystem"; export class GameModel { gameModelName: string @@ -45,9 +46,14 @@ export class GameModel { return undefined; } - createGamesystem(gamesystemName: string, parentGamesystemName: string | undefined) { + createGamesystem(gamesystemName: string, parentGamesystemName: string | undefined, templateType: TemplateType) { if(gamesystemName != undefined && this.findGamesystem(gamesystemName) == undefined) { - const simpleGamesystem = new SimpleGamesystem(gamesystemName, ""); + let simpleGamesystem = new SimpleGamesystem(gamesystemName, ""); + if(templateType == TemplateType.CHARACTER) { + simpleGamesystem = new SimpleTemplateGamesystem(gamesystemName, "") + } + + if(parentGamesystemName != undefined) { const parentGamesystem = this.findGamesystem(parentGamesystemName); if(parentGamesystem instanceof SimpleGamesystem) { diff --git a/src/app/project/game-model/TemplateType.ts b/src/app/project/game-model/TemplateType.ts new file mode 100644 index 0000000..c7dd90a --- /dev/null +++ b/src/app/project/game-model/TemplateType.ts @@ -0,0 +1,3 @@ +export enum TemplateType { + NORMAL, CHARACTER +} diff --git a/src/app/project/game-model/TemplateTypeUtilities.ts b/src/app/project/game-model/TemplateTypeUtilities.ts new file mode 100644 index 0000000..39deafa --- /dev/null +++ b/src/app/project/game-model/TemplateTypeUtilities.ts @@ -0,0 +1,11 @@ +import {TemplateType} from "./TemplateType"; + +export class TemplateTypeUtilities { + static fromString(value: string) { + if(value === 'character') { + return TemplateType.CHARACTER + } else { + return TemplateType.NORMAL + } + } +} diff --git a/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts b/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts index 39863fe..4e635ae 100644 --- a/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts +++ b/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts @@ -4,6 +4,7 @@ import {Gamesystem} from "./Gamesystem"; import {SimpleTransition} from "./transitions/SimpleTransition"; import {SimpleState} from "./states/SimpleState"; import {SimpleTemplateTransition} from "./transitions/SimpleTemplateTransition"; +import {TemplateType} from "../TemplateType"; export class SimpleTemplateGamesystem extends Gamesystem, SimpleTemplateTransition> { From 3aaf505365ef03700d73f4b27bc85385cdc0af84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 11 Apr 2024 13:40:40 +0200 Subject: [PATCH 03/10] Add Reference to CharacterSpecific Gamesystems in relevant characters --- .../game-model/characters/Character.ts | 15 +++++++++++++++ .../gamesystems/SimpleTemplateGamesystem.ts | 19 +++++++++++++++++++ .../gamesystems/states/SimpleTemplateState.ts | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/app/project/game-model/characters/Character.ts b/src/app/project/game-model/characters/Character.ts index 07acf19..9934a79 100644 --- a/src/app/project/game-model/characters/Character.ts +++ b/src/app/project/game-model/characters/Character.ts @@ -1,9 +1,24 @@ import {ModelComponent} from "../ModelComponent"; import {ModelComponentType} from "../ModelComponentType"; +import {SimpleTemplateGamesystem} from "../gamesystems/SimpleTemplateGamesystem"; export class Character extends ModelComponent{ + private characterSpecificGamesystems: SimpleTemplateGamesystem[] = [] + constructor(componentName: string, componentDescription: string) { super(componentName, componentDescription, ModelComponentType.CHARACTER); } + + addCharacterSpecificGamesystem(templateGamesystem: SimpleTemplateGamesystem) { + if(!this.isGamesystemCharacterSpecific(templateGamesystem.componentName)) { + this.characterSpecificGamesystems.push(templateGamesystem); + templateGamesystem.addReferenceKey(this); + } + } + + private isGamesystemCharacterSpecific(gamesystemName: string) { + const characterSpecificGamesystem = this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === gamesystemName); + return characterSpecificGamesystem != undefined + } } diff --git a/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts b/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts index 4e635ae..6eabd03 100644 --- a/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts +++ b/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts @@ -5,6 +5,7 @@ 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> { @@ -52,4 +53,22 @@ export class SimpleTemplateGamesystem extends Gamesystem { + if(!state.conditionMap.has(reference)) { + state.conditionMap.set(reference, state.conditions.concat()) + } + }) + + this.transitions.forEach(transition => { + if(!transition.conditions.has(reference)) { + transition.conditions.set(reference, transition.scriptAccountConditions.concat()) + } + + if(!transition.actions.has(reference)) { + transition.actions.set(reference, transition.scriptAccountActions.concat()) + } + }) + } + } diff --git a/src/app/project/game-model/gamesystems/states/SimpleTemplateState.ts b/src/app/project/game-model/gamesystems/states/SimpleTemplateState.ts index f10055c..52bb80c 100644 --- a/src/app/project/game-model/gamesystems/states/SimpleTemplateState.ts +++ b/src/app/project/game-model/gamesystems/states/SimpleTemplateState.ts @@ -3,6 +3,6 @@ import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition"; export class SimpleTemplateState extends SimpleState { - conditionMap: Map = new Map() + conditionMap: Map = new Map() } From 9a51cb3a80d7b06c9d1723feadf8963cfff9a98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 11 Apr 2024 13:45:29 +0200 Subject: [PATCH 04/10] Beginning of Editor for Characterspecific Gamesystems --- src/app/app.module.ts | 8 ++++++-- .../character-editor.component.html | 13 ++++++++++++- .../character-editor/character-editor.component.ts | 6 +++++- src/app/editor/editor.component.html | 3 ++- src/app/editor/editor.component.ts | 7 +++++++ src/app/project/game-model/characters/Character.ts | 2 +- 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 7412843..eb7f6e2 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -61,7 +61,7 @@ import { ProductStateEditorComponent } from "./editor/gamesystem-editor/state-editor/product-state-editor/product-state-editor.component"; import {MatTooltip} from "@angular/material/tooltip"; -import {MatCard, MatCardContent} from "@angular/material/card"; +import {MatCard, MatCardContent, MatCardHeader} from "@angular/material/card"; import { ScriptaccountActionEditorComponent } from "./editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component"; @@ -70,6 +70,7 @@ import { } from "./editor/gamesystem-editor/scriptaccount-condition-editor/scriptaccount-condition-editor.component"; import {CharacterOverviewComponent} from "./side-overviews/character-overview/character-overview.component"; import {CharacterEditorComponent} from "./editor/character-editor/character-editor.component"; +import {MatAccordion, MatExpansionPanel} from "@angular/material/expansion"; // AoT requires an exported function for factories const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new TranslateHttpLoader(http, './assets/i18n/', '.json'); @@ -150,7 +151,10 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl MatHint, MatTooltip, MatCard, - MatCardContent + MatCardContent, + MatCardHeader, + MatAccordion, + MatExpansionPanel ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/editor/character-editor/character-editor.component.html b/src/app/editor/character-editor/character-editor.component.html index 4750ae3..1bdd02b 100644 --- a/src/app/editor/character-editor/character-editor.component.html +++ b/src/app/editor/character-editor/character-editor.component.html @@ -1 +1,12 @@ -

character-editor works!

+ + + Characterspecific Gamesystems + + + + + {{gamesystem.componentName}} + + + + diff --git a/src/app/editor/character-editor/character-editor.component.ts b/src/app/editor/character-editor/character-editor.component.ts index 23e8438..cb49801 100644 --- a/src/app/editor/character-editor/character-editor.component.ts +++ b/src/app/editor/character-editor/character-editor.component.ts @@ -1,4 +1,6 @@ -import { Component } from '@angular/core'; +import {Component, Input} from '@angular/core'; +import {Character} from "../../project/game-model/characters/Character"; +import {GameModel} from "../../project/game-model/GameModel"; @Component({ selector: 'app-character-editor', @@ -7,4 +9,6 @@ import { Component } from '@angular/core'; }) export class CharacterEditorComponent { + @Input() character: Character | undefined + @Input() gameModel: GameModel | undefined } diff --git a/src/app/editor/editor.component.html b/src/app/editor/editor.component.html index b351774..e21bbcd 100644 --- a/src/app/editor/editor.component.html +++ b/src/app/editor/editor.component.html @@ -14,7 +14,8 @@ [gamesystem]="convertModelComponentToGamesystem(modelComponent)" (onOpenGamesystemEditor)="openGameModelComponent($event)" [scriptAccounts]="gameModel!.scriptAccounts"> - + diff --git a/src/app/editor/editor.component.ts b/src/app/editor/editor.component.ts index 887f4d8..6136245 100644 --- a/src/app/editor/editor.component.ts +++ b/src/app/editor/editor.component.ts @@ -6,6 +6,7 @@ import {Gamesystem} from "../project/game-model/gamesystems/Gamesystem"; import {State} from "../project/game-model/gamesystems/states/State"; import {Transition} from "../project/game-model/gamesystems/transitions/Transition"; import {ModelComponentType} from "../project/game-model/ModelComponentType"; +import {Character} from "../project/game-model/characters/Character"; @Component({ @@ -50,4 +51,10 @@ export class EditorComponent { } protected readonly ModelComponentType = ModelComponentType; + + convertModelComponentToCharacter(modelComponent: ModelComponent) { + if(modelComponent instanceof Character) { + return modelComponent as Character; + } + } } diff --git a/src/app/project/game-model/characters/Character.ts b/src/app/project/game-model/characters/Character.ts index 9934a79..d1a1ed2 100644 --- a/src/app/project/game-model/characters/Character.ts +++ b/src/app/project/game-model/characters/Character.ts @@ -4,7 +4,7 @@ import {SimpleTemplateGamesystem} from "../gamesystems/SimpleTemplateGamesystem" export class Character extends ModelComponent{ - private characterSpecificGamesystems: SimpleTemplateGamesystem[] = [] + characterSpecificGamesystems: SimpleTemplateGamesystem[] = [] constructor(componentName: string, componentDescription: string) { super(componentName, componentDescription, ModelComponentType.CHARACTER); 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 05/10] 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 From a13273b08d7b5ddc31f05feff15ca457a0046298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 11 Apr 2024 14:21:50 +0200 Subject: [PATCH 06/10] Specify Gamesystems for Characters --- src/app/app.module.ts | 12 +++++--- .../character-editor.component.html | 1 + .../character-editor.component.ts | 19 ++++++++++++ .../template-creator.component.html | 13 +++++++++ .../template-creator.component.scss | 0 .../template-creator.component.spec.ts | 23 +++++++++++++++ .../template-creator.component.ts | 26 +++++++++++++++++ src/app/project/game-model/GameModel.ts | 22 ++++++++++++++ .../gamesystemParser/GamesystemParser.ts | 3 +- .../parser/gamesystemParser/StateParser.ts | 17 ++++++++--- testModel/characters/Hicks Haddock.json | 29 ++++++++++++++++++- 11 files changed, 155 insertions(+), 10 deletions(-) create mode 100644 src/app/editor/gamesystem-editor/template-creator/template-creator.component.html create mode 100644 src/app/editor/gamesystem-editor/template-creator/template-creator.component.scss create mode 100644 src/app/editor/gamesystem-editor/template-creator/template-creator.component.spec.ts create mode 100644 src/app/editor/gamesystem-editor/template-creator/template-creator.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index eb7f6e2..30af657 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -61,7 +61,7 @@ import { ProductStateEditorComponent } from "./editor/gamesystem-editor/state-editor/product-state-editor/product-state-editor.component"; import {MatTooltip} from "@angular/material/tooltip"; -import {MatCard, MatCardContent, MatCardHeader} from "@angular/material/card"; +import {MatCard, MatCardContent, MatCardHeader, MatCardTitle} from "@angular/material/card"; import { ScriptaccountActionEditorComponent } from "./editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component"; @@ -70,7 +70,8 @@ import { } from "./editor/gamesystem-editor/scriptaccount-condition-editor/scriptaccount-condition-editor.component"; import {CharacterOverviewComponent} from "./side-overviews/character-overview/character-overview.component"; import {CharacterEditorComponent} from "./editor/character-editor/character-editor.component"; -import {MatAccordion, MatExpansionPanel} from "@angular/material/expansion"; +import {MatAccordion, MatExpansionPanel, MatExpansionPanelHeader} from "@angular/material/expansion"; +import {TemplateCreatorComponent} from "./editor/gamesystem-editor/template-creator/template-creator.component"; // AoT requires an exported function for factories const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new TranslateHttpLoader(http, './assets/i18n/', '.json'); @@ -94,7 +95,8 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl ScriptaccountActionEditorComponent, ScriptaccountConditionEditorComponent, CharacterOverviewComponent, - CharacterEditorComponent + CharacterEditorComponent, + TemplateCreatorComponent ], imports: [ BrowserModule, @@ -154,7 +156,9 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl MatCardContent, MatCardHeader, MatAccordion, - MatExpansionPanel + MatExpansionPanel, + MatCardTitle, + MatExpansionPanelHeader ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/editor/character-editor/character-editor.component.html b/src/app/editor/character-editor/character-editor.component.html index 1bdd02b..4e364f2 100644 --- a/src/app/editor/character-editor/character-editor.component.html +++ b/src/app/editor/character-editor/character-editor.component.html @@ -8,5 +8,6 @@ {{gamesystem.componentName}} + diff --git a/src/app/editor/character-editor/character-editor.component.ts b/src/app/editor/character-editor/character-editor.component.ts index cb49801..42e61ff 100644 --- a/src/app/editor/character-editor/character-editor.component.ts +++ b/src/app/editor/character-editor/character-editor.component.ts @@ -1,6 +1,9 @@ import {Component, Input} from '@angular/core'; import {Character} from "../../project/game-model/characters/Character"; import {GameModel} from "../../project/game-model/GameModel"; +import {MatDialog} from "@angular/material/dialog"; +import {TemplateCreatorComponent} from "../gamesystem-editor/template-creator/template-creator.component"; +import {TemplateType} from "../../project/game-model/TemplateType"; @Component({ selector: 'app-character-editor', @@ -11,4 +14,20 @@ export class CharacterEditorComponent { @Input() character: Character | undefined @Input() gameModel: GameModel | undefined + + constructor(private dialog: MatDialog) { + } + + onOpenTemplateCreator() { + const dialogRef = this.dialog.open(TemplateCreatorComponent, { + data: this.gameModel!.listGamesystems(TemplateType.CHARACTER), + minWidth: "400px" + }) + + dialogRef.afterClosed().subscribe(res => { + if(res != undefined) { + this.character!.addCharacterSpecificGamesystem(res) + } + }) + } } diff --git a/src/app/editor/gamesystem-editor/template-creator/template-creator.component.html b/src/app/editor/gamesystem-editor/template-creator/template-creator.component.html new file mode 100644 index 0000000..feb02e7 --- /dev/null +++ b/src/app/editor/gamesystem-editor/template-creator/template-creator.component.html @@ -0,0 +1,13 @@ +

Specify Gamesystem

+
+ + Referencesystem + + {{gamesystem.componentName}} + + +
+
+ + +
diff --git a/src/app/editor/gamesystem-editor/template-creator/template-creator.component.scss b/src/app/editor/gamesystem-editor/template-creator/template-creator.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/editor/gamesystem-editor/template-creator/template-creator.component.spec.ts b/src/app/editor/gamesystem-editor/template-creator/template-creator.component.spec.ts new file mode 100644 index 0000000..354ea63 --- /dev/null +++ b/src/app/editor/gamesystem-editor/template-creator/template-creator.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { TemplateCreatorComponent } from './template-creator.component'; + +describe('TemplateCreatorComponent', () => { + let component: TemplateCreatorComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [TemplateCreatorComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(TemplateCreatorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/editor/gamesystem-editor/template-creator/template-creator.component.ts b/src/app/editor/gamesystem-editor/template-creator/template-creator.component.ts new file mode 100644 index 0000000..ef9d86a --- /dev/null +++ b/src/app/editor/gamesystem-editor/template-creator/template-creator.component.ts @@ -0,0 +1,26 @@ +import {Component, Inject} from '@angular/core'; +import {MAT_DIALOG_DATA, MatDialogRef, MatDialogTitle} from "@angular/material/dialog"; +import {SimpleTemplateGamesystem} from "../../../project/game-model/gamesystems/SimpleTemplateGamesystem"; +import {FormControl, Validators} from "@angular/forms"; + +@Component({ + selector: 'app-template-creator', + templateUrl: './template-creator.component.html', + styleUrl: './template-creator.component.scss' +}) +export class TemplateCreatorComponent { + + templateCtrl = new FormControl('', [Validators.required]); + + constructor(@Inject(MAT_DIALOG_DATA) public templateGamesystems: SimpleTemplateGamesystem[], + private dialogRef: MatDialogRef) { + } + + cancel() { + this.dialogRef.close(); + } + + save() { + this.dialogRef.close(this.templateCtrl.value) + } +} diff --git a/src/app/project/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts index dab8a83..2fb19a5 100644 --- a/src/app/project/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -9,6 +9,7 @@ import {TemplateType} from "./TemplateType"; import {SimpleTemplateGamesystem} from "./gamesystems/SimpleTemplateGamesystem"; export class GameModel { + gameModelName: string gamesystems: Gamesystem[] = []; @@ -121,4 +122,25 @@ export class GameModel { } }) } + + listGamesystems(templateType: TemplateType): SimpleTemplateGamesystem[] { + const gamesystemList: SimpleTemplateGamesystem[] = [] + const gamesystemQueue: Gamesystem[] = this.gamesystems.concat() + while(gamesystemQueue.length > 0) { + const currentGamesystem = gamesystemQueue.shift()!; + + if(currentGamesystem.templateType === templateType) { + gamesystemList.push(currentGamesystem as SimpleTemplateGamesystem) + } + + if(currentGamesystem instanceof ProductGamesystem) { + currentGamesystem.innerGamesystems.forEach(innerGamesystem => { + gamesystemQueue.push(innerGamesystem) + }) + } + } + + console.log(gamesystemList) + return gamesystemList; + } } diff --git a/src/app/project/parser/gamesystemParser/GamesystemParser.ts b/src/app/project/parser/gamesystemParser/GamesystemParser.ts index 959c3dc..029fe25 100644 --- a/src/app/project/parser/gamesystemParser/GamesystemParser.ts +++ b/src/app/project/parser/gamesystemParser/GamesystemParser.ts @@ -47,10 +47,11 @@ export class GamesystemParser { let simpleGamesystem = new SimpleGamesystem(gamesystemData.componentName, gamesystemData.componentDescription) if(templateType == TemplateType.CHARACTER) { simpleGamesystem = new SimpleTemplateGamesystem(gamesystemData.componentName, gamesystemData.componentDescription) + simpleGamesystem.templateType = TemplateType.CHARACTER } const stateParser = new StateParser(this.scriptAccounts); - simpleGamesystem.states = stateParser.parseStates(gamesystemData.states) + simpleGamesystem.states = stateParser.parseStates(gamesystemData.states, templateType) const transitionParser = new TransitionParser(simpleGamesystem.states, this.scriptAccounts) simpleGamesystem.transitions = transitionParser.parseTransitions(gamesystemData.transitions) diff --git a/src/app/project/parser/gamesystemParser/StateParser.ts b/src/app/project/parser/gamesystemParser/StateParser.ts index 8da602a..fce00ce 100644 --- a/src/app/project/parser/gamesystemParser/StateParser.ts +++ b/src/app/project/parser/gamesystemParser/StateParser.ts @@ -2,6 +2,9 @@ import {SimpleState} from "../../game-model/gamesystems/states/SimpleState"; import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {ScriptAccountCondition} from "../../game-model/gamesystems/conditions/ScriptAccountCondition"; import {ScriptAccountConditionParser} from "./ScriptAccountConditionParser"; +import {TemplateType} from "../../game-model/TemplateType"; +import {SimpleTemplateState} from "../../game-model/gamesystems/states/SimpleTemplateState"; +import {Character} from "../../game-model/characters/Character"; export class StateParser { @@ -12,23 +15,29 @@ export class StateParser { this.conditionParser = new ScriptAccountConditionParser(scriptAccounts) } - public parseStates(stateData: any): SimpleState[] { + public parseStates(stateData: any, templateType: TemplateType): SimpleState[] { const parsedStates: SimpleState[] = [] for(let i=0; i(stateLabel, stateDescription); + } + simpleState.initial = initial; simpleState.conditions = conditions; diff --git a/testModel/characters/Hicks Haddock.json b/testModel/characters/Hicks Haddock.json index e11ab14..d70e908 100644 --- a/testModel/characters/Hicks Haddock.json +++ b/testModel/characters/Hicks Haddock.json @@ -1,5 +1,32 @@ { "componentName": "Hicks Haddock", "componentDescription": "", - "characterSpecificGamesystems": [] + "characterSpecificGamesystems": [ + { + "componentName": "Characterstimmung", + "componentDescription": "", + "states": [ + { + "incomingTransitions": [], + "outgoingTransitions": [], + "initial": true, + "conditions": [], + "stateLabel": "Fröhlich", + "stateDescription": "", + "conditionMap": {} + }, + { + "incomingTransitions": [], + "outgoingTransitions": [], + "initial": false, + "conditions": [], + "stateLabel": "Wütend", + "stateDescription": "", + "conditionMap": {} + } + ], + "transitions": [], + "templateType": 1 + } + ] } \ No newline at end of file From d31182cf3690dc4c99c049010150f01cd623bb14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 11 Apr 2024 14:39:38 +0200 Subject: [PATCH 07/10] Store Characterspecific Gamesystems --- .../project/serializer/CharacterSerializer.ts | 12 +++++++++++- testModel/characters/Astrid Hofferson.json | 1 - testModel/characters/Hicks Haddock.json | 16 ++-------------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/app/project/serializer/CharacterSerializer.ts b/src/app/project/serializer/CharacterSerializer.ts index 4923004..3cb00a2 100644 --- a/src/app/project/serializer/CharacterSerializer.ts +++ b/src/app/project/serializer/CharacterSerializer.ts @@ -2,9 +2,12 @@ import {Character} from "../game-model/characters/Character"; import {StoreComponent} from "../../../../app/storage/StoreComponent"; import {SerializeConstants} from "./SerializeConstants"; import {ModelComponentType} from "../game-model/ModelComponentType"; +import {Gamesystem} from "../game-model/gamesystems/Gamesystem"; export class CharacterSerializer { + private static ignoredKeys: string[] = ['unsaved', 'type', 'incomingTransitions', 'outgoingTransitions', 'initial', 'conditions', 'stateDescription', 'templateType'] + public static serializeCharacters(characters: Character[]): StoreComponent[] { const storedCharacters: StoreComponent[] = [] characters.forEach(character => storedCharacters.push(this.serializeSingleCharacter(character))) @@ -14,7 +17,14 @@ export class CharacterSerializer { private static serializeSingleCharacter(character: Character): StoreComponent{ const fileName = character.componentName const jsonString = JSON.stringify(character, (key, value) => { - if(key === 'unsaved' || key === 'type') { + if(value instanceof Gamesystem) { + return { + ...value, + componentDescription: undefined + } + } + + if(this.ignoredKeys.includes(key)) { return undefined } else { return value; diff --git a/testModel/characters/Astrid Hofferson.json b/testModel/characters/Astrid Hofferson.json index c0c32fc..c5a973f 100644 --- a/testModel/characters/Astrid Hofferson.json +++ b/testModel/characters/Astrid Hofferson.json @@ -1,5 +1,4 @@ { "componentName": "Astrid Hofferson", - "componentDescription": "", "characterSpecificGamesystems": [] } \ No newline at end of file diff --git a/testModel/characters/Hicks Haddock.json b/testModel/characters/Hicks Haddock.json index d70e908..8f3c8f5 100644 --- a/testModel/characters/Hicks Haddock.json +++ b/testModel/characters/Hicks Haddock.json @@ -1,32 +1,20 @@ { "componentName": "Hicks Haddock", - "componentDescription": "", + "componentDescription": "Das ist ein Test", "characterSpecificGamesystems": [ { "componentName": "Characterstimmung", - "componentDescription": "", "states": [ { - "incomingTransitions": [], - "outgoingTransitions": [], - "initial": true, - "conditions": [], "stateLabel": "Fröhlich", - "stateDescription": "", "conditionMap": {} }, { - "incomingTransitions": [], - "outgoingTransitions": [], - "initial": false, - "conditions": [], "stateLabel": "Wütend", - "stateDescription": "", "conditionMap": {} } ], - "transitions": [], - "templateType": 1 + "transitions": [] } ] } \ No newline at end of file From f80e4c3cfa5ecbc27561de9643755122e101b8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 11 Apr 2024 14:58:57 +0200 Subject: [PATCH 08/10] Load Basic Characterspecific Gamesystems --- src/app/app.component.ts | 2 +- .../parser/characterParser/CharacterParser.ts | 44 ++++++++++++++++++- .../gamesystemParser/GamesystemParser.ts | 4 ++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index b0c7035..be0a940 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -211,7 +211,7 @@ export class AppComponent implements OnInit{ const gamesystemParser = new GamesystemParser(scriptAccounts); const gamesystems = gamesystemParser.parseStoredGamesystems(storedGameModel.storedGamesystems); - const characterParser = new CharacterParser(); + const characterParser = new CharacterParser(gamesystemParser.getParsedTemplateGamesystems(TemplateType.CHARACTER)); const characters = characterParser.parseCharacters(storedGameModel.storedCharacters); gameModel.scriptAccounts = scriptAccounts diff --git a/src/app/project/parser/characterParser/CharacterParser.ts b/src/app/project/parser/characterParser/CharacterParser.ts index 07d7378..11b386d 100644 --- a/src/app/project/parser/characterParser/CharacterParser.ts +++ b/src/app/project/parser/characterParser/CharacterParser.ts @@ -1,9 +1,16 @@ import {StoreComponent} from "../../../../../app/storage/StoreComponent"; import {Character} from "../../game-model/characters/Character"; +import {SimpleTemplateGamesystem} from "../../game-model/gamesystems/SimpleTemplateGamesystem"; export class CharacterParser { + characterSpecificGamesystems: SimpleTemplateGamesystem[] + + constructor(characterSpecificGamesystems: SimpleTemplateGamesystem[]) { + this.characterSpecificGamesystems = characterSpecificGamesystems; + } + public parseCharacters(characters: StoreComponent[]): Character[] { const loadedCharacters: Character[] = [] characters.forEach(character => loadedCharacters.push(this.parseSingleCharacter(JSON.parse(character.jsonString)))) @@ -11,6 +18,41 @@ export class CharacterParser { } private parseSingleCharacter(characterData: any): Character { - return new Character(characterData.componentName, characterData.componentDescription); + const character = new Character(characterData.componentName, characterData.componentDescription); + character.characterSpecificGamesystems = this.parseCharacterSpecificGamesystems(characterData.characterSpecificGamesystems); + console.log("Parsed Character", character) + return character; + } + + private parseCharacterSpecificGamesystems(characterSpecificGamesystems: any): SimpleTemplateGamesystem[] { + const result: SimpleTemplateGamesystem[] = [] + for(let i=0; i | undefined{ + const referencedGamesystem = this.findCharacterSpecificGamesystem(characterSpecificGamesystem.componentName) + + if(referencedGamesystem != undefined) { + for(let i=0; i | undefined{ + return this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === componentName) + } + + private findReferencedState(gamesystem: SimpleTemplateGamesystem, stateLabel: string) { + return gamesystem.states.find(state => state.stateLabel === stateLabel); } } diff --git a/src/app/project/parser/gamesystemParser/GamesystemParser.ts b/src/app/project/parser/gamesystemParser/GamesystemParser.ts index 029fe25..eec11c1 100644 --- a/src/app/project/parser/gamesystemParser/GamesystemParser.ts +++ b/src/app/project/parser/gamesystemParser/GamesystemParser.ts @@ -94,4 +94,8 @@ export class GamesystemParser { return undefined } + getParsedTemplateGamesystems(templateType: TemplateType) { + const templateGamesystems = this.parsedGamesystems.filter(gamesystem => gamesystem.templateType === templateType); + return templateGamesystems.map(gamesystem => gamesystem as SimpleTemplateGamesystem) + } } From e962cc9594856c4e27f56179c3c7c8f12d0964bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 11 Apr 2024 15:39:58 +0200 Subject: [PATCH 09/10] Serialize ConditionMap of States --- .../character-editor.component.html | 2 ++ .../gamesystem-editor.component.html | 3 +- .../gamesystem-editor.component.ts | 2 ++ .../simple-gamesystem-editor.component.html | 2 +- .../simple-gamesystem-editor.component.ts | 2 ++ .../simple-state-editor.component.html | 2 +- .../simple-state-editor.component.ts | 28 ++++++++++++++++++- .../parser/characterParser/CharacterParser.ts | 10 +++---- .../project/serializer/CharacterSerializer.ts | 9 ++++++ testModel/characters/Hicks Haddock.json | 10 +++++-- 10 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/app/editor/character-editor/character-editor.component.html b/src/app/editor/character-editor/character-editor.component.html index 4e364f2..ae9343a 100644 --- a/src/app/editor/character-editor/character-editor.component.html +++ b/src/app/editor/character-editor/character-editor.component.html @@ -6,7 +6,9 @@ {{gamesystem.componentName}} + + diff --git a/src/app/editor/gamesystem-editor/gamesystem-editor.component.html b/src/app/editor/gamesystem-editor/gamesystem-editor.component.html index 2eb564e..229e455 100644 --- a/src/app/editor/gamesystem-editor/gamesystem-editor.component.html +++ b/src/app/editor/gamesystem-editor/gamesystem-editor.component.html @@ -1,3 +1,4 @@ - + diff --git a/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts b/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts index de5ef89..05898bb 100644 --- a/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts +++ b/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts @@ -6,6 +6,7 @@ import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccou import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem"; import {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem"; import {SimpleTemplateGamesystem} from "../../project/game-model/gamesystems/SimpleTemplateGamesystem"; +import {Character} from "../../project/game-model/characters/Character"; @Component({ selector: 'app-gamesystem-editor', @@ -16,6 +17,7 @@ export class GamesystemEditorComponent implements OnInit{ @Input() gamesystem: Gamesystem, Transition> | undefined @Input() scriptAccounts: ScriptAccount[] = []; + @Input() templateReference: Character | undefined @Output('onOpenGamesystemEditor') openGamesystemEmitter = new EventEmitter(); ngOnInit() { diff --git a/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.html b/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.html index 7d7dc52..717e165 100644 --- a/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.html +++ b/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.html @@ -1,4 +1,4 @@ - +
diff --git a/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.ts b/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.ts index abebbb8..328c2ee 100644 --- a/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.ts +++ b/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.ts @@ -3,6 +3,7 @@ import {MatTableDataSource} from "@angular/material/table"; import {SimpleGamesystem} from "../../../project/game-model/gamesystems/SimpleGamesystem"; import {ScriptAccount} from "../../../project/game-model/scriptAccounts/ScriptAccount"; import {SimpleTemplateGamesystem} from "../../../project/game-model/gamesystems/SimpleTemplateGamesystem"; +import {Character} from "../../../project/game-model/characters/Character"; @Component({ selector: 'app-simple-gamesystem-editor', @@ -13,6 +14,7 @@ export class SimpleGamesystemEditorComponent implements OnInit{ @Input() simpleGamesystem: SimpleGamesystem | SimpleTemplateGamesystem | undefined @Input() scriptAccunts: ScriptAccount[] = [] + @Input() templateReference: Character | undefined ngOnInit(): void { console.log("SimpleGamesystem: ", this.simpleGamesystem) diff --git a/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.html b/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.html index 4e74bda..bd9189d 100644 --- a/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.html +++ b/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.html @@ -27,7 +27,7 @@
-
diff --git a/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.ts b/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.ts index 049814c..802cac1 100644 --- a/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.ts +++ b/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.ts @@ -6,6 +6,8 @@ import {SimpleState} from "../../../../project/game-model/gamesystems/states/Sim import {SimpleGamesystem} from "../../../../project/game-model/gamesystems/SimpleGamesystem"; import {ScriptAccount} from "../../../../project/game-model/scriptAccounts/ScriptAccount"; import {ScriptAccountCondition} from "../../../../project/game-model/gamesystems/conditions/ScriptAccountCondition"; +import {Character} from "../../../../project/game-model/characters/Character"; +import {SimpleTemplateState} from "../../../../project/game-model/gamesystems/states/SimpleTemplateState"; @Component({ selector: 'app-simple-state-editor', @@ -24,6 +26,8 @@ export class SimpleStateEditorComponent implements OnInit{ @Input() states: SimpleState[] = []; @Input() gamesystem: SimpleGamesystem | undefined @Input() scriptAccounts: ScriptAccount[] = [] + @Input() templateReference: Character | undefined + dataSource = new MatTableDataSource(); displayedColumns = ["name", "initial", "edit", "delete"]; columnsToDisplayWithExpand = [...this.displayedColumns, 'expand']; @@ -96,11 +100,33 @@ export class SimpleStateEditorComponent implements OnInit{ } onCreateCondition(state: SimpleState, condition: ScriptAccountCondition) { - state.addScriptAccountCondition(condition); + if(this.templateReference instanceof Character) { + const templateState = state as SimpleTemplateState + console.log("CharacterRef: ", this.templateReference); + templateState.conditionMap.get(this.templateReference as Character)!.push(condition) + console.log(templateState) + } else { + state.addScriptAccountCondition(condition); + } } deleteCondition(state: SimpleState, condition: ScriptAccountCondition) { state.removeScriptAccountCondition(condition.scriptAccount); } + + getStateConditions(state: SimpleState) { + if(state instanceof SimpleTemplateState) { + if(this.templateReference instanceof Character) { + const referenceSpecificConditions = state.conditionMap.get(this.templateReference as Character) + if(referenceSpecificConditions == undefined) { + return [] + } else { + return referenceSpecificConditions; + } + } + } + + return state.conditions; + } } diff --git a/src/app/project/parser/characterParser/CharacterParser.ts b/src/app/project/parser/characterParser/CharacterParser.ts index 11b386d..6ded01a 100644 --- a/src/app/project/parser/characterParser/CharacterParser.ts +++ b/src/app/project/parser/characterParser/CharacterParser.ts @@ -19,21 +19,21 @@ export class CharacterParser { private parseSingleCharacter(characterData: any): Character { const character = new Character(characterData.componentName, characterData.componentDescription); - character.characterSpecificGamesystems = this.parseCharacterSpecificGamesystems(characterData.characterSpecificGamesystems); + character.characterSpecificGamesystems = this.parseCharacterSpecificGamesystems(character, characterData.characterSpecificGamesystems); console.log("Parsed Character", character) return character; } - private parseCharacterSpecificGamesystems(characterSpecificGamesystems: any): SimpleTemplateGamesystem[] { + private parseCharacterSpecificGamesystems(character: Character, characterSpecificGamesystems: any): SimpleTemplateGamesystem[] { const result: SimpleTemplateGamesystem[] = [] for(let i=0; i | undefined{ + private parseSingleCharacterSpecificGamesystem(character: Character, characterSpecificGamesystem: any): SimpleTemplateGamesystem | undefined{ const referencedGamesystem = this.findCharacterSpecificGamesystem(characterSpecificGamesystem.componentName) if(referencedGamesystem != undefined) { @@ -41,7 +41,7 @@ export class CharacterParser { const stateReference = characterSpecificGamesystem.states[i]; const state = this.findReferencedState(referencedGamesystem, stateReference.stateLabel)! - + state.conditionMap.set(character, []) } } diff --git a/src/app/project/serializer/CharacterSerializer.ts b/src/app/project/serializer/CharacterSerializer.ts index 3cb00a2..09e1028 100644 --- a/src/app/project/serializer/CharacterSerializer.ts +++ b/src/app/project/serializer/CharacterSerializer.ts @@ -3,6 +3,7 @@ import {StoreComponent} from "../../../../app/storage/StoreComponent"; import {SerializeConstants} from "./SerializeConstants"; import {ModelComponentType} from "../game-model/ModelComponentType"; import {Gamesystem} from "../game-model/gamesystems/Gamesystem"; +import {ScriptAccount} from "../game-model/scriptAccounts/ScriptAccount"; export class CharacterSerializer { @@ -24,6 +25,14 @@ export class CharacterSerializer { } } + if(key === 'scriptAccount') { + return value.componentName + } + + if(key === 'conditionMap') { + return value.get(character) + } + if(this.ignoredKeys.includes(key)) { return undefined } else { diff --git a/testModel/characters/Hicks Haddock.json b/testModel/characters/Hicks Haddock.json index 8f3c8f5..30e3fe8 100644 --- a/testModel/characters/Hicks Haddock.json +++ b/testModel/characters/Hicks Haddock.json @@ -7,11 +7,17 @@ "states": [ { "stateLabel": "Fröhlich", - "conditionMap": {} + "conditionMap": [ + { + "scriptAccount": "Luftfeuchtigkeit", + "minValue": 0, + "maxValue": "10" + } + ] }, { "stateLabel": "Wütend", - "conditionMap": {} + "conditionMap": [] } ], "transitions": [] From b398545b7a51cb5e416e658d26bd170f9f6d3604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 11 Apr 2024 15:47:25 +0200 Subject: [PATCH 10/10] Load ConditionMap from Disk --- src/app/app.component.ts | 2 +- .../parser/characterParser/CharacterParser.ts | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index be0a940..221fe57 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -211,7 +211,7 @@ export class AppComponent implements OnInit{ const gamesystemParser = new GamesystemParser(scriptAccounts); const gamesystems = gamesystemParser.parseStoredGamesystems(storedGameModel.storedGamesystems); - const characterParser = new CharacterParser(gamesystemParser.getParsedTemplateGamesystems(TemplateType.CHARACTER)); + const characterParser = new CharacterParser(gamesystemParser.getParsedTemplateGamesystems(TemplateType.CHARACTER), scriptAccounts); const characters = characterParser.parseCharacters(storedGameModel.storedCharacters); gameModel.scriptAccounts = scriptAccounts diff --git a/src/app/project/parser/characterParser/CharacterParser.ts b/src/app/project/parser/characterParser/CharacterParser.ts index 6ded01a..d1323f9 100644 --- a/src/app/project/parser/characterParser/CharacterParser.ts +++ b/src/app/project/parser/characterParser/CharacterParser.ts @@ -1,14 +1,19 @@ import {StoreComponent} from "../../../../../app/storage/StoreComponent"; import {Character} from "../../game-model/characters/Character"; import {SimpleTemplateGamesystem} from "../../game-model/gamesystems/SimpleTemplateGamesystem"; +import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; +import {ScriptAccountParser} from "../ScriptAccountParser"; +import {ScriptAccountConditionParser} from "../gamesystemParser/ScriptAccountConditionParser"; export class CharacterParser { characterSpecificGamesystems: SimpleTemplateGamesystem[] + scriptAccountConditionParser: ScriptAccountConditionParser - constructor(characterSpecificGamesystems: SimpleTemplateGamesystem[]) { + constructor(characterSpecificGamesystems: SimpleTemplateGamesystem[], scriptAccounts: ScriptAccount[]) { this.characterSpecificGamesystems = characterSpecificGamesystems; + this.scriptAccountConditionParser = new ScriptAccountConditionParser(scriptAccounts) } public parseCharacters(characters: StoreComponent[]): Character[] { @@ -20,7 +25,6 @@ export class CharacterParser { private parseSingleCharacter(characterData: any): Character { const character = new Character(characterData.componentName, characterData.componentDescription); character.characterSpecificGamesystems = this.parseCharacterSpecificGamesystems(character, characterData.characterSpecificGamesystems); - console.log("Parsed Character", character) return character; } @@ -41,13 +45,14 @@ export class CharacterParser { const stateReference = characterSpecificGamesystem.states[i]; const state = this.findReferencedState(referencedGamesystem, stateReference.stateLabel)! - state.conditionMap.set(character, []) + const conditions = this.scriptAccountConditionParser.parseStoredConditions(stateReference.conditionMap); + + state.conditionMap.set(character, conditions) } } return referencedGamesystem; } - private findCharacterSpecificGamesystem(componentName: string): SimpleTemplateGamesystem | undefined{ return this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === componentName) }