Compare commits

..

32 Commits

Author SHA1 Message Date
b30aed07cd Merge pull request 'CharacterSpecific Templatesystems' (#36) from template-systems into main
All checks were successful
E2E Testing / test (push) Successful in 1m36s
Reviewed-on: #36
2024-04-14 13:45:04 +02:00
b874188b10 Merge pull request 'Generate States and Transition Template Specific' (#35) from product-template-systems into template-systems
All checks were successful
E2E Testing / test (push) Successful in 1m33s
Reviewed-on: #35
2024-04-14 13:38:57 +02:00
Sebastian Böckelmann
42388de905 Generate States and Transition Template Specific
All checks were successful
E2E Testing / test (push) Successful in 1m33s
2024-04-14 12:25:23 +02:00
cb2e706ac7 Merge pull request 'product-template-systems' (#34) from product-template-systems into template-systems
All checks were successful
E2E Testing / test (push) Successful in 1m34s
Reviewed-on: #34
2024-04-14 12:01:23 +02:00
Sebastian Böckelmann
c127a0122f Display Characterspecific ProductTransitions
All checks were successful
E2E Testing / test (push) Successful in 1m30s
2024-04-14 11:59:30 +02:00
Sebastian Böckelmann
ebd3a54120 Display Characterspecific ProductStates
All checks were successful
E2E Testing / test (push) Successful in 1m33s
2024-04-14 11:55:06 +02:00
968e357845 Merge pull request 'product-template-systems' (#33) from product-template-systems into template-systems
All checks were successful
E2E Testing / test (push) Successful in 1m32s
Reviewed-on: #33
2024-04-14 11:45:39 +02:00
Sebastian Böckelmann
6496bd52c5 Persist and Load Characterspecified ProductTemplateSystems
All checks were successful
E2E Testing / test (push) Successful in 1m34s
2024-04-14 11:42:45 +02:00
Sebastian Böckelmann
4d4efa49c9 Exclude SiblingTemplates to be automatically specified only by recursive call
All checks were successful
E2E Testing / test (push) Successful in 1m31s
2024-04-14 11:39:39 +02:00
Sebastian Böckelmann
bf5403814a Exclude SiblingTemplates to be automatically specified
All checks were successful
E2E Testing / test (push) Successful in 1m34s
2024-04-14 11:36:30 +02:00
Sebastian Böckelmann
49521cba87 Add related Templatesystem as specified Gamesystems
All checks were successful
E2E Testing / test (push) Successful in 1m34s
2024-04-14 11:35:24 +02:00
Sebastian Böckelmann
10a32df859 Load Templatetype of ProductTemplateGamesystems
All checks were successful
E2E Testing / test (push) Successful in 1m35s
2024-04-14 11:20:36 +02:00
Sebastian Böckelmann
21d324d3b2 Persist TemplateType of ProductTemplateSystems
All checks were successful
E2E Testing / test (push) Successful in 1m37s
2024-04-14 11:18:23 +02:00
Sebastian Böckelmann
151531f970 Create ProductTemplatesystems
All checks were successful
E2E Testing / test (push) Successful in 1m35s
2024-04-14 11:14:04 +02:00
Sebastian Böckelmann
eaaac9ec7a Implement basic ProductTemplateSystem
All checks were successful
E2E Testing / test (push) Successful in 1m34s
2024-04-14 10:09:30 +02:00
Sebastian Böckelmann
c1070ed1ff Don't override default conditions/actions when loading character specific gamesystem
All checks were successful
E2E Testing / test (push) Successful in 1m33s
2024-04-14 09:32:19 +02:00
Sebastian Böckelmann
df3933d147 Parse CharacterSpecificTemplatesystems and reassign them to character
All checks were successful
E2E Testing / test (push) Successful in 1m29s
2024-04-14 09:28:50 +02:00
Sebastian Böckelmann
70880b28ef Ignore normal conditions and actions of template-transition when persisting character-specific gamesystems
All checks were successful
E2E Testing / test (push) Successful in 1m32s
2024-04-14 09:11:19 +02:00
Sebastian Böckelmann
1f5ed46fed Use conditionMaps and actionMaps when TemplateEditing
All checks were successful
E2E Testing / test (push) Successful in 1m33s
2024-04-14 09:09:38 +02:00
Sebastian Böckelmann
6acd3e75bc Ignore conditionMaps and actionMaps when persisting templatesystems
All checks were successful
E2E Testing / test (push) Successful in 1m31s
2024-04-14 08:46:17 +02:00
Sebastian Böckelmann
26ea30da13 Load States and Transition as Templates in Templatesystems
All checks were successful
E2E Testing / test (push) Successful in 1m33s
2024-04-14 08:44:26 +02:00
Sebastian Böckelmann
877d90171f Add Default DisplayCondition Case
All checks were successful
E2E Testing / test (push) Successful in 1m34s
2024-04-14 08:18:25 +02:00
Sebastian Böckelmann
b178d8595a Display Characterspecific conditions in simple-state-editor
Some checks failed
E2E Testing / test (push) Failing after 1m30s
2024-04-14 08:15:32 +02:00
Sebastian Böckelmann
fc77868d42 Store min and max value of conditions as numbers
All checks were successful
E2E Testing / test (push) Successful in 1m37s
2024-04-14 08:03:17 +02:00
Sebastian Böckelmann
21bc329778 Persist CharacterspecificTemplatesystems
All checks were successful
E2E Testing / test (push) Successful in 1m33s
2024-04-14 08:02:59 +02:00
Sebastian Böckelmann
5a2282ddd3 Specify Templatesystem
All checks were successful
E2E Testing / test (push) Successful in 1m30s
2024-04-14 07:57:50 +02:00
Sebastian Böckelmann
8a993bd93d Fix unkown component mat-expansion-panel-header (add import)
All checks were successful
E2E Testing / test (push) Successful in 1m36s
2024-04-14 07:53:13 +02:00
Sebastian Böckelmann
4868495e70 Open TemplateSpecificatir Dialog
Some checks failed
E2E Testing / test (push) Failing after 1m35s
2024-04-14 07:50:38 +02:00
Sebastian Böckelmann
3c9efa1bd5 Add SimpleTemplateSystems to Character
All checks were successful
E2E Testing / test (push) Successful in 1m37s
2024-04-13 12:52:55 +02:00
Sebastian Böckelmann
7e6dd4aa27 Load TemplateStatus of SimpleTemplateGamesystem
All checks were successful
E2E Testing / test (push) Successful in 1m33s
2024-04-13 12:38:26 +02:00
Sebastian Böckelmann
2c789b4cd0 Add States to SimpleTemplateGamesystem
All checks were successful
E2E Testing / test (push) Successful in 1m34s
2024-04-13 12:34:43 +02:00
Sebastian Böckelmann
cd48a10084 Introduce Basic concept of Templates for SimpleGamesystems and Characters
All checks were successful
E2E Testing / test (push) Successful in 1m32s
2024-04-13 12:30:42 +02:00
53 changed files with 1064 additions and 84 deletions

View File

@ -64,10 +64,21 @@ function createWindow(): BrowserWindow {
submenu: [ submenu: [
{ {
label: "Gamesystem", label: "Gamesystem",
submenu: [
{
label: "Normal",
click: () => { click: () => {
win!.webContents.send('context-menu', "new-gamesystem"); win!.webContents.send('context-menu', "new-gamesystem-normal");
} }
}, },
{
label: "Character",
click: () => {
win!.webContents.send('context-menu', "new-gamesystem-character");
}
}
]
},
{ {
label: "ScriptAccount", label: "ScriptAccount",
click: () => { click: () => {

View File

@ -24,6 +24,9 @@ import {Character} from "./project/game-model/characters/Character";
import {CharacterOverviewComponent} from "./side-overviews/character-overview/character-overview.component"; import {CharacterOverviewComponent} from "./side-overviews/character-overview/character-overview.component";
import {CharacterSerializer} from "./project/serializer/CharacterSerializer"; import {CharacterSerializer} from "./project/serializer/CharacterSerializer";
import {CharacterParser} from "./project/parser/characterParser/CharacterParser"; import {CharacterParser} from "./project/parser/characterParser/CharacterParser";
import {TemplateType} from "./project/game-model/templates/TemplateType";
import {TemplateTypeUtilities} from "./project/game-model/templates/TemplateTypeUtilities";
import {SimpleTemplateGamesystem} from "./project/game-model/templates/simpleGamesystem/SimpleTemplateGamesystem";
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
@ -76,8 +79,9 @@ export class AppComponent implements OnInit{
} else if(message.startsWith("new")) { } else if(message.startsWith("new")) {
const splittedMessage = message.split("-"); const splittedMessage = message.split("-");
const modelComponentType = ModelComponentTypeUtillities.fromString(splittedMessage[1]); const modelComponentType = ModelComponentTypeUtillities.fromString(splittedMessage[1]);
const templateType = TemplateTypeUtilities.fromString(splittedMessage[2]);
if(modelComponentType != undefined) { if(modelComponentType != undefined) {
this.onCreateModelComponent(modelComponentType); this.onCreateModelComponent(modelComponentType, templateType);
} else { } else {
console.log("[ERROR] [App-Component] Unknown Context-Menu Command!") console.log("[ERROR] [App-Component] Unknown Context-Menu Command!")
} }
@ -127,10 +131,10 @@ export class AppComponent implements OnInit{
}) })
} }
private onCreateModelComponent(modelComponentType: ModelComponentType) { private onCreateModelComponent(modelComponentType: ModelComponentType, templateType: TemplateType | undefined) {
switch (modelComponentType) { switch (modelComponentType) {
case ModelComponentType.SCRIPTACCOUNT: this.onCreateNewScriptAccount(); break 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 case ModelComponentType.CHARACTER: this.onCreateNewCharacter(); break
} }
} }
@ -144,7 +148,7 @@ export class AppComponent implements OnInit{
} }
} }
private onCreateNewGamesystem() { private onCreateNewGamesystem(templateType: TemplateType | undefined) {
let parentGamesystemName = undefined let parentGamesystemName = undefined
if(this.openContent != ModelComponentType.GAMESYTEM) { if(this.openContent != ModelComponentType.GAMESYTEM) {
this.openGamesystemsOverview(); this.openGamesystemsOverview();
@ -153,7 +157,13 @@ export class AppComponent implements OnInit{
} }
const createdGamesystem = this.gameModel!.createGamesystem("New Gamesystem", parentGamesystemName); let createdGamesystem;
if(parentGamesystemName == undefined) {
createdGamesystem = this.gameModel?.createSimpleGamesystem("New Gamesystem", templateType);
} else {
createdGamesystem = this.gameModel!.createSimpleGamesystemWithParent("New Gamesystem", parentGamesystemName, templateType)
}
if(createdGamesystem != undefined) { if(createdGamesystem != undefined) {
this.gamesystemOverview!.refresh(); this.gamesystemOverview!.refresh();
this.editor?.openGameModelComponent(createdGamesystem); this.editor?.openGameModelComponent(createdGamesystem);
@ -204,14 +214,13 @@ export class AppComponent implements OnInit{
const gamesystemParser = new GamesystemParser(scriptAccounts); const gamesystemParser = new GamesystemParser(scriptAccounts);
const gamesystems = gamesystemParser.parseStoredGamesystems(storedGameModel.storedGamesystems); const gamesystems = gamesystemParser.parseStoredGamesystems(storedGameModel.storedGamesystems);
const characterParser = new CharacterParser();
const characters = characterParser.parseCharacters(storedGameModel.storedCharacters);
gameModel.scriptAccounts = scriptAccounts gameModel.scriptAccounts = scriptAccounts
gameModel.gamesystems = gamesystems gameModel.gamesystems = gamesystems
gameModel.generateProductSystemContents() gameModel.generateProductSystemContents()
gameModel.characters = characters const characterTemplateSystems = gameModel.getTemplateSystems(TemplateType.CHARACTER).map(templateSystem => templateSystem as SimpleTemplateGamesystem)
const characterParser = new CharacterParser(characterTemplateSystems, gameModel.scriptAccounts);
gameModel.characters = characterParser.parseCharacters(storedGameModel.storedCharacters)
this.gameModel = gameModel; this.gameModel = gameModel;
} }

View File

@ -61,7 +61,7 @@ import {
ProductStateEditorComponent ProductStateEditorComponent
} from "./editor/gamesystem-editor/state-editor/product-state-editor/product-state-editor.component"; } from "./editor/gamesystem-editor/state-editor/product-state-editor/product-state-editor.component";
import {MatTooltip} from "@angular/material/tooltip"; import {MatTooltip} from "@angular/material/tooltip";
import {MatCard, MatCardContent} from "@angular/material/card"; import {MatCard, MatCardContent, MatCardHeader, MatCardTitle} from "@angular/material/card";
import { import {
ScriptaccountActionEditorComponent ScriptaccountActionEditorComponent
} from "./editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component"; } from "./editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component";
@ -70,6 +70,15 @@ import {
} from "./editor/gamesystem-editor/scriptaccount-condition-editor/scriptaccount-condition-editor.component"; } from "./editor/gamesystem-editor/scriptaccount-condition-editor/scriptaccount-condition-editor.component";
import {CharacterOverviewComponent} from "./side-overviews/character-overview/character-overview.component"; import {CharacterOverviewComponent} from "./side-overviews/character-overview/character-overview.component";
import {CharacterEditorComponent} from "./editor/character-editor/character-editor.component"; import {CharacterEditorComponent} from "./editor/character-editor/character-editor.component";
import {
MatAccordion,
MatExpansionPanel,
MatExpansionPanelHeader,
MatExpansionPanelTitle
} from "@angular/material/expansion";
import {
TemplateSpecificatorComponent
} from "./editor/gamesystem-editor/template-specificator/template-specificator.component";
// AoT requires an exported function for factories // AoT requires an exported function for factories
const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new TranslateHttpLoader(http, './assets/i18n/', '.json'); const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new TranslateHttpLoader(http, './assets/i18n/', '.json');
@ -93,7 +102,8 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl
ScriptaccountActionEditorComponent, ScriptaccountActionEditorComponent,
ScriptaccountConditionEditorComponent, ScriptaccountConditionEditorComponent,
CharacterOverviewComponent, CharacterOverviewComponent,
CharacterEditorComponent CharacterEditorComponent,
TemplateSpecificatorComponent
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
@ -150,7 +160,13 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl
MatHint, MatHint,
MatTooltip, MatTooltip,
MatCard, MatCard,
MatCardContent MatCardContent,
MatCardHeader,
MatAccordion,
MatExpansionPanel,
MatExpansionPanelTitle,
MatCardTitle,
MatExpansionPanelHeader
], ],
providers: [], providers: [],
bootstrap: [AppComponent] bootstrap: [AppComponent]

View File

@ -1 +1,16 @@
<p>character-editor works!</p> <mat-card>
<mat-card-header>
<mat-card-title>Characterspecific Gamesystems</mat-card-title>
</mat-card-header>
<mat-card-content>
<mat-accordion>
<mat-expansion-panel *ngFor="let templateSystem of character!.characterSpecificTemplateSystems">
<mat-expansion-panel-header>
<mat-panel-title>{{templateSystem.componentName}}</mat-panel-title>
</mat-expansion-panel-header>
<app-gamesystem-editor [templateElement]="character" [gamesystem]="templateSystem" [scriptAccounts]="gameModel!.scriptAccounts"></app-gamesystem-editor>
</mat-expansion-panel>
</mat-accordion>
<button mat-stroked-button class="specify-btn" (click)="openTemplateSpecificator()">Specify Templatesystem</button>
</mat-card-content>
</mat-card>

View File

@ -0,0 +1,4 @@
.specify-btn {
width: 100%;
margin-top: 10px;
}

View File

@ -1,4 +1,11 @@
import { Component } from '@angular/core'; import {Component, Input} from '@angular/core';
import {Character} from "../../project/game-model/characters/Character";
import {GameModel} from "../../project/game-model/GameModel";
import {MatDialog} from "@angular/material/dialog";
import {
TemplateSpecificatorComponent
} from "../gamesystem-editor/template-specificator/template-specificator.component";
import {TemplateType} from "../../project/game-model/templates/TemplateType";
@Component({ @Component({
selector: 'app-character-editor', selector: 'app-character-editor',
@ -7,4 +14,19 @@ import { Component } from '@angular/core';
}) })
export class CharacterEditorComponent { export class CharacterEditorComponent {
@Input() character: Character | undefined;
@Input() gameModel: GameModel | undefined;
constructor(private dialog: MatDialog) {
}
openTemplateSpecificator() {
const dialogRef = this.dialog.open(TemplateSpecificatorComponent, {data: this.gameModel?.getTemplateSystems(TemplateType.CHARACTER), minWidth: "400px"});
dialogRef.afterClosed().subscribe(res => {
if(res != undefined) {
this.character!.addCharacterSpecificSimpleTemplatesystem(res);
}
})
}
} }

View File

@ -14,7 +14,10 @@
[gamesystem]="convertModelComponentToGamesystem(modelComponent)" [gamesystem]="convertModelComponentToGamesystem(modelComponent)"
(onOpenGamesystemEditor)="openGameModelComponent($event)" (onOpenGamesystemEditor)="openGameModelComponent($event)"
[scriptAccounts]="gameModel!.scriptAccounts"></app-gamesystem-editor> [scriptAccounts]="gameModel!.scriptAccounts"></app-gamesystem-editor>
<app-character-editor *ngIf="modelComponent.type === ModelComponentType.CHARACTER"> <app-character-editor *ngIf="modelComponent.type === ModelComponentType.CHARACTER"
[character]="convertModelComponentToCharacter(modelComponent)"
[gameModel]="gameModel!"
>
</app-character-editor> </app-character-editor>
</mat-tab> </mat-tab>

View File

@ -6,6 +6,7 @@ import {Gamesystem} from "../project/game-model/gamesystems/Gamesystem";
import {State} from "../project/game-model/gamesystems/states/State"; import {State} from "../project/game-model/gamesystems/states/State";
import {Transition} from "../project/game-model/gamesystems/transitions/Transition"; import {Transition} from "../project/game-model/gamesystems/transitions/Transition";
import {ModelComponentType} from "../project/game-model/ModelComponentType"; import {ModelComponentType} from "../project/game-model/ModelComponentType";
import {Character} from "../project/game-model/characters/Character";
@Component({ @Component({
@ -50,4 +51,10 @@ export class EditorComponent {
} }
protected readonly ModelComponentType = ModelComponentType; protected readonly ModelComponentType = ModelComponentType;
convertModelComponentToCharacter(modelComponent: ModelComponent) {
if(modelComponent instanceof Character)
return modelComponent as Character
return undefined;
}
} }

View File

@ -1,3 +1,3 @@
<app-simple-gamesystem-editor *ngIf="isSimpleGamesystem()" [simpleGamesystem]="convertGamesystemToSimpleGamesystem()" [scriptAccunts]="scriptAccounts"></app-simple-gamesystem-editor> <app-simple-gamesystem-editor *ngIf="isSimpleGamesystem()" [templateElement]="templateElement" [simpleGamesystem]="convertGamesystemToSimpleGamesystem()" [scriptAccunts]="scriptAccounts"></app-simple-gamesystem-editor>
<app-product-gamesystem-editor *ngIf="!isSimpleGamesystem()" [gamesystem]="convertGamesystemToProductGamesystem()" <app-product-gamesystem-editor *ngIf="!isSimpleGamesystem()" [templateElement]="templateElement" [gamesystem]="convertGamesystemToProductGamesystem()"
(onOpenGamesystemEditor)="onOpenGamesystemEditor($event)"></app-product-gamesystem-editor> (onOpenGamesystemEditor)="onOpenGamesystemEditor($event)"></app-product-gamesystem-editor>

View File

@ -5,6 +5,7 @@ import { Transition } from '../../project/game-model/gamesystems/transitions/Tra
import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccount";
import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem"; import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem";
import {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem"; import {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem";
import {TemplateElement} from "../../project/game-model/templates/TemplateElement";
@Component({ @Component({
selector: 'app-gamesystem-editor', selector: 'app-gamesystem-editor',
@ -15,6 +16,7 @@ export class GamesystemEditorComponent implements OnInit{
@Input() gamesystem: Gamesystem<State<any>, Transition<any>> | undefined @Input() gamesystem: Gamesystem<State<any>, Transition<any>> | undefined
@Input() scriptAccounts: ScriptAccount[] = []; @Input() scriptAccounts: ScriptAccount[] = [];
@Input() templateElement: TemplateElement | undefined
@Output('onOpenGamesystemEditor') openGamesystemEmitter = new EventEmitter<SimpleGamesystem>(); @Output('onOpenGamesystemEditor') openGamesystemEmitter = new EventEmitter<SimpleGamesystem>();
ngOnInit() { ngOnInit() {

View File

@ -1,4 +1,4 @@
<app-product-state-editor [gamesystem]="gamesystem" (onOpenGamesystemEditor)="onOpenGamesystemEditor($event)"></app-product-state-editor> <app-product-state-editor [templateElement]="templateElement" [gamesystem]="gamesystem" (onOpenGamesystemEditor)="onOpenGamesystemEditor($event)"></app-product-state-editor>
<div id="productStateEditor"> <div id="productStateEditor">
<app-product-transition-editor [gamesystem]="gamesystem" (onOpenGamesystem)="onOpenGamesystemEditor($event)"></app-product-transition-editor> <app-product-transition-editor [templateElement]="templateElement" [gamesystem]="gamesystem" (onOpenGamesystem)="onOpenGamesystemEditor($event)"></app-product-transition-editor>
</div> </div>

View File

@ -4,6 +4,7 @@ import {
} from "../transition-editor/product-transition-editor/product-transition-editor.component"; } from "../transition-editor/product-transition-editor/product-transition-editor.component";
import {ProductGamesystem} from "../../../project/game-model/gamesystems/ProductGamesystem"; import {ProductGamesystem} from "../../../project/game-model/gamesystems/ProductGamesystem";
import {SimpleGamesystem} from "../../../project/game-model/gamesystems/SimpleGamesystem"; import {SimpleGamesystem} from "../../../project/game-model/gamesystems/SimpleGamesystem";
import {TemplateElement} from "../../../project/game-model/templates/TemplateElement";
@ -15,6 +16,7 @@ import {SimpleGamesystem} from "../../../project/game-model/gamesystems/SimpleGa
export class ProductGamesystemEditorComponent { export class ProductGamesystemEditorComponent {
@Input() gamesystem: ProductGamesystem | undefined @Input() gamesystem: ProductGamesystem | undefined
@Input() templateElement: TemplateElement | undefined
@Output("onOpenGamesystemEditor") openGamesystemEditorEmitter = new EventEmitter<SimpleGamesystem>(); @Output("onOpenGamesystemEditor") openGamesystemEditorEmitter = new EventEmitter<SimpleGamesystem>();
onOpenGamesystemEditor(gamesystem: SimpleGamesystem) { onOpenGamesystemEditor(gamesystem: SimpleGamesystem) {

View File

@ -18,7 +18,7 @@
<span *ngIf="condition !== editedCondition && condition !== addedCondition">{{condition.minValue}}</span> <span *ngIf="condition !== editedCondition && condition !== addedCondition">{{condition.minValue}}</span>
<mat-form-field appearance="fill" class="long-form" *ngIf=" condition === editedCondition"> <mat-form-field appearance="fill" class="long-form" *ngIf=" condition === editedCondition">
<mat-label>Minimal Value</mat-label> <mat-label>Minimal Value</mat-label>
<input matInput [(ngModel)]="editedCondition!.minValue"> <input matInput type="number" [(ngModel)]="editedCondition!.minValue">
</mat-form-field> </mat-form-field>
</td> </td>
</ng-container> </ng-container>
@ -29,7 +29,7 @@
<span *ngIf="condition !== editedCondition && condition !== addedCondition">{{condition.maxValue}}</span> <span *ngIf="condition !== editedCondition && condition !== addedCondition">{{condition.maxValue}}</span>
<mat-form-field appearance="fill" class="long-form" *ngIf=" condition === editedCondition"> <mat-form-field appearance="fill" class="long-form" *ngIf=" condition === editedCondition">
<mat-label>Maximal Value</mat-label> <mat-label>Maximal Value</mat-label>
<input matInput [(ngModel)]="editedCondition!.maxValue"> <input matInput type="number" [(ngModel)]="editedCondition!.maxValue">
</mat-form-field> </mat-form-field>
</td> </td>
</ng-container> </ng-container>

View File

@ -1,4 +1,4 @@
<app-simple-state-editor [states]="simpleGamesystem!.states" [gamesystem]="simpleGamesystem" [scriptAccounts]="scriptAccunts"></app-simple-state-editor> <app-simple-state-editor [templateElement]="templateElement" [states]="simpleGamesystem!.states" [gamesystem]="simpleGamesystem" [scriptAccounts]="scriptAccunts"></app-simple-state-editor>
<div id="transition-editor"> <div id="transition-editor">
<app-simple-transition-editor [gamesystem]="simpleGamesystem" [scriptAccounts]="scriptAccunts"></app-simple-transition-editor> <app-simple-transition-editor [templateElement]="templateElement" [gamesystem]="simpleGamesystem" [scriptAccounts]="scriptAccunts"></app-simple-transition-editor>
</div> </div>

View File

@ -2,6 +2,7 @@ import {Component, Input} from '@angular/core';
import {MatTableDataSource} from "@angular/material/table"; import {MatTableDataSource} from "@angular/material/table";
import {SimpleGamesystem} from "../../../project/game-model/gamesystems/SimpleGamesystem"; import {SimpleGamesystem} from "../../../project/game-model/gamesystems/SimpleGamesystem";
import {ScriptAccount} from "../../../project/game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "../../../project/game-model/scriptAccounts/ScriptAccount";
import {TemplateElement} from "../../../project/game-model/templates/TemplateElement";
@Component({ @Component({
selector: 'app-simple-gamesystem-editor', selector: 'app-simple-gamesystem-editor',
@ -12,6 +13,7 @@ export class SimpleGamesystemEditorComponent {
@Input() simpleGamesystem: SimpleGamesystem | undefined @Input() simpleGamesystem: SimpleGamesystem | undefined
@Input() scriptAccunts: ScriptAccount[] = [] @Input() scriptAccunts: ScriptAccount[] = []
@Input() templateElement: TemplateElement | undefined
} }

View File

@ -8,6 +8,8 @@ import {ProductGamesystem} from "../../../../project/game-model/gamesystems/Prod
import {SimpleGamesystem} from "../../../../project/game-model/gamesystems/SimpleGamesystem"; import {SimpleGamesystem} from "../../../../project/game-model/gamesystems/SimpleGamesystem";
import {ProductState} from "../../../../project/game-model/gamesystems/states/ProductState"; import {ProductState} from "../../../../project/game-model/gamesystems/states/ProductState";
import {State} from "../../../../project/game-model/gamesystems/states/State"; import {State} from "../../../../project/game-model/gamesystems/states/State";
import {TemplateElement} from "../../../../project/game-model/templates/TemplateElement";
import {ProductTemplateSystem} from "../../../../project/game-model/templates/productGamesystem/ProductTemplateSystem";
@Component({ @Component({
selector: 'app-product-state-editor', selector: 'app-product-state-editor',
@ -24,6 +26,7 @@ import {State} from "../../../../project/game-model/gamesystems/states/State";
export class ProductStateEditorComponent implements OnInit{ export class ProductStateEditorComponent implements OnInit{
@Input() gamesystem: ProductGamesystem | undefined @Input() gamesystem: ProductGamesystem | undefined
@Input() templateElement: TemplateElement | undefined
@Output('onOpenGamesystemEditor') openGamesystemEditorEmitter = new EventEmitter<SimpleGamesystem>(); @Output('onOpenGamesystemEditor') openGamesystemEditorEmitter = new EventEmitter<SimpleGamesystem>();
displayedColumns: string[] = []; displayedColumns: string[] = [];
expandedColumns: string[] = [] expandedColumns: string[] = []
@ -36,7 +39,13 @@ export class ProductStateEditorComponent implements OnInit{
this.generateColumnNamesRecursively(this.gamesystem!, ""); this.generateColumnNamesRecursively(this.gamesystem!, "");
this.displayedColumns.push('Initial'); this.displayedColumns.push('Initial');
this.expandedColumns = [...this.displayedColumns, 'expand']; this.expandedColumns = [...this.displayedColumns, 'expand'];
if(this.templateElement == undefined) {
this.datasource.data = this.gamesystem!.states; this.datasource.data = this.gamesystem!.states;
} else if(this.gamesystem instanceof ProductTemplateSystem) {
this.datasource.data = this.gamesystem!.stateMap.get(this.templateElement)!
}
this.datasource.filterPredicate = (data: ProductState, filter: string) => { this.datasource.filterPredicate = (data: ProductState, filter: string) => {
const leaf_states = LeafGamesystemCalculator.calcLeafStates(data); const leaf_states = LeafGamesystemCalculator.calcLeafStates(data);
return leaf_states.some((state) => state.stateLabel.toLowerCase().includes(filter)) return leaf_states.some((state) => state.stateLabel.toLowerCase().includes(filter))

View File

@ -27,7 +27,7 @@
</mat-form-field> </mat-form-field>
<div class="long-form"> <div class="long-form">
<app-scriptaccount-condition-editor [conditions]="element.conditions" [scriptAccounts]="scriptAccounts" [enableEditiong]="true" <app-scriptaccount-condition-editor [conditions]="getDisplayedConditions(element)" [scriptAccounts]="scriptAccounts" [enableEditiong]="true"
(onCreateCondition)="onCreateCondition(element, $event)" (onDeleteCondition)="deleteCondition(element, $event)"></app-scriptaccount-condition-editor> (onCreateCondition)="onCreateCondition(element, $event)" (onDeleteCondition)="deleteCondition(element, $event)"></app-scriptaccount-condition-editor>
</div> </div>
</div> </div>

View File

@ -6,6 +6,8 @@ import {SimpleState} from "../../../../project/game-model/gamesystems/states/Sim
import {SimpleGamesystem} from "../../../../project/game-model/gamesystems/SimpleGamesystem"; import {SimpleGamesystem} from "../../../../project/game-model/gamesystems/SimpleGamesystem";
import {ScriptAccount} from "../../../../project/game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "../../../../project/game-model/scriptAccounts/ScriptAccount";
import {ScriptAccountCondition} from "../../../../project/game-model/gamesystems/conditions/ScriptAccountCondition"; import {ScriptAccountCondition} from "../../../../project/game-model/gamesystems/conditions/ScriptAccountCondition";
import {TemplateElement} from "../../../../project/game-model/templates/TemplateElement";
import {SimpleTemplateState} from "../../../../project/game-model/templates/simpleGamesystem/SimpleTemplateState";
@Component({ @Component({
selector: 'app-simple-state-editor', selector: 'app-simple-state-editor',
@ -24,6 +26,7 @@ export class SimpleStateEditorComponent implements OnInit{
@Input() states: SimpleState[] = []; @Input() states: SimpleState[] = [];
@Input() gamesystem: SimpleGamesystem | undefined @Input() gamesystem: SimpleGamesystem | undefined
@Input() scriptAccounts: ScriptAccount[] = [] @Input() scriptAccounts: ScriptAccount[] = []
@Input() templateElement: TemplateElement | undefined
dataSource = new MatTableDataSource<SimpleState>(); dataSource = new MatTableDataSource<SimpleState>();
displayedColumns = ["name", "initial", "edit", "delete"]; displayedColumns = ["name", "initial", "edit", "delete"];
columnsToDisplayWithExpand = [...this.displayedColumns, 'expand']; columnsToDisplayWithExpand = [...this.displayedColumns, 'expand'];
@ -40,6 +43,7 @@ export class SimpleStateEditorComponent implements OnInit{
this.dataSource.filterPredicate = (data: SimpleState, filter: string) => { this.dataSource.filterPredicate = (data: SimpleState, filter: string) => {
return data.stateLabel.toLowerCase().includes(filter); return data.stateLabel.toLowerCase().includes(filter);
} }
console.log(this.templateElement)
} }
editState(state: SimpleState) { editState(state: SimpleState) {
@ -96,11 +100,31 @@ export class SimpleStateEditorComponent implements OnInit{
} }
onCreateCondition(state: SimpleState, condition: ScriptAccountCondition) { onCreateCondition(state: SimpleState, condition: ScriptAccountCondition) {
if(this.templateElement != undefined && state instanceof SimpleTemplateState) {
state.conditionMap.get(this.templateElement)!.push(condition)
} else {
state.addScriptAccountCondition(condition); state.addScriptAccountCondition(condition);
} }
}
deleteCondition(state: SimpleState, condition: ScriptAccountCondition) { deleteCondition(state: SimpleState, condition: ScriptAccountCondition) {
if(this.templateElement != undefined && state instanceof SimpleTemplateState) {
let conditions = state.conditionMap.get(this.templateElement)!
conditions = conditions.filter(currentCondition => condition.scriptAccount !== currentCondition.scriptAccount)!;
state.conditionMap.set(this.templateElement, conditions);
} else {
state.removeScriptAccountCondition(condition.scriptAccount); state.removeScriptAccountCondition(condition.scriptAccount);
} }
}
getDisplayedConditions(state: SimpleState) {
if(this.templateElement == undefined) {
return state.conditions
} else if(state instanceof SimpleTemplateState){
return (state as SimpleTemplateState).conditionMap.get(this.templateElement)!
} else {
return [];
}
}
} }

View File

@ -0,0 +1,14 @@
<h1 mat-dialog-title>Specify Templatesystem</h1>
<div mat-dialog-content>
<p>This will not affect the properties of the Templatesystem itself!</p>
<mat-form-field appearance="outline" class="long-form">
<mat-label>Select Templatesystem</mat-label>
<mat-select [formControl]="templateCtrl">
<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)="cancelSpecification()">Cancel</button>
<button mat-raised-button color="accent" [disabled]="templateCtrl.invalid" (click)="confirmSpecification()">Confirm</button>
</div>

View File

@ -0,0 +1,3 @@
.long-form {
width: 100%;
}

View File

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TemplateSpecificatorComponent } from './template-specificator.component';
describe('TemplateSpecificatorComponent', () => {
let component: TemplateSpecificatorComponent;
let fixture: ComponentFixture<TemplateSpecificatorComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TemplateSpecificatorComponent]
})
.compileComponents();
fixture = TestBed.createComponent(TemplateSpecificatorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,26 @@
import {Component, Inject} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
import {Gamesystem} from "../../../project/game-model/gamesystems/Gamesystem";
import {FormControl, Validators} from "@angular/forms";
@Component({
selector: 'app-template-specificator',
templateUrl: './template-specificator.component.html',
styleUrl: './template-specificator.component.scss'
})
export class TemplateSpecificatorComponent {
templateCtrl: FormControl = new FormControl('', [Validators.required])
constructor(private dialogRef: MatDialogRef<TemplateSpecificatorComponent>,
@Inject(MAT_DIALOG_DATA) public templateSystems: Gamesystem<any, any>[] = []) {
}
cancelSpecification() {
this.dialogRef.close()
}
confirmSpecification() {
this.dialogRef.close(this.templateCtrl.value)
}
}

View File

@ -8,6 +8,8 @@ import {ProductGamesystem} from "../../../../project/game-model/gamesystems/Prod
import {SimpleGamesystem} from "../../../../project/game-model/gamesystems/SimpleGamesystem"; import {SimpleGamesystem} from "../../../../project/game-model/gamesystems/SimpleGamesystem";
import {ProductTransition} from "../../../../project/game-model/gamesystems/transitions/ProductTransition"; import {ProductTransition} from "../../../../project/game-model/gamesystems/transitions/ProductTransition";
import {ProductState} from "../../../../project/game-model/gamesystems/states/ProductState"; import {ProductState} from "../../../../project/game-model/gamesystems/states/ProductState";
import {TemplateElement} from "../../../../project/game-model/templates/TemplateElement";
import {ProductTemplateSystem} from "../../../../project/game-model/templates/productGamesystem/ProductTemplateSystem";
class DisplayedColumnName { class DisplayedColumnName {
displayedName: string displayedName: string
internalName: string internalName: string
@ -34,6 +36,7 @@ export class ProductTransitionEditorComponent implements OnInit{
@Input() gamesystem: ProductGamesystem | undefined @Input() gamesystem: ProductGamesystem | undefined
@Output() onOpenGamesystem = new EventEmitter<SimpleGamesystem>(); @Output() onOpenGamesystem = new EventEmitter<SimpleGamesystem>();
@Input() templateElement: TemplateElement | undefined
dataSource = new MatTableDataSource<ProductTransition>(); dataSource = new MatTableDataSource<ProductTransition>();
displayedColumns: DisplayedColumnName[] = []; displayedColumns: DisplayedColumnName[] = [];
@ -52,7 +55,12 @@ export class ProductTransitionEditorComponent implements OnInit{
this.columns = this.displayedColumns.map(column => column.internalName) this.columns = this.displayedColumns.map(column => column.internalName)
this.columnsToDisplayWithExpand = [...this.columns, 'expand'] this.columnsToDisplayWithExpand = [...this.columns, 'expand']
if(this.templateElement == undefined) {
this.dataSource.data = this.gamesystem.transitions; this.dataSource.data = this.gamesystem.transitions;
} else if(this.gamesystem instanceof ProductTemplateSystem){
this.dataSource.data = this.gamesystem!.transitionMap.get(this.templateElement)!
}
this.dataSource.filterPredicate = (data: ProductTransition, filter: string) => { this.dataSource.filterPredicate = (data: ProductTransition, filter: string) => {
const leaf_starting_states = LeafGamesystemCalculator.calcLeafStates(data.startingState); const leaf_starting_states = LeafGamesystemCalculator.calcLeafStates(data.startingState);
const leaf_ending_states = LeafGamesystemCalculator.calcLeafStates(data.endingState); const leaf_ending_states = LeafGamesystemCalculator.calcLeafStates(data.endingState);

View File

@ -3,6 +3,10 @@ import {MatTableDataSource} from "@angular/material/table";
import {ScriptAccount} from "../../../../project/game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "../../../../project/game-model/scriptAccounts/ScriptAccount";
import {Transition} from "../../../../project/game-model/gamesystems/transitions/Transition"; import {Transition} from "../../../../project/game-model/gamesystems/transitions/Transition";
import {ScriptAccountAction} from "../../../../project/game-model/gamesystems/actions/ScriptAccountAction"; import {ScriptAccountAction} from "../../../../project/game-model/gamesystems/actions/ScriptAccountAction";
import {TemplateElement} from "../../../../project/game-model/templates/TemplateElement";
import {
SimpleTemplateTransition
} from "../../../../project/game-model/templates/simpleGamesystem/SimpleTemplateTransition";
@Component({ @Component({
selector: 'app-scriptaccount-action-editor', selector: 'app-scriptaccount-action-editor',
@ -13,6 +17,7 @@ export class ScriptaccountActionEditorComponent implements OnInit{
@Input() transition: Transition<any> | undefined @Input() transition: Transition<any> | undefined
@Input() scriptAccounts: ScriptAccount[] = [] @Input() scriptAccounts: ScriptAccount[] = []
@Input() enableEditing: boolean = false; @Input() enableEditing: boolean = false;
@Input() templateElement: TemplateElement | undefined
dataSource: MatTableDataSource<ScriptAccountAction> = new MatTableDataSource(); dataSource: MatTableDataSource<ScriptAccountAction> = new MatTableDataSource();
displayedColumns: string[] = ['scriptAccount', "valueChange", 'edit', 'delete']; displayedColumns: string[] = ['scriptAccount', "valueChange", 'edit', 'delete'];
@ -21,7 +26,9 @@ export class ScriptaccountActionEditorComponent implements OnInit{
addedAction: ScriptAccountAction | undefined addedAction: ScriptAccountAction | undefined
ngOnInit() { ngOnInit() {
this.dataSource.data = this.transition!.scriptAccountActions.map(action => action); this.dataSource.data = this.getDisplayedActions()
if(!this.enableEditing) { if(!this.enableEditing) {
this.displayedColumns = this.displayedColumns.slice(0, -2); this.displayedColumns = this.displayedColumns.slice(0, -2);
@ -41,17 +48,42 @@ export class ScriptaccountActionEditorComponent implements OnInit{
finishEditing() { finishEditing() {
if(this.addedAction != undefined && this.addedAction.scriptAccount.componentName !== '') { if(this.addedAction != undefined && this.addedAction.scriptAccount.componentName !== '') {
if(this.templateElement != undefined && this.transition instanceof SimpleTemplateTransition) {
if(this.transition.actionMap.has(this.templateElement!)) {
this.transition.actionMap.get(this.templateElement!)!.push(this.addedAction)
} else {
this.transition.actionMap.set(this.templateElement!, [this.addedAction])
}
} else {
this.transition?.addScriptAccountAction(this.addedAction) this.transition?.addScriptAccountAction(this.addedAction)
console.log(this.addedAction.scriptAccount) }
this.dataSource.data = this.transition!.scriptAccountActions;
console.log(this.dataSource.data.length, this.transition!.scriptAccountActions.length)
this.dataSource.data = this.getDisplayedActions();
this.addedAction = undefined; this.addedAction = undefined;
} }
this.editedAction = undefined; this.editedAction = undefined;
} }
getDisplayedActions(): ScriptAccountAction[] {
if(this.templateElement == undefined) {
return this.transition!.scriptAccountActions.map(action => action);
} else if(this.transition instanceof SimpleTemplateTransition) {
return this.transition!.actionMap.get(this.templateElement)!
} else {
return []
}
}
deleteAction(action: ScriptAccountAction) { deleteAction(action: ScriptAccountAction) {
if(this.templateElement != undefined && this.transition instanceof SimpleTemplateTransition && this.transition.actionMap.has(this.templateElement!)) {
const updatedAction = this.transition.actionMap.get(this.templateElement)!.filter(currentAction =>
currentAction.scriptAccount !== action.scriptAccount)
this.transition.actionMap.set(this.templateElement!, updatedAction)
} else {
this.transition!.removeScriptAccountAction(action.scriptAccount) this.transition!.removeScriptAccountAction(action.scriptAccount)
this.dataSource.data = this.transition!.scriptAccountActions }
this.dataSource.data = this.getDisplayedActions()
} }
} }

View File

@ -42,10 +42,10 @@
[@detailExpand]="element == expandedElement ? 'expanded' : 'collapsed'"> [@detailExpand]="element == expandedElement ? 'expanded' : 'collapsed'">
<div class="condition-action-container"> <div class="condition-action-container">
<div class="action-container"> <div class="action-container">
<app-scriptaccount-action-editor [transition]="element" [scriptAccounts]="scriptAccounts" [enableEditing]="true"></app-scriptaccount-action-editor> <app-scriptaccount-action-editor [templateElement]="templateElement" [transition]="element" [scriptAccounts]="scriptAccounts" [enableEditing]="true"></app-scriptaccount-action-editor>
</div> </div>
<div class="condition-container"> <div class="condition-container">
<app-scriptaccount-condition-editor [conditions]="element.scriptAccountConditions" [scriptAccounts]="scriptAccounts" [enableEditiong]="true" <app-scriptaccount-condition-editor [conditions]="getDisplayedConditions(element)" [scriptAccounts]="scriptAccounts" [enableEditiong]="true"
(onCreateCondition)="onCreateCondition(element, $event)" (onDeleteCondition)="deleteCondition(element, $event)"></app-scriptaccount-condition-editor> (onCreateCondition)="onCreateCondition(element, $event)" (onDeleteCondition)="deleteCondition(element, $event)"></app-scriptaccount-condition-editor>
</div> </div>
</div> </div>

View File

@ -8,6 +8,10 @@ import {ScriptAccount} from "../../../../project/game-model/scriptAccounts/Scrip
import {SimpleTransition} from "../../../../project/game-model/gamesystems/transitions/SimpleTransition"; import {SimpleTransition} from "../../../../project/game-model/gamesystems/transitions/SimpleTransition";
import {SimpleState} from "../../../../project/game-model/gamesystems/states/SimpleState"; import {SimpleState} from "../../../../project/game-model/gamesystems/states/SimpleState";
import {ScriptAccountCondition} from "../../../../project/game-model/gamesystems/conditions/ScriptAccountCondition"; import {ScriptAccountCondition} from "../../../../project/game-model/gamesystems/conditions/ScriptAccountCondition";
import {TemplateElement} from "../../../../project/game-model/templates/TemplateElement";
import {
SimpleTemplateTransition
} from "../../../../project/game-model/templates/simpleGamesystem/SimpleTemplateTransition";
@Component({ @Component({
selector: 'app-simple-transition-editor', selector: 'app-simple-transition-editor',
templateUrl: './simple-transition-editor.component.html', templateUrl: './simple-transition-editor.component.html',
@ -24,6 +28,8 @@ export class SimpleTransitionEditorComponent implements OnInit {
@Input() gamesystem: SimpleGamesystem | undefined @Input() gamesystem: SimpleGamesystem | undefined
@Input() scriptAccounts: ScriptAccount[] = [] @Input() scriptAccounts: ScriptAccount[] = []
@Input() templateElement: TemplateElement | undefined
displayedColumns: string[] = ["starting-state", "ending-state", "edit", "delete"]; displayedColumns: string[] = ["starting-state", "ending-state", "edit", "delete"];
dataSource = new MatTableDataSource<SimpleTransition>(); dataSource = new MatTableDataSource<SimpleTransition>();
columnsToDisplayWithExpand = [...this.displayedColumns, 'expand']; columnsToDisplayWithExpand = [...this.displayedColumns, 'expand'];
@ -91,10 +97,33 @@ export class SimpleTransitionEditorComponent implements OnInit {
protected readonly transition = transition; protected readonly transition = transition;
onCreateCondition(transition: SimpleTransition, condition: ScriptAccountCondition) { onCreateCondition(transition: SimpleTransition, condition: ScriptAccountCondition) {
if(this.templateElement != undefined && transition instanceof SimpleTemplateTransition) {
transition.conditionMap.get(this.templateElement)!.push(condition)
} else {
transition.addScriptAccountCondition(condition); transition.addScriptAccountCondition(condition);
} }
}
deleteCondition(trasition: SimpleTransition, condition: ScriptAccountCondition) { deleteCondition(trasition: SimpleTransition, condition: ScriptAccountCondition) {
if(this.templateElement != undefined && trasition instanceof SimpleTemplateTransition) {
let updatedConditions = trasition.conditionMap.get(this.templateElement)!
updatedConditions = updatedConditions.filter(currentCondition => condition.scriptAccount !== currentCondition.scriptAccount);
trasition.conditionMap.set(this.templateElement, updatedConditions);
} else {
console.log(this.templateElement)
trasition.removeScriptAccountCondition(condition.scriptAccount); trasition.removeScriptAccountCondition(condition.scriptAccount);
} }
}
getDisplayedConditions(transition: SimpleTransition) {
if(this.templateElement == undefined) {
return transition.scriptAccountConditions
} else if(transition instanceof SimpleTemplateTransition) {
return transition.conditionMap.get(this.templateElement)!
} else {
return [];
}
}
} }

View File

@ -6,6 +6,10 @@ import {ProductGamesystem} from "./gamesystems/ProductGamesystem";
import {SimpleGamesystem} from "./gamesystems/SimpleGamesystem"; import {SimpleGamesystem} from "./gamesystems/SimpleGamesystem";
import {Character} from "./characters/Character"; import {Character} from "./characters/Character";
import {ModelComponentType} from "./ModelComponentType"; import {ModelComponentType} from "./ModelComponentType";
import {TemplateType} from "./templates/TemplateType";
import {SimpleTemplateGamesystem} from "./templates/simpleGamesystem/SimpleTemplateGamesystem";
import {ProductTemplateSystem} from "./templates/productGamesystem/ProductTemplateSystem";
import {ProductTemplateCreator} from "./templates/productGamesystem/ProductTemplateCreator";
export class GameModel { export class GameModel {
gameModelName: string gameModelName: string
@ -45,9 +49,62 @@ export class GameModel {
return undefined; return undefined;
} }
createGamesystem(gamesystemName: string, parentGamesystemName: string | undefined) { createSimpleGamesystem(gamesystemName: string, templateType: TemplateType | undefined, pushToTop: boolean = true) {
if(gamesystemName != undefined && this.findGamesystem(gamesystemName) == undefined) {
let simpleGamesystem: SimpleGamesystem
if(templateType == undefined) {
simpleGamesystem = new SimpleGamesystem(gamesystemName, "")
} else {
simpleGamesystem = new SimpleTemplateGamesystem(gamesystemName, "", templateType)
}
if(pushToTop) {
this.gamesystems.push(simpleGamesystem)
}
return simpleGamesystem;
}
return undefined;
}
createSimpleGamesystemWithParent(gamesystemName: string, parentGamesystemName: string, templateType: TemplateType | undefined) {
const simpleGamesystem = this.createSimpleGamesystem(gamesystemName, templateType, false)!;
const parentGamesystem = this.findGamesystem(parentGamesystemName)
if(parentGamesystem == undefined) {return undefined}
let parentProductGamesystem: ProductGamesystem;
if(parentGamesystem instanceof SimpleTemplateGamesystem) {
parentProductGamesystem = ProductTemplateCreator.constructTemplateFromSimpleGamesystem(parentGamesystem, this, templateType!)
} else if(parentGamesystem instanceof SimpleGamesystem) {
if(simpleGamesystem instanceof SimpleTemplateGamesystem) {
parentProductGamesystem = ProductTemplateCreator.constructTemplateFromSimpleGamesystem(parentGamesystem, this, templateType!)
} else {
console.log("Test")
parentProductGamesystem = ProductGamesystem.constructFromSimpleGamesystem(parentGamesystem, this);
console.log(this.gamesystems)
}
} else {
if(simpleGamesystem instanceof SimpleTemplateGamesystem) {
parentProductGamesystem = ProductTemplateCreator.convertProductToTemplate(parentGamesystem as ProductGamesystem, this, templateType!)
} else {
parentProductGamesystem = parentGamesystem as ProductGamesystem
}
}
parentProductGamesystem.addChildGamesystem(simpleGamesystem);
simpleGamesystem.parentGamesystem = parentProductGamesystem;
return simpleGamesystem;
}
createGamesystem(gamesystemName: string, parentGamesystemName: string | undefined, templateType: TemplateType | undefined) {
if(gamesystemName != undefined && this.findGamesystem(gamesystemName) == undefined) { if(gamesystemName != undefined && this.findGamesystem(gamesystemName) == undefined) {
const simpleGamesystem = new SimpleGamesystem(gamesystemName, ""); const simpleGamesystem = new SimpleGamesystem(gamesystemName, "");
if(parentGamesystemName != undefined) { if(parentGamesystemName != undefined) {
const parentGamesystem = this.findGamesystem(parentGamesystemName); const parentGamesystem = this.findGamesystem(parentGamesystemName);
if(parentGamesystem instanceof SimpleGamesystem) { if(parentGamesystem instanceof SimpleGamesystem) {
@ -61,7 +118,6 @@ export class GameModel {
} }
} else { } else {
this.gamesystems.push(simpleGamesystem); this.gamesystems.push(simpleGamesystem);
} }
return simpleGamesystem; return simpleGamesystem;
} }
@ -115,4 +171,24 @@ export class GameModel {
} }
}) })
} }
getTemplateSystems(templateType: TemplateType) {
const requestedTemplates: Gamesystem<any, any>[] = []
const gamesystemQueue: Gamesystem<any, any>[] = this.gamesystems.concat();
while(gamesystemQueue.length > 0) {
const currentGamesystem = gamesystemQueue.shift()!;
if(currentGamesystem instanceof SimpleTemplateGamesystem && currentGamesystem.templateType === templateType) {
requestedTemplates.push(currentGamesystem)
} else if(currentGamesystem instanceof ProductTemplateSystem && currentGamesystem.templateType === templateType) {
requestedTemplates.push(currentGamesystem)
}
if(currentGamesystem instanceof ProductGamesystem) {
currentGamesystem.innerGamesystems.forEach(innerGamesystem => gamesystemQueue.push(innerGamesystem))
}
}
return requestedTemplates;
}
} }

View File

@ -1,9 +1,43 @@
import {ModelComponent} from "../ModelComponent"; import {ModelComponent} from "../ModelComponent";
import {ModelComponentType} from "../ModelComponentType"; import {ModelComponentType} from "../ModelComponentType";
import {TemplateElement} from "../templates/TemplateElement";
import {TemplateGamesystem} from "../templates/TemplateGamesystem";
import {Gamesystem} from "../gamesystems/Gamesystem";
import {SimpleTemplateGamesystem} from "../templates/simpleGamesystem/SimpleTemplateGamesystem";
import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem";
import {ProductGamesystem} from "../gamesystems/ProductGamesystem";
export class Character extends ModelComponent{ export class Character extends ModelComponent implements TemplateElement {
characterSpecificTemplateSystems: Gamesystem<any, any>[] = []
constructor(componentName: string, componentDescription: string) { constructor(componentName: string, componentDescription: string) {
super(componentName, componentDescription, ModelComponentType.CHARACTER); super(componentName, componentDescription, ModelComponentType.CHARACTER);
} }
addCharacterSpecificSimpleTemplatesystem(gamesystem: Gamesystem<any, any>, recursiveCall: boolean = false) {
if(!this.isTemplateSystemCharacterSpecific(gamesystem.componentName)) {
if(gamesystem instanceof SimpleTemplateGamesystem) {
this.characterSpecificTemplateSystems.push(gamesystem)
gamesystem.addTemplateElement(this)
} else if(gamesystem instanceof ProductTemplateSystem) {
this.characterSpecificTemplateSystems.push(gamesystem)
gamesystem.addTemplateElement(this)
if(!recursiveCall) {
gamesystem.innerGamesystems.forEach(innerGamesystem => this.addCharacterSpecificSimpleTemplatesystem(innerGamesystem, true))
}
}
if(gamesystem.parentGamesystem != undefined) {
this.addCharacterSpecificSimpleTemplatesystem(gamesystem.parentGamesystem, true)
}
}
}
private isTemplateSystemCharacterSpecific(gamesystemName: string) {
return this.characterSpecificTemplateSystems.find(gamesystem => gamesystem.componentName === gamesystemName) != undefined
}
} }

View File

@ -9,6 +9,8 @@ import {GameModel} from "../GameModel";
import {ScriptAccountCondition} from "./conditions/ScriptAccountCondition"; import {ScriptAccountCondition} from "./conditions/ScriptAccountCondition";
import {ScriptAccountAction} from "./actions/ScriptAccountAction"; import {ScriptAccountAction} from "./actions/ScriptAccountAction";
import {ProductSystemGenerator} from "./productSystemGenerator/ProductSystemGenerator"; import {ProductSystemGenerator} from "./productSystemGenerator/ProductSystemGenerator";
import {TemplateType} from "../templates/TemplateType";
import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem";
export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> { export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> {
@ -16,25 +18,28 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
static constructFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel) { static constructFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel) {
const productGamesystem = new ProductGamesystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription); const productGamesystem = new ProductGamesystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription);
productGamesystem.constructHierarchyFromSimpleGamesystem(simpleGamesystem, gameModel);
return productGamesystem;
}
constructHierarchyFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel) {
const parentGamesystem = simpleGamesystem.parentGamesystem; const parentGamesystem = simpleGamesystem.parentGamesystem;
if(simpleGamesystem.states.length > 0) { if(simpleGamesystem.states.length > 0) {
simpleGamesystem.componentName += "(Child)"; simpleGamesystem.componentName += "(Child)";
productGamesystem.addChildGamesystem(simpleGamesystem); this.addChildGamesystem(simpleGamesystem);
simpleGamesystem.parentGamesystem = productGamesystem simpleGamesystem.parentGamesystem = this
} }
if(parentGamesystem != undefined) { if(parentGamesystem != undefined) {
parentGamesystem.removeChildGamesystem(simpleGamesystem); parentGamesystem.removeChildGamesystem(simpleGamesystem);
parentGamesystem.addChildGamesystem(productGamesystem); parentGamesystem.addChildGamesystem(this);
productGamesystem.parentGamesystem = parentGamesystem this.parentGamesystem = parentGamesystem
} else { } else {
gameModel.removeGamesystem(simpleGamesystem); gameModel.removeGamesystem(simpleGamesystem);
gameModel.addGamesystem(productGamesystem); gameModel.addGamesystem(this);
} }
return productGamesystem;
} }
createState(innerStates: State<any>[]): ProductState | undefined { createState(innerStates: State<any>[]): ProductState | undefined {

View File

@ -8,6 +8,7 @@ import {ProductGeneratorResult} from "./ProductGeneratorResult";
import {Gamesystem} from "../Gamesystem"; import {Gamesystem} from "../Gamesystem";
import {ProductGenerationData} from "./ProductGenerationData"; import {ProductGenerationData} from "./ProductGenerationData";
import {ProductTransition} from "../transitions/ProductTransition"; import {ProductTransition} from "../transitions/ProductTransition";
import {SimpleTemplateTransition} from "../../templates/simpleGamesystem/SimpleTemplateTransition";
export class ProductSystemGenerator { export class ProductSystemGenerator {
productGamesystem: ProductGamesystem productGamesystem: ProductGamesystem
@ -109,35 +110,34 @@ export class ProductSystemGenerator {
protected generateBinaryProductTransition(startingState: ProductState, endingState: ProductState, usedTransition: Transition<any>, generatedTransitions: ProductTransition[]) { protected generateBinaryProductTransition(startingState: ProductState, endingState: ProductState, usedTransition: Transition<any>, generatedTransitions: ProductTransition[]) {
const transition = new ProductTransition(startingState, endingState); const transition = new ProductTransition(startingState, endingState);
transition.scriptAccountActions = [... usedTransition.scriptAccountActions]; transition.scriptAccountActions = [... this.getTransitionActions(usedTransition)];
transition.scriptAccountConditions = [... usedTransition.scriptAccountConditions]; transition.scriptAccountConditions = [... this.getTransitionConditions(usedTransition)];
if(generatedTransitions.find(generatedTransition => generatedTransition.startingState.equals(startingState) && generatedTransition.endingState.equals(endingState)) == undefined) { if(generatedTransitions.find(generatedTransition => generatedTransition.startingState.equals(startingState) && generatedTransition.endingState.equals(endingState)) == undefined) {
generatedTransitions.push(transition) generatedTransitions.push(transition)
} else {
console.log(transition)
} }
} }
protected generateBinaryProductTransitionMulti(startingState: ProductState, endingState: ProductState, leftTransition: Transition<any>, rightTransition: Transition<any>, generatedTransitions: ProductTransition[]) { protected generateBinaryProductTransitionMulti(startingState: ProductState, endingState: ProductState, leftTransition: Transition<any>, rightTransition: Transition<any>, generatedTransitions: ProductTransition[]) {
const leftConditions = leftTransition.scriptAccountConditions; const leftConditions = this.getTransitionConditions(leftTransition)
const rightConditions = rightTransition.scriptAccountConditions; const rightConditions = this.getTransitionConditions(rightTransition)
if(!this.contradictCombinedConditions(leftConditions, rightConditions)) { if(!this.contradictCombinedConditions(leftConditions, rightConditions)) {
const transition = new ProductTransition(startingState, endingState) const transition = new ProductTransition(startingState, endingState)
transition.scriptAccountActions = this.generateCombinedActions(leftTransition.scriptAccountActions, rightTransition.scriptAccountActions); transition.scriptAccountActions = this.generateCombinedActions(this.getTransitionActions(leftTransition), this.getTransitionActions(rightTransition));
transition.scriptAccountConditions = this.generateCombinedConditions(leftTransition.scriptAccountConditions, rightTransition.scriptAccountConditions); transition.scriptAccountConditions = this.generateCombinedConditions(this.getTransitionConditions(leftTransition), this.getTransitionConditions(rightTransition));
if(generatedTransitions.find(generatedTransition => generatedTransition.startingState.equals(startingState) && generatedTransition.endingState.equals(endingState)) == undefined) { if(generatedTransitions.find(generatedTransition => generatedTransition.startingState.equals(startingState) && generatedTransition.endingState.equals(endingState)) == undefined) {
generatedTransitions.push(transition) generatedTransitions.push(transition)
} else {
console.log(transition)
} }
} }
} }
protected generateBinaryProductState(leftState: State<any>, rightState: State<any>, generatedStates: ProductState[]): ProductState | undefined { protected generateBinaryProductState(leftState: State<any>, rightState: State<any>, generatedStates: ProductState[]): ProductState | undefined {
const combinedStateConditions: ScriptAccountCondition[] = leftState.conditions.concat(rightState.conditions); const leftConditions = this.getStateConditions(leftState)
const rightConditions = this.getStateConditions(rightState)
const combinedStateConditions: ScriptAccountCondition[] = leftConditions.concat(rightConditions)
for(let i=0; i<combinedStateConditions.length; i++) { for(let i=0; i<combinedStateConditions.length; i++) {
for(let j=0; j<combinedStateConditions.length; j++) { for(let j=0; j<combinedStateConditions.length; j++) {
if(combinedStateConditions[i].isContradicting(combinedStateConditions[j])) { if(combinedStateConditions[i].isContradicting(combinedStateConditions[j])) {
@ -231,4 +231,16 @@ export class ProductSystemGenerator {
return false; return false;
} }
protected getTransitionConditions(transition: Transition<any>) {
return transition.scriptAccountConditions;
}
protected getTransitionActions(transition: Transition<any>) {
return transition.scriptAccountActions;
}
protected getStateConditions(state: State<any>) {
return state.conditions;
}
} }

View File

@ -0,0 +1,54 @@
import {ProductSystemGenerator} from "./ProductSystemGenerator";
import {ProductGeneratorResult} from "./ProductGeneratorResult";
import {TemplateElement} from "../../templates/TemplateElement";
import {ProductTemplateSystem} from "../../templates/productGamesystem/ProductTemplateSystem";
import {ProductState} from "../states/ProductState";
import {Transition} from "../transitions/Transition";
import {ProductTransition} from "../transitions/ProductTransition";
import {State} from "../states/State";
import {SimpleTemplateTransition} from "../../templates/simpleGamesystem/SimpleTemplateTransition";
import {state, transition} from "@angular/animations";
import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition";
import {SimpleTemplateState} from "../../templates/simpleGamesystem/SimpleTemplateState";
export class TemplateProductSystemGenerator extends ProductSystemGenerator {
templateElement: TemplateElement
constructor(productGamesystem: ProductTemplateSystem, templateElement: TemplateElement) {
super(productGamesystem);
this.templateElement = templateElement;
}
protected assignGeneratedStatesAndTransitions(generationResult: ProductGeneratorResult) {
const productTemplateSystem = this.productGamesystem as ProductTemplateSystem
productTemplateSystem.transitionMap.set(this.templateElement, generationResult.transitions)
productTemplateSystem.stateMap.set(this.templateElement, generationResult.states)
}
protected getTransitionConditions(transition: Transition<any>) {
if(transition instanceof SimpleTemplateTransition) {
return transition.conditionMap.get(this.templateElement)!
} else {
return transition.scriptAccountConditions;
}
}
protected getTransitionActions(transition: Transition<any>) {
if(transition instanceof SimpleTemplateTransition) {
return transition.actionMap.get(this.templateElement)!
} else {
return transition.scriptAccountActions;
}
}
protected getStateConditions(state: State<any>): ScriptAccountCondition[] {
if(state instanceof SimpleTemplateState) {
return state.conditionMap.get(this.templateElement)!
} else {
return state.conditions
}
}
}

View File

@ -0,0 +1,2 @@
export interface TemplateElement {
}

View File

@ -0,0 +1,9 @@
import {Gamesystem} from "../gamesystems/Gamesystem";
import {TemplateElement} from "./TemplateElement";
export interface TemplateGamesystem {
addTemplateElement(templateElement: TemplateElement): void;
}

View File

@ -0,0 +1,3 @@
export enum TemplateType {
CHARACTER
}

View File

@ -0,0 +1,9 @@
import {TemplateType} from "./TemplateType";
export class TemplateTypeUtilities {
static fromString(string: string) {
if(string === 'character') {
return TemplateType.CHARACTER
}
}
}

View File

@ -0,0 +1,30 @@
import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem";
import {GameModel} from "../../GameModel";
import {TemplateType} from "../TemplateType";
import {ProductTemplateSystem} from "./ProductTemplateSystem";
import {ProductGamesystem} from "../../gamesystems/ProductGamesystem";
export class ProductTemplateCreator {
static constructTemplateFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel, templateType: TemplateType) {
const productGamesystem = new ProductTemplateSystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription, templateType);
productGamesystem.constructHierarchyFromSimpleGamesystem(simpleGamesystem, gameModel);
return productGamesystem;
}
static convertProductToTemplate(productGamesystem: ProductGamesystem, gameModel: GameModel, templateType: TemplateType) {
const productTemplate = new ProductTemplateSystem(productGamesystem.componentName, productGamesystem.componentDescription, templateType);
productTemplate.states = productGamesystem.states
productTemplate.transitions = productGamesystem.transitions
productTemplate.innerGamesystems = productGamesystem.innerGamesystems;
productGamesystem.innerGamesystems.forEach(innerGamesystem => innerGamesystem.parentGamesystem = productTemplate);
if(productGamesystem.parentGamesystem == undefined) {
gameModel.removeGamesystem(productGamesystem)
gameModel.gamesystems.push(productTemplate)
} else {
productTemplate.parentGamesystem = productGamesystem.parentGamesystem;
productGamesystem.parentGamesystem.addChildGamesystem(productTemplate);
}
return productTemplate;
}
}

View File

@ -0,0 +1,28 @@
import {ProductGamesystem} from "../../gamesystems/ProductGamesystem";
import {TemplateGamesystem} from "../TemplateGamesystem";
import {TemplateElement} from "../TemplateElement";
import {ProductState} from "../../gamesystems/states/ProductState";
import {ProductTransition} from "../../gamesystems/transitions/ProductTransition";
import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem";
import {GameModel} from "../../GameModel";
import {TemplateType} from "../TemplateType";
import {TemplateProductSystemGenerator} from "../../gamesystems/productSystemGenerator/TemplateProductSystemGenerator";
export class ProductTemplateSystem extends ProductGamesystem implements TemplateGamesystem{
stateMap: Map<TemplateElement, ProductState[]> = new Map();
transitionMap: Map<TemplateElement, ProductTransition[]> = new Map<TemplateElement, ProductTransition[]>()
templateType: TemplateType
constructor(gamesystemName: string, gamesystemDescription: string, templateType: TemplateType) {
super(gamesystemName, gamesystemDescription);
this.templateType = templateType;
}
addTemplateElement(templateElement: TemplateElement): void {
const productTemplateGenerator = new TemplateProductSystemGenerator(this, templateElement);
productTemplateGenerator.generateFromChildsystems()
}
}

View File

@ -0,0 +1,42 @@
import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem";
import {TemplateGamesystem} from "../TemplateGamesystem";
import {TemplateElement} from "../TemplateElement";
import {SimpleState} from "../../gamesystems/states/SimpleState";
import {SimpleTransition} from "../../gamesystems/transitions/SimpleTransition";
import {SimpleTemplateState} from "./SimpleTemplateState";
import {SimpleTemplateTransition} from "./SimpleTemplateTransition";
import {TemplateType} from "../TemplateType";
export class SimpleTemplateGamesystem extends SimpleGamesystem implements TemplateGamesystem {
templateType: TemplateType
constructor(gamesystemName: string, gamesystemDescription: string, templateType: TemplateType) {
super(gamesystemName, gamesystemDescription);
this.templateType = templateType;
}
addTemplateElement(templateElement: TemplateElement): void {
this.states.forEach(state => {
(state as SimpleTemplateState).addTemplateElement(templateElement);
})
this.transitions.forEach(transition => {
(transition as SimpleTemplateTransition).addTemplateElement(templateElement);
})
}
createState(label: string, description: string): SimpleState | undefined {
const state = new SimpleTemplateState(label, description);
this.states.push(state)
return state;
}
createTransition(startingState: SimpleState, endingState: SimpleState): SimpleTransition | undefined {
return new SimpleTemplateTransition(startingState, endingState);
}
removeState(state: SimpleState): boolean {
return super.removeState(state);
}
}

View File

@ -0,0 +1,18 @@
import {SimpleState} from "../../gamesystems/states/SimpleState";
import {TemplateElement} from "../TemplateElement";
import {ScriptAccountCondition} from "../../gamesystems/conditions/ScriptAccountCondition";
export class SimpleTemplateState extends SimpleState {
conditionMap: Map<TemplateElement, ScriptAccountCondition[]> = new Map();
addTemplateElement(templateElement: TemplateElement) {
if(!this.conditionMap.has(templateElement)) {
this.conditionMap.set(templateElement, this.conditions)
}
}
removeTemplateElement(templateElement: TemplateElement) {
this.conditionMap.delete(templateElement)
}
}

View File

@ -0,0 +1,25 @@
import {SimpleTransition} from "../../gamesystems/transitions/SimpleTransition";
import {TemplateElement} from "../TemplateElement";
import {ScriptAccountCondition} from "../../gamesystems/conditions/ScriptAccountCondition";
import {ScriptAccountAction} from "../../gamesystems/actions/ScriptAccountAction";
export class SimpleTemplateTransition extends SimpleTransition{
conditionMap: Map<TemplateElement, ScriptAccountCondition[]> = new Map();
actionMap: Map<TemplateElement, ScriptAccountAction[]> = new Map();
addTemplateElement(templateElement: TemplateElement) {
if(!this.conditionMap.has(templateElement)) {
this.conditionMap.set(templateElement, this.scriptAccountConditions.concat())
}
if(!this.actionMap.has(templateElement)) {
this.actionMap.set(templateElement, this.scriptAccountActions.concat())
}
}
removeTemplateElement(templateElement: TemplateElement) {
this.conditionMap.delete(templateElement)
this.actionMap.delete(templateElement)
}
}

View File

@ -1,9 +1,26 @@
import {StoreComponent} from "../../../../../app/storage/StoreComponent"; import {StoreComponent} from "../../../../../app/storage/StoreComponent";
import {Character} from "../../game-model/characters/Character"; import {Character} from "../../game-model/characters/Character";
import {SimpleTemplateGamesystem} from "../../game-model/templates/simpleGamesystem/SimpleTemplateGamesystem";
import {ScriptAccountActionParser} from "../gamesystemParser/ScriptAccountActionParser";
import {ScriptAccountConditionParser} from "../gamesystemParser/ScriptAccountConditionParser";
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {SimpleTemplateState} from "../../game-model/templates/simpleGamesystem/SimpleTemplateState";
import {SimpleTemplateTransition} from "../../game-model/templates/simpleGamesystem/SimpleTemplateTransition";
export class CharacterParser { export class CharacterParser {
characterSpecificGamesystems: SimpleTemplateGamesystem[]
scriptAccountConditionParser: ScriptAccountConditionParser
scriptAccountActionParser: ScriptAccountActionParser
constructor(characterSpecificGamesystems: SimpleTemplateGamesystem[], scriptAccounts: ScriptAccount[]) {
this.characterSpecificGamesystems = characterSpecificGamesystems;
this.scriptAccountActionParser = new ScriptAccountActionParser(scriptAccounts);
this.scriptAccountConditionParser = new ScriptAccountConditionParser(scriptAccounts)
}
public parseCharacters(characters: StoreComponent[]): Character[] { public parseCharacters(characters: StoreComponent[]): Character[] {
const loadedCharacters: Character[] = [] const loadedCharacters: Character[] = []
characters.forEach(character => loadedCharacters.push(this.parseSingleCharacter(JSON.parse(character.jsonString)))) characters.forEach(character => loadedCharacters.push(this.parseSingleCharacter(JSON.parse(character.jsonString))))
@ -11,6 +28,61 @@ export class CharacterParser {
} }
private parseSingleCharacter(characterData: any): Character { private parseSingleCharacter(characterData: any): Character {
return new Character(characterData.componentName, characterData.componentDescription); const character = new Character(characterData.componentName, characterData.componentDescription);
const templateSpecificGamesystems = this.parseCharacterSpecificGamesystems(character, characterData.characterSpecificTemplateSystems);
templateSpecificGamesystems.forEach(system => character.addCharacterSpecificSimpleTemplatesystem(system))
return character;
} }
private parseCharacterSpecificGamesystems(character: Character, characterSpecificGamesystems: any): SimpleTemplateGamesystem[] {
const result: SimpleTemplateGamesystem[] = []
for(let i=0; i<characterSpecificGamesystems.length; i++) {
const characterSpecificGamesystem = characterSpecificGamesystems[i];
result.push(this.parseSingleCharacterSpecificGamesystem(character, characterSpecificGamesystem)!)
}
return result;
}
private parseSingleCharacterSpecificGamesystem(character: Character, characterSpecificGamesystem: any): SimpleTemplateGamesystem | undefined{
const referencedGamesystem = this.findCharacterSpecificGamesystem(characterSpecificGamesystem.componentName)
if(referencedGamesystem != undefined) {
for(let i=0; i<characterSpecificGamesystem.states.length; i++) {
const stateReference = characterSpecificGamesystem.states[i];
const state = this.findReferencedState(referencedGamesystem, stateReference.stateLabel)! as SimpleTemplateState
const conditions = this.scriptAccountConditionParser.parseStoredConditions(stateReference.conditionMap);
state.conditionMap.set(character, conditions)
}
for(let i=0; i<characterSpecificGamesystem.transitions.length; i++) {
const transitionReference = characterSpecificGamesystem.transitions[i];
const transition = this.findReferencedTransition(referencedGamesystem, transitionReference.startingState, transitionReference.endingState) as SimpleTemplateTransition;
const condititions = this.scriptAccountConditionParser.parseStoredConditions(transitionReference.conditionMap);
const actions = this.scriptAccountActionParser.parseActions(transitionReference.actionMap);
transition!.actionMap.set(character, actions);
transition!.conditionMap.set(character, condititions);
}
} else {
console.log(this.characterSpecificGamesystems)
console.log("Cannot find system: ", characterSpecificGamesystem.componentName)
}
return referencedGamesystem;
}
private findCharacterSpecificGamesystem(componentName: string): SimpleTemplateGamesystem | undefined{
return this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === componentName)
}
private findReferencedState(gamesystem: SimpleTemplateGamesystem, stateLabel: string) {
return gamesystem.states.find(state => state.stateLabel === stateLabel);
}
private findReferencedTransition(gamesystem: SimpleTemplateGamesystem, startingLabel: string, endingLabel: string) {
return gamesystem.transitions.find(transition => transition.startingState.stateLabel === startingLabel && transition.endingState.stateLabel === endingLabel);
}
} }

View File

@ -6,6 +6,8 @@ import {SimpleGamesystem} from "../../game-model/gamesystems/SimpleGamesystem";
import {StateParser} from "./StateParser"; import {StateParser} from "./StateParser";
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {TransitionParser} from "./TransitionParser"; import {TransitionParser} from "./TransitionParser";
import {SimpleTemplateGamesystem} from "../../game-model/templates/simpleGamesystem/SimpleTemplateGamesystem";
import {ProductTemplateSystem} from "../../game-model/templates/productGamesystem/ProductTemplateSystem";
export class GamesystemParser { export class GamesystemParser {
@ -40,18 +42,32 @@ export class GamesystemParser {
} }
parseSimpleGamesystem(gamesystemData: any): SimpleGamesystem { parseSimpleGamesystem(gamesystemData: any): SimpleGamesystem {
const simpleGamesystem = new SimpleGamesystem(gamesystemData.componentName, gamesystemData.componentDescription) let simpleGamesystem
if(gamesystemData.templateType != undefined) {
simpleGamesystem = new SimpleTemplateGamesystem(gamesystemData.componentName, gamesystemData.componentDescription, gamesystemData.templateType)
} else {
simpleGamesystem = new SimpleGamesystem(gamesystemData.componentName, gamesystemData.componentDescription)
}
const stateParser = new StateParser(this.scriptAccounts); const stateParser = new StateParser(this.scriptAccounts);
simpleGamesystem.states = stateParser.parseStates(gamesystemData.states) simpleGamesystem.states = stateParser.parseStates(gamesystemData.states, gamesystemData.templateType)
const transitionParser = new TransitionParser(simpleGamesystem.states, this.scriptAccounts) const transitionParser = new TransitionParser(simpleGamesystem.states, this.scriptAccounts)
simpleGamesystem.transitions = transitionParser.parseTransitions(gamesystemData.transitions) simpleGamesystem.transitions = transitionParser.parseTransitions(gamesystemData.transitions, gamesystemData.templateType)
return simpleGamesystem return simpleGamesystem
} }
parseProductGamesystem(gamesystemData: any) { parseProductGamesystem(gamesystemData: any) {
const productGamesystem = new ProductGamesystem(gamesystemData.componentName, gamesystemData.componentDescription); let productGamesystem;
if(gamesystemData.templateType == undefined) {
productGamesystem = new ProductGamesystem(gamesystemData.componentName, gamesystemData.componentDescription);
} else {
productGamesystem = new ProductTemplateSystem(gamesystemData.componentName, gamesystemData.componentDescription, gamesystemData.templateType)
}
const childsystemNames: string[] = [] const childsystemNames: string[] = []
for(let i=0; i<gamesystemData.childsystems.length; i++) { for(let i=0; i<gamesystemData.childsystems.length; i++) {
childsystemNames.push(gamesystemData.childsystems[i].componentName) childsystemNames.push(gamesystemData.childsystems[i].componentName)

View File

@ -2,6 +2,8 @@ import {SimpleState} from "../../game-model/gamesystems/states/SimpleState";
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {ScriptAccountCondition} from "../../game-model/gamesystems/conditions/ScriptAccountCondition"; import {ScriptAccountCondition} from "../../game-model/gamesystems/conditions/ScriptAccountCondition";
import {ScriptAccountConditionParser} from "./ScriptAccountConditionParser"; import {ScriptAccountConditionParser} from "./ScriptAccountConditionParser";
import {TemplateType} from "../../game-model/templates/TemplateType";
import {SimpleTemplateState} from "../../game-model/templates/simpleGamesystem/SimpleTemplateState";
export class StateParser { export class StateParser {
@ -12,23 +14,28 @@ export class StateParser {
this.conditionParser = new ScriptAccountConditionParser(scriptAccounts) this.conditionParser = new ScriptAccountConditionParser(scriptAccounts)
} }
public parseStates(stateData: any): SimpleState[] { public parseStates(stateData: any, templateType: TemplateType | undefined): SimpleState[] {
const parsedStates: SimpleState[] = [] const parsedStates: SimpleState[] = []
for(let i=0; i<stateData.length; i++) { for(let i=0; i<stateData.length; i++) {
parsedStates.push(this.parseState(stateData[i])) parsedStates.push(this.parseState(stateData[i], templateType))
} }
return parsedStates; return parsedStates;
} }
private parseState(stateData: any): SimpleState { private parseState(stateData: any, templateType: TemplateType | undefined): SimpleState {
const initial = stateData.initial const initial = stateData.initial
const stateLabel = stateData.stateLabel const stateLabel = stateData.stateLabel
const stateDescription = stateData.stateDescription const stateDescription = stateData.stateDescription
const conditions = this.conditionParser.parseStoredConditions(stateData.conditions) const conditions = this.conditionParser.parseStoredConditions(stateData.conditions)
const simpleState = new SimpleState(stateLabel, stateDescription); let simpleState;
if(templateType == undefined) {
simpleState = new SimpleState(stateLabel, stateDescription)
} else {
simpleState = new SimpleTemplateState(stateLabel, stateDescription)
}
simpleState.initial = initial; simpleState.initial = initial;
simpleState.conditions = conditions; simpleState.conditions = conditions;

View File

@ -3,6 +3,8 @@ import {ScriptAccountConditionParser} from "./ScriptAccountConditionParser";
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {SimpleTransition} from "../../game-model/gamesystems/transitions/SimpleTransition"; import {SimpleTransition} from "../../game-model/gamesystems/transitions/SimpleTransition";
import {ScriptAccountActionParser} from "./ScriptAccountActionParser"; import {ScriptAccountActionParser} from "./ScriptAccountActionParser";
import {TemplateType} from "../../game-model/templates/TemplateType";
import {SimpleTemplateTransition} from "../../game-model/templates/simpleGamesystem/SimpleTemplateTransition";
export class TransitionParser { export class TransitionParser {
@ -18,10 +20,10 @@ export class TransitionParser {
this.actionParser = new ScriptAccountActionParser(scriptAccounts) this.actionParser = new ScriptAccountActionParser(scriptAccounts)
} }
public parseTransitions(transitionData: any): SimpleTransition[] { public parseTransitions(transitionData: any, templateType: TemplateType | undefined): SimpleTransition[] {
const transitions: SimpleTransition[] = [] const transitions: SimpleTransition[] = []
for(let i=0; i<transitionData.length; i++) { for(let i=0; i<transitionData.length; i++) {
const parsedTransition = this.parseSingleTransition(transitionData[i]); const parsedTransition = this.parseSingleTransition(transitionData[i], templateType);
if(parsedTransition != undefined) { if(parsedTransition != undefined) {
transitions.push(parsedTransition) transitions.push(parsedTransition)
} }
@ -29,7 +31,7 @@ export class TransitionParser {
return transitions return transitions
} }
private parseSingleTransition(transitionData: any): SimpleTransition | undefined{ private parseSingleTransition(transitionData: any, templateType: TemplateType | undefined): SimpleTransition | undefined{
const startingState = this.findStateByLabel(transitionData.startingState) const startingState = this.findStateByLabel(transitionData.startingState)
const endingState = this.findStateByLabel(transitionData.endingState); const endingState = this.findStateByLabel(transitionData.endingState);
@ -37,7 +39,14 @@ export class TransitionParser {
return undefined return undefined
} }
const simpleTransition = new SimpleTransition(startingState, endingState)
let simpleTransition;
if(templateType == undefined) {
simpleTransition = new SimpleTransition(startingState, endingState)
} else {
simpleTransition = new SimpleTemplateTransition(startingState, endingState)
}
simpleTransition.scriptAccountConditions = this.conditionParser.parseStoredConditions(transitionData.scriptAccountConditions) simpleTransition.scriptAccountConditions = this.conditionParser.parseStoredConditions(transitionData.scriptAccountConditions)
simpleTransition.scriptAccountActions = this.actionParser.parseActions(transitionData.scriptAccountActions); simpleTransition.scriptAccountActions = this.actionParser.parseActions(transitionData.scriptAccountActions);

View File

@ -2,9 +2,13 @@ import {Character} from "../game-model/characters/Character";
import {StoreComponent} from "../../../../app/storage/StoreComponent"; import {StoreComponent} from "../../../../app/storage/StoreComponent";
import {SerializeConstants} from "./SerializeConstants"; import {SerializeConstants} from "./SerializeConstants";
import {ModelComponentType} from "../game-model/ModelComponentType"; import {ModelComponentType} from "../game-model/ModelComponentType";
import {SimpleTemplateGamesystem} from "../game-model/templates/simpleGamesystem/SimpleTemplateGamesystem";
import {Gamesystem} from "../game-model/gamesystems/Gamesystem";
export class CharacterSerializer { export class CharacterSerializer {
private static ignoredKeys: string[] = ['unsaved', 'type', 'incomingTransitions', 'outgoingTransitions', 'initial', 'conditions', 'stateDescription', 'templateType', 'parentGamesystem', 'scriptAccountActions', 'scriptAccountConditions']
public static serializeCharacters(characters: Character[]): StoreComponent[] { public static serializeCharacters(characters: Character[]): StoreComponent[] {
const storedCharacters: StoreComponent[] = [] const storedCharacters: StoreComponent[] = []
characters.forEach(character => storedCharacters.push(this.serializeSingleCharacter(character))) characters.forEach(character => storedCharacters.push(this.serializeSingleCharacter(character)))
@ -13,14 +17,41 @@ export class CharacterSerializer {
private static serializeSingleCharacter(character: Character): StoreComponent{ private static serializeSingleCharacter(character: Character): StoreComponent{
const fileName = character.componentName const fileName = character.componentName
const templateGamesystemBackup = character.characterSpecificTemplateSystems.concat();
character.characterSpecificTemplateSystems = character.characterSpecificTemplateSystems.filter(system => system instanceof SimpleTemplateGamesystem)
console.log("Templatesystem: ", character.characterSpecificTemplateSystems)
const jsonString = JSON.stringify(character, (key, value) => { const jsonString = JSON.stringify(character, (key, value) => {
if(key === 'unsaved' || key === 'type') { if(value instanceof Gamesystem) {
return {
...value,
componentDescription: undefined,
parentGamesystem: undefined
}
}
if(key === 'scriptAccount') {
return value.componentName
}
if(key === 'conditionMap' || key === 'actionMap') {
if(value.get(character) == undefined) {
return []
}
return value.get(character)
}
if(key === 'startingState' || key === 'endingState') {
return value.stateLabel
}
if(this.ignoredKeys.includes(key)) {
return undefined return undefined
} else { } else {
return value; return value;
} }
}, SerializeConstants.JSON_INDENT) }, SerializeConstants.JSON_INDENT)
character.characterSpecificTemplateSystems = templateGamesystemBackup
return new StoreComponent(jsonString, fileName, ModelComponentType.CHARACTER); return new StoreComponent(jsonString, fileName, ModelComponentType.CHARACTER);
} }
} }

View File

@ -4,10 +4,11 @@ import {SimpleGamesystem} from "../game-model/gamesystems/SimpleGamesystem";
import {ProductGamesystem} from "../game-model/gamesystems/ProductGamesystem"; import {ProductGamesystem} from "../game-model/gamesystems/ProductGamesystem";
import {SerializeConstants} from "./SerializeConstants"; import {SerializeConstants} from "./SerializeConstants";
import {ModelComponentType} from "../game-model/ModelComponentType"; import {ModelComponentType} from "../game-model/ModelComponentType";
import {ProductTemplateSystem} from "../game-model/templates/productGamesystem/ProductTemplateSystem";
export class GamesystemSerializer { export class GamesystemSerializer {
private static IGNORED_SIMPLE_ATTRIBUTES = ["parentGamesystem", 'incomingTransitions', "outgoingTransitions", "unsaved", "type"] private static IGNORED_SIMPLE_ATTRIBUTES = ["parentGamesystem", 'incomingTransitions', "outgoingTransitions", "unsaved", "type", "conditionMap", "actionMap"]
public static serializeGamesystems(gamesystems: Gamesystem<any, any>[]): StoreComponent[] { public static serializeGamesystems(gamesystems: Gamesystem<any, any>[]): StoreComponent[] {
let storedGamesystems: StoreComponent[] = [] let storedGamesystems: StoreComponent[] = []
@ -59,11 +60,23 @@ export class GamesystemSerializer {
storedChildsystems.forEach(storedChildsystem => storedGamesystems.push(storedChildsystem)) storedChildsystems.forEach(storedChildsystem => storedGamesystems.push(storedChildsystem))
}) })
const jsonString = { let jsonString;
if(productGamesystem instanceof ProductTemplateSystem) {
jsonString = {
'componentName': productGamesystem.componentName, 'componentName': productGamesystem.componentName,
'componentDescription': productGamesystem.componentDescription, 'componentDescription': productGamesystem.componentDescription,
'childsystems': innerGamesystemJsonArray 'childsystems': innerGamesystemJsonArray,
'templateType': productGamesystem.templateType
} }
} else {
jsonString = {
'componentName': productGamesystem.componentName,
'componentDescription': productGamesystem.componentDescription,
'childsystems': innerGamesystemJsonArray,
}
}
const storedProductsystem = new StoreComponent(JSON.stringify(jsonString, null, SerializeConstants.JSON_INDENT), fileName, ModelComponentType.GAMESYTEM) const storedProductsystem = new StoreComponent(JSON.stringify(jsonString, null, SerializeConstants.JSON_INDENT), fileName, ModelComponentType.GAMESYTEM)
storedGamesystems.push(storedProductsystem) storedGamesystems.push(storedProductsystem)

View File

@ -1,4 +1,50 @@
{ {
"componentName": "Astrid Hofferson", "componentName": "Astrid Hofferson",
"componentDescription": "" "componentDescription": "",
"characterSpecificTemplateSystems": [
{
"componentName": "TemplateGamesystem",
"states": [
{
"stateLabel": "A",
"conditionMap": [
{
"scriptAccount": "Luftfeuchtigkeit",
"minValue": 0,
"maxValue": "10"
}
]
},
{
"stateLabel": "B",
"conditionMap": [
{
"scriptAccount": "New ScriptAccount",
"minValue": 0,
"maxValue": 100
}
]
}
],
"transitions": [
{
"startingState": "A",
"endingState": "B",
"conditionMap": [
{
"scriptAccount": "Temperature",
"minValue": 0,
"maxValue": 10
}
],
"actionMap": [
{
"changingValue": 10,
"scriptAccount": "Luftfeuchtigkeit"
}
]
}
]
}
]
} }

View File

@ -1,4 +1,60 @@
{ {
"componentName": "Hicks Haddock", "componentName": "Hicks Haddock",
"componentDescription": "" "componentDescription": "",
"characterSpecificTemplateSystems": [
{
"componentName": "TemplateGamesystem",
"states": [
{
"stateLabel": "A",
"conditionMap": [
{
"scriptAccount": "Luftfeuchtigkeit",
"minValue": 0,
"maxValue": "10"
}
]
},
{
"stateLabel": "B",
"conditionMap": [
{
"scriptAccount": "New ScriptAccount",
"minValue": 0,
"maxValue": 100
}
]
}
],
"transitions": [
{
"startingState": "A",
"endingState": "B",
"conditionMap": [],
"actionMap": []
}
]
},
{
"componentName": "Letters",
"states": [
{
"stateLabel": "A",
"conditionMap": []
},
{
"stateLabel": "B",
"conditionMap": []
}
],
"transitions": [
{
"startingState": "A",
"endingState": "B",
"conditionMap": [],
"actionMap": []
}
]
}
]
} }

View File

@ -0,0 +1,6 @@
{
"componentName": "NormalGamesystem",
"componentDescription": "",
"states": [],
"transitions": []
}

View File

@ -0,0 +1,27 @@
{
"componentName": "Letters",
"componentDescription": "",
"states": [
{
"initial": false,
"conditions": [],
"stateLabel": "A",
"stateDescription": ""
},
{
"initial": false,
"conditions": [],
"stateLabel": "B",
"stateDescription": ""
}
],
"transitions": [
{
"scriptAccountActions": [],
"scriptAccountConditions": [],
"startingState": "A",
"endingState": "B"
}
],
"templateType": 0
}

View File

@ -0,0 +1,26 @@
{
"componentName": "Numbers",
"componentDescription": "",
"states": [
{
"initial": false,
"conditions": [],
"stateLabel": "1",
"stateDescription": ""
},
{
"initial": false,
"conditions": [],
"stateLabel": "2",
"stateDescription": ""
}
],
"transitions": [
{
"scriptAccountActions": [],
"scriptAccountConditions": [],
"startingState": "1",
"endingState": "2"
}
]
}

View File

@ -0,0 +1,13 @@
{
"componentName": "Producttest",
"componentDescription": "",
"childsystems": [
{
"componentName": "Letters"
},
{
"componentName": "Numbers"
}
],
"templateType": 0
}

View File

@ -0,0 +1,50 @@
{
"componentName": "TemplateGamesystem",
"componentDescription": "",
"states": [
{
"initial": false,
"conditions": [
{
"scriptAccount": "Luftfeuchtigkeit",
"minValue": 0,
"maxValue": "10"
}
],
"stateLabel": "A",
"stateDescription": ""
},
{
"initial": false,
"conditions": [
{
"scriptAccount": "New ScriptAccount",
"minValue": 0,
"maxValue": 100
}
],
"stateLabel": "B",
"stateDescription": ""
}
],
"transitions": [
{
"scriptAccountActions": [
{
"changingValue": 10,
"scriptAccount": "Luftfeuchtigkeit"
}
],
"scriptAccountConditions": [
{
"scriptAccount": "Temperature",
"minValue": 0,
"maxValue": 10
}
],
"startingState": "A",
"endingState": "B"
}
],
"templateType": 0
}