alt-templatesystem-impl #29
							
								
								
									
										17
									
								
								app/main.ts
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								app/main.ts
									
									
									
									
									
								
							@ -64,9 +64,20 @@ function createWindow(): BrowserWindow {
 | 
			
		||||
      submenu: [
 | 
			
		||||
        {
 | 
			
		||||
          label: "Gamesystem",
 | 
			
		||||
          click: () => {
 | 
			
		||||
            win!.webContents.send('context-menu', "new-gamesystem");
 | 
			
		||||
          }
 | 
			
		||||
          submenu: [
 | 
			
		||||
            {
 | 
			
		||||
              label: "Normal",
 | 
			
		||||
              click: () => {
 | 
			
		||||
                win!.webContents.send('context-menu', "new-gamesystem-normal");
 | 
			
		||||
              }
 | 
			
		||||
            },
 | 
			
		||||
            {
 | 
			
		||||
              label: "Characterspecific",
 | 
			
		||||
              click: () => {
 | 
			
		||||
                win!.webContents.send('context-menu', "new-gamesystem-character");
 | 
			
		||||
              }
 | 
			
		||||
            }
 | 
			
		||||
          ]
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          label: "ScriptAccount",
 | 
			
		||||
 | 
			
		||||
@ -24,6 +24,8 @@ import {Character} from "./project/game-model/characters/Character";
 | 
			
		||||
import {CharacterOverviewComponent} from "./side-overviews/character-overview/character-overview.component";
 | 
			
		||||
import {CharacterSerializer} from "./project/serializer/CharacterSerializer";
 | 
			
		||||
import {CharacterParser} from "./project/parser/characterParser/CharacterParser";
 | 
			
		||||
import {TemplateType} from "./project/game-model/TemplateType";
 | 
			
		||||
import {TemplateTypeUtilities} from "./project/game-model/TemplateTypeUtilities";
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'app-root',
 | 
			
		||||
@ -76,8 +78,13 @@ export class AppComponent implements OnInit{
 | 
			
		||||
    } else if(message.startsWith("new")) {
 | 
			
		||||
      const splittedMessage = message.split("-");
 | 
			
		||||
      const modelComponentType = ModelComponentTypeUtillities.fromString(splittedMessage[1]);
 | 
			
		||||
      let templateType: TemplateType = TemplateType.NORMAL
 | 
			
		||||
      if(splittedMessage.length > 2) {
 | 
			
		||||
        templateType = TemplateTypeUtilities.fromString(splittedMessage[2]);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if(modelComponentType != undefined) {
 | 
			
		||||
        this.onCreateModelComponent(modelComponentType);
 | 
			
		||||
        this.onCreateModelComponent(modelComponentType, templateType);
 | 
			
		||||
      } else {
 | 
			
		||||
        console.log("[ERROR] [App-Component] Unknown Context-Menu Command!")
 | 
			
		||||
      }
 | 
			
		||||
@ -127,10 +134,10 @@ export class AppComponent implements OnInit{
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private onCreateModelComponent(modelComponentType: ModelComponentType) {
 | 
			
		||||
  private onCreateModelComponent(modelComponentType: ModelComponentType, templateType: TemplateType) {
 | 
			
		||||
    switch (modelComponentType) {
 | 
			
		||||
      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
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@ -144,7 +151,7 @@ export class AppComponent implements OnInit{
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private onCreateNewGamesystem() {
 | 
			
		||||
  private onCreateNewGamesystem(templateType: TemplateType) {
 | 
			
		||||
    let parentGamesystemName = undefined
 | 
			
		||||
    if(this.openContent != ModelComponentType.GAMESYTEM) {
 | 
			
		||||
      this.openGamesystemsOverview();
 | 
			
		||||
@ -153,7 +160,7 @@ export class AppComponent implements OnInit{
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    const createdGamesystem = this.gameModel!.createGamesystem("New Gamesystem", parentGamesystemName);
 | 
			
		||||
    const createdGamesystem = this.gameModel!.createGamesystem("New Gamesystem "+ templateType, parentGamesystemName, templateType);
 | 
			
		||||
    if(createdGamesystem != undefined) {
 | 
			
		||||
      this.gamesystemOverview!.refresh();
 | 
			
		||||
      this.editor?.openGameModelComponent(createdGamesystem);
 | 
			
		||||
@ -204,7 +211,7 @@ export class AppComponent implements OnInit{
 | 
			
		||||
    const gamesystemParser = new GamesystemParser(scriptAccounts);
 | 
			
		||||
    const gamesystems = gamesystemParser.parseStoredGamesystems(storedGameModel.storedGamesystems);
 | 
			
		||||
 | 
			
		||||
    const characterParser = new CharacterParser();
 | 
			
		||||
    const characterParser = new CharacterParser(gamesystemParser.getParsedTemplateGamesystems(TemplateType.CHARACTER), scriptAccounts);
 | 
			
		||||
    const characters = characterParser.parseCharacters(storedGameModel.storedCharacters);
 | 
			
		||||
 | 
			
		||||
    gameModel.scriptAccounts = scriptAccounts
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ import {ModelComponentEditorComponent} from "./editor/model-component-editor/mod
 | 
			
		||||
import {DeleteConfirmationDialogComponent} from "./delete-confirmation-dialog/delete-confirmation-dialog.component";
 | 
			
		||||
import {MatDialogActions, MatDialogContent, MatDialogTitle} from "@angular/material/dialog";
 | 
			
		||||
import {GamescriptOverviewComponent} from "./side-overviews/gamescript-overview/gamescript-overview.component";
 | 
			
		||||
import { MatTreeModule} from "@angular/material/tree";
 | 
			
		||||
import {MatTree, MatTreeModule} from "@angular/material/tree";
 | 
			
		||||
import {GamesystemEditorComponent} from "./editor/gamesystem-editor/gamesystem-editor.component";
 | 
			
		||||
import {
 | 
			
		||||
  SimpleGamesystemEditorComponent
 | 
			
		||||
@ -70,15 +70,8 @@ import {
 | 
			
		||||
} from "./editor/gamesystem-editor/scriptaccount-condition-editor/scriptaccount-condition-editor.component";
 | 
			
		||||
import {CharacterOverviewComponent} from "./side-overviews/character-overview/character-overview.component";
 | 
			
		||||
import {CharacterEditorComponent} from "./editor/character-editor/character-editor.component";
 | 
			
		||||
import {
 | 
			
		||||
  MatAccordion,
 | 
			
		||||
  MatExpansionPanel,
 | 
			
		||||
  MatExpansionPanelHeader,
 | 
			
		||||
  MatExpansionPanelTitle
 | 
			
		||||
} from "@angular/material/expansion";
 | 
			
		||||
import {
 | 
			
		||||
  TemplateSystemEditorComponent
 | 
			
		||||
} from "./editor/gamesystem-editor/template-system-editor/template-system-editor.component";
 | 
			
		||||
import {MatAccordion, MatExpansionPanel, MatExpansionPanelHeader} from "@angular/material/expansion";
 | 
			
		||||
import {TemplateCreatorComponent} from "./editor/gamesystem-editor/template-creator/template-creator.component";
 | 
			
		||||
 | 
			
		||||
// AoT requires an exported function for factories
 | 
			
		||||
const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader =>  new TranslateHttpLoader(http, './assets/i18n/', '.json');
 | 
			
		||||
@ -103,7 +96,7 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader =>  new Transl
 | 
			
		||||
    ScriptaccountConditionEditorComponent,
 | 
			
		||||
    CharacterOverviewComponent,
 | 
			
		||||
    CharacterEditorComponent,
 | 
			
		||||
    TemplateSystemEditorComponent
 | 
			
		||||
    TemplateCreatorComponent
 | 
			
		||||
  ],
 | 
			
		||||
  imports: [
 | 
			
		||||
    BrowserModule,
 | 
			
		||||
@ -162,10 +155,9 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader =>  new Transl
 | 
			
		||||
    MatCard,
 | 
			
		||||
    MatCardContent,
 | 
			
		||||
    MatCardHeader,
 | 
			
		||||
    MatCardTitle,
 | 
			
		||||
    MatAccordion,
 | 
			
		||||
    MatExpansionPanel,
 | 
			
		||||
    MatExpansionPanelTitle,
 | 
			
		||||
    MatCardTitle,
 | 
			
		||||
    MatExpansionPanelHeader
 | 
			
		||||
  ],
 | 
			
		||||
  providers: [],
 | 
			
		||||
 | 
			
		||||
@ -1,16 +1,15 @@
 | 
			
		||||
<mat-card>
 | 
			
		||||
  <mat-card-header>
 | 
			
		||||
    <mat-card-title>Charactersystems</mat-card-title>
 | 
			
		||||
    <mat-card-title>Characterspecific Gamesystems</mat-card-title>
 | 
			
		||||
  </mat-card-header>
 | 
			
		||||
  <mat-card-content>
 | 
			
		||||
    <mat-accordion>
 | 
			
		||||
      <mat-expansion-panel *ngFor="let characterSystem of character!.characterSpecificGamesystems">
 | 
			
		||||
        <mat-expansion-panel-header>
 | 
			
		||||
          <mat-panel-title>{{characterSystem.componentName}}</mat-panel-title>
 | 
			
		||||
        </mat-expansion-panel-header>
 | 
			
		||||
        <app-gamesystem-editor [gamesystem]="characterSystem" [scriptAccounts]="gameModel!.scriptAccounts"></app-gamesystem-editor>
 | 
			
		||||
      <mat-expansion-panel *ngFor="let gamesystem of character!.characterSpecificGamesystems">
 | 
			
		||||
        <mat-expansion-panel-header>{{gamesystem.componentName}}</mat-expansion-panel-header>
 | 
			
		||||
        <app-gamesystem-editor [scriptAccounts]="gameModel!.scriptAccounts" [gamesystem]="gamesystem" [templateReference]="character!"></app-gamesystem-editor>
 | 
			
		||||
      </mat-expansion-panel>
 | 
			
		||||
 | 
			
		||||
    </mat-accordion>
 | 
			
		||||
    <button style="width: 100%; margin-top: 10px" mat-stroked-button (click)="openTemplateEditor()">Add Charactersystem</button>
 | 
			
		||||
    <button mat-stroked-button style="width: 100%; margin-top: 10px" (click)="onOpenTemplateCreator()">Add Gamesystem</button>
 | 
			
		||||
  </mat-card-content>
 | 
			
		||||
</mat-card>
 | 
			
		||||
 | 
			
		||||
@ -1,14 +1,9 @@
 | 
			
		||||
import {Component, Input} from '@angular/core';
 | 
			
		||||
import {Character} from '../../project/game-model/characters/Character';
 | 
			
		||||
import {MatDialog} from "@angular/material/dialog";
 | 
			
		||||
import {
 | 
			
		||||
  TemplateSystemEditorComponent
 | 
			
		||||
} from "../gamesystem-editor/template-system-editor/template-system-editor.component";
 | 
			
		||||
import {Character} from "../../project/game-model/characters/Character";
 | 
			
		||||
import {GameModel} from "../../project/game-model/GameModel";
 | 
			
		||||
import {TemplateType} from "../../project/game-model/gamesystems/TemplateType";
 | 
			
		||||
import {Gamesystem} from "../../project/game-model/gamesystems/Gamesystem";
 | 
			
		||||
import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem";
 | 
			
		||||
import {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem";
 | 
			
		||||
import {MatDialog} from "@angular/material/dialog";
 | 
			
		||||
import {TemplateCreatorComponent} from "../gamesystem-editor/template-creator/template-creator.component";
 | 
			
		||||
import {TemplateType} from "../../project/game-model/TemplateType";
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'app-character-editor',
 | 
			
		||||
@ -23,20 +18,15 @@ export class CharacterEditorComponent {
 | 
			
		||||
  constructor(private dialog: MatDialog) {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  openTemplateEditor() {
 | 
			
		||||
    const dialogRef = this.dialog.open(TemplateSystemEditorComponent, {
 | 
			
		||||
      minWidth: "400px",
 | 
			
		||||
      data: this.gameModel!.getTemplateGamesystems(TemplateType.CHARACTER)
 | 
			
		||||
  onOpenTemplateCreator() {
 | 
			
		||||
    const dialogRef = this.dialog.open(TemplateCreatorComponent, {
 | 
			
		||||
      data: this.gameModel!.listGamesystems(TemplateType.CHARACTER),
 | 
			
		||||
      minWidth: "400px"
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    dialogRef.afterClosed().subscribe(res => {
 | 
			
		||||
      if(res != undefined) {
 | 
			
		||||
        const referenceSystem: Gamesystem<any, any> = res
 | 
			
		||||
        if(referenceSystem instanceof SimpleGamesystem) {
 | 
			
		||||
          this.character!.addCharacterSpecificSimpleGamesystem(referenceSystem)
 | 
			
		||||
        } else if(referenceSystem instanceof ProductGamesystem) {
 | 
			
		||||
          this.character!.addCharacterSpecificProductTemplateGamesystem(referenceSystem)
 | 
			
		||||
        }
 | 
			
		||||
        this.character!.addCharacterSpecificGamesystem(res)
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -15,8 +15,7 @@
 | 
			
		||||
                                (onOpenGamesystemEditor)="openGameModelComponent($event)"
 | 
			
		||||
                                [scriptAccounts]="gameModel!.scriptAccounts"></app-gamesystem-editor>
 | 
			
		||||
    <app-character-editor *ngIf="modelComponent.type === ModelComponentType.CHARACTER"
 | 
			
		||||
                                [character]="convertModelComponentToCharacter(modelComponent)"
 | 
			
		||||
                                [gameModel]="gameModel!">
 | 
			
		||||
                                [gameModel]="gameModel!" [character]="convertModelComponentToCharacter(modelComponent)">
 | 
			
		||||
 | 
			
		||||
    </app-character-editor>
 | 
			
		||||
  </mat-tab>
 | 
			
		||||
 | 
			
		||||
@ -54,7 +54,7 @@ export class EditorComponent {
 | 
			
		||||
 | 
			
		||||
  convertModelComponentToCharacter(modelComponent: ModelComponent) {
 | 
			
		||||
    if(modelComponent instanceof Character) {
 | 
			
		||||
      return modelComponent as Character
 | 
			
		||||
      return modelComponent as Character;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,10 +1,4 @@
 | 
			
		||||
<mat-form-field appearance="fill">
 | 
			
		||||
  <mat-label>Templatetype</mat-label>
 | 
			
		||||
  <mat-select [(ngModel)]="gamesystem!.template">
 | 
			
		||||
    <mat-option [value]="TemplateType.NONE">None</mat-option>
 | 
			
		||||
    <mat-option [value]="TemplateType.CHARACTER">Character</mat-option>
 | 
			
		||||
  </mat-select>
 | 
			
		||||
</mat-form-field>
 | 
			
		||||
<app-simple-gamesystem-editor *ngIf="isSimpleGamesystem()" [simpleGamesystem]="convertGamesystemToSimpleGamesystem()" [scriptAccunts]="scriptAccounts"></app-simple-gamesystem-editor>
 | 
			
		||||
<app-simple-gamesystem-editor *ngIf="isSimpleGamesystem()" [simpleGamesystem]="convertGamesystemToSimpleGamesystem()" [scriptAccunts]="scriptAccounts"
 | 
			
		||||
                  [templateReference]="templateReference"></app-simple-gamesystem-editor>
 | 
			
		||||
<app-product-gamesystem-editor *ngIf="!isSimpleGamesystem()" [gamesystem]="convertGamesystemToProductGamesystem()"
 | 
			
		||||
                               (onOpenGamesystemEditor)="onOpenGamesystemEditor($event)"></app-product-gamesystem-editor>
 | 
			
		||||
 | 
			
		||||
@ -5,7 +5,8 @@ import { Transition } from '../../project/game-model/gamesystems/transitions/Tra
 | 
			
		||||
import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccount";
 | 
			
		||||
import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem";
 | 
			
		||||
import {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem";
 | 
			
		||||
import {TemplateType} from "../../project/game-model/gamesystems/TemplateType";
 | 
			
		||||
import {SimpleTemplateGamesystem} from "../../project/game-model/gamesystems/SimpleTemplateGamesystem";
 | 
			
		||||
import {Character} from "../../project/game-model/characters/Character";
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'app-gamesystem-editor',
 | 
			
		||||
@ -16,6 +17,7 @@ export class GamesystemEditorComponent implements OnInit{
 | 
			
		||||
 | 
			
		||||
  @Input() gamesystem: Gamesystem<State<any>, Transition<any>> | undefined
 | 
			
		||||
  @Input() scriptAccounts: ScriptAccount[] = [];
 | 
			
		||||
  @Input() templateReference: Character | undefined
 | 
			
		||||
  @Output('onOpenGamesystemEditor') openGamesystemEmitter = new EventEmitter<SimpleGamesystem>();
 | 
			
		||||
 | 
			
		||||
  ngOnInit() {
 | 
			
		||||
@ -23,11 +25,11 @@ export class GamesystemEditorComponent implements OnInit{
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  isSimpleGamesystem() {
 | 
			
		||||
    return this.gamesystem instanceof SimpleGamesystem;
 | 
			
		||||
    return this.gamesystem instanceof SimpleGamesystem || this.gamesystem instanceof SimpleTemplateGamesystem;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  convertGamesystemToSimpleGamesystem() {
 | 
			
		||||
    if(this.gamesystem instanceof SimpleGamesystem) {
 | 
			
		||||
    if(!(this.gamesystem instanceof ProductGamesystem)) {
 | 
			
		||||
      return this.gamesystem as SimpleGamesystem;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@ -41,6 +43,4 @@ export class GamesystemEditorComponent implements OnInit{
 | 
			
		||||
  onOpenGamesystemEditor(gamesystem: SimpleGamesystem) {
 | 
			
		||||
    this.openGamesystemEmitter.emit(gamesystem);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected readonly TemplateType = TemplateType;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
<app-simple-state-editor [states]="simpleGamesystem!.states" [gamesystem]="simpleGamesystem" [scriptAccounts]="scriptAccunts"></app-simple-state-editor>
 | 
			
		||||
<app-simple-state-editor [states]="simpleGamesystem!.states" [gamesystem]="simpleGamesystem" [scriptAccounts]="scriptAccunts" [templateReference]="templateReference"></app-simple-state-editor>
 | 
			
		||||
<div id="transition-editor">
 | 
			
		||||
  <app-simple-transition-editor [gamesystem]="simpleGamesystem" [scriptAccounts]="scriptAccunts"></app-simple-transition-editor>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
@ -1,17 +1,24 @@
 | 
			
		||||
import {Component, Input} from '@angular/core';
 | 
			
		||||
import {Component, Input, OnInit} from '@angular/core';
 | 
			
		||||
import {MatTableDataSource} from "@angular/material/table";
 | 
			
		||||
import {SimpleGamesystem} from "../../../project/game-model/gamesystems/SimpleGamesystem";
 | 
			
		||||
import {ScriptAccount} from "../../../project/game-model/scriptAccounts/ScriptAccount";
 | 
			
		||||
import {SimpleTemplateGamesystem} from "../../../project/game-model/gamesystems/SimpleTemplateGamesystem";
 | 
			
		||||
import {Character} from "../../../project/game-model/characters/Character";
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'app-simple-gamesystem-editor',
 | 
			
		||||
  templateUrl: './simple-gamesystem-editor.component.html',
 | 
			
		||||
  styleUrl: './simple-gamesystem-editor.component.scss'
 | 
			
		||||
})
 | 
			
		||||
export class SimpleGamesystemEditorComponent {
 | 
			
		||||
export class SimpleGamesystemEditorComponent implements OnInit{
 | 
			
		||||
 | 
			
		||||
  @Input() simpleGamesystem: SimpleGamesystem | undefined
 | 
			
		||||
  @Input() simpleGamesystem: SimpleGamesystem | SimpleTemplateGamesystem<any> | undefined
 | 
			
		||||
  @Input() scriptAccunts: ScriptAccount[] = []
 | 
			
		||||
  @Input() templateReference: Character | undefined
 | 
			
		||||
 | 
			
		||||
  ngOnInit(): void {
 | 
			
		||||
    console.log("SimpleGamesystem: ", this.simpleGamesystem)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -27,7 +27,7 @@
 | 
			
		||||
            </mat-form-field>
 | 
			
		||||
 | 
			
		||||
            <div class="long-form">
 | 
			
		||||
              <app-scriptaccount-condition-editor [conditions]="element.conditions" [scriptAccounts]="scriptAccounts" [enableEditiong]="true"
 | 
			
		||||
              <app-scriptaccount-condition-editor [conditions]="getStateConditions(element)" [scriptAccounts]="scriptAccounts" [enableEditiong]="true"
 | 
			
		||||
                                                  (onCreateCondition)="onCreateCondition(element, $event)" (onDeleteCondition)="deleteCondition(element, $event)"></app-scriptaccount-condition-editor>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,8 @@ import {SimpleState} from "../../../../project/game-model/gamesystems/states/Sim
 | 
			
		||||
import {SimpleGamesystem} from "../../../../project/game-model/gamesystems/SimpleGamesystem";
 | 
			
		||||
import {ScriptAccount} from "../../../../project/game-model/scriptAccounts/ScriptAccount";
 | 
			
		||||
import {ScriptAccountCondition} from "../../../../project/game-model/gamesystems/conditions/ScriptAccountCondition";
 | 
			
		||||
import {Character} from "../../../../project/game-model/characters/Character";
 | 
			
		||||
import {SimpleTemplateState} from "../../../../project/game-model/gamesystems/states/SimpleTemplateState";
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'app-simple-state-editor',
 | 
			
		||||
@ -24,6 +26,8 @@ export class SimpleStateEditorComponent implements OnInit{
 | 
			
		||||
  @Input() states: SimpleState[] = [];
 | 
			
		||||
  @Input() gamesystem: SimpleGamesystem | undefined
 | 
			
		||||
  @Input() scriptAccounts: ScriptAccount[] = []
 | 
			
		||||
  @Input() templateReference: Character | undefined
 | 
			
		||||
 | 
			
		||||
  dataSource = new MatTableDataSource<SimpleState>();
 | 
			
		||||
  displayedColumns = ["name", "initial", "edit", "delete"];
 | 
			
		||||
  columnsToDisplayWithExpand = [...this.displayedColumns, 'expand'];
 | 
			
		||||
@ -96,11 +100,33 @@ export class SimpleStateEditorComponent implements OnInit{
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  onCreateCondition(state: SimpleState, condition: ScriptAccountCondition) {
 | 
			
		||||
    state.addScriptAccountCondition(condition);
 | 
			
		||||
    if(this.templateReference instanceof Character) {
 | 
			
		||||
      const templateState = state as SimpleTemplateState<Character>
 | 
			
		||||
      console.log("CharacterRef: ", this.templateReference);
 | 
			
		||||
      templateState.conditionMap.get(this.templateReference as Character)!.push(condition)
 | 
			
		||||
      console.log(templateState)
 | 
			
		||||
    } else {
 | 
			
		||||
      state.addScriptAccountCondition(condition);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  deleteCondition(state: SimpleState, condition: ScriptAccountCondition) {
 | 
			
		||||
    state.removeScriptAccountCondition(condition.scriptAccount);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getStateConditions(state: SimpleState) {
 | 
			
		||||
    if(state instanceof SimpleTemplateState) {
 | 
			
		||||
      if(this.templateReference instanceof Character) {
 | 
			
		||||
        const referenceSpecificConditions = state.conditionMap.get(this.templateReference as Character)
 | 
			
		||||
        if(referenceSpecificConditions == undefined) {
 | 
			
		||||
          return []
 | 
			
		||||
        } else {
 | 
			
		||||
          return referenceSpecificConditions;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return state.conditions;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,13 @@
 | 
			
		||||
<h1 mat-dialog-title>Specify Gamesystem</h1>
 | 
			
		||||
<div matDialogContent>
 | 
			
		||||
  <mat-form-field appearance="outline" style="width: 100%">
 | 
			
		||||
    <mat-label>Referencesystem</mat-label>
 | 
			
		||||
    <mat-select [formControl]="templateCtrl">
 | 
			
		||||
      <mat-option *ngFor="let gamesystem of templateGamesystems" [value]="gamesystem">{{gamesystem.componentName}}</mat-option>
 | 
			
		||||
    </mat-select>
 | 
			
		||||
  </mat-form-field>
 | 
			
		||||
</div>
 | 
			
		||||
<div matDialogActions align="end">
 | 
			
		||||
  <button mat-stroked-button (click)="cancel()">Cancel</button>
 | 
			
		||||
  <button mat-raised-button color="accent" (click)="save()">Specify</button>
 | 
			
		||||
</div>
 | 
			
		||||
@ -0,0 +1,23 @@
 | 
			
		||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
 | 
			
		||||
 | 
			
		||||
import { TemplateCreatorComponent } from './template-creator.component';
 | 
			
		||||
 | 
			
		||||
describe('TemplateCreatorComponent', () => {
 | 
			
		||||
  let component: TemplateCreatorComponent;
 | 
			
		||||
  let fixture: ComponentFixture<TemplateCreatorComponent>;
 | 
			
		||||
 | 
			
		||||
  beforeEach(async () => {
 | 
			
		||||
    await TestBed.configureTestingModule({
 | 
			
		||||
      imports: [TemplateCreatorComponent]
 | 
			
		||||
    })
 | 
			
		||||
    .compileComponents();
 | 
			
		||||
    
 | 
			
		||||
    fixture = TestBed.createComponent(TemplateCreatorComponent);
 | 
			
		||||
    component = fixture.componentInstance;
 | 
			
		||||
    fixture.detectChanges();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('should create', () => {
 | 
			
		||||
    expect(component).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
@ -0,0 +1,26 @@
 | 
			
		||||
import {Component, Inject} from '@angular/core';
 | 
			
		||||
import {MAT_DIALOG_DATA, MatDialogRef, MatDialogTitle} from "@angular/material/dialog";
 | 
			
		||||
import {SimpleTemplateGamesystem} from "../../../project/game-model/gamesystems/SimpleTemplateGamesystem";
 | 
			
		||||
import {FormControl, Validators} from "@angular/forms";
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'app-template-creator',
 | 
			
		||||
  templateUrl: './template-creator.component.html',
 | 
			
		||||
  styleUrl: './template-creator.component.scss'
 | 
			
		||||
})
 | 
			
		||||
export class TemplateCreatorComponent {
 | 
			
		||||
 | 
			
		||||
  templateCtrl = new FormControl('', [Validators.required]);
 | 
			
		||||
 | 
			
		||||
  constructor(@Inject(MAT_DIALOG_DATA) public templateGamesystems: SimpleTemplateGamesystem<any>[],
 | 
			
		||||
              private dialogRef: MatDialogRef<TemplateCreatorComponent>)  {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  cancel() {
 | 
			
		||||
    this.dialogRef.close();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  save() {
 | 
			
		||||
    this.dialogRef.close(this.templateCtrl.value)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -5,10 +5,11 @@ import {State} from "./gamesystems/states/State";
 | 
			
		||||
import {ProductGamesystem} from "./gamesystems/ProductGamesystem";
 | 
			
		||||
import {SimpleGamesystem} from "./gamesystems/SimpleGamesystem";
 | 
			
		||||
import {Character} from "./characters/Character";
 | 
			
		||||
import {ModelComponentType} from "./ModelComponentType";
 | 
			
		||||
import {TemplateType} from "./gamesystems/TemplateType";
 | 
			
		||||
import {TemplateType} from "./TemplateType";
 | 
			
		||||
import {SimpleTemplateGamesystem} from "./gamesystems/SimpleTemplateGamesystem";
 | 
			
		||||
 | 
			
		||||
export class GameModel {
 | 
			
		||||
 | 
			
		||||
  gameModelName: string
 | 
			
		||||
 | 
			
		||||
  gamesystems: Gamesystem<any, any>[] = [];
 | 
			
		||||
@ -46,9 +47,14 @@ export class GameModel {
 | 
			
		||||
    return undefined;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  createGamesystem(gamesystemName: string, parentGamesystemName: string | undefined) {
 | 
			
		||||
  createGamesystem(gamesystemName: string, parentGamesystemName: string | undefined, templateType: TemplateType) {
 | 
			
		||||
    if(gamesystemName != undefined && this.findGamesystem(gamesystemName) == undefined) {
 | 
			
		||||
      const simpleGamesystem = new SimpleGamesystem(gamesystemName, "");
 | 
			
		||||
      let simpleGamesystem = new SimpleGamesystem(gamesystemName, "");
 | 
			
		||||
      if(templateType == TemplateType.CHARACTER) {
 | 
			
		||||
        simpleGamesystem = new SimpleTemplateGamesystem<Character>(gamesystemName, "")
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
      if(parentGamesystemName != undefined) {
 | 
			
		||||
        const parentGamesystem = this.findGamesystem(parentGamesystemName);
 | 
			
		||||
        if(parentGamesystem instanceof SimpleGamesystem) {
 | 
			
		||||
@ -117,22 +123,24 @@ export class GameModel {
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getTemplateGamesystems(templateType: TemplateType) {
 | 
			
		||||
    const gamesystems = this.getGamesystemsAsList()
 | 
			
		||||
    return gamesystems.filter(gamesystem => gamesystem.template === templateType);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private getGamesystemsAsList() : Gamesystem<any, any>[]{
 | 
			
		||||
    const gamesystemList: Gamesystem<any, any>[] = []
 | 
			
		||||
 | 
			
		||||
    const gamesystemQueue : Gamesystem<any, any>[] = this.gamesystems.map(gamesystem => gamesystem)
 | 
			
		||||
  listGamesystems(templateType: TemplateType): SimpleTemplateGamesystem<any>[] {
 | 
			
		||||
    const gamesystemList:  SimpleTemplateGamesystem<any>[] = []
 | 
			
		||||
    const gamesystemQueue: Gamesystem<any, any>[] = this.gamesystems.concat()
 | 
			
		||||
    while(gamesystemQueue.length > 0) {
 | 
			
		||||
      const currentGamesystem = gamesystemQueue.shift()!;
 | 
			
		||||
      gamesystemList.push(currentGamesystem)
 | 
			
		||||
 | 
			
		||||
      if(currentGamesystem.templateType === templateType) {
 | 
			
		||||
        gamesystemList.push(currentGamesystem as SimpleTemplateGamesystem<any>)
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if(currentGamesystem instanceof ProductGamesystem) {
 | 
			
		||||
        currentGamesystem.innerGamesystems.forEach(innerGamesystem => gamesystemQueue.push(innerGamesystem))
 | 
			
		||||
        currentGamesystem.innerGamesystems.forEach(innerGamesystem => {
 | 
			
		||||
          gamesystemQueue.push(innerGamesystem)
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return gamesystemList
 | 
			
		||||
 | 
			
		||||
    console.log(gamesystemList)
 | 
			
		||||
    return gamesystemList;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										3
									
								
								src/app/project/game-model/TemplateType.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/app/project/game-model/TemplateType.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
			
		||||
export enum TemplateType {
 | 
			
		||||
  NORMAL, CHARACTER
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								src/app/project/game-model/TemplateTypeUtilities.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/app/project/game-model/TemplateTypeUtilities.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
import {TemplateType} from "./TemplateType";
 | 
			
		||||
 | 
			
		||||
export class TemplateTypeUtilities {
 | 
			
		||||
  static fromString(value: string) {
 | 
			
		||||
    if(value === 'character') {
 | 
			
		||||
      return TemplateType.CHARACTER
 | 
			
		||||
    } else {
 | 
			
		||||
      return TemplateType.NORMAL
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -1,35 +1,24 @@
 | 
			
		||||
import {ModelComponent} from "../ModelComponent";
 | 
			
		||||
import {ModelComponentType} from "../ModelComponentType";
 | 
			
		||||
import { Gamesystem } from "../gamesystems/Gamesystem";
 | 
			
		||||
import { ProductGamesystem } from "../gamesystems/ProductGamesystem";
 | 
			
		||||
import { ProductTemplateGamesystem } from "../gamesystems/ProductTemplateGamesystem";
 | 
			
		||||
import { SimpleGamesystem } from "../gamesystems/SimpleGamesystem";
 | 
			
		||||
import { SimpleTemplateGamesystem } from "../gamesystems/SimpleTemplateGamesystem";
 | 
			
		||||
import {SimpleTemplateGamesystem} from "../gamesystems/SimpleTemplateGamesystem";
 | 
			
		||||
 | 
			
		||||
export class Character extends ModelComponent{
 | 
			
		||||
 | 
			
		||||
  characterSpecificGamesystems: Gamesystem<any, any>[] = []
 | 
			
		||||
  characterSpecificGamesystems: SimpleTemplateGamesystem<Character>[] = []
 | 
			
		||||
 | 
			
		||||
  constructor(componentName: string, componentDescription: string) {
 | 
			
		||||
    super(componentName, componentDescription, ModelComponentType.CHARACTER);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  addCharacterSpecificSimpleGamesystem(referenceSystem: SimpleGamesystem) {
 | 
			
		||||
    if(!this.findCharacterSpecificGameystemByName(referenceSystem.componentName)) {
 | 
			
		||||
      const templateGamesystem = new SimpleTemplateGamesystem(referenceSystem);
 | 
			
		||||
      this.characterSpecificGamesystems.push(templateGamesystem)
 | 
			
		||||
  addCharacterSpecificGamesystem(templateGamesystem: SimpleTemplateGamesystem<Character>) {
 | 
			
		||||
    if(!this.isGamesystemCharacterSpecific(templateGamesystem.componentName)) {
 | 
			
		||||
      this.characterSpecificGamesystems.push(templateGamesystem);
 | 
			
		||||
      templateGamesystem.addReferenceKey(this);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  addCharacterSpecificProductTemplateGamesystem(referenceSystem: ProductGamesystem) {
 | 
			
		||||
    if(!this.findCharacterSpecificGameystemByName(referenceSystem.componentName)) {
 | 
			
		||||
      const templateGamesystem = new ProductTemplateGamesystem(referenceSystem);
 | 
			
		||||
      this.characterSpecificGamesystems.push(templateGamesystem)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  findCharacterSpecificGameystemByName(referenceName: string) {
 | 
			
		||||
    return this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === referenceName) != undefined
 | 
			
		||||
  private isGamesystemCharacterSpecific(gamesystemName: string) {
 | 
			
		||||
    const characterSpecificGamesystem = this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === gamesystemName);
 | 
			
		||||
    return characterSpecificGamesystem != undefined
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -2,14 +2,16 @@ import {SimpleGamesystem} from "./SimpleGamesystem";
 | 
			
		||||
import {ProductGamesystem} from "./ProductGamesystem";
 | 
			
		||||
import {ModelComponent} from "../ModelComponent";
 | 
			
		||||
import {ModelComponentType} from "../ModelComponentType";
 | 
			
		||||
import {TemplateType} from "./TemplateType";
 | 
			
		||||
import {TemplateType} from "../TemplateType";
 | 
			
		||||
 | 
			
		||||
export abstract class Gamesystem<S, T> extends ModelComponent{
 | 
			
		||||
 | 
			
		||||
  states: S[] = [];
 | 
			
		||||
  transitions: T[] = [];
 | 
			
		||||
  parentGamesystem: ProductGamesystem | undefined
 | 
			
		||||
  template: TemplateType = TemplateType.NONE
 | 
			
		||||
 | 
			
		||||
  templateType: TemplateType = TemplateType.NORMAL
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  constructor(gamesystemName: string, gamesystemDescription: string) {
 | 
			
		||||
   super(gamesystemName, gamesystemDescription, ModelComponentType.GAMESYTEM);
 | 
			
		||||
 | 
			
		||||
@ -1,42 +1,70 @@
 | 
			
		||||
import { SimpleGamesystem } from "./SimpleGamesystem";
 | 
			
		||||
import { ScriptAccountAction } from "./actions/ScriptAccountAction";
 | 
			
		||||
import { ScriptAccountCondition } from "./conditions/ScriptAccountCondition";
 | 
			
		||||
import { SimpleState } from "./states/SimpleState";
 | 
			
		||||
import { SimpleTransition } from "./transitions/SimpleTransition";
 | 
			
		||||
import {SimpleTemplateState} from "./states/SimpleTemplateState";
 | 
			
		||||
import {Gamesystem} from "./Gamesystem";
 | 
			
		||||
import {SimpleState} from "./states/SimpleState";
 | 
			
		||||
import {SimpleTemplateTransition} from "./transitions/SimpleTemplateTransition";
 | 
			
		||||
import {TemplateType} from "../TemplateType";
 | 
			
		||||
 | 
			
		||||
export class SimpleTemplateGamesystem extends SimpleGamesystem {
 | 
			
		||||
  referenceSystem: SimpleGamesystem
 | 
			
		||||
export class SimpleTemplateGamesystem<ReferenceType> extends Gamesystem<SimpleTemplateState<ReferenceType>, SimpleTemplateTransition<ReferenceType>> {
 | 
			
		||||
  createState(label: string, description: string): SimpleState | undefined {
 | 
			
		||||
    if(label == null) {
 | 
			
		||||
      return undefined;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  constructor(referenceSystem: SimpleGamesystem) {
 | 
			
		||||
    super(referenceSystem.componentName, referenceSystem.componentDescription)
 | 
			
		||||
    this.referenceSystem = referenceSystem;
 | 
			
		||||
    if(description == null) {
 | 
			
		||||
      description = "";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this.referenceSystem.states.forEach(state => {
 | 
			
		||||
      const templateState = new SimpleState(state.stateLabel, state.stateDescription)
 | 
			
		||||
      templateState.initial = state.initial;
 | 
			
		||||
      templateState.conditions = state.conditions.map(condition => ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue, condition.maxValue)!)
 | 
			
		||||
 | 
			
		||||
      this.states.push(templateState);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    this.referenceSystem.transitions.forEach(transition => {
 | 
			
		||||
      const startingState = this.findStateByStateLabel(transition.startingState.stateLabel);
 | 
			
		||||
      const endingState = this.findStateByStateLabel(transition.endingState.stateLabel);
 | 
			
		||||
 | 
			
		||||
      const templateTransition = new SimpleTransition(startingState!, endingState!)
 | 
			
		||||
 | 
			
		||||
      templateTransition.scriptAccountConditions = transition.scriptAccountConditions.map(condition =>
 | 
			
		||||
          ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue, condition.maxValue)!)
 | 
			
		||||
 | 
			
		||||
      templateTransition.scriptAccountActions = transition.scriptAccountActions.map(action => {
 | 
			
		||||
        return new ScriptAccountAction(action.scriptAccount, action.changingValue);
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      this.transitions.push(templateTransition);
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    this.referenceSystem.addTemplateSystem(this)
 | 
			
		||||
    const state = new SimpleTemplateState<ReferenceType>(label, description);
 | 
			
		||||
    if(this.states.find(s => s.stateLabel == label) == undefined) {
 | 
			
		||||
      this.states.push(state);
 | 
			
		||||
      return state;
 | 
			
		||||
    } else {
 | 
			
		||||
      return undefined
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  createTransition(startingState: SimpleTemplateState<ReferenceType>, endingState: SimpleTemplateState<ReferenceType>): SimpleTemplateTransition<ReferenceType> | undefined {
 | 
			
		||||
    if((startingState == null || endingState == null) || startingState === endingState) {
 | 
			
		||||
      return undefined;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const transition = new SimpleTemplateTransition<ReferenceType>(startingState, endingState);
 | 
			
		||||
    if(this.transitions.find(t => t.startingState === startingState && t.endingState === endingState) == undefined) {
 | 
			
		||||
      this.transitions.push(transition)
 | 
			
		||||
      return transition;
 | 
			
		||||
    } else {
 | 
			
		||||
      startingState.removeOutgoingTransition(transition);
 | 
			
		||||
      endingState.removeIncomingTransition(transition);
 | 
			
		||||
      return undefined
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  removeState(state: SimpleTemplateState<ReferenceType>): boolean {
 | 
			
		||||
    const updatedStates = this.states.filter(s => s !== state);
 | 
			
		||||
    const updated = updatedStates.length != this.states.length;
 | 
			
		||||
    this.states = updatedStates;
 | 
			
		||||
 | 
			
		||||
    this.transitions = this.transitions.filter(t => t.startingState !== state && t.endingState !== state);
 | 
			
		||||
 | 
			
		||||
    return updated;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  addReferenceKey(reference: ReferenceType) {
 | 
			
		||||
    this.states.forEach(state => {
 | 
			
		||||
      if(!state.conditionMap.has(reference)) {
 | 
			
		||||
        state.conditionMap.set(reference, state.conditions.concat())
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    this.transitions.forEach(transition => {
 | 
			
		||||
      if(!transition.conditions.has(reference)) {
 | 
			
		||||
        transition.conditions.set(reference, transition.scriptAccountConditions.concat())
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if(!transition.actions.has(reference)) {
 | 
			
		||||
        transition.actions.set(reference, transition.scriptAccountActions.concat())
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,8 @@
 | 
			
		||||
import {SimpleState} from "./SimpleState";
 | 
			
		||||
import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition";
 | 
			
		||||
 | 
			
		||||
export class SimpleTemplateState<ReferenceType> extends SimpleState {
 | 
			
		||||
 | 
			
		||||
  conditionMap: Map<ReferenceType, ScriptAccountCondition[]> = new Map<ReferenceType, ScriptAccountCondition[]>()
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,9 @@
 | 
			
		||||
import {SimpleTransition} from "./SimpleTransition";
 | 
			
		||||
import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition";
 | 
			
		||||
import {ScriptAccountAction} from "../actions/ScriptAccountAction";
 | 
			
		||||
 | 
			
		||||
export class SimpleTemplateTransition<ReferenceType> extends SimpleTransition {
 | 
			
		||||
 | 
			
		||||
  conditions: Map<ReferenceType, ScriptAccountCondition[]> = new Map();
 | 
			
		||||
  actions: Map<ReferenceType, ScriptAccountAction[]> = new Map();
 | 
			
		||||
}
 | 
			
		||||
@ -1,9 +1,21 @@
 | 
			
		||||
import {StoreComponent} from "../../../../../app/storage/StoreComponent";
 | 
			
		||||
import {Character} from "../../game-model/characters/Character";
 | 
			
		||||
import {SimpleTemplateGamesystem} from "../../game-model/gamesystems/SimpleTemplateGamesystem";
 | 
			
		||||
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
 | 
			
		||||
import {ScriptAccountParser} from "../ScriptAccountParser";
 | 
			
		||||
import {ScriptAccountConditionParser} from "../gamesystemParser/ScriptAccountConditionParser";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
export class CharacterParser {
 | 
			
		||||
 | 
			
		||||
  characterSpecificGamesystems: SimpleTemplateGamesystem<Character>[]
 | 
			
		||||
  scriptAccountConditionParser: ScriptAccountConditionParser
 | 
			
		||||
 | 
			
		||||
  constructor(characterSpecificGamesystems: SimpleTemplateGamesystem<Character>[], scriptAccounts: ScriptAccount[]) {
 | 
			
		||||
    this.characterSpecificGamesystems = characterSpecificGamesystems;
 | 
			
		||||
    this.scriptAccountConditionParser = new ScriptAccountConditionParser(scriptAccounts)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public parseCharacters(characters: StoreComponent[]): Character[] {
 | 
			
		||||
    const loadedCharacters: Character[] = []
 | 
			
		||||
    characters.forEach(character => loadedCharacters.push(this.parseSingleCharacter(JSON.parse(character.jsonString))))
 | 
			
		||||
@ -11,6 +23,41 @@ export class CharacterParser {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private parseSingleCharacter(characterData: any): Character {
 | 
			
		||||
    return new Character(characterData.componentName, characterData.componentDescription);
 | 
			
		||||
    const character = new Character(characterData.componentName, characterData.componentDescription);
 | 
			
		||||
    character.characterSpecificGamesystems = this.parseCharacterSpecificGamesystems(character, characterData.characterSpecificGamesystems);
 | 
			
		||||
    return character;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private parseCharacterSpecificGamesystems(character: Character, characterSpecificGamesystems: any): SimpleTemplateGamesystem<Character>[] {
 | 
			
		||||
    const result: SimpleTemplateGamesystem<Character>[] = []
 | 
			
		||||
    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<Character> | 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)!
 | 
			
		||||
 | 
			
		||||
        const conditions = this.scriptAccountConditionParser.parseStoredConditions(stateReference.conditionMap);
 | 
			
		||||
 | 
			
		||||
        state.conditionMap.set(character, conditions)
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return referencedGamesystem;
 | 
			
		||||
  }
 | 
			
		||||
  private findCharacterSpecificGamesystem(componentName: string): SimpleTemplateGamesystem<Character> | undefined{
 | 
			
		||||
    return this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === componentName)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private findReferencedState(gamesystem: SimpleTemplateGamesystem<Character>, stateLabel: string) {
 | 
			
		||||
    return gamesystem.states.find(state => state.stateLabel === stateLabel);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,9 @@ import {SimpleGamesystem} from "../../game-model/gamesystems/SimpleGamesystem";
 | 
			
		||||
import {StateParser} from "./StateParser";
 | 
			
		||||
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
 | 
			
		||||
import {TransitionParser} from "./TransitionParser";
 | 
			
		||||
import {TemplateType} from "../../game-model/TemplateType";
 | 
			
		||||
import {SimpleTemplateGamesystem} from "../../game-model/gamesystems/SimpleTemplateGamesystem";
 | 
			
		||||
import {Character} from "../../game-model/characters/Character";
 | 
			
		||||
 | 
			
		||||
export class GamesystemParser {
 | 
			
		||||
 | 
			
		||||
@ -40,15 +43,20 @@ export class GamesystemParser {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  parseSimpleGamesystem(gamesystemData: any): SimpleGamesystem {
 | 
			
		||||
    const simpleGamesystem = new SimpleGamesystem(gamesystemData.componentName, gamesystemData.componentDescription)
 | 
			
		||||
    const templateType = gamesystemData.templateType
 | 
			
		||||
    let simpleGamesystem = new SimpleGamesystem(gamesystemData.componentName, gamesystemData.componentDescription)
 | 
			
		||||
    if(templateType == TemplateType.CHARACTER) {
 | 
			
		||||
      simpleGamesystem = new SimpleTemplateGamesystem<Character>(gamesystemData.componentName, gamesystemData.componentDescription)
 | 
			
		||||
      simpleGamesystem.templateType = TemplateType.CHARACTER
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const stateParser = new StateParser(this.scriptAccounts);
 | 
			
		||||
    simpleGamesystem.states = stateParser.parseStates(gamesystemData.states)
 | 
			
		||||
    simpleGamesystem.states = stateParser.parseStates(gamesystemData.states, templateType)
 | 
			
		||||
 | 
			
		||||
    const transitionParser = new TransitionParser(simpleGamesystem.states, this.scriptAccounts)
 | 
			
		||||
    simpleGamesystem.transitions = transitionParser.parseTransitions(gamesystemData.transitions)
 | 
			
		||||
 | 
			
		||||
    simpleGamesystem.template = gamesystemData.template;
 | 
			
		||||
 | 
			
		||||
    return simpleGamesystem
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -86,4 +94,8 @@ export class GamesystemParser {
 | 
			
		||||
    return undefined
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getParsedTemplateGamesystems(templateType: TemplateType) {
 | 
			
		||||
    const templateGamesystems =  this.parsedGamesystems.filter(gamesystem => gamesystem.templateType === templateType);
 | 
			
		||||
    return templateGamesystems.map(gamesystem => gamesystem as SimpleTemplateGamesystem<any>)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,9 @@ import {SimpleState} from "../../game-model/gamesystems/states/SimpleState";
 | 
			
		||||
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
 | 
			
		||||
import {ScriptAccountCondition} from "../../game-model/gamesystems/conditions/ScriptAccountCondition";
 | 
			
		||||
import {ScriptAccountConditionParser} from "./ScriptAccountConditionParser";
 | 
			
		||||
import {TemplateType} from "../../game-model/TemplateType";
 | 
			
		||||
import {SimpleTemplateState} from "../../game-model/gamesystems/states/SimpleTemplateState";
 | 
			
		||||
import {Character} from "../../game-model/characters/Character";
 | 
			
		||||
 | 
			
		||||
export class StateParser {
 | 
			
		||||
 | 
			
		||||
@ -12,23 +15,29 @@ export class StateParser {
 | 
			
		||||
      this.conditionParser = new ScriptAccountConditionParser(scriptAccounts)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public  parseStates(stateData: any): SimpleState[] {
 | 
			
		||||
    public  parseStates(stateData: any, templateType: TemplateType): SimpleState[] {
 | 
			
		||||
      const parsedStates: SimpleState[] = []
 | 
			
		||||
      for(let i=0; i<stateData.length; i++) {
 | 
			
		||||
        parsedStates.push(this.parseState(stateData[i]))
 | 
			
		||||
        parsedStates.push(this.parseState(stateData[i], templateType))
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      return parsedStates;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
   private parseState(stateData: any): SimpleState {
 | 
			
		||||
   private parseState(stateData: any, templateType: TemplateType): SimpleState {
 | 
			
		||||
      const initial = stateData.initial
 | 
			
		||||
      const stateLabel = stateData.stateLabel
 | 
			
		||||
      const stateDescription = stateData.stateDescription
 | 
			
		||||
 | 
			
		||||
      const conditions = this.conditionParser.parseStoredConditions(stateData.conditions)
 | 
			
		||||
 | 
			
		||||
      const simpleState = new SimpleState(stateLabel, stateDescription);
 | 
			
		||||
      let simpleState;
 | 
			
		||||
      if(templateType === TemplateType.NORMAL) {
 | 
			
		||||
        simpleState = new SimpleState(stateLabel, stateDescription);
 | 
			
		||||
      } else {
 | 
			
		||||
        simpleState = new SimpleTemplateState<Character>(stateLabel, stateDescription);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      simpleState.initial = initial;
 | 
			
		||||
      simpleState.conditions = conditions;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -2,9 +2,13 @@ import {Character} from "../game-model/characters/Character";
 | 
			
		||||
import {StoreComponent} from "../../../../app/storage/StoreComponent";
 | 
			
		||||
import {SerializeConstants} from "./SerializeConstants";
 | 
			
		||||
import {ModelComponentType} from "../game-model/ModelComponentType";
 | 
			
		||||
import {Gamesystem} from "../game-model/gamesystems/Gamesystem";
 | 
			
		||||
import {ScriptAccount} from "../game-model/scriptAccounts/ScriptAccount";
 | 
			
		||||
 | 
			
		||||
export class CharacterSerializer {
 | 
			
		||||
 | 
			
		||||
  private static ignoredKeys: string[] = ['unsaved', 'type', 'incomingTransitions', 'outgoingTransitions', 'initial', 'conditions', 'stateDescription', 'templateType']
 | 
			
		||||
 | 
			
		||||
  public static serializeCharacters(characters: Character[]): StoreComponent[] {
 | 
			
		||||
    const storedCharacters: StoreComponent[] = []
 | 
			
		||||
    characters.forEach(character => storedCharacters.push(this.serializeSingleCharacter(character)))
 | 
			
		||||
@ -14,7 +18,22 @@ export class CharacterSerializer {
 | 
			
		||||
  private static serializeSingleCharacter(character: Character): StoreComponent{
 | 
			
		||||
    const fileName = character.componentName
 | 
			
		||||
    const jsonString = JSON.stringify(character, (key, value) => {
 | 
			
		||||
      if(key === 'unsaved' || key === 'type') {
 | 
			
		||||
      if(value instanceof Gamesystem) {
 | 
			
		||||
        return {
 | 
			
		||||
          ...value,
 | 
			
		||||
          componentDescription: undefined
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if(key === 'scriptAccount') {
 | 
			
		||||
        return value.componentName
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if(key === 'conditionMap') {
 | 
			
		||||
        return value.get(character)
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if(this.ignoredKeys.includes(key)) {
 | 
			
		||||
        return undefined
 | 
			
		||||
      } else {
 | 
			
		||||
        return value;
 | 
			
		||||
 | 
			
		||||
@ -4,10 +4,11 @@ import {SimpleGamesystem} from "../game-model/gamesystems/SimpleGamesystem";
 | 
			
		||||
import {ProductGamesystem} from "../game-model/gamesystems/ProductGamesystem";
 | 
			
		||||
import {SerializeConstants} from "./SerializeConstants";
 | 
			
		||||
import {ModelComponentType} from "../game-model/ModelComponentType";
 | 
			
		||||
import {SimpleTemplateGamesystem} from "../game-model/gamesystems/SimpleTemplateGamesystem";
 | 
			
		||||
 | 
			
		||||
export class GamesystemSerializer {
 | 
			
		||||
 | 
			
		||||
  private static IGNORED_SIMPLE_ATTRIBUTES  = ["parentGamesystem", 'incomingTransitions', "outgoingTransitions", "unsaved", "type"]
 | 
			
		||||
  private static IGNORED_SIMPLE_ATTRIBUTES  = ["parentGamesystem", 'incomingTransitions', "outgoingTransitions", "unsaved", "type", "conditionMap"]
 | 
			
		||||
 | 
			
		||||
  public static serializeGamesystems(gamesystems: Gamesystem<any, any>[]): StoreComponent[] {
 | 
			
		||||
    let storedGamesystems: StoreComponent[] = []
 | 
			
		||||
@ -16,7 +17,7 @@ export class GamesystemSerializer {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static serializeSingleGamesystem(gamesystem: Gamesystem<any, any>): StoreComponent[] {
 | 
			
		||||
    if(gamesystem instanceof SimpleGamesystem) {
 | 
			
		||||
    if(gamesystem instanceof SimpleGamesystem || gamesystem instanceof SimpleTemplateGamesystem) {
 | 
			
		||||
      console.log("Simple Gamesystem")
 | 
			
		||||
      return [this.serializeSimpleGamesystem(gamesystem as SimpleGamesystem)]
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,4 @@
 | 
			
		||||
{
 | 
			
		||||
    "componentName": "Astrid Hofferson",
 | 
			
		||||
    "componentDescription": "",
 | 
			
		||||
    "characterSpecificGamesystems": []
 | 
			
		||||
}
 | 
			
		||||
@ -1,5 +1,26 @@
 | 
			
		||||
{
 | 
			
		||||
    "componentName": "Hicks Haddock",
 | 
			
		||||
    "componentDescription": "",
 | 
			
		||||
    "characterSpecificGamesystems": []
 | 
			
		||||
    "componentDescription": "Das ist ein Test",
 | 
			
		||||
    "characterSpecificGamesystems": [
 | 
			
		||||
        {
 | 
			
		||||
            "componentName": "Characterstimmung",
 | 
			
		||||
            "states": [
 | 
			
		||||
                {
 | 
			
		||||
                    "stateLabel": "Fröhlich",
 | 
			
		||||
                    "conditionMap": [
 | 
			
		||||
                        {
 | 
			
		||||
                            "scriptAccount": "Luftfeuchtigkeit",
 | 
			
		||||
                            "minValue": 0,
 | 
			
		||||
                            "maxValue": "10"
 | 
			
		||||
                        }
 | 
			
		||||
                    ]
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    "stateLabel": "Wütend",
 | 
			
		||||
                    "conditionMap": []
 | 
			
		||||
                }
 | 
			
		||||
            ],
 | 
			
		||||
            "transitions": []
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
@ -1,7 +1,20 @@
 | 
			
		||||
{
 | 
			
		||||
    "componentName": "Characterstimmung",
 | 
			
		||||
    "componentDescription": "",
 | 
			
		||||
    "states": [],
 | 
			
		||||
    "states": [
 | 
			
		||||
        {
 | 
			
		||||
            "initial": true,
 | 
			
		||||
            "conditions": [],
 | 
			
		||||
            "stateLabel": "Fröhlich",
 | 
			
		||||
            "stateDescription": ""
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
            "initial": false,
 | 
			
		||||
            "conditions": [],
 | 
			
		||||
            "stateLabel": "Wütend",
 | 
			
		||||
            "stateDescription": ""
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    "transitions": [],
 | 
			
		||||
    "template": 1
 | 
			
		||||
    "templateType": 1
 | 
			
		||||
}
 | 
			
		||||
@ -34,5 +34,5 @@
 | 
			
		||||
            "endingState": "B"
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    "template": 0
 | 
			
		||||
    "templateType": 0
 | 
			
		||||
}
 | 
			
		||||
@ -77,5 +77,5 @@
 | 
			
		||||
            "endingState": "Frühling"
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    "template": 0
 | 
			
		||||
    "templateType": 0
 | 
			
		||||
}
 | 
			
		||||
@ -77,5 +77,5 @@
 | 
			
		||||
            "endingState": "Wolke"
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    "template": 0
 | 
			
		||||
    "templateType": 0
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user