Add Templatesystem to Characterspecific Systems
All checks were successful
E2E Testing / test (push) Successful in 1m30s

This commit is contained in:
Sebastian Böckelmann 2024-04-11 08:43:12 +02:00
parent 81971a48ca
commit d643f6bb1c
9 changed files with 139 additions and 10 deletions

View File

@ -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]

View File

@ -8,8 +8,9 @@
<mat-expansion-panel-header>
<mat-panel-title>{{characterSystem.componentName}}</mat-panel-title>
</mat-expansion-panel-header>
<app-gamesystem-editor [gamesystem]="characterSystem" [scriptAccounts]="scriptAccounts"></app-gamesystem-editor>
<app-gamesystem-editor [gamesystem]="characterSystem" [scriptAccounts]="gameModel!.scriptAccounts"></app-gamesystem-editor>
</mat-expansion-panel>
</mat-accordion>
<button style="width: 100%; margin-top: 10px" mat-stroked-button (click)="openTemplateEditor()">Add Charactersystem</button>
</mat-card-content>
</mat-card>

View File

@ -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<any, any> = res
if(referenceSystem instanceof SimpleGamesystem) {
this.character!.addCharacterSpecificSimpleGamesystem(referenceSystem)
} else if(referenceSystem instanceof ProductGamesystem) {
this.character!.addCharacterSpecificProductTemplateGamesystem(referenceSystem)
}
}
})
}
}

View File

@ -16,7 +16,7 @@
[scriptAccounts]="gameModel!.scriptAccounts"></app-gamesystem-editor>
<app-character-editor *ngIf="modelComponent.type === ModelComponentType.CHARACTER"
[character]="convertModelComponentToCharacter(modelComponent)"
[scriptAccounts]="gameModel!.scriptAccounts">
[gameModel]="gameModel!">
</app-character-editor>
</mat-tab>

View File

@ -0,0 +1,14 @@
<h1 mat-dialog-title>Create Templatesystem</h1>
<div mat-dialog-content>
<p>Select the System to be specified. This will not change the original system. </p>
<mat-form-field appearance="outline" style="width: 100%">
<mat-label>Referencesystem</mat-label>
<mat-select [formControl]="referenceCtrl">
<mat-option *ngFor="let templateSystem of templateSystems" [value]="templateSystem">{{templateSystem.componentName}}</mat-option>
</mat-select>
</mat-form-field>
</div>
<div mat-dialog-actions align="end">
<button mat-stroked-button (click)="cancel()">Cancel</button>
<button mat-raised-button color="accent" [disabled]="referenceCtrl.invalid" (click)="submit()">Confirm</button>
</div>

View File

@ -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<TemplateSystemEditorComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TemplateSystemEditorComponent]
})
.compileComponents();
fixture = TestBed.createComponent(TemplateSystemEditorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -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<TemplateSystemEditorComponent>,
@Inject(MAT_DIALOG_DATA) public templateSystems: Gamesystem<any, any>[] = []) {
}
cancel() {
this.dialogRef.close()
}
submit() {
this.dialogRef.close(this.referenceCtrl.value)
}
}

View File

@ -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<any, any>[]{
const gamesystemList: Gamesystem<any, any>[] = []
const gamesystemQueue : Gamesystem<any, any>[] = 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
}
}