From ccb53df8154a7151e7695531e405f1d826da4ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 9 May 2024 19:17:43 +0200 Subject: [PATCH] Refactor Gamesystem Creation --- src/app/app.component.ts | 5 ++ .../game-model/gamesystems/Gamesystem.ts | 1 - .../utils/creator/GamesystemCreator.ts | 46 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/app/project/game-model/utils/creator/GamesystemCreator.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 790132e..2ff3758 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -35,6 +35,7 @@ import {Overview} from "./side-overviews/Overview"; import {ItemCreator} from "./project/game-model/utils/creator/ItemCreator"; import {ScriptAccountCreator} from "./project/game-model/utils/creator/ScriptAccountCreator"; import {CharacterCreator} from "./project/game-model/utils/creator/CharacterCreator"; +import {GamesystemCreator} from "./project/game-model/utils/creator/GamesystemCreator"; @Component({ selector: 'app-root', @@ -108,6 +109,9 @@ export class AppComponent implements OnInit{ case ModelComponentType.CHARACTER: { componentCreator = new CharacterCreator(creationContext, this.gameModel!, this.selectedModelComponent); } break + case ModelComponentType.GAMESYTEM: { + componentCreator = new GamesystemCreator(creationContext, this.gameModel!, this.selectedModelComponent); + } break } if(componentCreator) { @@ -146,6 +150,7 @@ export class AppComponent implements OnInit{ } }break + } } diff --git a/src/app/project/game-model/gamesystems/Gamesystem.ts b/src/app/project/game-model/gamesystems/Gamesystem.ts index 981590a..e50cf3f 100644 --- a/src/app/project/game-model/gamesystems/Gamesystem.ts +++ b/src/app/project/game-model/gamesystems/Gamesystem.ts @@ -27,5 +27,4 @@ export abstract class Gamesystem extends ModelComponent{ this.transitions = updatedTransitions; return true; } - } diff --git a/src/app/project/game-model/utils/creator/GamesystemCreator.ts b/src/app/project/game-model/utils/creator/GamesystemCreator.ts new file mode 100644 index 0000000..f7a250f --- /dev/null +++ b/src/app/project/game-model/utils/creator/GamesystemCreator.ts @@ -0,0 +1,46 @@ +import {ModelComponentCreator} from "./ModelComponentCreator"; +import {GameModel} from "../../GameModel"; +import {ModelComponent} from "../../ModelComponent"; +import {TemplateTypeUtilities} from "../../templates/TemplateTypeUtilities"; +import {Gamesystem} from "../../gamesystems/Gamesystem"; +import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem"; +import {ProductGamesystem} from "../../gamesystems/ProductGamesystem"; +import {SimpleTemplateGamesystem} from "../../templates/simpleGamesystem/SimpleTemplateGamesystem"; +import {ProductTemplateCreator} from "../../templates/productGamesystem/ProductTemplateCreator"; + +export class GamesystemCreator extends ModelComponentCreator{ + + + constructor(context: string, gameModel: GameModel, selectedComponent: ModelComponent | undefined) { + super(context, gameModel, selectedComponent); + } + + createModelComponent(): ModelComponent | undefined { + const templateType = TemplateTypeUtilities.fromString(this.context); + let simpleGamesystem; + if(templateType == undefined) /**Aka normal**/{ + simpleGamesystem = new SimpleGamesystem("New Simple Gamesystem", ""); + } else { + simpleGamesystem = new SimpleTemplateGamesystem("New Simple Gamesystem", "", templateType) + } + + if(this.selectedComponent !== undefined && this.selectedComponent instanceof Gamesystem)/**Aka productGamesystem**/ { + let productParentsystem: ProductGamesystem; + if(this.selectedComponent instanceof SimpleTemplateGamesystem) { + productParentsystem = ProductTemplateCreator.constructTemplateFromSimpleGamesystem(this.selectedComponent, this.gameModel!, this.selectedComponent.templateType); + } else if(this.selectedComponent instanceof SimpleGamesystem) { + productParentsystem = ProductGamesystem.constructFromSimpleGamesystem(this.selectedComponent, this.gameModel); + } else { + productParentsystem = this.selectedComponent as ProductGamesystem; + } + + productParentsystem.addChildGamesystem(simpleGamesystem); + } else { + this.gameModel!.gamesystems.push(simpleGamesystem); + } + + return simpleGamesystem; + } + + +}