From d643f6bb1c2b3e46e3af9c60b2b5fdfa62ef960b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 11 Apr 2024 08:43:12 +0200 Subject: [PATCH] Add Templatesystem to Characterspecific Systems --- src/app/app.module.ts | 19 ++++++++-- .../character-editor.component.html | 3 +- .../character-editor.component.ts | 37 +++++++++++++++++-- src/app/editor/editor.component.html | 2 +- .../template-system-editor.component.html | 14 +++++++ .../template-system-editor.component.scss | 0 .../template-system-editor.component.spec.ts | 23 ++++++++++++ .../template-system-editor.component.ts | 31 ++++++++++++++++ src/app/project/game-model/GameModel.ts | 20 ++++++++++ 9 files changed, 139 insertions(+), 10 deletions(-) create mode 100644 src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.html create mode 100644 src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.scss create mode 100644 src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.spec.ts create mode 100644 src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index ab95304..ea5f6b7 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,15 @@ 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, MatExpansionPanelTitle} from "@angular/material/expansion"; +import { + MatAccordion, + MatExpansionPanel, + MatExpansionPanelHeader, + MatExpansionPanelTitle +} from "@angular/material/expansion"; +import { + TemplateSystemEditorComponent +} from "./editor/gamesystem-editor/template-system-editor/template-system-editor.component"; // AoT requires an exported function for factories const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new TranslateHttpLoader(http, './assets/i18n/', '.json'); @@ -94,7 +102,8 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl ScriptaccountActionEditorComponent, ScriptaccountConditionEditorComponent, CharacterOverviewComponent, - CharacterEditorComponent + CharacterEditorComponent, + TemplateSystemEditorComponent ], imports: [ BrowserModule, @@ -153,9 +162,11 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl MatCard, MatCardContent, MatCardHeader, + MatCardTitle, MatAccordion, MatExpansionPanel, - MatExpansionPanelTitle + MatExpansionPanelTitle, + 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 648137c..5a38d04 100644 --- a/src/app/editor/character-editor/character-editor.component.html +++ b/src/app/editor/character-editor/character-editor.component.html @@ -8,8 +8,9 @@ {{characterSystem.componentName}} - + + diff --git a/src/app/editor/character-editor/character-editor.component.ts b/src/app/editor/character-editor/character-editor.component.ts index 8eba0b2..5d37f19 100644 --- a/src/app/editor/character-editor/character-editor.component.ts +++ b/src/app/editor/character-editor/character-editor.component.ts @@ -1,6 +1,14 @@ -import { Component, Input } from '@angular/core'; -import { Character } from '../../project/game-model/characters/Character'; -import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccount"; +import {Component, Input} from '@angular/core'; +import {Character} from '../../project/game-model/characters/Character'; +import {MatDialog} from "@angular/material/dialog"; +import { + TemplateSystemEditorComponent +} from "../gamesystem-editor/template-system-editor/template-system-editor.component"; +import {GameModel} from "../../project/game-model/GameModel"; +import {TemplateType} from "../../project/game-model/gamesystems/TemplateType"; +import {Gamesystem} from "../../project/game-model/gamesystems/Gamesystem"; +import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem"; +import {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem"; @Component({ selector: 'app-character-editor', @@ -10,5 +18,26 @@ import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccou export class CharacterEditorComponent { @Input() character: Character | undefined - @Input() scriptAccounts: ScriptAccount[] = [] + @Input() gameModel: GameModel | undefined + + constructor(private dialog: MatDialog) { + } + + openTemplateEditor() { + const dialogRef = this.dialog.open(TemplateSystemEditorComponent, { + minWidth: "400px", + data: this.gameModel!.getTemplateGamesystems(TemplateType.CHARACTER) + }) + + dialogRef.afterClosed().subscribe(res => { + if(res != undefined) { + const referenceSystem: Gamesystem = res + if(referenceSystem instanceof SimpleGamesystem) { + this.character!.addCharacterSpecificSimpleGamesystem(referenceSystem) + } else if(referenceSystem instanceof ProductGamesystem) { + this.character!.addCharacterSpecificProductTemplateGamesystem(referenceSystem) + } + } + }) + } } diff --git a/src/app/editor/editor.component.html b/src/app/editor/editor.component.html index acf4c2e..5c7a222 100644 --- a/src/app/editor/editor.component.html +++ b/src/app/editor/editor.component.html @@ -16,7 +16,7 @@ [scriptAccounts]="gameModel!.scriptAccounts"> + [gameModel]="gameModel!"> diff --git a/src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.html b/src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.html new file mode 100644 index 0000000..5630d8d --- /dev/null +++ b/src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.html @@ -0,0 +1,14 @@ +

Create Templatesystem

+
+

Select the System to be specified. This will not change the original system.

+ + Referencesystem + + {{templateSystem.componentName}} + + +
+
+ + +
diff --git a/src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.scss b/src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.spec.ts b/src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.spec.ts new file mode 100644 index 0000000..c50620a --- /dev/null +++ b/src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { TemplateSystemEditorComponent } from './template-system-editor.component'; + +describe('TemplateSystemEditorComponent', () => { + let component: TemplateSystemEditorComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [TemplateSystemEditorComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(TemplateSystemEditorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.ts b/src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.ts new file mode 100644 index 0000000..3ce84ff --- /dev/null +++ b/src/app/editor/gamesystem-editor/template-system-editor/template-system-editor.component.ts @@ -0,0 +1,31 @@ +import {Component, Inject} from '@angular/core'; +import {MAT_DIALOG_DATA, MatDialogContent, MatDialogRef, MatDialogTitle} from "@angular/material/dialog"; +import {TemplateType} from "../../../project/game-model/gamesystems/TemplateType"; +import {Gamesystem} from "../../../project/game-model/gamesystems/Gamesystem"; +import {MatFormField} from "@angular/material/form-field"; +import {MatOption, MatSelect} from "@angular/material/select"; +import {NgForOf} from "@angular/common"; +import {FormControl, Validators} from "@angular/forms"; + +@Component({ + selector: 'app-template-system-editor', + templateUrl: './template-system-editor.component.html', + styleUrl: './template-system-editor.component.scss' +}) +export class TemplateSystemEditorComponent { + + referenceCtrl: FormControl = new FormControl('', [Validators.required]) + + constructor(private dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public templateSystems: Gamesystem[] = []) { + + } + + cancel() { + this.dialogRef.close() + } + + submit() { + this.dialogRef.close(this.referenceCtrl.value) + } +} diff --git a/src/app/project/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts index 8497737..e565728 100644 --- a/src/app/project/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -6,6 +6,7 @@ import {ProductGamesystem} from "./gamesystems/ProductGamesystem"; import {SimpleGamesystem} from "./gamesystems/SimpleGamesystem"; import {Character} from "./characters/Character"; import {ModelComponentType} from "./ModelComponentType"; +import {TemplateType} from "./gamesystems/TemplateType"; export class GameModel { gameModelName: string @@ -115,4 +116,23 @@ 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 + } }