From 8016f55e8557e36482e84349ee8d976ff2ee8d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Wed, 20 Mar 2024 09:26:14 +0100 Subject: [PATCH] Refactor Loading of ScriptAccounts --- app/DeleteModel.js | 50 -------- app/DeleteModel.ts | 50 -------- app/LoadModel.js | 11 -- app/LoadModel.ts | 12 -- app/LoadedProject.js | 11 -- app/LoadedProject.ts | 12 -- app/RecursiveLoadModel.js | 12 -- app/RecursiveLoadModel.ts | 12 -- app/SaveProject.js | 105 ---------------- app/SaveProject.ts | 114 ------------------ app/StorageModel.ts | 12 -- app/main.ts | 22 ++-- app/storage/FileUtils.ts | 13 ++ app/storage/ModelComponentFileDirectory.ts | 6 + app/storage/StoreComponent.ts | 13 ++ app/storage/StoredGameModel.ts | 12 ++ app/storage/loader/GameModelLoader.ts | 43 +++++++ app/storage/loader/ScriptAccountLoader.ts | 34 ++++++ src/app/app.component.html | 2 +- src/app/app.component.ts | 74 +++--------- .../delete-confirmation-dialog.component.ts | 5 +- src/app/editor/editor.component.ts | 18 +-- .../gamesystem-editor.component.ts | 13 +- .../LeafGamesystemCalculator.ts | 12 +- .../product-gamesystem-editor.component.ts | 5 +- ...criptaccount-condition-editor.component.ts | 4 +- .../simple-gamesystem-editor.component.ts | 4 +- .../product-state-editor.component.ts | 11 +- .../simple-state-editor.component.ts | 10 +- .../product-transition-editor.component.ts | 8 +- .../scriptaccount-action-editor.component.ts | 6 +- .../simple-transition-editor.component.ts | 10 +- .../model-component-editor.component.ts | 2 +- .../script-account-editor.component.ts | 4 +- src/app/{ => project}/game-model/GameModel.ts | 0 .../game-model/ModelComponent.ts | 0 .../game-model/ModelComponentType.ts | 0 .../ModelComponentTypeUtillities.ts | 0 .../{ => project}/game-model/SaveComponent.ts | 0 .../game-model/fs/DeleteModel.ts | 0 .../game-model/fs/ProcessLoadedProject.ts | 0 .../game-model/fs/StorageModel.ts | 0 .../fs/parser/ProductGamesystemParser.ts | 0 .../fs/parser/SimpleGamesystemParser.ts | 0 .../game-model/fs/store/StoreProject.ts | 0 .../game-model/game-model.module.ts | 0 .../game-model/gamesystems/Gamesystem.ts | 0 .../gamesystems/ProductGamesystem.ts | 1 - .../gamesystems/SimpleGamesystem.ts | 0 .../actions/ScriptAccountAction.ts | 0 .../conditions/ScriptAccountCondition.ts | 0 .../gamesystems/states/ProductState.ts | 0 .../gamesystems/states/SimpleState.ts | 0 .../game-model/gamesystems/states/State.ts | 0 .../transitions/ProductTransition.ts | 0 .../transitions/SimpleTransition.ts | 0 .../gamesystems/transitions/Transition.ts | 0 .../scriptAccounts/ScriptAccount.ts | 0 src/app/project/parser/ScriptAccountParser.ts | 12 ++ .../gamescript-overview.component.ts | 12 +- .../script-account-overview.component.ts | 4 +- 61 files changed, 223 insertions(+), 538 deletions(-) delete mode 100644 app/DeleteModel.js delete mode 100644 app/DeleteModel.ts delete mode 100644 app/LoadModel.js delete mode 100644 app/LoadModel.ts delete mode 100644 app/LoadedProject.js delete mode 100644 app/LoadedProject.ts delete mode 100644 app/RecursiveLoadModel.js delete mode 100644 app/RecursiveLoadModel.ts delete mode 100644 app/SaveProject.js delete mode 100644 app/SaveProject.ts delete mode 100644 app/StorageModel.ts create mode 100644 app/storage/FileUtils.ts create mode 100644 app/storage/ModelComponentFileDirectory.ts create mode 100644 app/storage/StoreComponent.ts create mode 100644 app/storage/StoredGameModel.ts create mode 100644 app/storage/loader/GameModelLoader.ts create mode 100644 app/storage/loader/ScriptAccountLoader.ts rename src/app/{ => project}/game-model/GameModel.ts (100%) rename src/app/{ => project}/game-model/ModelComponent.ts (100%) rename src/app/{ => project}/game-model/ModelComponentType.ts (100%) rename src/app/{ => project}/game-model/ModelComponentTypeUtillities.ts (100%) rename src/app/{ => project}/game-model/SaveComponent.ts (100%) rename src/app/{ => project}/game-model/fs/DeleteModel.ts (100%) rename src/app/{ => project}/game-model/fs/ProcessLoadedProject.ts (100%) rename src/app/{ => project}/game-model/fs/StorageModel.ts (100%) rename src/app/{ => project}/game-model/fs/parser/ProductGamesystemParser.ts (100%) rename src/app/{ => project}/game-model/fs/parser/SimpleGamesystemParser.ts (100%) rename src/app/{ => project}/game-model/fs/store/StoreProject.ts (100%) rename src/app/{ => project}/game-model/game-model.module.ts (100%) rename src/app/{ => project}/game-model/gamesystems/Gamesystem.ts (100%) rename src/app/{ => project}/game-model/gamesystems/ProductGamesystem.ts (99%) rename src/app/{ => project}/game-model/gamesystems/SimpleGamesystem.ts (100%) rename src/app/{ => project}/game-model/gamesystems/actions/ScriptAccountAction.ts (100%) rename src/app/{ => project}/game-model/gamesystems/conditions/ScriptAccountCondition.ts (100%) rename src/app/{ => project}/game-model/gamesystems/states/ProductState.ts (100%) rename src/app/{ => project}/game-model/gamesystems/states/SimpleState.ts (100%) rename src/app/{ => project}/game-model/gamesystems/states/State.ts (100%) rename src/app/{ => project}/game-model/gamesystems/transitions/ProductTransition.ts (100%) rename src/app/{ => project}/game-model/gamesystems/transitions/SimpleTransition.ts (100%) rename src/app/{ => project}/game-model/gamesystems/transitions/Transition.ts (100%) rename src/app/{ => project}/game-model/scriptAccounts/ScriptAccount.ts (100%) create mode 100644 src/app/project/parser/ScriptAccountParser.ts diff --git a/app/DeleteModel.js b/app/DeleteModel.js deleted file mode 100644 index c9d7b3f..0000000 --- a/app/DeleteModel.js +++ /dev/null @@ -1,50 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.DeleteTransaction = void 0; -const path = require("node:path"); -const fs = require("fs"); -class DeleteTransaction { - static deleteScriptAccount(projectDir, componentName) { - const filename = path.join(projectDir, "script-accounts", componentName + ".json"); - fs.unlinkSync(filename); - console.log("Delete ", filename); - } - static deleteGamesystem(projectDir, componentName) { - const gamesystemDir = path.join(projectDir, "gamesystems"); - const gamesystemFile = this.findGamesystemPath(gamesystemDir, componentName); - try { - if (gamesystemFile != undefined) { - console.log("Delete Gamesystem under File: ", gamesystemFile); - if (fs.lstatSync(gamesystemFile).isDirectory()) { - fs.rmSync(gamesystemFile, { recursive: true, force: true }); - } - else { - fs.unlinkSync(gamesystemFile); - } - } - } - catch (e) { - console.log(e); - } - } - static findGamesystemPath(gamesystemRootDir, searchedFilename) { - const directoriesToProcess = []; - directoriesToProcess.push(gamesystemRootDir); - while (directoriesToProcess.length > 0) { - const currentDirectory = directoriesToProcess.shift(); - const filesInDirectory = fs.readdirSync(currentDirectory); - for (let i = 0; i < filesInDirectory.length; i++) { - const currentFile = path.join(currentDirectory, filesInDirectory[i]); - if (fs.lstatSync(currentFile).isDirectory()) { - directoriesToProcess.push(currentFile); - } - if (path.parse(path.basename(currentFile)).name === searchedFilename) { - return currentFile; - } - } - } - return undefined; - } -} -exports.DeleteTransaction = DeleteTransaction; -//# sourceMappingURL=DeleteModel.js.map \ No newline at end of file diff --git a/app/DeleteModel.ts b/app/DeleteModel.ts deleted file mode 100644 index 3ac58f2..0000000 --- a/app/DeleteModel.ts +++ /dev/null @@ -1,50 +0,0 @@ -import * as path from "node:path"; -import * as fs from "fs"; -import {json} from "node:stream/consumers"; - -export class DeleteTransaction { - static deleteScriptAccount(projectDir: string, componentName: string) { - const filename = path.join(projectDir, "script-accounts", componentName + ".json") - fs.unlinkSync(filename) - console.log("Delete ", filename) - } - - static deleteGamesystem(projectDir: string, componentName: string) { - const gamesystemDir = path.join(projectDir, "gamesystems") - const gamesystemFile = this.findGamesystemPath(gamesystemDir, componentName) - try { - if(gamesystemFile != undefined) { - console.log("Delete Gamesystem under File: ", gamesystemFile) - if(fs.lstatSync(gamesystemFile).isDirectory()) { - fs.rmSync(gamesystemFile, {recursive: true, force: true}) - } else { - fs.unlinkSync(gamesystemFile) - } - } - }catch (e) { - console.log(e) - } - - } - - static findGamesystemPath(gamesystemRootDir: string, searchedFilename: string) { - const directoriesToProcess: string[] = []; - directoriesToProcess.push(gamesystemRootDir); - while(directoriesToProcess.length > 0) { - const currentDirectory = directoriesToProcess.shift(); - const filesInDirectory = fs.readdirSync(currentDirectory!) - for(let i=0; i { - let modelDir = path.join(projectDir, storageModel.storageRootDir); - storageModel.storagePath.forEach(pathElement => modelDir = path.join(modelDir, pathElement)); - if (!fs.existsSync(modelDir)) { - fs.mkdirSync(modelDir, { recursive: true }); - } - const filePath = path.join(modelDir, storageModel.fileName + ".json"); - fs.writeFile(filePath, storageModel.jsonString, 'utf-8', (err) => { - if (err) { - console.error('Error writing JSON to file:', err); - } - else { - console.log('JSON file saved successfully:', filePath); - } - }); - }); - } - static loadProject(projectDir) { - let loadedScriptAccounts = SaveProject.loadScriptAccounts(projectDir); - loadedScriptAccounts = loadedScriptAccounts.concat(SaveProject.loadGamesystems(projectDir)); - return new LoadedProject_1.LoadedProject(path.basename(projectDir), loadedScriptAccounts); - } - static loadScriptAccounts(projectDir) { - const scriptAccountDir = path.join(projectDir, "script-accounts"); - if (!fs.existsSync(scriptAccountDir)) { - return []; - } - const loadedScriptAccounts = []; - const scriptAccountFileNames = fs.readdirSync(scriptAccountDir); - scriptAccountFileNames.forEach(scriptAccountFileName => { - const scriptAccountFile = path.join(scriptAccountDir, scriptAccountFileName); - const scriptAccountData = fs.readFileSync(scriptAccountFile, 'utf-8'); - loadedScriptAccounts.push({ - modelType: ModelComponentType_1.ModelComponentType.SCRIPTACCOUNT, - jsonString: scriptAccountData - }); - }); - return loadedScriptAccounts; - } - static loadGamesystems(projectDir) { - const gamesystemDir = path.join(projectDir, "gamesystems"); - if (fs.existsSync(gamesystemDir)) { - const loadedGamesystems = this.loadGamesystemsRecursively(gamesystemDir); - console.log("LoadedGamesystems: ", loadedGamesystems.length); - return loadedGamesystems; - } - else { - return []; - } - } - static loadGamesystemsRecursively(gamesystemDir) { - let loadedGamesystems = []; - const gamesystemFileNames = fs.readdirSync(gamesystemDir); - gamesystemFileNames.forEach(fileName => { - const gamesystemPath = path.join(gamesystemDir, fileName); - if (fs.lstatSync(gamesystemPath).isDirectory()) { - const childModels = SaveProject.loadGamesystemsRecursively(gamesystemPath); - loadedGamesystems = loadedGamesystems.concat(childModels); - } - else { - const gamesystemData = fs.readFileSync(path.join(gamesystemDir, fileName), "utf-8"); - if (path.parse(fileName).name === path.basename(gamesystemDir)) { - if ((path.basename(gamesystemDir) === path.parse(fileName).name) && path.basename(path.parse(gamesystemDir).dir) === "gamesystems") { - const loadedModel = new LoadModel_1.LoadModel(gamesystemData, ModelComponentType_1.ModelComponentType.GAMESYTEM); - loadedGamesystems.unshift(loadedModel); - } - else { - const loadedModel = new RecursiveLoadModel_1.RecursiveLoadModel(gamesystemData, ModelComponentType_1.ModelComponentType.GAMESYTEM, path.basename(gamesystemDir)); - loadedGamesystems.unshift(loadedModel); - } - } - else { - const secondCon = path.basename(gamesystemDir) === path.parse(fileName).name; - const thirdCon = path.basename(path.parse(gamesystemDir).dir) === "gamesystems"; - if (path.basename(gamesystemDir) === "gamesystems") { - const loadedModel = new LoadModel_1.LoadModel(gamesystemData, ModelComponentType_1.ModelComponentType.GAMESYTEM); - loadedGamesystems.push(loadedModel); - } - else { - const loadedModel = new RecursiveLoadModel_1.RecursiveLoadModel(gamesystemData, ModelComponentType_1.ModelComponentType.GAMESYTEM, path.basename(gamesystemDir)); - loadedGamesystems.push(loadedModel); - } - } - } - }); - return loadedGamesystems; - } -} -exports.SaveProject = SaveProject; -//# sourceMappingURL=SaveProject.js.map \ No newline at end of file diff --git a/app/SaveProject.ts b/app/SaveProject.ts deleted file mode 100644 index a042f9e..0000000 --- a/app/SaveProject.ts +++ /dev/null @@ -1,114 +0,0 @@ -import {StorageModel} from "../src/app/game-model/fs/StorageModel"; -import * as fs from "fs"; -import * as path from "node:path"; -import {LoadModel} from "./LoadModel"; -import {ModelComponentType} from "../src/app/game-model/ModelComponentType"; -import {LoadedProject} from "./LoadedProject"; -import {RecursiveLoadModel} from "./RecursiveLoadModel"; - - -export class SaveProject { - static saveProject(projectDir: string, storageModels: StorageModel[]) { - if(!fs.existsSync(projectDir)) { - fs.mkdirSync(projectDir, {recursive: true}); - } - - console.log(storageModels) - storageModels.forEach(storageModel => { - let modelDir = path.join(projectDir, storageModel.storageRootDir); - storageModel.storagePath.forEach(pathElement => modelDir = path.join(modelDir, pathElement)); - if(!fs.existsSync(modelDir)) { - fs.mkdirSync(modelDir, {recursive: true}); - } - - const filePath = path.join(modelDir, storageModel.fileName + ".json"); - fs.writeFile(filePath, storageModel.jsonString ,'utf-8', (err) => { - if (err) { - console.error('Error writing JSON to file:', err); - } else { - console.log('JSON file saved successfully:', filePath); - } - }) - }) - } - - static loadProject(projectDir: string) { - let loadedScriptAccounts: LoadModel[] = SaveProject.loadScriptAccounts(projectDir) - loadedScriptAccounts = loadedScriptAccounts.concat(SaveProject.loadGamesystems(projectDir)) - return new LoadedProject(path.basename(projectDir), loadedScriptAccounts); - } - - static loadScriptAccounts(projectDir: string): LoadModel[] { - const scriptAccountDir = path.join(projectDir, "script-accounts"); - if (!fs.existsSync(scriptAccountDir)) { - return []; - } - - const loadedScriptAccounts: LoadModel[] = []; - - const scriptAccountFileNames = fs.readdirSync(scriptAccountDir); - scriptAccountFileNames.forEach(scriptAccountFileName => { - const scriptAccountFile = path.join(scriptAccountDir, scriptAccountFileName) - const scriptAccountData: string = fs.readFileSync(scriptAccountFile, 'utf-8'); - - loadedScriptAccounts.push({ - modelType: ModelComponentType.SCRIPTACCOUNT, - jsonString: scriptAccountData - }); - }) - - return loadedScriptAccounts; - } - - static loadGamesystems(projectDir: string): LoadModel[] { - const gamesystemDir = path.join(projectDir, "gamesystems"); - if(fs.existsSync(gamesystemDir)) { - const loadedGamesystems = this.loadGamesystemsRecursively(gamesystemDir); - console.log("LoadedGamesystems: ", loadedGamesystems.length); - return loadedGamesystems; - } else { - return [] - } - } - - static loadGamesystemsRecursively(gamesystemDir: string): LoadModel[] { - let loadedGamesystems: LoadModel[] = []; - const gamesystemFileNames = fs.readdirSync(gamesystemDir); - - gamesystemFileNames.forEach(fileName => { - const gamesystemPath = path.join(gamesystemDir, fileName); - - if(fs.lstatSync(gamesystemPath).isDirectory()) { - const childModels: LoadModel[] = SaveProject.loadGamesystemsRecursively(gamesystemPath); - loadedGamesystems = loadedGamesystems.concat(childModels); - } else { - const gamesystemData = fs.readFileSync(path.join(gamesystemDir, fileName), "utf-8"); - if(path.parse(fileName).name === path.basename(gamesystemDir) ) { - if((path.basename(gamesystemDir) === path.parse(fileName).name) && path.basename(path.parse(gamesystemDir).dir) === "gamesystems") { - const loadedModel = new LoadModel(gamesystemData, ModelComponentType.GAMESYTEM); - loadedGamesystems.unshift(loadedModel) - } else { - const loadedModel = new RecursiveLoadModel(gamesystemData, ModelComponentType.GAMESYTEM, path.basename(gamesystemDir)) - loadedGamesystems.unshift(loadedModel); - } - - } else { - const secondCon = path.basename(gamesystemDir) === path.parse(fileName).name - const thirdCon = path.basename(path.parse(gamesystemDir).dir) === "gamesystems" - - if(path.basename(gamesystemDir) === "gamesystems"){ - const loadedModel = new LoadModel(gamesystemData, ModelComponentType.GAMESYTEM) - loadedGamesystems.push(loadedModel); - } else { - - const loadedModel = new RecursiveLoadModel(gamesystemData, ModelComponentType.GAMESYTEM, path.basename(gamesystemDir)) - loadedGamesystems.push(loadedModel); - } - - } - } - }) - return loadedGamesystems; - } - -} diff --git a/app/StorageModel.ts b/app/StorageModel.ts deleted file mode 100644 index 392016a..0000000 --- a/app/StorageModel.ts +++ /dev/null @@ -1,12 +0,0 @@ -class StorageModel { - jsonString: string - fileName: string - storageDir: string - - - constructor(jsonString: string, fileName: string, storageDir: string) { - this.jsonString = jsonString; - this.fileName = fileName; - this.storageDir = storageDir; - } -} diff --git a/app/main.ts b/app/main.ts index 3d4cf11..71b92c3 100644 --- a/app/main.ts +++ b/app/main.ts @@ -1,11 +1,7 @@ import {app, BrowserWindow, dialog, globalShortcut, ipcMain, Menu, screen} from 'electron'; import * as path from 'path'; import * as fs from 'fs'; -import {StorageModel} from "../src/app/game-model/fs/StorageModel"; -import {SaveProject} from "./SaveProject"; -import {DeleteModel} from "../src/app/game-model/fs/DeleteModel"; -import {ModelComponentType} from "../src/app/game-model/ModelComponentType"; -import {DeleteTransaction} from "./DeleteModel"; +import {GameModelLoader} from "./storage/loader/GameModelLoader"; let win: BrowserWindow | null = null; const args = process.argv.slice(1), @@ -96,15 +92,15 @@ function createWindow(): BrowserWindow { contextMenu.popup({ window: win!, x: params.x, y: params.y }); }) - ipcMain.on('save-model', (event, storageModels: StorageModel[]) => { + /*ipcMain.on('save-model', (event, storageModels: StorageModel[]) => { console.log("Save Model") SaveProject.saveProject(projectDirectory, storageModels); - }) + })*/ - ipcMain.on('delete-component', (event, deletedComponent: DeleteModel) => { + /*ipcMain.on('delete-component', (event, deletedComponent: DeleteModel) => { console.log("Delete Model: ", deletedComponent) deleteComponent(deletedComponent); - }) + })*/ const menuTemplate = [ { @@ -206,8 +202,8 @@ function loadDevProjectAtStart() { function openProjectFromFile(openProjectDir: string) { projectDirectory = openProjectDir - console.log("Open Project-Directory: ", openProjectDir) - const loadedProject = SaveProject.loadProject(openProjectDir) + const gameModelLoader = new GameModelLoader(openProjectDir); + const loadedProject = gameModelLoader.loadGameModel(); win!.webContents.send("open-project", loadedProject) } @@ -215,11 +211,11 @@ function saveProject() { win!.webContents.send('get-project-data') } -function deleteComponent(component: DeleteModel) { +/*function deleteComponent(component: DeleteModel) { console.log("Delete Component") if(component.modeltype == ModelComponentType.SCRIPTACCOUNT) { DeleteTransaction.deleteScriptAccount(projectDirectory, component.componentName); } else if(component.modeltype === ModelComponentType.GAMESYTEM) { DeleteTransaction.deleteGamesystem(projectDirectory, component.componentName); } -} +}*/ diff --git a/app/storage/FileUtils.ts b/app/storage/FileUtils.ts new file mode 100644 index 0000000..3d267fb --- /dev/null +++ b/app/storage/FileUtils.ts @@ -0,0 +1,13 @@ +import * as fs from "fs"; +import * as path from "node:path"; + + +export class FileUtils { + public static listFilesInDirectory(directory: string) { + if(fs.lstatSync(directory).isDirectory()) { + return fs.readdirSync(directory).map(fileName => path.join(directory, fileName)) + } else { + return []; + } + } +} diff --git a/app/storage/ModelComponentFileDirectory.ts b/app/storage/ModelComponentFileDirectory.ts new file mode 100644 index 0000000..35514b9 --- /dev/null +++ b/app/storage/ModelComponentFileDirectory.ts @@ -0,0 +1,6 @@ +export class ModelComponentFileDirectory { + public static SCRIPTACCOUNT_DIR_NAME = "script-accounts" + public static GAMESYSTEM_DIR_NAME = "gamesystems"; + public static GAMESYSTEM_SIMPLE_DIR_NAME = "simple"; + public static GAMESYSTEM_PRODUCT_DIR_NAME = "product"; +} diff --git a/app/storage/StoreComponent.ts b/app/storage/StoreComponent.ts new file mode 100644 index 0000000..95dea82 --- /dev/null +++ b/app/storage/StoreComponent.ts @@ -0,0 +1,13 @@ +import {ModelComponentType} from "../../src/app/project/game-model/ModelComponentType"; + + +export class StoreComponent { + jsonString: string + fileName: string + componentType: ModelComponentType + constructor(jsonString: string, fileName: string, componentType: ModelComponentType) { + this.jsonString = jsonString; + this.fileName = fileName; + this.componentType = componentType + } +} diff --git a/app/storage/StoredGameModel.ts b/app/storage/StoredGameModel.ts new file mode 100644 index 0000000..8104b44 --- /dev/null +++ b/app/storage/StoredGameModel.ts @@ -0,0 +1,12 @@ +import {StoreComponent} from "./StoreComponent"; + +export class StoredGameModel { + gameModelName: string + loadedModels: StoreComponent[] + + + constructor(gameModelName: string, loadedModels: StoreComponent[]) { + this.gameModelName = gameModelName; + this.loadedModels = loadedModels; + } +} diff --git a/app/storage/loader/GameModelLoader.ts b/app/storage/loader/GameModelLoader.ts new file mode 100644 index 0000000..b077721 --- /dev/null +++ b/app/storage/loader/GameModelLoader.ts @@ -0,0 +1,43 @@ +import {StoredGameModel} from "../StoredGameModel"; +import {StoreComponent} from "../StoreComponent"; +import * as path from "node:path"; +import * as fs from "fs"; +import {ModelComponentFileDirectory} from "../ModelComponentFileDirectory"; +import {ScriptAccountLoader} from "./ScriptAccountLoader"; + +export class GameModelLoader { + gameModelDir: string + + + constructor(gameModelDir: string) { + this.gameModelDir = gameModelDir; + } + + loadGameModel(): StoredGameModel { + const gameModelName = path.basename(this.gameModelDir) + const gameModelComponents: StoreComponent[] = this.loadGameModelComponents(); + + return new StoredGameModel(gameModelName, gameModelComponents); + } + + private loadGameModelComponents(): StoreComponent[] { + let gameModelComponents: StoreComponent[] = this.loadScriptAccountComponents() + gameModelComponents = gameModelComponents.concat(this.loadGamesystems()) + return gameModelComponents + } + + private loadScriptAccountComponents() { + const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME); + const scriptAccountLoader = new ScriptAccountLoader(scriptAccountDir); + return scriptAccountLoader.loadScriptAccounts() + } + + private loadGamesystems(): StoreComponent[] { + return [] + } + + + + + +} diff --git a/app/storage/loader/ScriptAccountLoader.ts b/app/storage/loader/ScriptAccountLoader.ts new file mode 100644 index 0000000..4914584 --- /dev/null +++ b/app/storage/loader/ScriptAccountLoader.ts @@ -0,0 +1,34 @@ +import {StoreComponent} from "../StoreComponent"; +import {FileUtils} from "../FileUtils"; +import {ModelComponentType} from "../../../src/app/project/game-model/ModelComponentType"; +import * as fs from "fs"; +import {ModelComponentFileDirectory} from "../ModelComponentFileDirectory"; +import {load} from "@angular-devkit/build-angular/src/utils/server-rendering/esm-in-memory-loader/loader-hooks"; + +export class ScriptAccountLoader { + scriptAccountDir: string + + + constructor(scriptAccountDir: string) { + this.scriptAccountDir = scriptAccountDir; + } + + loadScriptAccounts(): StoreComponent[] { + const scriptAccountFiles = FileUtils.listFilesInDirectory(this.scriptAccountDir); + const loadedScriptAccounts: StoreComponent[] = [] + scriptAccountFiles.forEach(scriptAccountFile => { + const loadedScriptAccount = this.loadScriptAccount(scriptAccountFile); + if(loadedScriptAccount != undefined) { + loadedScriptAccounts.push(loadedScriptAccount) + } + }) + return loadedScriptAccounts; + } + + private loadScriptAccount(scriptAccountFile: string) { + if(scriptAccountFile.endsWith(".json")) { + const scriptAccountData = fs.readFileSync(scriptAccountFile, 'utf-8'); + return new StoreComponent(scriptAccountData, scriptAccountFile, ModelComponentType.SCRIPTACCOUNT); + } + } +} diff --git a/src/app/app.component.html b/src/app/app.component.html index 2801b21..e345414 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -22,7 +22,7 @@ - + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 3c81077..c3a6b1a 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,24 +1,20 @@ import {Component, NgZone, OnInit, ViewChild} from '@angular/core'; -import {ElectronService} from './core/services'; -import {APP_CONFIG} from '../environments/environment'; -import {ModelComponentType} from "./game-model/ModelComponentType"; import {MatDrawerContainer} from "@angular/material/sidenav"; -import {ModelComponentTypeUtillities} from "./game-model/ModelComponentTypeUtillities"; -import {GameModel} from "./game-model/GameModel"; import {EditorComponent} from "./editor/editor.component"; -import {ModelComponent} from "./game-model/ModelComponent"; import { ScriptAccountOverviewComponent } from "./side-overviews/script-account-overview/script-account-overview.component"; import {MatDialog} from "@angular/material/dialog"; import {DeleteConfirmationDialogComponent} from "./delete-confirmation-dialog/delete-confirmation-dialog.component"; -import {ScriptAccount} from "./game-model/scriptAccounts/ScriptAccount"; import {GamescriptOverviewComponent} from "./side-overviews/gamescript-overview/gamescript-overview.component"; -import {LoadedProject} from "../../app/LoadedProject"; -import {ProcessLoadedProject} from "./game-model/fs/ProcessLoadedProject"; -import {StoreProject} from "./game-model/fs/store/StoreProject"; -import {Gamesystem} from "./game-model/gamesystems/Gamesystem"; -import {DeleteModel} from "./game-model/fs/DeleteModel"; + +import {ProjectService} from "./project/project.service"; +import {ModelComponentType} from "./project/game-model/ModelComponentType"; +import {ModelComponentTypeUtillities} from "./project/game-model/ModelComponentTypeUtillities"; +import {ScriptAccount} from "./project/game-model/scriptAccounts/ScriptAccount"; +import {Gamesystem} from "./project/game-model/gamesystems/Gamesystem"; +import {ModelComponent} from "./project/game-model/ModelComponent"; +import {GameModel} from "./project/game-model/GameModel"; @Component({ selector: 'app-root', @@ -35,44 +31,11 @@ export class AppComponent implements OnInit{ gameModel: GameModel | undefined - constructor(private electronService: ElectronService, - private zone: NgZone, - private dialog: MatDialog + constructor(private zone: NgZone, + private dialog: MatDialog, + private projectService: ProjectService ) { - console.log('APP_CONFIG', APP_CONFIG); - if(this.gameModel == undefined) { - this.gameModel = new GameModel("Unknown GameModel") - } - if (electronService.isElectron) { - console.log(process.env); - console.log('Run in electron'); - console.log('Electron ipcRenderer', this.electronService.ipcRenderer); - console.log('NodeJS childProcess', this.electronService.childProcess); - - electronService.ipcRenderer.on('context-menu', (event: any, message: string) => { - this.zone.run(() => { - this.onContextMenuMessageRecieved(message); - }); - }) - - electronService.ipcRenderer.on('get-project-data', (event: any, message: string) => { - this.zone.run(() => { - this.saveGameModel(); - }) - }) - - electronService.ipcRenderer.on('open-project', (event: any, loadedProject: LoadedProject) => { - this.gameModel = ProcessLoadedProject.processLoadedProject(loadedProject) - }) - } else { - console.log('Run in browser'); - } - } - - saveGameModel() { - const storageModels = StoreProject.storeProject(this.gameModel!); - this.electronService.ipcRenderer.send('save-model', storageModels) } onContextMenuMessageRecieved(message: string) { @@ -100,7 +63,7 @@ export class AppComponent implements OnInit{ } break; case ModelComponentType.GAMESYTEM: { if(this.gamesystemOverview!.selectedGamesystem != undefined) { - const gamesystem = this.gameModel!.findGamesystem(this.gamesystemOverview!.selectedGamesystemName!); + const gamesystem = this.projectService!.gameModel!.findGamesystem(this.gamesystemOverview!.selectedGamesystemName!); this.editor!.openGameModelComponent(gamesystem!); } } break @@ -115,11 +78,11 @@ export class AppComponent implements OnInit{ dialogRef.afterClosed().subscribe(res => { if(res != undefined && res) { if(affectedModelComponent instanceof ScriptAccount) { - this.gameModel!.removeScriptAccount(affectedModelComponent); - this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.SCRIPTACCOUNT)) + this.projectService!.gameModel!.removeScriptAccount(affectedModelComponent); + //this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.SCRIPTACCOUNT)) } else if(affectedModelComponent instanceof Gamesystem) { - this.gameModel!.removeGamesystem(affectedModelComponent); - this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.GAMESYTEM)) + //this.gameModel!.removeGamesystem(affectedModelComponent); + //this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.GAMESYTEM)) this.gamesystemOverview!.refresh() } } @@ -134,7 +97,7 @@ export class AppComponent implements OnInit{ } private onCreateNewScriptAccount() { - const createdScriptAccount = this.gameModel!.createScriptAccount("New ScriptAccount"); + const createdScriptAccount = this.projectService!.gameModel!.createScriptAccount("New ScriptAccount"); if(createdScriptAccount != undefined) { this.editor?.openGameModelComponent(createdScriptAccount); } else { @@ -151,7 +114,7 @@ export class AppComponent implements OnInit{ } - const createdGamesystem = this.gameModel!.createGamesystem("New Gamesystem", parentGamesystemName); + const createdGamesystem = this.projectService!.gameModel!.createGamesystem("New Gamesystem", parentGamesystemName); if(createdGamesystem != undefined) { this.gamesystemOverview!.refresh(); this.editor?.openGameModelComponent(createdGamesystem); @@ -176,6 +139,7 @@ export class AppComponent implements OnInit{ } ngOnInit() { + this.gameModel = this.projectService.gameModel /*this.gameModel = new GameModel("No More"); this.gameModel.createScriptAccount("Temperature"); this.gameModel.createScriptAccount("Luftfeuchtigkeit"); diff --git a/src/app/delete-confirmation-dialog/delete-confirmation-dialog.component.ts b/src/app/delete-confirmation-dialog/delete-confirmation-dialog.component.ts index 8eacb90..00c63d2 100644 --- a/src/app/delete-confirmation-dialog/delete-confirmation-dialog.component.ts +++ b/src/app/delete-confirmation-dialog/delete-confirmation-dialog.component.ts @@ -1,7 +1,7 @@ import {Component, Inject} from '@angular/core'; import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; -import {ModelComponentTypeUtillities} from "../game-model/ModelComponentTypeUtillities"; -import {ModelComponent} from "../game-model/ModelComponent"; +import {ModelComponent} from "../project/game-model/ModelComponent"; + @Component({ selector: 'app-delete-confirmation-dialog', @@ -13,7 +13,6 @@ export class DeleteConfirmationDialogComponent { constructor(private dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public deleteModelComponent: ModelComponent) { } - protected readonly ModelComponentTypeUtillities = ModelComponentTypeUtillities; cancel() { this.dialogRef.close(false); diff --git a/src/app/editor/editor.component.ts b/src/app/editor/editor.component.ts index a1e377f..887f4d8 100644 --- a/src/app/editor/editor.component.ts +++ b/src/app/editor/editor.component.ts @@ -1,11 +1,12 @@ import {Component, EventEmitter, Input, Output} from '@angular/core'; -import {GameModel} from "../game-model/GameModel"; -import {ModelComponent} from "../game-model/ModelComponent"; -import {ModelComponentType} from "../game-model/ModelComponentType"; -import {ScriptAccount} from "../game-model/scriptAccounts/ScriptAccount"; -import {Gamesystem} from "../game-model/gamesystems/Gamesystem"; -import {State} from "../game-model/gamesystems/states/State"; -import {Transition} from "../game-model/gamesystems/transitions/Transition"; +import {ModelComponent} from "../project/game-model/ModelComponent"; +import {GameModel} from "../project/game-model/GameModel"; +import {ScriptAccount} from "../project/game-model/scriptAccounts/ScriptAccount"; +import {Gamesystem} from "../project/game-model/gamesystems/Gamesystem"; +import {State} from "../project/game-model/gamesystems/states/State"; +import {Transition} from "../project/game-model/gamesystems/transitions/Transition"; +import {ModelComponentType} from "../project/game-model/ModelComponentType"; + @Component({ selector: 'app-editor', @@ -43,9 +44,10 @@ export class EditorComponent { } } - protected readonly ModelComponentType = ModelComponentType; onModelNameUpdate() { this.onModelNameUpdateEmitter.emit(true); } + + protected readonly ModelComponentType = ModelComponentType; } diff --git a/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts b/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts index a35cc1b..f14dda3 100644 --- a/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts +++ b/src/app/editor/gamesystem-editor/gamesystem-editor.component.ts @@ -1,11 +1,10 @@ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {GameModel} from "../../game-model/GameModel"; -import {Gamesystem} from "../../game-model/gamesystems/Gamesystem"; -import {State} from "../../game-model/gamesystems/states/State"; -import {Transition} from "../../game-model/gamesystems/transitions/Transition"; -import {SimpleGamesystem} from "../../game-model/gamesystems/SimpleGamesystem"; -import {ProductGamesystem} from "../../game-model/gamesystems/ProductGamesystem"; -import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; +import {State} from "../../project/game-model/gamesystems/states/State"; +import {Gamesystem} from "../../project/game-model/gamesystems/Gamesystem"; +import { Transition } from '../../project/game-model/gamesystems/transitions/Transition'; +import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccount"; +import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem"; +import {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem"; @Component({ selector: 'app-gamesystem-editor', diff --git a/src/app/editor/gamesystem-editor/product-gamesystem-editor/LeafGamesystemCalculator.ts b/src/app/editor/gamesystem-editor/product-gamesystem-editor/LeafGamesystemCalculator.ts index d1951be..2d0c7d0 100644 --- a/src/app/editor/gamesystem-editor/product-gamesystem-editor/LeafGamesystemCalculator.ts +++ b/src/app/editor/gamesystem-editor/product-gamesystem-editor/LeafGamesystemCalculator.ts @@ -1,9 +1,9 @@ -import {Gamesystem} from "../../../game-model/gamesystems/Gamesystem"; -import {SimpleGamesystem} from "../../../game-model/gamesystems/SimpleGamesystem"; -import {ProductGamesystem} from "../../../game-model/gamesystems/ProductGamesystem"; -import {State} from "../../../game-model/gamesystems/states/State"; -import {ProductState} from "../../../game-model/gamesystems/states/ProductState"; -import {SimpleState} from "../../../game-model/gamesystems/states/SimpleState"; +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 {State} from "../../../project/game-model/gamesystems/states/State"; +import {SimpleState} from "../../../project/game-model/gamesystems/states/SimpleState"; +import {ProductState} from "../../../project/game-model/gamesystems/states/ProductState"; export class LeafGamesystemCalculator { diff --git a/src/app/editor/gamesystem-editor/product-gamesystem-editor/product-gamesystem-editor.component.ts b/src/app/editor/gamesystem-editor/product-gamesystem-editor/product-gamesystem-editor.component.ts index eebcefd..d1f7f23 100644 --- a/src/app/editor/gamesystem-editor/product-gamesystem-editor/product-gamesystem-editor.component.ts +++ b/src/app/editor/gamesystem-editor/product-gamesystem-editor/product-gamesystem-editor.component.ts @@ -1,10 +1,9 @@ import {Component, EventEmitter, Input, Output} from '@angular/core'; -import {ProductGamesystem} from "../../../game-model/gamesystems/ProductGamesystem"; -import {ProductStateEditorComponent} from "../state-editor/product-state-editor/product-state-editor.component"; -import {SimpleGamesystem} from "../../../game-model/gamesystems/SimpleGamesystem"; import { ProductTransitionEditorComponent } from "../transition-editor/product-transition-editor/product-transition-editor.component"; +import {ProductGamesystem} from "../../../project/game-model/gamesystems/ProductGamesystem"; +import {SimpleGamesystem} from "../../../project/game-model/gamesystems/SimpleGamesystem"; diff --git a/src/app/editor/gamesystem-editor/scriptaccount-condition-editor/scriptaccount-condition-editor.component.ts b/src/app/editor/gamesystem-editor/scriptaccount-condition-editor/scriptaccount-condition-editor.component.ts index d93d81a..4eaeff9 100644 --- a/src/app/editor/gamesystem-editor/scriptaccount-condition-editor/scriptaccount-condition-editor.component.ts +++ b/src/app/editor/gamesystem-editor/scriptaccount-condition-editor/scriptaccount-condition-editor.component.ts @@ -1,7 +1,7 @@ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {ScriptAccountCondition} from "../../../game-model/gamesystems/conditions/ScriptAccountCondition"; import {MatTableDataSource} from "@angular/material/table"; -import {ScriptAccount} from "../../../game-model/scriptAccounts/ScriptAccount"; +import {ScriptAccountCondition} from "../../../project/game-model/gamesystems/conditions/ScriptAccountCondition"; +import {ScriptAccount} from "../../../project/game-model/scriptAccounts/ScriptAccount"; @Component({ selector: 'app-scriptaccount-condition-editor', diff --git a/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.ts b/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.ts index 5baf0e9..36af424 100644 --- a/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.ts +++ b/src/app/editor/gamesystem-editor/simple-gamesystem-editor/simple-gamesystem-editor.component.ts @@ -1,7 +1,7 @@ import {Component, Input} from '@angular/core'; -import {SimpleGamesystem} from "../../../game-model/gamesystems/SimpleGamesystem"; import {MatTableDataSource} from "@angular/material/table"; -import {ScriptAccount} from "../../../game-model/scriptAccounts/ScriptAccount"; +import {SimpleGamesystem} from "../../../project/game-model/gamesystems/SimpleGamesystem"; +import {ScriptAccount} from "../../../project/game-model/scriptAccounts/ScriptAccount"; @Component({ selector: 'app-simple-gamesystem-editor', diff --git a/src/app/editor/gamesystem-editor/state-editor/product-state-editor/product-state-editor.component.ts b/src/app/editor/gamesystem-editor/state-editor/product-state-editor/product-state-editor.component.ts index a0b6afe..328928e 100644 --- a/src/app/editor/gamesystem-editor/state-editor/product-state-editor/product-state-editor.component.ts +++ b/src/app/editor/gamesystem-editor/state-editor/product-state-editor/product-state-editor.component.ts @@ -1,15 +1,13 @@ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {ProductGamesystem} from "../../../../game-model/gamesystems/ProductGamesystem"; -import {SimpleGamesystem} from "../../../../game-model/gamesystems/SimpleGamesystem"; import { MatTableDataSource } from "@angular/material/table"; -import {SimpleState} from "../../../../game-model/gamesystems/states/SimpleState"; -import {State} from "../../../../game-model/gamesystems/states/State"; import {LeafGamesystemCalculator} from "../../product-gamesystem-editor/LeafGamesystemCalculator"; -import {ProductTransition} from "../../../../game-model/gamesystems/transitions/ProductTransition"; -import {ProductState} from "../../../../game-model/gamesystems/states/ProductState"; import {animate, state, style, transition, trigger} from "@angular/animations"; +import {ProductGamesystem} from "../../../../project/game-model/gamesystems/ProductGamesystem"; +import {SimpleGamesystem} from "../../../../project/game-model/gamesystems/SimpleGamesystem"; +import {ProductState} from "../../../../project/game-model/gamesystems/states/ProductState"; +import {State} from "../../../../project/game-model/gamesystems/states/State"; @Component({ selector: 'app-product-state-editor', @@ -55,7 +53,6 @@ export class ProductStateEditorComponent implements OnInit{ }) } - protected readonly SimpleState = SimpleState; getLeafState(state: State, i: number) { return LeafGamesystemCalculator.calcLeafStates(state)[i]; diff --git a/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.ts b/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.ts index 93dd0b1..049814c 100644 --- a/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.ts +++ b/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.ts @@ -1,13 +1,11 @@ import {Component, Input, OnInit} from '@angular/core'; -import {SimpleState} from "../../../../game-model/gamesystems/states/SimpleState"; import {MatTableDataSource} from "@angular/material/table"; import {animate, state, style, transition, trigger} from "@angular/animations"; import {MatSnackBar} from "@angular/material/snack-bar"; -import {SimpleGamesystem} from "../../../../game-model/gamesystems/SimpleGamesystem"; -import {ProductState} from "../../../../game-model/gamesystems/states/ProductState"; -import {LeafGamesystemCalculator} from "../../product-gamesystem-editor/LeafGamesystemCalculator"; -import {ScriptAccount} from "../../../../game-model/scriptAccounts/ScriptAccount"; -import {ScriptAccountCondition} from "../../../../game-model/gamesystems/conditions/ScriptAccountCondition"; +import {SimpleState} from "../../../../project/game-model/gamesystems/states/SimpleState"; +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"; @Component({ selector: 'app-simple-state-editor', diff --git a/src/app/editor/gamesystem-editor/transition-editor/product-transition-editor/product-transition-editor.component.ts b/src/app/editor/gamesystem-editor/transition-editor/product-transition-editor/product-transition-editor.component.ts index 741f8b6..2f164d6 100644 --- a/src/app/editor/gamesystem-editor/transition-editor/product-transition-editor/product-transition-editor.component.ts +++ b/src/app/editor/gamesystem-editor/transition-editor/product-transition-editor/product-transition-editor.component.ts @@ -1,13 +1,13 @@ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {ProductGamesystem} from "../../../../game-model/gamesystems/ProductGamesystem"; -import {SimpleGamesystem} from "../../../../game-model/gamesystems/SimpleGamesystem"; import { MatTableDataSource } from "@angular/material/table"; import {LeafGamesystemCalculator} from "../../product-gamesystem-editor/LeafGamesystemCalculator"; -import {ProductTransition} from "../../../../game-model/gamesystems/transitions/ProductTransition"; -import {ProductState} from "../../../../game-model/gamesystems/states/ProductState"; import {animate, state, style, transition, trigger} from "@angular/animations"; +import {ProductGamesystem} from "../../../../project/game-model/gamesystems/ProductGamesystem"; +import {SimpleGamesystem} from "../../../../project/game-model/gamesystems/SimpleGamesystem"; +import {ProductTransition} from "../../../../project/game-model/gamesystems/transitions/ProductTransition"; +import {ProductState} from "../../../../project/game-model/gamesystems/states/ProductState"; class DisplayedColumnName { displayedName: string internalName: string diff --git a/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.ts b/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.ts index b569ba1..e8392ee 100644 --- a/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.ts +++ b/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.ts @@ -1,8 +1,8 @@ import {Component, Input, OnInit} from '@angular/core'; -import {Transition} from "../../../../game-model/gamesystems/transitions/Transition"; import {MatTableDataSource} from "@angular/material/table"; -import {ScriptAccountAction} from "../../../../game-model/gamesystems/actions/ScriptAccountAction"; -import {ScriptAccount} from "../../../../game-model/scriptAccounts/ScriptAccount"; +import {ScriptAccount} from "../../../../project/game-model/scriptAccounts/ScriptAccount"; +import {Transition} from "../../../../project/game-model/gamesystems/transitions/Transition"; +import {ScriptAccountAction} from "../../../../project/game-model/gamesystems/actions/ScriptAccountAction"; @Component({ selector: 'app-scriptaccount-action-editor', diff --git a/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.ts b/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.ts index 4c0030e..d26acd6 100644 --- a/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.ts +++ b/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.ts @@ -1,13 +1,13 @@ import {Component, Input, OnInit} from '@angular/core'; -import {SimpleGamesystem} from "../../../../game-model/gamesystems/SimpleGamesystem"; import { MatTableDataSource } from "@angular/material/table"; -import {SimpleTransition} from "../../../../game-model/gamesystems/transitions/SimpleTransition"; import {animate, state, style, transition, trigger} from "@angular/animations"; -import {SimpleState} from "../../../../game-model/gamesystems/states/SimpleState"; -import {ScriptAccount} from "../../../../game-model/scriptAccounts/ScriptAccount"; -import {ScriptAccountCondition} from "../../../../game-model/gamesystems/conditions/ScriptAccountCondition"; +import {SimpleGamesystem} from "../../../../project/game-model/gamesystems/SimpleGamesystem"; +import {ScriptAccount} from "../../../../project/game-model/scriptAccounts/ScriptAccount"; +import {SimpleTransition} from "../../../../project/game-model/gamesystems/transitions/SimpleTransition"; +import {SimpleState} from "../../../../project/game-model/gamesystems/states/SimpleState"; +import {ScriptAccountCondition} from "../../../../project/game-model/gamesystems/conditions/ScriptAccountCondition"; @Component({ selector: 'app-simple-transition-editor', templateUrl: './simple-transition-editor.component.html', diff --git a/src/app/editor/model-component-editor/model-component-editor.component.ts b/src/app/editor/model-component-editor/model-component-editor.component.ts index c527bb5..a94547c 100644 --- a/src/app/editor/model-component-editor/model-component-editor.component.ts +++ b/src/app/editor/model-component-editor/model-component-editor.component.ts @@ -1,6 +1,6 @@ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {ModelComponent} from "../../game-model/ModelComponent"; import {FormControl, Validators} from "@angular/forms"; +import {ModelComponent} from "../../project/game-model/ModelComponent"; @Component({ selector: 'app-model-component-editor', diff --git a/src/app/editor/script-account-editor/script-account-editor.component.ts b/src/app/editor/script-account-editor/script-account-editor.component.ts index 4ee4a56..75670de 100644 --- a/src/app/editor/script-account-editor/script-account-editor.component.ts +++ b/src/app/editor/script-account-editor/script-account-editor.component.ts @@ -1,12 +1,12 @@ import {Component, Input, OnInit} from '@angular/core'; -import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; -import {ModelComponent} from "../../game-model/ModelComponent"; + import {MatFormField} from "@angular/material/form-field"; import {MatInput} from "@angular/material/input"; import {FormControl, FormGroupDirective, FormsModule, NgForm, Validators} from "@angular/forms"; import {NgIf} from "@angular/common"; import {ErrorStateMatcher} from "@angular/material/core"; import {ElectronService} from "../../core/services"; +import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccount"; export class MyErrorStateMatcher implements ErrorStateMatcher { isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { diff --git a/src/app/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts similarity index 100% rename from src/app/game-model/GameModel.ts rename to src/app/project/game-model/GameModel.ts diff --git a/src/app/game-model/ModelComponent.ts b/src/app/project/game-model/ModelComponent.ts similarity index 100% rename from src/app/game-model/ModelComponent.ts rename to src/app/project/game-model/ModelComponent.ts diff --git a/src/app/game-model/ModelComponentType.ts b/src/app/project/game-model/ModelComponentType.ts similarity index 100% rename from src/app/game-model/ModelComponentType.ts rename to src/app/project/game-model/ModelComponentType.ts diff --git a/src/app/game-model/ModelComponentTypeUtillities.ts b/src/app/project/game-model/ModelComponentTypeUtillities.ts similarity index 100% rename from src/app/game-model/ModelComponentTypeUtillities.ts rename to src/app/project/game-model/ModelComponentTypeUtillities.ts diff --git a/src/app/game-model/SaveComponent.ts b/src/app/project/game-model/SaveComponent.ts similarity index 100% rename from src/app/game-model/SaveComponent.ts rename to src/app/project/game-model/SaveComponent.ts diff --git a/src/app/game-model/fs/DeleteModel.ts b/src/app/project/game-model/fs/DeleteModel.ts similarity index 100% rename from src/app/game-model/fs/DeleteModel.ts rename to src/app/project/game-model/fs/DeleteModel.ts diff --git a/src/app/game-model/fs/ProcessLoadedProject.ts b/src/app/project/game-model/fs/ProcessLoadedProject.ts similarity index 100% rename from src/app/game-model/fs/ProcessLoadedProject.ts rename to src/app/project/game-model/fs/ProcessLoadedProject.ts diff --git a/src/app/game-model/fs/StorageModel.ts b/src/app/project/game-model/fs/StorageModel.ts similarity index 100% rename from src/app/game-model/fs/StorageModel.ts rename to src/app/project/game-model/fs/StorageModel.ts diff --git a/src/app/game-model/fs/parser/ProductGamesystemParser.ts b/src/app/project/game-model/fs/parser/ProductGamesystemParser.ts similarity index 100% rename from src/app/game-model/fs/parser/ProductGamesystemParser.ts rename to src/app/project/game-model/fs/parser/ProductGamesystemParser.ts diff --git a/src/app/game-model/fs/parser/SimpleGamesystemParser.ts b/src/app/project/game-model/fs/parser/SimpleGamesystemParser.ts similarity index 100% rename from src/app/game-model/fs/parser/SimpleGamesystemParser.ts rename to src/app/project/game-model/fs/parser/SimpleGamesystemParser.ts diff --git a/src/app/game-model/fs/store/StoreProject.ts b/src/app/project/game-model/fs/store/StoreProject.ts similarity index 100% rename from src/app/game-model/fs/store/StoreProject.ts rename to src/app/project/game-model/fs/store/StoreProject.ts diff --git a/src/app/game-model/game-model.module.ts b/src/app/project/game-model/game-model.module.ts similarity index 100% rename from src/app/game-model/game-model.module.ts rename to src/app/project/game-model/game-model.module.ts diff --git a/src/app/game-model/gamesystems/Gamesystem.ts b/src/app/project/game-model/gamesystems/Gamesystem.ts similarity index 100% rename from src/app/game-model/gamesystems/Gamesystem.ts rename to src/app/project/game-model/gamesystems/Gamesystem.ts diff --git a/src/app/game-model/gamesystems/ProductGamesystem.ts b/src/app/project/game-model/gamesystems/ProductGamesystem.ts similarity index 99% rename from src/app/game-model/gamesystems/ProductGamesystem.ts rename to src/app/project/game-model/gamesystems/ProductGamesystem.ts index 087e019..630b2c3 100644 --- a/src/app/game-model/gamesystems/ProductGamesystem.ts +++ b/src/app/project/game-model/gamesystems/ProductGamesystem.ts @@ -6,7 +6,6 @@ import {Transition} from "./transitions/Transition"; import {SimpleState} from "./states/SimpleState"; import {SimpleGamesystem} from "./SimpleGamesystem"; import {GameModel} from "../GameModel"; -import {ProductStateTrainer} from "../../../../e2e/game-model/gamesystems/productGamesystems/ProductStateTrainer"; import {ScriptAccountCondition} from "./conditions/ScriptAccountCondition"; import {ScriptAccountAction} from "./actions/ScriptAccountAction"; diff --git a/src/app/game-model/gamesystems/SimpleGamesystem.ts b/src/app/project/game-model/gamesystems/SimpleGamesystem.ts similarity index 100% rename from src/app/game-model/gamesystems/SimpleGamesystem.ts rename to src/app/project/game-model/gamesystems/SimpleGamesystem.ts diff --git a/src/app/game-model/gamesystems/actions/ScriptAccountAction.ts b/src/app/project/game-model/gamesystems/actions/ScriptAccountAction.ts similarity index 100% rename from src/app/game-model/gamesystems/actions/ScriptAccountAction.ts rename to src/app/project/game-model/gamesystems/actions/ScriptAccountAction.ts diff --git a/src/app/game-model/gamesystems/conditions/ScriptAccountCondition.ts b/src/app/project/game-model/gamesystems/conditions/ScriptAccountCondition.ts similarity index 100% rename from src/app/game-model/gamesystems/conditions/ScriptAccountCondition.ts rename to src/app/project/game-model/gamesystems/conditions/ScriptAccountCondition.ts diff --git a/src/app/game-model/gamesystems/states/ProductState.ts b/src/app/project/game-model/gamesystems/states/ProductState.ts similarity index 100% rename from src/app/game-model/gamesystems/states/ProductState.ts rename to src/app/project/game-model/gamesystems/states/ProductState.ts diff --git a/src/app/game-model/gamesystems/states/SimpleState.ts b/src/app/project/game-model/gamesystems/states/SimpleState.ts similarity index 100% rename from src/app/game-model/gamesystems/states/SimpleState.ts rename to src/app/project/game-model/gamesystems/states/SimpleState.ts diff --git a/src/app/game-model/gamesystems/states/State.ts b/src/app/project/game-model/gamesystems/states/State.ts similarity index 100% rename from src/app/game-model/gamesystems/states/State.ts rename to src/app/project/game-model/gamesystems/states/State.ts diff --git a/src/app/game-model/gamesystems/transitions/ProductTransition.ts b/src/app/project/game-model/gamesystems/transitions/ProductTransition.ts similarity index 100% rename from src/app/game-model/gamesystems/transitions/ProductTransition.ts rename to src/app/project/game-model/gamesystems/transitions/ProductTransition.ts diff --git a/src/app/game-model/gamesystems/transitions/SimpleTransition.ts b/src/app/project/game-model/gamesystems/transitions/SimpleTransition.ts similarity index 100% rename from src/app/game-model/gamesystems/transitions/SimpleTransition.ts rename to src/app/project/game-model/gamesystems/transitions/SimpleTransition.ts diff --git a/src/app/game-model/gamesystems/transitions/Transition.ts b/src/app/project/game-model/gamesystems/transitions/Transition.ts similarity index 100% rename from src/app/game-model/gamesystems/transitions/Transition.ts rename to src/app/project/game-model/gamesystems/transitions/Transition.ts diff --git a/src/app/game-model/scriptAccounts/ScriptAccount.ts b/src/app/project/game-model/scriptAccounts/ScriptAccount.ts similarity index 100% rename from src/app/game-model/scriptAccounts/ScriptAccount.ts rename to src/app/project/game-model/scriptAccounts/ScriptAccount.ts diff --git a/src/app/project/parser/ScriptAccountParser.ts b/src/app/project/parser/ScriptAccountParser.ts new file mode 100644 index 0000000..56a99b7 --- /dev/null +++ b/src/app/project/parser/ScriptAccountParser.ts @@ -0,0 +1,12 @@ +import {StoreComponent} from "../../../../app/storage/StoreComponent"; +import {ScriptAccount} from "../game-model/scriptAccounts/ScriptAccount"; + +export class ScriptAccountParser { + + public static parseScriptAccount(storedComponent: StoreComponent): ScriptAccount { + console.log("Parse ScriptAccount: ", storedComponent.fileName) + const parsedScriptAccount = new ScriptAccount("", ""); + Object.assign(parsedScriptAccount, JSON.parse(storedComponent.jsonString)); + return parsedScriptAccount; + } +} diff --git a/src/app/side-overviews/gamescript-overview/gamescript-overview.component.ts b/src/app/side-overviews/gamescript-overview/gamescript-overview.component.ts index a3341ac..3194a5f 100644 --- a/src/app/side-overviews/gamescript-overview/gamescript-overview.component.ts +++ b/src/app/side-overviews/gamescript-overview/gamescript-overview.component.ts @@ -1,13 +1,13 @@ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {Gamesystem} from "../../game-model/gamesystems/Gamesystem"; -import {State} from "../../game-model/gamesystems/states/State"; -import {Transition} from "../../game-model/gamesystems/transitions/Transition"; -import {ProductGamesystem} from "../../game-model/gamesystems/ProductGamesystem"; import {FlatTreeControl} from "@angular/cdk/tree"; import {MatTreeFlatDataSource, MatTreeFlattener} from "@angular/material/tree"; -import {SimpleGamesystem} from "../../game-model/gamesystems/SimpleGamesystem"; -import {GameModel} from "../../game-model/GameModel"; import {ElectronService} from "../../core/services"; +import {GameModel} from "../../project/game-model/GameModel"; +import {Gamesystem} from "../../project/game-model/gamesystems/Gamesystem"; +import {State} from "../../project/game-model/gamesystems/states/State"; +import {Transition} from "../../project/game-model/gamesystems/transitions/Transition"; +import {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem"; +import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem"; interface FlatNode { diff --git a/src/app/side-overviews/script-account-overview/script-account-overview.component.ts b/src/app/side-overviews/script-account-overview/script-account-overview.component.ts index f0d15da..3643289 100644 --- a/src/app/side-overviews/script-account-overview/script-account-overview.component.ts +++ b/src/app/side-overviews/script-account-overview/script-account-overview.component.ts @@ -1,7 +1,7 @@ import {Component, EventEmitter, Input, NgZone, Output} from '@angular/core'; -import {GameModel} from "../../game-model/GameModel"; -import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {ElectronService} from "../../core/services"; +import {GameModel} from "../../project/game-model/GameModel"; +import {ScriptAccount} from "../../project/game-model/scriptAccounts/ScriptAccount"; @Component({ selector: 'app-script-account-overview',