From 21dc74376bb90ca35516a9428317351dee4b4d74 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] Create Characterspecific Systems and open their editor correctly --- app/main.ts | 17 ++++++++-- src/app/app.component.ts | 17 +++++++--- .../gamesystem-editor.component.ts | 8 ++--- .../simple-gamesystem-editor.component.ts | 11 +++++-- src/app/project/game-model/GameModel.ts | 32 ++++++------------- src/app/project/game-model/TemplateType.ts | 3 ++ .../game-model/TemplateTypeUtilities.ts | 11 +++++++ .../gamesystems/SimpleTemplateGamesystem.ts | 1 + 8 files changed, 61 insertions(+), 39 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 17e5dad..de5ef89 100644 --- a/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts +++ b/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts @@ -5,7 +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 {TemplateType} from "../../project/game-model/gamesystems/TemplateType"; +import {SimpleTemplateGamesystem} from "../../project/game-model/gamesystems/SimpleTemplateGamesystem"; @Component({ selector: 'app-gamesystem-editor', @@ -23,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; } } @@ -41,6 +41,4 @@ export class GamesystemEditorComponent implements OnInit{ onOpenGamesystemEditor(gamesystem: SimpleGamesystem) { this.openGamesystemEmitter.emit(gamesystem); } - - protected readonly TemplateType = TemplateType; } 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 e565728..dab8a83 100644 --- a/src/app/project/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -5,8 +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 "./gamesystems/TemplateType"; +import {TemplateType} from "./TemplateType"; +import {SimpleTemplateGamesystem} from "./gamesystems/SimpleTemplateGamesystem"; export class GameModel { gameModelName: string @@ -46,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) { @@ -116,23 +121,4 @@ export class GameModel { } }) } - - getTemplateGamesystems(templateType: TemplateType) { - const gamesystems = this.getGamesystemsAsList() - return gamesystems.filter(gamesystem => gamesystem.template === templateType); - } - - private getGamesystemsAsList() : Gamesystem[]{ - const gamesystemList: Gamesystem[] = [] - - const gamesystemQueue : Gamesystem[] = this.gamesystems.map(gamesystem => gamesystem) - while(gamesystemQueue.length > 0) { - const currentGamesystem = gamesystemQueue.shift()!; - gamesystemList.push(currentGamesystem) - if(currentGamesystem instanceof ProductGamesystem) { - currentGamesystem.innerGamesystems.forEach(innerGamesystem => gamesystemQueue.push(innerGamesystem)) - } - } - return gamesystemList - } } 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> {