From b68d2a812cd93d05bce9578c0fe4786a2c43e182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Mon, 18 Mar 2024 18:12:55 +0100 Subject: [PATCH] Delete Childsystems (and correct loading childgamesystems (relation was not loaded bidirectional)) --- src/app/app.component.ts | 15 +++++++++++---- src/app/game-model/GameModel.ts | 7 ++++++- src/app/game-model/fs/ProcessLoadedProject.ts | 2 ++ src/app/game-model/gamesystems/Gamesystem.ts | 1 + .../gamesystems/ProductGamesystem.ts | 5 ++--- .../game-model/gamesystems/SimpleGamesystem.ts | 2 -- .../gamescript-overview.component.ts | 18 +++++++++--------- 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 3577b36..8c8ef98 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -14,13 +14,10 @@ import {MatDialog} from "@angular/material/dialog"; import {DeleteConfirmationDialogComponent} from "./delete-confirmation-dialog/delete-confirmation-dialog.component"; import {ScriptAccount} from "./game-model/scriptAccounts/ScriptAccount"; import {GamescriptOverviewComponent} from "./side-overviews/gamescript-overview/gamescript-overview.component"; -import {SimpleGamesystem} from "./game-model/gamesystems/SimpleGamesystem"; -import {ProductGamesystem} from "./game-model/gamesystems/ProductGamesystem"; -import {ProductState} from "./game-model/gamesystems/states/ProductState"; -import {LoadModel} from "../../app/LoadModel"; import {LoadedProject} from "../../app/LoadedProject"; import {ProcessLoadedProject} from "./game-model/fs/ProcessLoadedProject"; import {StoreProject} from "./game-model/fs/store/StoreProject"; +import {Gamesystem} from "./game-model/gamesystems/Gamesystem"; @Component({ selector: 'app-root', @@ -111,12 +108,16 @@ export class AppComponent implements OnInit{ private onDeleteModelComponent() { const affectedModelComponent = this.getSelectedModelComponent(); + console.log("Affected ModelComponent: ", affectedModelComponent) const dialogRef = this.dialog.open(DeleteConfirmationDialogComponent, {data: affectedModelComponent, minWidth: "400px"}); dialogRef.afterClosed().subscribe(res => { if(res != undefined && res) { if(affectedModelComponent instanceof ScriptAccount) { this.gameModel!.removeScriptAccount(affectedModelComponent); + } else if(affectedModelComponent instanceof Gamesystem) { + this.gameModel!.removeGamesystem(affectedModelComponent); + this.gamesystemOverview!.refresh() } } }) @@ -159,6 +160,12 @@ export class AppComponent implements OnInit{ } else { console.log("[WARN] [App.component] ScriptAccountOverview is undefined") } + } else if(this.openContent == ModelComponentType.GAMESYTEM){ + if(this.gamesystemOverview != undefined) { + return this.gamesystemOverview!.getSelectedGamesystem() + } else { + console.log("[WARN] [App.component] GamesystemOverview is undefined") + } } return undefined; } diff --git a/src/app/game-model/GameModel.ts b/src/app/game-model/GameModel.ts index e184c18..ec53871 100644 --- a/src/app/game-model/GameModel.ts +++ b/src/app/game-model/GameModel.ts @@ -33,7 +33,12 @@ export class GameModel { } removeGamesystem(gamesystem : Gamesystem) { - this._gamesystems = this._gamesystems.filter(g => g !== gamesystem); + if(gamesystem.parentGamesystem == undefined) { + this._gamesystems = this._gamesystems.filter(g => g !== gamesystem); + } else { + (gamesystem.parentGamesystem as ProductGamesystem).removeChildGamesystem(gamesystem); + console.log(gamesystem.parentGamesystem) + } } createScriptAccount(scriptAccountName: string) { diff --git a/src/app/game-model/fs/ProcessLoadedProject.ts b/src/app/game-model/fs/ProcessLoadedProject.ts index 7c427a1..faf6719 100644 --- a/src/app/game-model/fs/ProcessLoadedProject.ts +++ b/src/app/game-model/fs/ProcessLoadedProject.ts @@ -50,12 +50,14 @@ export class ProcessLoadedProject { const simpleGamesystem: SimpleGamesystem = SimpleGamesystemParser.parseSimpleGamesystem(parsedJsonString, gameModel.scriptAccounts); const parentModel: ProductGamesystem = gameModel.findGamesystem(recursiveLoadModel.parentLoadModelname) as ProductGamesystem parentModel.addChildGamesystem(simpleGamesystem); + simpleGamesystem.parentGamesystem = parentModel } else { console.log("Gamesystems: ", ) //ProductGamesystem const productGamesystem: ProductGamesystem = ProductGamesystemParser.parseProductGamesystem(parsedJsonString); const parentModel: ProductGamesystem = gameModel.findGamesystem(recursiveLoadModel.parentLoadModelname) as ProductGamesystem; parentModel.addChildGamesystem(productGamesystem); + productGamesystem.parentGamesystem = parentModel } } else { //Top Gamesystem diff --git a/src/app/game-model/gamesystems/Gamesystem.ts b/src/app/game-model/gamesystems/Gamesystem.ts index e182c25..2e94174 100644 --- a/src/app/game-model/gamesystems/Gamesystem.ts +++ b/src/app/game-model/gamesystems/Gamesystem.ts @@ -7,6 +7,7 @@ export abstract class Gamesystem extends ModelComponent{ states: S[] = []; transitions: T[] = []; + parentGamesystem: ProductGamesystem | undefined constructor(gamesystemName: string, gamesystemDescription: string) { super(gamesystemName, gamesystemDescription, ModelComponentType.GAMESYTEM); } diff --git a/src/app/game-model/gamesystems/ProductGamesystem.ts b/src/app/game-model/gamesystems/ProductGamesystem.ts index 1757ca4..6166b18 100644 --- a/src/app/game-model/gamesystems/ProductGamesystem.ts +++ b/src/app/game-model/gamesystems/ProductGamesystem.ts @@ -11,7 +11,6 @@ import {ProductStateTrainer} from "../../../../e2e/game-model/gamesystems/produc export class ProductGamesystem extends Gamesystem { innerGamesystems: Gamesystem, Transition>[] = []; - parentGamesystem: ProductGamesystem | undefined static constructFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel) { const productGamesystem = new ProductGamesystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription); @@ -154,8 +153,8 @@ export class ProductGamesystem extends Gamesystem, Transition>) { - this.innerGamesystems = this.innerGamesystems.filter(childSystem => childSystem != gamesystem); + removeChildGamesystem(gamesystem: Gamesystem, Transition>) { + this.innerGamesystems = this.innerGamesystems.filter(childSystem => childSystem.componentName !== gamesystem.componentName); } findProductStateByInnerStates(innerStates: State[]) { diff --git a/src/app/game-model/gamesystems/SimpleGamesystem.ts b/src/app/game-model/gamesystems/SimpleGamesystem.ts index dedb8f2..9b04b03 100644 --- a/src/app/game-model/gamesystems/SimpleGamesystem.ts +++ b/src/app/game-model/gamesystems/SimpleGamesystem.ts @@ -8,8 +8,6 @@ import {ProductTransition} from "./transitions/ProductTransition"; import {ProductGamesystem} from "./ProductGamesystem"; export class SimpleGamesystem extends Gamesystem { - parentGamesystem: ProductGamesystem | undefined - createState(label: string, description: string): SimpleState | undefined { diff --git a/src/app/side-overviews/gamescript-overview/gamescript-overview.component.ts b/src/app/side-overviews/gamescript-overview/gamescript-overview.component.ts index dbd0d52..38c0c5c 100644 --- a/src/app/side-overviews/gamescript-overview/gamescript-overview.component.ts +++ b/src/app/side-overviews/gamescript-overview/gamescript-overview.component.ts @@ -4,15 +4,7 @@ import {State} from "../../game-model/gamesystems/states/State"; import {Transition} from "../../game-model/gamesystems/transitions/Transition"; import {ProductGamesystem} from "../../game-model/gamesystems/ProductGamesystem"; import {FlatTreeControl} from "@angular/cdk/tree"; -import { - MatTree, - MatTreeFlatDataSource, - MatTreeFlattener, - MatTreeNode, MatTreeNodeDef, - MatTreeNodePadding, MatTreeNodeToggle -} from "@angular/material/tree"; -import {MatIcon} from "@angular/material/icon"; -import {MatIconButton} from "@angular/material/button"; +import {MatTreeFlatDataSource, MatTreeFlattener} from "@angular/material/tree"; import {SimpleGamesystem} from "../../game-model/gamesystems/SimpleGamesystem"; import {GameModel} from "../../game-model/GameModel"; import {ElectronService} from "../../core/services"; @@ -100,6 +92,14 @@ export class GamescriptOverviewComponent implements OnInit { } } + getSelectedGamesystem() { + if(this.selectedGamesystem != undefined) { + return this.gameModel!.findGamesystem(this.selectedGamesystem!.name); + } else { + return undefined; + } + } + refresh() { this.dataSource.data = this.gameModel!.gamesystems; }