issue-15 #21
							
								
								
									
										41
									
								
								app/storage/loader/GamesystemLoader.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								app/storage/loader/GamesystemLoader.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,41 @@
 | 
				
			|||||||
 | 
					"use strict";
 | 
				
			||||||
 | 
					Object.defineProperty(exports, "__esModule", { value: true });
 | 
				
			||||||
 | 
					exports.GamesystemLoader = void 0;
 | 
				
			||||||
 | 
					const StoreComponent_1 = require("../StoreComponent");
 | 
				
			||||||
 | 
					const FileUtils_1 = require("../FileUtils");
 | 
				
			||||||
 | 
					const fs = require("fs");
 | 
				
			||||||
 | 
					const path = require("node:path");
 | 
				
			||||||
 | 
					const ModelComponentType_1 = require("../../../src/app/project/game-model/ModelComponentType");
 | 
				
			||||||
 | 
					class GamesystemLoader {
 | 
				
			||||||
 | 
					    constructor(gamesystemDir) {
 | 
				
			||||||
 | 
					        this.gamesystemDir = gamesystemDir;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    loadGamesystems() {
 | 
				
			||||||
 | 
					        return this.loadGamesystemsRecursivly(this.gamesystemDir);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    loadGamesystemsRecursivly(currentGamesystemDir) {
 | 
				
			||||||
 | 
					        let loadedGamesystems = [];
 | 
				
			||||||
 | 
					        const gamesystemFiles = FileUtils_1.FileUtils.listFilesInDirectory(currentGamesystemDir);
 | 
				
			||||||
 | 
					        gamesystemFiles.forEach(gamesystemFile => {
 | 
				
			||||||
 | 
					            if (fs.lstatSync(gamesystemFile).isDirectory()) {
 | 
				
			||||||
 | 
					                const childGamesystems = this.loadGamesystemsRecursivly(gamesystemFile);
 | 
				
			||||||
 | 
					                loadedGamesystems = loadedGamesystems.concat(childGamesystems);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else if (path.basename(gamesystemFile).endsWith(".json")) {
 | 
				
			||||||
 | 
					                const loadedGamesystem = this.loadGamesystem(gamesystemFile);
 | 
				
			||||||
 | 
					                if (loadedGamesystem != undefined) {
 | 
				
			||||||
 | 
					                    loadedGamesystems.push(loadedGamesystem);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        return loadedGamesystems;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    loadGamesystem(gamesystemFile) {
 | 
				
			||||||
 | 
					        if (gamesystemFile.endsWith(".json")) {
 | 
				
			||||||
 | 
					            const gamesystemData = fs.readFileSync(gamesystemFile, 'utf-8');
 | 
				
			||||||
 | 
					            return new StoreComponent_1.StoreComponent(gamesystemData, gamesystemFile, ModelComponentType_1.ModelComponentType.GAMESYTEM);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					exports.GamesystemLoader = GamesystemLoader;
 | 
				
			||||||
 | 
					//# sourceMappingURL=GamesystemLoader.js.map
 | 
				
			||||||
@ -1,4 +1,4 @@
 | 
				
			|||||||
import {Component, NgZone, OnInit, ViewChild} from '@angular/core';
 | 
					import {Component, OnInit, ViewChild} from '@angular/core';
 | 
				
			||||||
import {MatDrawerContainer} from "@angular/material/sidenav";
 | 
					import {MatDrawerContainer} from "@angular/material/sidenav";
 | 
				
			||||||
import {EditorComponent} from "./editor/editor.component";
 | 
					import {EditorComponent} from "./editor/editor.component";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
@ -7,14 +7,16 @@ import {
 | 
				
			|||||||
import {MatDialog} from "@angular/material/dialog";
 | 
					import {MatDialog} from "@angular/material/dialog";
 | 
				
			||||||
import {DeleteConfirmationDialogComponent} from "./delete-confirmation-dialog/delete-confirmation-dialog.component";
 | 
					import {DeleteConfirmationDialogComponent} from "./delete-confirmation-dialog/delete-confirmation-dialog.component";
 | 
				
			||||||
import {GamescriptOverviewComponent} from "./side-overviews/gamescript-overview/gamescript-overview.component";
 | 
					import {GamescriptOverviewComponent} from "./side-overviews/gamescript-overview/gamescript-overview.component";
 | 
				
			||||||
 | 
					 | 
				
			||||||
import {ProjectService} from "./project/project.service";
 | 
					 | 
				
			||||||
import {ModelComponentType} from "./project/game-model/ModelComponentType";
 | 
					import {ModelComponentType} from "./project/game-model/ModelComponentType";
 | 
				
			||||||
import {ModelComponentTypeUtillities} from "./project/game-model/ModelComponentTypeUtillities";
 | 
					import {ModelComponentTypeUtillities} from "./project/game-model/ModelComponentTypeUtillities";
 | 
				
			||||||
import {ScriptAccount} from "./project/game-model/scriptAccounts/ScriptAccount";
 | 
					import {ScriptAccount} from "./project/game-model/scriptAccounts/ScriptAccount";
 | 
				
			||||||
import {Gamesystem} from "./project/game-model/gamesystems/Gamesystem";
 | 
					import {Gamesystem} from "./project/game-model/gamesystems/Gamesystem";
 | 
				
			||||||
import {ModelComponent} from "./project/game-model/ModelComponent";
 | 
					import {ModelComponent} from "./project/game-model/ModelComponent";
 | 
				
			||||||
import {GameModel} from "./project/game-model/GameModel";
 | 
					import {GameModel} from "./project/game-model/GameModel";
 | 
				
			||||||
 | 
					import {StoredGameModel} from "../../app/storage/StoredGameModel";
 | 
				
			||||||
 | 
					import {GamesystemParser} from "./project/parser/gamesystemParser/GamesystemParser";
 | 
				
			||||||
 | 
					import {ScriptAccountParser} from "./project/parser/ScriptAccountParser";
 | 
				
			||||||
 | 
					import {ElectronService} from "./core/services";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Component({
 | 
					@Component({
 | 
				
			||||||
  selector: 'app-root',
 | 
					  selector: 'app-root',
 | 
				
			||||||
@ -31,9 +33,8 @@ export class AppComponent implements OnInit{
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  gameModel: GameModel | undefined
 | 
					  gameModel: GameModel | undefined
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(private zone: NgZone,
 | 
					  constructor(private electronService: ElectronService,
 | 
				
			||||||
              private dialog: MatDialog,
 | 
					              private dialog: MatDialog
 | 
				
			||||||
              private projectService: ProjectService
 | 
					 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -63,7 +64,7 @@ export class AppComponent implements OnInit{
 | 
				
			|||||||
      } break;
 | 
					      } break;
 | 
				
			||||||
      case ModelComponentType.GAMESYTEM: {
 | 
					      case ModelComponentType.GAMESYTEM: {
 | 
				
			||||||
        if(this.gamesystemOverview!.selectedGamesystem != undefined) {
 | 
					        if(this.gamesystemOverview!.selectedGamesystem != undefined) {
 | 
				
			||||||
          const gamesystem = this.projectService!.gameModel!.findGamesystem(this.gamesystemOverview!.selectedGamesystemName!);
 | 
					          const gamesystem = this.gameModel!.findGamesystem(this.gamesystemOverview!.selectedGamesystemName!);
 | 
				
			||||||
          this.editor!.openGameModelComponent(gamesystem!);
 | 
					          this.editor!.openGameModelComponent(gamesystem!);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      } break
 | 
					      } break
 | 
				
			||||||
@ -78,7 +79,7 @@ export class AppComponent implements OnInit{
 | 
				
			|||||||
    dialogRef.afterClosed().subscribe(res => {
 | 
					    dialogRef.afterClosed().subscribe(res => {
 | 
				
			||||||
      if(res != undefined && res) {
 | 
					      if(res != undefined && res) {
 | 
				
			||||||
        if(affectedModelComponent instanceof ScriptAccount) {
 | 
					        if(affectedModelComponent instanceof ScriptAccount) {
 | 
				
			||||||
          this.projectService!.gameModel!.removeScriptAccount(affectedModelComponent);
 | 
					          this.gameModel!.removeScriptAccount(affectedModelComponent);
 | 
				
			||||||
          //this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.SCRIPTACCOUNT))
 | 
					          //this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.SCRIPTACCOUNT))
 | 
				
			||||||
        } else if(affectedModelComponent instanceof Gamesystem) {
 | 
					        } else if(affectedModelComponent instanceof Gamesystem) {
 | 
				
			||||||
          //this.gameModel!.removeGamesystem(affectedModelComponent);
 | 
					          //this.gameModel!.removeGamesystem(affectedModelComponent);
 | 
				
			||||||
@ -97,7 +98,7 @@ export class AppComponent implements OnInit{
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private onCreateNewScriptAccount() {
 | 
					  private onCreateNewScriptAccount() {
 | 
				
			||||||
    const createdScriptAccount = this.projectService!.gameModel!.createScriptAccount("New ScriptAccount");
 | 
					    const createdScriptAccount = this.gameModel!.createScriptAccount("New ScriptAccount");
 | 
				
			||||||
    if(createdScriptAccount != undefined) {
 | 
					    if(createdScriptAccount != undefined) {
 | 
				
			||||||
      this.editor?.openGameModelComponent(createdScriptAccount);
 | 
					      this.editor?.openGameModelComponent(createdScriptAccount);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
@ -114,7 +115,7 @@ export class AppComponent implements OnInit{
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const createdGamesystem = this.projectService!.gameModel!.createGamesystem("New Gamesystem", parentGamesystemName);
 | 
					    const createdGamesystem = this.gameModel!.createGamesystem("New Gamesystem", parentGamesystemName);
 | 
				
			||||||
    if(createdGamesystem != undefined) {
 | 
					    if(createdGamesystem != undefined) {
 | 
				
			||||||
      this.gamesystemOverview!.refresh();
 | 
					      this.gamesystemOverview!.refresh();
 | 
				
			||||||
      this.editor?.openGameModelComponent(createdGamesystem);
 | 
					      this.editor?.openGameModelComponent(createdGamesystem);
 | 
				
			||||||
@ -124,13 +125,13 @@ export class AppComponent implements OnInit{
 | 
				
			|||||||
  private getSelectedModelComponent(): ModelComponent | undefined {
 | 
					  private getSelectedModelComponent(): ModelComponent | undefined {
 | 
				
			||||||
    if(this.openContent == ModelComponentType.SCRIPTACCOUNT) {
 | 
					    if(this.openContent == ModelComponentType.SCRIPTACCOUNT) {
 | 
				
			||||||
      if(this.scriptAccountOverview != undefined) {
 | 
					      if(this.scriptAccountOverview != undefined) {
 | 
				
			||||||
        return this.scriptAccountOverview!.selectedScriptAccount;
 | 
					        return this.scriptAccountOverview.selectedScriptAccount;
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        console.log("[WARN] [App.component] ScriptAccountOverview is undefined")
 | 
					        console.log("[WARN] [App.component] ScriptAccountOverview is undefined")
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    } else if(this.openContent == ModelComponentType.GAMESYTEM){
 | 
					    } else if(this.openContent == ModelComponentType.GAMESYTEM){
 | 
				
			||||||
      if(this.gamesystemOverview != undefined) {
 | 
					      if(this.gamesystemOverview != undefined) {
 | 
				
			||||||
        return this.gamesystemOverview!.getSelectedGamesystem()
 | 
					        return this.gamesystemOverview.getSelectedGamesystem()
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        console.log("[WARN] [App.component] GamesystemOverview is undefined")
 | 
					        console.log("[WARN] [App.component] GamesystemOverview is undefined")
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@ -139,30 +140,41 @@ export class AppComponent implements OnInit{
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngOnInit() {
 | 
					  ngOnInit() {
 | 
				
			||||||
    this.gameModel = this.projectService.gameModel
 | 
					    if(this.electronService.isElectron) {
 | 
				
			||||||
    /*this.gameModel = new GameModel("No More");
 | 
					      this.electronService.ipcRenderer.on('get-project-data', () => {
 | 
				
			||||||
    this.gameModel.createScriptAccount("Temperature");
 | 
					        this.onSaveProject();
 | 
				
			||||||
    this.gameModel.createScriptAccount("Luftfeuchtigkeit");
 | 
					      })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const weather = new SimpleGamesystem("Weather");
 | 
					      this.electronService.ipcRenderer.on('open-project', (event: any, loadedProject: StoredGameModel) => {
 | 
				
			||||||
    const season = new SimpleGamesystem("Season");
 | 
					        this.onLoadProject(loadedProject);
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const springState = season.createState("Spring", "Spring, also known as springtime, is one of the four temperate seasons, succeeding winter and preceding summer.");
 | 
					  onLoadProject(storedGameModel: StoredGameModel) {
 | 
				
			||||||
    const summerState = season.createState("Summer", "Summer is the hottest and brightest of the four temperate seasons, occurring after spring and before autumn. ");
 | 
					    const gameModel = new GameModel(storedGameModel.gameModelName)
 | 
				
			||||||
 | 
					    const gamesystemParser = new GamesystemParser();
 | 
				
			||||||
 | 
					    storedGameModel.loadedModels.forEach(storedComponent => {
 | 
				
			||||||
 | 
					      switch (storedComponent.componentType) {
 | 
				
			||||||
 | 
					        case ModelComponentType.SCRIPTACCOUNT: {
 | 
				
			||||||
 | 
					          const scriptAccount = ScriptAccountParser.parseScriptAccount(storedComponent);
 | 
				
			||||||
 | 
					          gameModel.addScriptAccount(scriptAccount);
 | 
				
			||||||
 | 
					        } break
 | 
				
			||||||
 | 
					        case ModelComponentType.GAMESYTEM: {
 | 
				
			||||||
 | 
					          gamesystemParser.parseGamesystem(storedComponent);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const sunnyState = weather.createState("Sunny", "The sun is shining. No clouds, no rain, no storm.");
 | 
					    gamesystemParser.computeGamesystemStructure().forEach(topGamesystem => {
 | 
				
			||||||
    const rainingState = weather.createState("Raining", "It rains")
 | 
					      gameModel.addGamesystem(topGamesystem)
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    season.createTransition(springState!, summerState!);
 | 
					    this.gameModel = gameModel;
 | 
				
			||||||
    weather.createTransition(sunnyState!, rainingState!);
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const weather_season = new ProductGamesystem("Weather-Season");
 | 
					  onSaveProject() {
 | 
				
			||||||
    weather_season.addChildGamesystem(weather);
 | 
					 | 
				
			||||||
    weather_season.addChildGamesystem(season);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    weather_season.createState([springState!, sunnyState!]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    this.gameModel.addGamesystem(weather_season);*/
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  openScriptAccountsOverview() {
 | 
					  openScriptAccountsOverview() {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,16 +0,0 @@
 | 
				
			|||||||
import { TestBed } from '@angular/core/testing';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import { ProjectService } from './project.service';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
describe('ProjectService', () => {
 | 
					 | 
				
			||||||
  let service: ProjectService;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  beforeEach(() => {
 | 
					 | 
				
			||||||
    TestBed.configureTestingModule({});
 | 
					 | 
				
			||||||
    service = TestBed.inject(ProjectService);
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  it('should be created', () => {
 | 
					 | 
				
			||||||
    expect(service).toBeTruthy();
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
@ -1,57 +0,0 @@
 | 
				
			|||||||
import { Injectable } from '@angular/core';
 | 
					 | 
				
			||||||
import {ElectronService} from "../core/services";
 | 
					 | 
				
			||||||
import {GameModel} from "./game-model/GameModel";
 | 
					 | 
				
			||||||
import {StoredGameModel} from "../../../app/storage/StoredGameModel";
 | 
					 | 
				
			||||||
import {ScriptAccount} from "./game-model/scriptAccounts/ScriptAccount";
 | 
					 | 
				
			||||||
import {ModelComponentType} from "./game-model/ModelComponentType";
 | 
					 | 
				
			||||||
import {ScriptAccountParser} from "./parser/ScriptAccountParser";
 | 
					 | 
				
			||||||
import {GamesystemParser} from "./parser/gamesystemParser/GamesystemParser";
 | 
					 | 
				
			||||||
import {Gamesystem} from "./game-model/gamesystems/Gamesystem";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@Injectable({
 | 
					 | 
				
			||||||
  providedIn: 'root'
 | 
					 | 
				
			||||||
})
 | 
					 | 
				
			||||||
export class ProjectService {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  gameModel: GameModel = new GameModel("New GameModel")
 | 
					 | 
				
			||||||
  constructor(private electronService: ElectronService) {
 | 
					 | 
				
			||||||
    if(electronService.isElectron) {
 | 
					 | 
				
			||||||
      electronService.ipcRenderer.on('get-project-data', (event: any, message: string) => {
 | 
					 | 
				
			||||||
        this.saveProject();
 | 
					 | 
				
			||||||
      })
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      electronService.ipcRenderer.on('open-project', (event: any, loadedProject: StoredGameModel) => {
 | 
					 | 
				
			||||||
        this.loadProject(loadedProject);
 | 
					 | 
				
			||||||
      })
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  saveProject() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  loadProject(storedGameModel: StoredGameModel) {
 | 
					 | 
				
			||||||
    const gameModel = new GameModel(storedGameModel.gameModelName)
 | 
					 | 
				
			||||||
    const gamesystemParser = new GamesystemParser();
 | 
					 | 
				
			||||||
    storedGameModel.loadedModels.forEach(storedComponent => {
 | 
					 | 
				
			||||||
      switch (storedComponent.componentType) {
 | 
					 | 
				
			||||||
        case ModelComponentType.SCRIPTACCOUNT: {
 | 
					 | 
				
			||||||
          const scriptAccount = ScriptAccountParser.parseScriptAccount(storedComponent);
 | 
					 | 
				
			||||||
          gameModel.addScriptAccount(scriptAccount);
 | 
					 | 
				
			||||||
        } break
 | 
					 | 
				
			||||||
        case ModelComponentType.GAMESYTEM: {
 | 
					 | 
				
			||||||
          gamesystemParser.parseGamesystem(storedComponent);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    gamesystemParser.computeGamesystemStructure().forEach(topGamesystem => {
 | 
					 | 
				
			||||||
      gameModel.addGamesystem(topGamesystem)
 | 
					 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    console.log(gameModel)
 | 
					 | 
				
			||||||
    this.gameModel = gameModel;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user