diff --git a/.eslintrc.json b/.eslintrc.json index 011e046..84baaef 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,7 +3,8 @@ "ignorePatterns": [ "app/**/*", // ignore nodeJs files "dist/**/*", - "release/**/*" + "release/**/*", + "src/**/*" ], "overrides": [ { diff --git a/app/LoadModel.js b/app/LoadModel.js deleted file mode 100644 index a376e51..0000000 --- a/app/LoadModel.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.LoadModel = void 0; -class LoadModel { - constructor(jsonString, modelType) { - this.jsonString = jsonString; - this.modelType = modelType; - } -} -exports.LoadModel = LoadModel; -//# sourceMappingURL=LoadModel.js.map \ No newline at end of file diff --git a/app/LoadModel.ts b/app/LoadModel.ts deleted file mode 100644 index 9effb8d..0000000 --- a/app/LoadModel.ts +++ /dev/null @@ -1,12 +0,0 @@ -import {ModelComponentType} from "../src/app/game-model/ModelComponentType"; - -export class LoadModel { - jsonString: string - modelType: ModelComponentType - - - constructor(jsonString: string, modelType: ModelComponentType) { - this.jsonString = jsonString; - this.modelType = modelType; - } -} diff --git a/app/LoadedProject.js b/app/LoadedProject.js deleted file mode 100644 index 66d4596..0000000 --- a/app/LoadedProject.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.LoadedProject = void 0; -class LoadedProject { - constructor(projectName, loadedModels) { - this.projectName = projectName; - this.loadedModels = loadedModels; - } -} -exports.LoadedProject = LoadedProject; -//# sourceMappingURL=LoadedProject.js.map \ No newline at end of file diff --git a/app/LoadedProject.ts b/app/LoadedProject.ts deleted file mode 100644 index be710b8..0000000 --- a/app/LoadedProject.ts +++ /dev/null @@ -1,12 +0,0 @@ -import {LoadModel} from "./LoadModel"; - -export class LoadedProject { - projectName: string - loadedModels: LoadModel[] - - - constructor(projectName: string, loadedModels: LoadModel[]) { - this.projectName = projectName; - this.loadedModels = loadedModels; - } -} diff --git a/app/RecursiveLoadModel.js b/app/RecursiveLoadModel.js deleted file mode 100644 index 7599083..0000000 --- a/app/RecursiveLoadModel.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.RecursiveLoadModel = void 0; -const LoadModel_1 = require("./LoadModel"); -class RecursiveLoadModel extends LoadModel_1.LoadModel { - constructor(jsonString, modelType, parentLoadModelname) { - super(jsonString, modelType); - this.parentLoadModelname = parentLoadModelname; - } -} -exports.RecursiveLoadModel = RecursiveLoadModel; -//# sourceMappingURL=RecursiveLoadModel.js.map \ No newline at end of file diff --git a/app/RecursiveLoadModel.ts b/app/RecursiveLoadModel.ts deleted file mode 100644 index 1b9d251..0000000 --- a/app/RecursiveLoadModel.ts +++ /dev/null @@ -1,12 +0,0 @@ -import {LoadModel} from "./LoadModel"; -import {ModelComponentType} from "../src/app/game-model/ModelComponentType"; - -export class RecursiveLoadModel extends LoadModel { - parentLoadModelname: string - - - constructor(jsonString: string, modelType: ModelComponentType, parentLoadModelname: string) { - super(jsonString, modelType); - this.parentLoadModelname = parentLoadModelname; - } -} diff --git a/app/SaveProject.js b/app/SaveProject.js deleted file mode 100644 index 0e77adc..0000000 --- a/app/SaveProject.js +++ /dev/null @@ -1,100 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.SaveProject = void 0; -const fs = require("fs"); -const path = require("node:path"); -const LoadModel_1 = require("./LoadModel"); -const ModelComponentType_1 = require("../src/app/game-model/ModelComponentType"); -const LoadedProject_1 = require("./LoadedProject"); -const RecursiveLoadModel_1 = require("./RecursiveLoadModel"); -class SaveProject { - static saveProject(projectDir, storageModels) { - 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) { - 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"); - const loadedGamesystems = this.loadGamesystemsRecursively(gamesystemDir); - console.log("LoadedGamesystems: ", loadedGamesystems.length); - return loadedGamesystems; - } - 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 7c010d3..0000000 --- a/app/SaveProject.ts +++ /dev/null @@ -1,110 +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"); - const loadedGamesystems = this.loadGamesystemsRecursively(gamesystemDir); - console.log("LoadedGamesystems: ", loadedGamesystems.length); - return loadedGamesystems; - } - - 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 af69ce5..f651a10 100644 --- a/app/main.ts +++ b/app/main.ts @@ -1,9 +1,11 @@ -import {app, BrowserWindow, screen, Menu, ipcMain, dialog, globalShortcut} from 'electron'; +import {app, BrowserWindow, dialog, globalShortcut, ipcMain, Menu, screen} from 'electron'; import * as path from 'path'; import * as fs from 'fs'; -import {json} from "node:stream/consumers"; -import {StorageModel} from "../src/app/game-model/fs/StorageModel"; -import {SaveProject} from "./SaveProject"; +import {GameModelLoader} from "./storage/loader/GameModelLoader"; +import {StoredGameModel} from "./storage/StoredGameModel"; +import {ScriptAccountStorage} from "./storage/storing/ScriptAccountStoring"; +import {ModelComponentFileDirectory} from "./storage/ModelComponentFileDirectory"; +import {GamesystemStorage} from "./storage/storing/GamesystemStorage"; let win: BrowserWindow | null = null; const args = process.argv.slice(1), @@ -94,11 +96,15 @@ function createWindow(): BrowserWindow { contextMenu.popup({ window: win!, x: params.x, y: params.y }); }) - ipcMain.on('save-model', (event, storageModels: StorageModel[]) => { - console.log("Save Model") - SaveProject.saveProject(projectDirectory, storageModels); + ipcMain.on('save-model', (event, storedGameModel: StoredGameModel) => { + recieveGameModelToStore(storedGameModel) }) + /*ipcMain.on('delete-component', (event, deletedComponent: DeleteModel) => { + console.log("Delete Model: ", deletedComponent) + deleteComponent(deletedComponent); + })*/ + const menuTemplate = [ { label: 'File', @@ -127,6 +133,10 @@ function createWindow(): BrowserWindow { const menu = Menu.buildFromTemplate(menuTemplate); Menu.setApplicationMenu(menu) + win.webContents.on('did-finish-load', () => { + loadDevProjectAtStart() + }) + return win; } @@ -160,6 +170,10 @@ try { }) }) + + + + } catch (e) { // Catch Error // throw e; @@ -179,13 +193,39 @@ function openProject() { }) if(selectedPaths != undefined) { - projectDirectory = selectedPaths[0]; - console.log("Open Project-Directory: ", projectDirectory) - const loadedProject = SaveProject.loadProject(projectDirectory) - win!.webContents.send("open-project", loadedProject) + openProjectFromFile(selectedPaths[0]) } } +function loadDevProjectAtStart() { + const projectDir = path.join(process.cwd(), "testModel/") + openProjectFromFile(projectDir) +} + +function openProjectFromFile(openProjectDir: string) { + projectDirectory = openProjectDir + const gameModelLoader = new GameModelLoader(openProjectDir); + const loadedProject = gameModelLoader.loadGameModel(); + win!.webContents.send("open-project", loadedProject) +} + function saveProject() { win!.webContents.send('get-project-data') } + +function recieveGameModelToStore(gameModel: StoredGameModel) { + const scriptAccountStorage = new ScriptAccountStorage(path.join(projectDirectory, ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME)) + scriptAccountStorage.storeScriptAccounts(gameModel.storedScriptAccounts) + + const gamesystemStorage = new GamesystemStorage(path.join(projectDirectory, ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME)) + gamesystemStorage.storeGamesystems(gameModel.storedGamesystems) +} + +/*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.js b/app/storage/FileUtils.js new file mode 100644 index 0000000..55d504f --- /dev/null +++ b/app/storage/FileUtils.js @@ -0,0 +1,34 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.FileUtils = void 0; +const fs = require("fs"); +const path = require("node:path"); +const fs_1 = require("fs"); +class FileUtils { + static listFilesInDirectory(directory) { + if (fs.lstatSync(directory).isDirectory()) { + return fs.readdirSync(directory).map(fileName => path.join(directory, fileName)); + } + else { + return []; + } + } + static prepareFileForWriting(file) { + const parentDirectory = path.dirname(file); + if (!fs.existsSync(parentDirectory)) { + (0, fs_1.mkdirSync)(parentDirectory, { recursive: true }); + } + } + static removeFiles(files) { + files.forEach(file => { + if (fs.lstatSync(file).isDirectory()) { + fs.rmdirSync(file); + } + else { + fs.unlinkSync(file); + } + }); + } +} +exports.FileUtils = FileUtils; +//# sourceMappingURL=FileUtils.js.map \ No newline at end of file diff --git a/app/storage/FileUtils.ts b/app/storage/FileUtils.ts new file mode 100644 index 0000000..cfab96a --- /dev/null +++ b/app/storage/FileUtils.ts @@ -0,0 +1,33 @@ +import * as fs from "fs"; +import * as path from "node:path"; +import {mkdirSync} from "fs"; +import {lstatSync} from "node:fs"; + + +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 []; + } + } + + public static prepareFileForWriting(file: string) { + const parentDirectory = path.dirname(file) + + if(!fs.existsSync(parentDirectory)) { + mkdirSync(parentDirectory, {recursive: true}) + } + } + + public static removeFiles(files: string[]) { + files.forEach(file => { + if(fs.lstatSync(file).isDirectory()) { + fs.rmdirSync(file) + } else { + fs.unlinkSync(file); + } + }) + } +} diff --git a/app/storage/ModelComponentFileDirectory.js b/app/storage/ModelComponentFileDirectory.js new file mode 100644 index 0000000..9e2de51 --- /dev/null +++ b/app/storage/ModelComponentFileDirectory.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ModelComponentFileDirectory = void 0; +class ModelComponentFileDirectory { +} +exports.ModelComponentFileDirectory = ModelComponentFileDirectory; +ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME = "script-accounts"; +ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME = "gamesystems"; +ModelComponentFileDirectory.GAMESYSTEM_SIMPLE_DIR_NAME = "simple"; +ModelComponentFileDirectory.GAMESYSTEM_PRODUCT_DIR_NAME = "product"; +//# sourceMappingURL=ModelComponentFileDirectory.js.map \ No newline at end of file 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.js b/app/storage/StoreComponent.js new file mode 100644 index 0000000..a4ca044 --- /dev/null +++ b/app/storage/StoreComponent.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.StoreComponent = void 0; +class StoreComponent { + constructor(jsonString, fileName, componentType) { + this.jsonString = jsonString; + this.fileName = fileName; + this.componentType = componentType; + } +} +exports.StoreComponent = StoreComponent; +//# sourceMappingURL=StoreComponent.js.map \ No newline at end of file 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.js b/app/storage/StoredGameModel.js new file mode 100644 index 0000000..126a61b --- /dev/null +++ b/app/storage/StoredGameModel.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.StoredGameModel = void 0; +class StoredGameModel { + constructor(gameModelName, storedScriptAccounts, storedGamesystems) { + this.gameModelName = gameModelName; + this.storedGamesystems = storedGamesystems; + this.storedScriptAccounts = storedScriptAccounts; + } +} +exports.StoredGameModel = StoredGameModel; +//# sourceMappingURL=StoredGameModel.js.map \ No newline at end of file diff --git a/app/storage/StoredGameModel.ts b/app/storage/StoredGameModel.ts new file mode 100644 index 0000000..8edfee0 --- /dev/null +++ b/app/storage/StoredGameModel.ts @@ -0,0 +1,15 @@ +import {StoreComponent} from "./StoreComponent"; + +export class StoredGameModel { + gameModelName: string + + storedGamesystems: StoreComponent[] + storedScriptAccounts: StoreComponent[] + + + constructor(gameModelName: string, storedScriptAccounts: StoreComponent[], storedGamesystems: StoreComponent[]) { + this.gameModelName = gameModelName; + this.storedGamesystems = storedGamesystems; + this.storedScriptAccounts = storedScriptAccounts; + } +} diff --git a/app/storage/loader/GameModelLoader.js b/app/storage/loader/GameModelLoader.js new file mode 100644 index 0000000..7139cc9 --- /dev/null +++ b/app/storage/loader/GameModelLoader.js @@ -0,0 +1,31 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.GameModelLoader = void 0; +const StoredGameModel_1 = require("../StoredGameModel"); +const path = require("node:path"); +const ModelComponentFileDirectory_1 = require("../ModelComponentFileDirectory"); +const ScriptAccountLoader_1 = require("./ScriptAccountLoader"); +const GamesystemLoader_1 = require("./GamesystemLoader"); +class GameModelLoader { + constructor(gameModelDir) { + this.gameModelDir = gameModelDir; + } + loadGameModel() { + const gameModelName = path.basename(this.gameModelDir); + const storedScriptAccounts = this.loadScriptAccountComponents(); + const storedGamesystems = this.loadGamesystems(); + return new StoredGameModel_1.StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems); + } + loadScriptAccountComponents() { + const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME); + const scriptAccountLoader = new ScriptAccountLoader_1.ScriptAccountLoader(scriptAccountDir); + return scriptAccountLoader.loadScriptAccounts(); + } + loadGamesystems() { + const gamesystemDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME); + const gamesystemLoader = new GamesystemLoader_1.GamesystemLoader(gamesystemDir); + return gamesystemLoader.loadGamesystems(); + } +} +exports.GameModelLoader = GameModelLoader; +//# sourceMappingURL=GameModelLoader.js.map \ No newline at end of file diff --git a/app/storage/loader/GameModelLoader.ts b/app/storage/loader/GameModelLoader.ts new file mode 100644 index 0000000..bcbfa63 --- /dev/null +++ b/app/storage/loader/GameModelLoader.ts @@ -0,0 +1,42 @@ +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"; +import {GamesystemLoader} from "./GamesystemLoader"; + +export class GameModelLoader { + gameModelDir: string + + + constructor(gameModelDir: string) { + this.gameModelDir = gameModelDir; + } + + loadGameModel(): StoredGameModel { + const gameModelName = path.basename(this.gameModelDir) + + const storedScriptAccounts = this.loadScriptAccountComponents(); + const storedGamesystems = this.loadGamesystems(); + + return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems); + } + + private loadScriptAccountComponents() { + const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME); + const scriptAccountLoader = new ScriptAccountLoader(scriptAccountDir); + return scriptAccountLoader.loadScriptAccounts() + } + + private loadGamesystems(): StoreComponent[] { + const gamesystemDir = path.join(this.gameModelDir, ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME); + const gamesystemLoader = new GamesystemLoader(gamesystemDir); + return gamesystemLoader.loadGamesystems(); + } + + + + + +} diff --git a/app/storage/loader/GamesystemLoader.js b/app/storage/loader/GamesystemLoader.js new file mode 100644 index 0000000..551404b --- /dev/null +++ b/app/storage/loader/GamesystemLoader.js @@ -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 \ No newline at end of file diff --git a/app/storage/loader/GamesystemLoader.ts b/app/storage/loader/GamesystemLoader.ts new file mode 100644 index 0000000..8ade2ca --- /dev/null +++ b/app/storage/loader/GamesystemLoader.ts @@ -0,0 +1,44 @@ +import {StoreComponent} from "../StoreComponent"; +import {FileUtils} from "../FileUtils"; +import * as fs from "fs"; +import * as path from "node:path"; +import {ModelComponentType} from "../../../src/app/project/game-model/ModelComponentType"; + +export class GamesystemLoader { + + gamesystemDir: string + + + constructor(gamesystemDir: string) { + this.gamesystemDir = gamesystemDir; + } + + loadGamesystems() { + return this.loadGamesystemsRecursivly(this.gamesystemDir) + } + + private loadGamesystemsRecursivly(currentGamesystemDir: string) { + let loadedGamesystems: StoreComponent[] = [] + const gamesystemFiles = 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; + } + + private loadGamesystem(gamesystemFile: string) { + if(gamesystemFile.endsWith(".json")) { + const gamesystemData = fs.readFileSync(gamesystemFile, 'utf-8'); + return new StoreComponent(gamesystemData, gamesystemFile, ModelComponentType.GAMESYTEM); + } + } +} diff --git a/app/storage/loader/ScriptAccountLoader.js b/app/storage/loader/ScriptAccountLoader.js new file mode 100644 index 0000000..5b5c1a2 --- /dev/null +++ b/app/storage/loader/ScriptAccountLoader.js @@ -0,0 +1,31 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ScriptAccountLoader = void 0; +const StoreComponent_1 = require("../StoreComponent"); +const FileUtils_1 = require("../FileUtils"); +const ModelComponentType_1 = require("../../../src/app/project/game-model/ModelComponentType"); +const fs = require("fs"); +class ScriptAccountLoader { + constructor(scriptAccountDir) { + this.scriptAccountDir = scriptAccountDir; + } + loadScriptAccounts() { + const scriptAccountFiles = FileUtils_1.FileUtils.listFilesInDirectory(this.scriptAccountDir); + const loadedScriptAccounts = []; + scriptAccountFiles.forEach(scriptAccountFile => { + const loadedScriptAccount = this.loadScriptAccount(scriptAccountFile); + if (loadedScriptAccount != undefined) { + loadedScriptAccounts.push(loadedScriptAccount); + } + }); + return loadedScriptAccounts; + } + loadScriptAccount(scriptAccountFile) { + if (scriptAccountFile.endsWith(".json")) { + const scriptAccountData = fs.readFileSync(scriptAccountFile, 'utf-8'); + return new StoreComponent_1.StoreComponent(scriptAccountData, scriptAccountFile, ModelComponentType_1.ModelComponentType.SCRIPTACCOUNT); + } + } +} +exports.ScriptAccountLoader = ScriptAccountLoader; +//# sourceMappingURL=ScriptAccountLoader.js.map \ No newline at end of file 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/app/storage/storing/GamesystemStorage.js b/app/storage/storing/GamesystemStorage.js new file mode 100644 index 0000000..003890e --- /dev/null +++ b/app/storage/storing/GamesystemStorage.js @@ -0,0 +1,57 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.GamesystemStorage = void 0; +const FileUtils_1 = require("../FileUtils"); +const path = require("node:path"); +const fs = require("fs"); +class GamesystemStorage { + constructor(gamesystemRootDir) { + this.gamesystemRootDir = gamesystemRootDir; + } + storeGamesystems(gamesystems) { + const unreferencedFiles = this.detectUnusedGamesystemFiles(gamesystems); + FileUtils_1.FileUtils.removeFiles(unreferencedFiles); + gamesystems.forEach(gamesystem => this.storeGamesystem(gamesystem)); + } + detectUnusedGamesystemFiles(gamesystems) { + const unreferencedFiles = []; + const gamesystemFiles = FileUtils_1.FileUtils.listFilesInDirectory(this.gamesystemRootDir); + while (gamesystemFiles.length > 0) { + const currentGamesystemFile = gamesystemFiles.shift(); + const referencedGamesystemName = path.parse(path.basename(currentGamesystemFile)).name; + const referencedGamesystem = this.findReferencedGamesystem(referencedGamesystemName, gamesystems); + if (referencedGamesystem == undefined) { + unreferencedFiles.push(currentGamesystemFile); + } + else { + const decodedJSONData = JSON.parse(referencedGamesystem.jsonString); + if (decodedJSONData.childsystems != undefined) { + //Check if current file is a directory. When it is a directory, everything is fine + if (fs.lstatSync(currentGamesystemFile).isDirectory()) { + } + else { + const parentDirName = path.basename(path.dirname(currentGamesystemFile)); + if (parentDirName !== referencedGamesystemName) { + unreferencedFiles.push(currentGamesystemFile); + } + } + } + } + if (fs.lstatSync(currentGamesystemFile).isDirectory()) { + gamesystemFiles.push(...FileUtils_1.FileUtils.listFilesInDirectory(currentGamesystemFile)); + } + } + return unreferencedFiles; + } + findReferencedGamesystem(referencedName, gamesystems) { + return gamesystems.find(gamesystem => path.basename(gamesystem.fileName) === referencedName); + } + storeGamesystem(gamesystem) { + const gamesystemFile = path.join(...gamesystem.fileName.split("/")); + const completeGamesystemFile = path.join(this.gamesystemRootDir, gamesystemFile); + FileUtils_1.FileUtils.prepareFileForWriting(completeGamesystemFile); + fs.writeFileSync(completeGamesystemFile + ".json", gamesystem.jsonString, 'utf-8'); + } +} +exports.GamesystemStorage = GamesystemStorage; +//# sourceMappingURL=GamesystemStorage.js.map \ No newline at end of file diff --git a/app/storage/storing/GamesystemStorage.ts b/app/storage/storing/GamesystemStorage.ts new file mode 100644 index 0000000..c414f65 --- /dev/null +++ b/app/storage/storing/GamesystemStorage.ts @@ -0,0 +1,64 @@ +import {StoreComponent} from "../StoreComponent"; +import {FileUtils} from "../FileUtils"; +import * as path from "node:path"; +import * as fs from "fs"; + +export class GamesystemStorage { + + private gamesystemRootDir: string + + + constructor(gamesystemRootDir: string) { + this.gamesystemRootDir = gamesystemRootDir; + } + + public storeGamesystems(gamesystems: StoreComponent[]) { + const unreferencedFiles = this.detectUnusedGamesystemFiles(gamesystems) + FileUtils.removeFiles(unreferencedFiles) + gamesystems.forEach(gamesystem => this.storeGamesystem(gamesystem)) + } + + private detectUnusedGamesystemFiles(gamesystems: StoreComponent[]) { + const unreferencedFiles: string[] = [] + const gamesystemFiles = FileUtils.listFilesInDirectory(this.gamesystemRootDir); + while(gamesystemFiles.length > 0) { + const currentGamesystemFile = gamesystemFiles.shift() + const referencedGamesystemName = path.parse(path.basename(currentGamesystemFile!)).name + const referencedGamesystem = this.findReferencedGamesystem(referencedGamesystemName, gamesystems) + if(referencedGamesystem == undefined) { + unreferencedFiles.push(currentGamesystemFile!) + } else { + const decodedJSONData = JSON.parse(referencedGamesystem!.jsonString) + if(decodedJSONData.childsystems != undefined) { + //Check if current file is a directory. When it is a directory, everything is fine + if(fs.lstatSync(currentGamesystemFile!).isDirectory()) { + + } else { + const parentDirName = path.basename(path.dirname(currentGamesystemFile!)) + if(parentDirName !== referencedGamesystemName) { + unreferencedFiles.push(currentGamesystemFile!) + } + } + } + } + + if(fs.lstatSync(currentGamesystemFile!).isDirectory()) { + gamesystemFiles.push(... FileUtils.listFilesInDirectory(currentGamesystemFile!)) + } + } + + return unreferencedFiles; + } + + private findReferencedGamesystem(referencedName: string, gamesystems: StoreComponent[]): StoreComponent | undefined { + return gamesystems.find(gamesystem => + path.basename(gamesystem.fileName) === referencedName) + } + + private storeGamesystem(gamesystem: StoreComponent) { + const gamesystemFile = path.join(... gamesystem.fileName.split("/")) + const completeGamesystemFile = path.join(this.gamesystemRootDir, gamesystemFile) + FileUtils.prepareFileForWriting(completeGamesystemFile) + fs.writeFileSync(completeGamesystemFile + ".json", gamesystem.jsonString, 'utf-8') + } +} diff --git a/app/storage/storing/ScriptAccountStoring.js b/app/storage/storing/ScriptAccountStoring.js new file mode 100644 index 0000000..49b0eab --- /dev/null +++ b/app/storage/storing/ScriptAccountStoring.js @@ -0,0 +1,33 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ScriptAccountStorage = void 0; +const FileUtils_1 = require("../FileUtils"); +const path = require("node:path"); +const fs = require("fs"); +class ScriptAccountStorage { + constructor(scriptAccountDir) { + this.scriptAccountDir = scriptAccountDir; + } + storeScriptAccounts(scriptAccounts) { + this.persistDeletedScriptAccounts(scriptAccounts); + scriptAccounts.forEach(scriptAccount => { + this.storeScriptAccount(scriptAccount); + }); + } + persistDeletedScriptAccounts(existingScriptAccount) { + const scriptAccountFiles = FileUtils_1.FileUtils.listFilesInDirectory(this.scriptAccountDir); + scriptAccountFiles.forEach(scriptAccountFile => { + const scriptAccountFileName = path.parse(path.basename(scriptAccountFile)).name; + if (existingScriptAccount.find(scriptAccount => scriptAccount.fileName === scriptAccountFileName) == undefined) { + //No scriptAccountFile was found with that nae of the file. So the scriptAccount was deleted. Remove file + fs.unlinkSync(scriptAccountFile); + } + }); + } + storeScriptAccount(scriptAccount) { + const completeScriptAccountFile = path.join(this.scriptAccountDir, scriptAccount.fileName + ".json"); + fs.writeFileSync(completeScriptAccountFile, scriptAccount.jsonString, 'utf-8'); + } +} +exports.ScriptAccountStorage = ScriptAccountStorage; +//# sourceMappingURL=ScriptAccountStoring.js.map \ No newline at end of file diff --git a/app/storage/storing/ScriptAccountStoring.ts b/app/storage/storing/ScriptAccountStoring.ts new file mode 100644 index 0000000..6e73b17 --- /dev/null +++ b/app/storage/storing/ScriptAccountStoring.ts @@ -0,0 +1,36 @@ +import {StoreComponent} from "../StoreComponent"; +import {FileUtils} from "../FileUtils"; +import * as path from "node:path"; +import * as fs from "fs"; + +export class ScriptAccountStorage { + + private scriptAccountDir: string + + constructor(scriptAccountDir: string) { + this.scriptAccountDir = scriptAccountDir; + } + + storeScriptAccounts(scriptAccounts: StoreComponent[]) { + this.persistDeletedScriptAccounts(scriptAccounts) + scriptAccounts.forEach(scriptAccount => { + this.storeScriptAccount(scriptAccount) + }) + } + + private persistDeletedScriptAccounts(existingScriptAccount: StoreComponent[]) { + const scriptAccountFiles = FileUtils.listFilesInDirectory(this.scriptAccountDir); + scriptAccountFiles.forEach(scriptAccountFile => { + const scriptAccountFileName = path.parse(path.basename(scriptAccountFile)).name + if(existingScriptAccount.find(scriptAccount => scriptAccount.fileName === scriptAccountFileName) == undefined) { + //No scriptAccountFile was found with that nae of the file. So the scriptAccount was deleted. Remove file + fs.unlinkSync(scriptAccountFile) + } + }) + } + + private storeScriptAccount(scriptAccount: StoreComponent) { + const completeScriptAccountFile = path.join(this.scriptAccountDir, scriptAccount.fileName + ".json") + fs.writeFileSync(completeScriptAccountFile, scriptAccount.jsonString, 'utf-8') + } +} diff --git a/e2e/game-model/AddingGamesystems.spec.ts b/e2e/game-model/AddingGamesystems.spec.ts index 4d65fd0..9d6d13a 100644 --- a/e2e/game-model/AddingGamesystems.spec.ts +++ b/e2e/game-model/AddingGamesystems.spec.ts @@ -1,8 +1,8 @@ import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright'; import { test, expect } from '@playwright/test'; import * as PATH from 'path'; -import {GameModel} from "../../src/app/game-model/GameModel"; -import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem"; +import {GameModel} from "../../src/app/project/game-model/GameModel"; +import {Gamesystem} from "../../src/app/project/game-model/gamesystems/Gamesystem"; test.describe('Adding Gamesystems', () => { diff --git a/e2e/game-model/RemovingGamesystems.spec.ts b/e2e/game-model/RemovingGamesystems.spec.ts index e5777fe..0caa1e1 100644 --- a/e2e/game-model/RemovingGamesystems.spec.ts +++ b/e2e/game-model/RemovingGamesystems.spec.ts @@ -1,8 +1,9 @@ import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright'; import { test, expect } from '@playwright/test'; import * as PATH from 'path'; -import {GameModel} from "../../src/app/game-model/GameModel"; -import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem"; + +import {Gamesystem} from "../../src/app/project/game-model/gamesystems/Gamesystem"; +import {GameModel} from "../../src/app/project/game-model/GameModel"; test.describe('Removing Gamesystems', () => { diff --git a/e2e/game-model/gamesystems/CreateGamesystem.spec.ts b/e2e/game-model/gamesystems/CreateGamesystem.spec.ts index 84e01c5..fffea92 100644 --- a/e2e/game-model/gamesystems/CreateGamesystem.spec.ts +++ b/e2e/game-model/gamesystems/CreateGamesystem.spec.ts @@ -1,15 +1,6 @@ -import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright'; import { test, expect } from '@playwright/test'; -import * as PATH from 'path'; -import {GameModel} from "../../../src/app/game-model/GameModel"; -import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem"; -import {ScriptAccount} from "../../../src/app/game-model/scriptAccounts/ScriptAccount"; -import {ModelComponentType} from "../../../src/app/game-model/ModelComponentType"; -import {SimpleGamesystem} from "../../../src/app/game-model/gamesystems/SimpleGamesystem"; -import exp = require("node:constants"); -import {end} from "electron-debug"; import {GamesystemTrainer} from "./GamesystemTrainer"; -import {ProductGamesystem} from "../../../src/app/game-model/gamesystems/ProductGamesystem"; +import {ProductGamesystem} from "../../../src/app/project/game-model/gamesystems/ProductGamesystem"; test.describe('Test Create Gamesystems', () => { test('Test creating gamesystem with invalid name', async => { diff --git a/e2e/game-model/gamesystems/FindGamesystem.spec.ts b/e2e/game-model/gamesystems/FindGamesystem.spec.ts index 879717b..095432d 100644 --- a/e2e/game-model/gamesystems/FindGamesystem.spec.ts +++ b/e2e/game-model/gamesystems/FindGamesystem.spec.ts @@ -1,13 +1,6 @@ -import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright'; import { test, expect } from '@playwright/test'; -import * as PATH from 'path'; -import {GameModel} from "../../../src/app/game-model/GameModel"; -import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem"; -import {ScriptAccount} from "../../../src/app/game-model/scriptAccounts/ScriptAccount"; -import {ModelComponentType} from "../../../src/app/game-model/ModelComponentType"; -import {SimpleGamesystem} from "../../../src/app/game-model/gamesystems/SimpleGamesystem"; -import exp = require("node:constants"); -import {end} from "electron-debug"; +import {GameModel} from "../../../src/app/project/game-model/GameModel"; +import {SimpleGamesystem} from "../../../src/app/project/game-model/gamesystems/SimpleGamesystem"; import {GamesystemTrainer} from "./GamesystemTrainer"; test.describe('Test Find Gamesystems', () => { const GAMEMODELNAME: string = "GameModel"; diff --git a/e2e/game-model/gamesystems/GamesystemTrainer.ts b/e2e/game-model/gamesystems/GamesystemTrainer.ts index 515882e..f70ce51 100644 --- a/e2e/game-model/gamesystems/GamesystemTrainer.ts +++ b/e2e/game-model/gamesystems/GamesystemTrainer.ts @@ -1,6 +1,6 @@ -import {GameModel} from "../../../src/app/game-model/GameModel"; -import {SimpleGamesystem} from "../../../src/app/game-model/gamesystems/SimpleGamesystem"; -import {ProductGamesystem} from "../../../src/app/game-model/gamesystems/ProductGamesystem"; +import {GameModel} from "../../../src/app/project/game-model/GameModel"; +import {SimpleGamesystem} from "../../../src/app/project/game-model/gamesystems/SimpleGamesystem"; +import {ProductGamesystem} from "../../../src/app/project/game-model/gamesystems/ProductGamesystem"; export class GamesystemTrainer { diff --git a/e2e/game-model/gamesystems/SimpleGamesystem.spec.ts b/e2e/game-model/gamesystems/SimpleGamesystem.spec.ts index 4c61efd..a47f181 100644 --- a/e2e/game-model/gamesystems/SimpleGamesystem.spec.ts +++ b/e2e/game-model/gamesystems/SimpleGamesystem.spec.ts @@ -1,13 +1,5 @@ -import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright'; import { test, expect } from '@playwright/test'; -import * as PATH from 'path'; -import {GameModel} from "../../../src/app/game-model/GameModel"; -import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem"; -import {ScriptAccount} from "../../../src/app/game-model/scriptAccounts/ScriptAccount"; -import {ModelComponentType} from "../../../src/app/game-model/ModelComponentType"; -import {SimpleGamesystem} from "../../../src/app/game-model/gamesystems/SimpleGamesystem"; -import exp = require("node:constants"); -import {end} from "electron-debug"; +import {SimpleGamesystem} from "../../../src/app/project/game-model/gamesystems/SimpleGamesystem"; test.describe('Test SimpleGamesystem', () => { diff --git a/e2e/game-model/gamesystems/actions/AddActions.spec.ts b/e2e/game-model/gamesystems/actions/AddActions.spec.ts new file mode 100644 index 0000000..19ea15e --- /dev/null +++ b/e2e/game-model/gamesystems/actions/AddActions.spec.ts @@ -0,0 +1,59 @@ + +import { test, expect } from '@playwright/test'; +import {GamesystemTrainer} from "../GamesystemTrainer"; +import {SimpleActionTrainer} from "./SimpleActionTrainer"; +import {ScriptAccount} from "../../../../src/app/project/game-model/scriptAccounts/ScriptAccount"; +import {ScriptAccountAction} from "../../../../src/app/project/game-model/gamesystems/actions/ScriptAccountAction"; +test.describe('Test Create SimpleActions', () => { + + test('Test creating gamesystem with invalid name', async => { + const gameModel = GamesystemTrainer.givenEmptyGameModel(); + let result = gameModel.createGamesystem(undefined, undefined); + expect(result).toBeUndefined(); + + result = gameModel.createGamesystem(null, undefined); + expect(result).toBeUndefined(); + }) + + test("Adding invalid actions", async () => { + const transition = SimpleActionTrainer.withEmptyActions(); + + transition.addScriptAccountAction(null); + expect(transition.scriptAccountActions.length).toEqual(0); + + transition.addScriptAccountAction(undefined); + expect(transition.scriptAccountActions.length).toEqual(0); + }) + + test("Adding not existing action", async () => { + const transition = SimpleActionTrainer.withEmptyActions(); + const scriptAccount = new ScriptAccount("test", ""); + + const action = new ScriptAccountAction(scriptAccount, 10); + transition.addScriptAccountAction(action); + + expect(transition.scriptAccountActions.length).toEqual(1); + expect(transition.scriptAccountActions[0].scriptAccount).toEqual(action.scriptAccount); + expect(transition.scriptAccountActions[0].changingValue).toEqual(10); + }) + + test("Adding existing action", async () => { + const transition = SimpleActionTrainer.withSingleAction(); + const action = transition.scriptAccountActions[0]; + + transition.addScriptAccountAction(action); + expect(transition.scriptAccountActions.length).toEqual(1); + expect(transition.scriptAccountActions[0].changingValue).toEqual(20); + expect(transition.scriptAccountActions[0].scriptAccount).toEqual(action.scriptAccount); + }) + + test("Adding not existing action into non empty actions", async () => { + const transition = SimpleActionTrainer.withSingleAction(); + + const scriptAccount = new ScriptAccount("Tes", ""); + + transition.addScriptAccountAction(new ScriptAccountAction(scriptAccount, 10)); + expect(transition.scriptAccountActions.length).toEqual(2); + }) + +}); diff --git a/e2e/game-model/gamesystems/actions/RemoveActions.spec.ts b/e2e/game-model/gamesystems/actions/RemoveActions.spec.ts new file mode 100644 index 0000000..40cd9a4 --- /dev/null +++ b/e2e/game-model/gamesystems/actions/RemoveActions.spec.ts @@ -0,0 +1,33 @@ + +import { test, expect } from '@playwright/test'; +import {GamesystemTrainer} from "../GamesystemTrainer"; +import {SimpleActionTrainer} from "./SimpleActionTrainer"; +import {ScriptAccount} from "../../../../src/app/project/game-model/scriptAccounts/ScriptAccount"; +import {ScriptAccountAction} from "../../../../src/app/project/game-model/gamesystems/actions/ScriptAccountAction"; +import {SimpleTransition} from "../../../../src/app/project/game-model/gamesystems/transitions/SimpleTransition"; +test.describe('Test Remove SimpleActions', () => { + + test("Test Removing invalid Actions", async () => { + const transition = SimpleActionTrainer.withSingleAction(); + + transition.removeScriptAccountAction(null); + expect(transition.scriptAccountActions.length).toEqual(1) + + transition.removeScriptAccountAction(undefined); + expect(transition.scriptAccountActions.length).toEqual(1); + }) + + test("Test removing unknown scriptAccount Action", async () => { + const transition = SimpleActionTrainer.withSingleAction(); + const scriptAccount = new ScriptAccount("Test"); + + transition.removeScriptAccountAction(scriptAccount); + expect(transition.scriptAccountActions.length).toEqual(1); + }) + + test("Test removing known ScriptAccount", async () => { + const transition = SimpleActionTrainer.withSingleAction(); + transition.removeScriptAccountAction(transition.scriptAccountActions[0].scriptAccount) + expect(transition.scriptAccountActions.length).toEqual(0); + }) +}); diff --git a/e2e/game-model/gamesystems/actions/SimpleActionTrainer.ts b/e2e/game-model/gamesystems/actions/SimpleActionTrainer.ts new file mode 100644 index 0000000..1e0b7d3 --- /dev/null +++ b/e2e/game-model/gamesystems/actions/SimpleActionTrainer.ts @@ -0,0 +1,25 @@ +import {SimpleState} from "../../../../src/app/project/game-model/gamesystems/states/SimpleState"; +import {SimpleTransition} from "../../../../src/app/project/game-model/gamesystems/transitions/SimpleTransition"; +import {Script} from "node:vm"; +import {ScriptAccount} from "../../../../src/app/project/game-model/scriptAccounts/ScriptAccount"; +import {ScriptAccountAction} from "../../../../src/app/project/game-model/gamesystems/actions/ScriptAccountAction"; + +export class SimpleActionTrainer { + static withEmptyActions() { + const startingState = new SimpleState("Wolkig", ""); + const endingState = new SimpleState("Schnee", ""); + + return new SimpleTransition(startingState, endingState); + } + + static withSingleAction() { + const startingState = new SimpleState("Wolkig", ""); + const endingState = new SimpleState("Schnee", ""); + + const scriptAccount = new ScriptAccount("Temperature", ""); + const transition = new SimpleTransition(startingState, endingState); + transition.scriptAccountActions.push(new ScriptAccountAction(scriptAccount, 10)); + + return transition; + } +} diff --git a/e2e/game-model/gamesystems/conditions/AddTransitionConditions.spec.ts b/e2e/game-model/gamesystems/conditions/AddTransitionConditions.spec.ts new file mode 100644 index 0000000..5cb1797 --- /dev/null +++ b/e2e/game-model/gamesystems/conditions/AddTransitionConditions.spec.ts @@ -0,0 +1,41 @@ + +import { test, expect } from '@playwright/test'; +import {ScriptAccountCondition} from "../../../../src/app/project/game-model/gamesystems/conditions/ScriptAccountCondition"; +import {ScriptAccount} from "../../../../src/app/project/game-model/scriptAccounts/ScriptAccount"; +import exp = require("node:constants"); +import {ConditionTrainer} from "./ConditionTrainer"; +import {Conditional} from "@angular/compiler"; +import {TransitionConditionTrainer} from "./TransitionConditionTrainer"; +import {transition} from "@angular/animations"; +test.describe('Test Adding Conditions To Transitions', () => { + + test("Test adding not contradicting Conditions", async () => { + const transition = TransitionConditionTrainer.withTransitionWithCondition(); + const condition = ScriptAccountCondition.constructScriptAccountCondition(new ScriptAccount("Test", ""), -200, -100); + + transition.addScriptAccountCondition(condition); + expect(transition.scriptAccountConditions.length).toEqual(2); + expect(transition.scriptAccountConditions.includes(condition)).toBeTruthy(); + }) + + test("Test adding contradicting Conditions", async () => { + const transition = TransitionConditionTrainer.withTransitionWithCondition(); + const condition = ConditionTrainer.withContradictingCondition(transition.scriptAccountConditions[0]); + + transition.addScriptAccountCondition(condition) + expect(transition.scriptAccountConditions.length).toEqual(1); + expect(transition.scriptAccountConditions.includes(condition)).toBeFalsy(); + }) + + test("Test expanding Conditions", async () => { + const transition = TransitionConditionTrainer.withTransitionWithCondition(); + const condition = ConditionTrainer.withExpendingCondition(transition.scriptAccountConditions[0]); + + transition.addScriptAccountCondition(condition); + expect(transition.scriptAccountConditions.length).toEqual(1); + expect(transition.scriptAccountConditions.includes(condition)).toBeFalsy(); + expect(transition.scriptAccountConditions[0].minValue).toEqual(-10) + expect(transition.scriptAccountConditions[0].maxValue).toEqual(20) + }) + +}); diff --git a/e2e/game-model/gamesystems/conditions/ConditionContradicting.spec.ts b/e2e/game-model/gamesystems/conditions/ConditionContradicting.spec.ts new file mode 100644 index 0000000..d71e5ef --- /dev/null +++ b/e2e/game-model/gamesystems/conditions/ConditionContradicting.spec.ts @@ -0,0 +1,43 @@ + +import { test, expect } from '@playwright/test'; +import {ScriptAccountCondition} from "../../../../src/app/project/game-model/gamesystems/conditions/ScriptAccountCondition"; +import {ScriptAccount} from "../../../../src/app/project/game-model/scriptAccounts/ScriptAccount"; +import exp = require("node:constants"); +import {ConditionTrainer} from "./ConditionTrainer"; +import {Conditional} from "@angular/compiler"; +test.describe('Test Contradicting Conditions', () => { + + test("Test contradicting conditions", async () => { + const condition = ConditionTrainer.withSimpleCondition(); + + let contradictingCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.maxValue + 10, condition.maxValue+200); + expect(condition.isContradicting(contradictingCondition)).toBeTruthy(); + + contradictingCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-100, condition.minValue-50); + expect(condition.isContradicting(contradictingCondition)).toBeTruthy(); + }) + + test("Test intersecting conditions", async () => { + const condition = ConditionTrainer.withSimpleCondition(); + let otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-1, condition.minValue+1); + expect(condition.isContradicting(otherCondition)).toBeFalsy(); + + otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.maxValue-1, condition.maxValue+1); + expect(condition.isContradicting(otherCondition)).toBeFalsy(); + + otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-1, condition.maxValue+1); + expect(condition.isContradicting(otherCondition)).toBeFalsy(); + + expect(condition.isContradicting(condition)).toBeFalsy(); + }) + + test("Test contradicting conditions with different ScriptAccount", async () => { + const condition = ConditionTrainer.withSimpleCondition(); + const otherCondition = ScriptAccountCondition.constructScriptAccountCondition( + new ScriptAccount("Another test", ""), condition.minValue-20, condition.minValue-10); + + expect(condition.isContradicting(otherCondition)).toBeFalsy(); + }) + + +}); diff --git a/e2e/game-model/gamesystems/conditions/ConditionCreation.spec.ts b/e2e/game-model/gamesystems/conditions/ConditionCreation.spec.ts new file mode 100644 index 0000000..112de84 --- /dev/null +++ b/e2e/game-model/gamesystems/conditions/ConditionCreation.spec.ts @@ -0,0 +1,55 @@ + +import { test, expect } from '@playwright/test'; +import {ScriptAccountCondition} from "../../../../src/app/project/game-model/gamesystems/conditions/ScriptAccountCondition"; +import {ScriptAccount} from "../../../../src/app/project/game-model/scriptAccounts/ScriptAccount"; +import exp = require("node:constants"); +test.describe('Test Create Gamesystems', () => { + + test("Test creation with null/undefined parameters", async () => { + let result = ScriptAccountCondition.constructScriptAccountCondition(null, 1, 2); + expect(result).toBeUndefined() + + result = ScriptAccountCondition.constructScriptAccountCondition(undefined, 1, 2); + expect(result).toBeUndefined(); + + result = ScriptAccountCondition.constructScriptAccountCondition(new ScriptAccount("Test", ""), null, 2); + expect(result).toBeUndefined(); + + result = ScriptAccountCondition.constructScriptAccountCondition(new ScriptAccount("Test", ""), undefined, 2); + expect(result).toBeUndefined(); + + result = ScriptAccountCondition.constructScriptAccountCondition(new ScriptAccount("Test", ""), 1, undefined); + expect(result).toBeUndefined(); + + result = ScriptAccountCondition.constructScriptAccountCondition(new ScriptAccount("Test", ""),1, null); + expect(result).toBeUndefined(); + }) + + test("Test Creation with swapped Min Max Parameter", async () => { + let result = ScriptAccountCondition.constructScriptAccountCondition(new ScriptAccount("Test", ""), 2, 1); + expect(result).toBeUndefined(); + }) + + test("Test Correct Condition Creation", async () => { + const scriptAccount = new ScriptAccount("Test", ""); + + let result = ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, 1, 2); + expect(result).toBeDefined(); + expect(result!.scriptAccount).toEqual(scriptAccount) + expect(result!.minValue).toEqual(1); + expect(result!.maxValue).toEqual(2) + + result = ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, -10, 2); + expect(result).toBeDefined(); + expect(result!.scriptAccount).toEqual(scriptAccount) + expect(result!.minValue).toEqual(-10); + expect(result!.maxValue).toEqual(2) + + result = ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, -20, -10); + expect(result).toBeDefined(); + expect(result!.scriptAccount).toEqual(scriptAccount) + expect(result!.minValue).toEqual(-20); + expect(result!.maxValue).toEqual(-10) + }) + +}); diff --git a/e2e/game-model/gamesystems/conditions/ConditionExpansion.spec.ts b/e2e/game-model/gamesystems/conditions/ConditionExpansion.spec.ts new file mode 100644 index 0000000..bd5b2cb --- /dev/null +++ b/e2e/game-model/gamesystems/conditions/ConditionExpansion.spec.ts @@ -0,0 +1,44 @@ + +import { test, expect } from '@playwright/test'; +import {ScriptAccountCondition} from "../../../../src/app/project/game-model/gamesystems/conditions/ScriptAccountCondition"; +import {ScriptAccount} from "../../../../src/app/project/game-model/scriptAccounts/ScriptAccount"; +import exp = require("node:constants"); +import {ConditionTrainer} from "./ConditionTrainer"; +test.describe('Test Expand Conditions', () => { + + test("Test expansion with contradiccting Conditions", async () => { + const condition = ConditionTrainer.withSimpleCondition(); + const otherCondition = ConditionTrainer.withContradictingCondition(condition); + + condition.extendCondition(otherCondition) + expect(condition.minValue).toEqual(ConditionTrainer.withSimpleCondition().minValue); + expect(condition.maxValue).toEqual(ConditionTrainer.withSimpleCondition().maxValue); + }) + + test("Test lower expansion of Conditions", async () => { + const condition = ConditionTrainer.withSimpleCondition(); + const otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-10, condition.minValue+10) + + condition.extendCondition(otherCondition); + expect(condition.minValue).toEqual(ConditionTrainer.withSimpleCondition().minValue-10) + expect(condition.maxValue).toEqual(ConditionTrainer.withSimpleCondition().maxValue); + }) + + test("Test higher expansion of conditions", async () => { + const condition = ConditionTrainer.withSimpleCondition(); + const otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.maxValue-10, condition.maxValue+10) + + condition.extendCondition(otherCondition) + expect(condition.minValue).toEqual(ConditionTrainer.withSimpleCondition().minValue) + expect(condition.maxValue).toEqual(ConditionTrainer.withSimpleCondition().maxValue+10) + }) + + test("Test higher and lower Expansion of Conditions", async () => { + const condition = ConditionTrainer.withSimpleCondition(); + const otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-10, condition.maxValue+10); + + condition.extendCondition(otherCondition); + expect(condition.minValue).toEqual(ConditionTrainer.withSimpleCondition().minValue-10) + expect(condition.maxValue).toEqual(ConditionTrainer.withSimpleCondition().maxValue+10) + }) +}); diff --git a/e2e/game-model/gamesystems/conditions/ConditionTrainer.ts b/e2e/game-model/gamesystems/conditions/ConditionTrainer.ts new file mode 100644 index 0000000..47718d3 --- /dev/null +++ b/e2e/game-model/gamesystems/conditions/ConditionTrainer.ts @@ -0,0 +1,17 @@ +import {ScriptAccount} from "../../../../src/app/project/game-model/scriptAccounts/ScriptAccount"; +import {ScriptAccountCondition} from "../../../../src/app/project/game-model/gamesystems/conditions/ScriptAccountCondition"; + +export class ConditionTrainer { + static withSimpleCondition(): ScriptAccountCondition { + const scriptAccount = new ScriptAccount("Test", ""); + return ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, 0, 10); + } + + static withContradictingCondition(condition: ScriptAccountCondition): ScriptAccountCondition { + return ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-20, condition.minValue-10); + } + + static withExpendingCondition(condition: ScriptAccountCondition): ScriptAccount { + return ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-10, condition.maxValue+10); + } +} diff --git a/e2e/game-model/gamesystems/conditions/TransitionConditionTrainer.ts b/e2e/game-model/gamesystems/conditions/TransitionConditionTrainer.ts new file mode 100644 index 0000000..7c94d20 --- /dev/null +++ b/e2e/game-model/gamesystems/conditions/TransitionConditionTrainer.ts @@ -0,0 +1,24 @@ +import {SimpleState} from "../../../../src/app/project/game-model/gamesystems/states/SimpleState"; +import {SimpleTransition} from "../../../../src/app/project/game-model/gamesystems/transitions/SimpleTransition"; +import {ScriptAccount} from "../../../../src/app/project/game-model/scriptAccounts/ScriptAccount"; +import {ScriptAccountCondition} from "../../../../src/app/project/game-model/gamesystems/conditions/ScriptAccountCondition"; +export class TransitionConditionTrainer { + static withTransitionWithoutConditions() { + const startingState = new SimpleState("StartingState", ""); + const endingState = new SimpleState("EndingState", ""); + + return new SimpleTransition(startingState, endingState); + } + + static withTransitionWithCondition() { + const startingState = new SimpleState("StartingState", ""); + const endingState = new SimpleState("EndingState", ""); + + const transition = new SimpleTransition(startingState, endingState); + + const scriptAccount = new ScriptAccount("ScriptAccount", ""); + transition.scriptAccountConditions.push(ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, 0, 10)!) + + return transition; + } +} diff --git a/e2e/game-model/gamesystems/productGamesystems/CreateProductStates.spec.ts b/e2e/game-model/gamesystems/productGamesystems/CreateProductStates.spec.ts index 3ee77ef..0e35828 100644 --- a/e2e/game-model/gamesystems/productGamesystems/CreateProductStates.spec.ts +++ b/e2e/game-model/gamesystems/productGamesystems/CreateProductStates.spec.ts @@ -1,17 +1,6 @@ -import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright'; import { test, expect } from '@playwright/test'; -import * as PATH from 'path'; -import {GameModel} from "../../../src/app/game-model/GameModel"; -import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem"; -import {ScriptAccount} from "../../../src/app/game-model/scriptAccounts/ScriptAccount"; -import {ModelComponentType} from "../../../src/app/game-model/ModelComponentType"; -import {SimpleGamesystem} from "../../../src/app/game-model/gamesystems/SimpleGamesystem"; -import exp = require("node:constants"); -import {end} from "electron-debug"; -import {GamesystemTrainer} from "./GamesystemTrainer"; -import {ProductGamesystem} from "../../../src/app/game-model/gamesystems/ProductGamesystem"; import {ProductStateTrainer} from "./ProductStateTrainer"; -import {SimpleState} from "../../../../src/app/game-model/gamesystems/SimpleState"; +import {SimpleState} from "../../../../src/app/project/game-model/gamesystems/states/SimpleState"; test.describe('Test Create ProductStates', () => { test("Adding already existent ProductState", async () => { diff --git a/e2e/game-model/gamesystems/productGamesystems/CreateProductTransitions.spec.ts b/e2e/game-model/gamesystems/productGamesystems/CreateProductTransitions.spec.ts index fc7dcab..44b3dce 100644 --- a/e2e/game-model/gamesystems/productGamesystems/CreateProductTransitions.spec.ts +++ b/e2e/game-model/gamesystems/productGamesystems/CreateProductTransitions.spec.ts @@ -1,7 +1,7 @@ import { test, expect } from '@playwright/test'; import {ProductStateTrainer} from "./ProductStateTrainer"; -import {ProductState} from "../../../../src/app/game-model/gamesystems/ProductState"; -import {SimpleGamesystem} from "../../../../src/app/game-model/gamesystems/SimpleGamesystem"; +import {ProductState} from "../../../../src/app/project/game-model/gamesystems/states/ProductState"; +import {SimpleGamesystem} from "../../../../src/app/project/game-model/gamesystems/SimpleGamesystem"; test.describe('Test Create ProductTransitions', () => { test("Test ProductTransition Creation with invalid inputs", async ()=> { const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates(); diff --git a/e2e/game-model/gamesystems/productGamesystems/EqualInnerStates.spec.ts b/e2e/game-model/gamesystems/productGamesystems/EqualInnerStates.spec.ts index 1b6415e..070f5dc 100644 --- a/e2e/game-model/gamesystems/productGamesystems/EqualInnerStates.spec.ts +++ b/e2e/game-model/gamesystems/productGamesystems/EqualInnerStates.spec.ts @@ -1,17 +1,5 @@ -import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright'; import { test, expect } from '@playwright/test'; -import * as PATH from 'path'; -import {GameModel} from "../../../src/app/game-model/GameModel"; -import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem"; -import {ScriptAccount} from "../../../src/app/game-model/scriptAccounts/ScriptAccount"; -import {ModelComponentType} from "../../../src/app/game-model/ModelComponentType"; -import {SimpleGamesystem} from "../../../src/app/game-model/gamesystems/SimpleGamesystem"; -import exp = require("node:constants"); -import {end} from "electron-debug"; -import {GamesystemTrainer} from "./GamesystemTrainer"; -import {ProductGamesystem} from "../../../src/app/game-model/gamesystems/ProductGamesystem"; import {ProductStateTrainer} from "./ProductStateTrainer"; -import {SimpleState} from "../../../../src/app/game-model/gamesystems/SimpleState"; test.describe('Test Check Equal of Innerstates', () => { test("Test invalid input for equal checking", async()=> { diff --git a/e2e/game-model/gamesystems/productGamesystems/ProductStateGeneration.spec.ts b/e2e/game-model/gamesystems/productGamesystems/ProductStateGeneration.spec.ts index c9991f3..d1ae17a 100644 --- a/e2e/game-model/gamesystems/productGamesystems/ProductStateGeneration.spec.ts +++ b/e2e/game-model/gamesystems/productGamesystems/ProductStateGeneration.spec.ts @@ -1,17 +1,4 @@ -import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright'; import { test, expect } from '@playwright/test'; -import * as PATH from 'path'; -import {GameModel} from "../../../src/app/game-model/GameModel"; -import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem"; -import {ScriptAccount} from "../../../src/app/game-model/scriptAccounts/ScriptAccount"; -import {ModelComponentType} from "../../../src/app/game-model/ModelComponentType"; -import {SimpleGamesystem} from "../../../src/app/game-model/gamesystems/SimpleGamesystem"; -import exp = require("node:constants"); -import {end} from "electron-debug"; -import {GamesystemTrainer} from "./GamesystemTrainer"; -import {ProductGamesystem} from "../../../src/app/game-model/gamesystems/ProductGamesystem"; -import {ProductStateTrainer} from "./ProductStateTrainer"; -import {SimpleState} from "../../../../src/app/game-model/gamesystems/SimpleState"; import {ProductSystemGenerationTrainer} from "./ProductSystemGenerationTrainer"; test.describe('Test Create ProductStates', () => { diff --git a/e2e/game-model/gamesystems/productGamesystems/ProductStateTrainer.ts b/e2e/game-model/gamesystems/productGamesystems/ProductStateTrainer.ts index e473f9f..a9a2d9c 100644 --- a/e2e/game-model/gamesystems/productGamesystems/ProductStateTrainer.ts +++ b/e2e/game-model/gamesystems/productGamesystems/ProductStateTrainer.ts @@ -1,7 +1,7 @@ -import {ProductGamesystem} from "../../../../src/app/game-model/gamesystems/ProductGamesystem"; -import {SimpleGamesystem} from "../../../../src/app/game-model/gamesystems/SimpleGamesystem"; -import {ProductState} from "../../../../src/app/game-model/gamesystems/ProductState"; -import {ProductTransition} from "../../../../src/app/game-model/gamesystems/ProductTransition"; +import {ProductGamesystem} from "../../../../src/app/project/game-model/gamesystems/ProductGamesystem"; +import {SimpleGamesystem} from "../../../../src/app/project/game-model/gamesystems/SimpleGamesystem"; +import {ProductState} from "../../../../src/app/project/game-model/gamesystems/states/ProductState"; +import {ProductTransition} from "../../../../src/app/project/game-model/gamesystems/transitions/ProductTransition"; export class ProductStateTrainer { static INNERSTATE_LETTER_1 = "A"; diff --git a/e2e/game-model/gamesystems/productGamesystems/ProductSystemGenerationTrainer.ts b/e2e/game-model/gamesystems/productGamesystems/ProductSystemGenerationTrainer.ts index aa34557..2d6011e 100644 --- a/e2e/game-model/gamesystems/productGamesystems/ProductSystemGenerationTrainer.ts +++ b/e2e/game-model/gamesystems/productGamesystems/ProductSystemGenerationTrainer.ts @@ -1,5 +1,5 @@ -import {ProductGamesystem} from "../../../../src/app/game-model/gamesystems/ProductGamesystem"; -import {SimpleGamesystem} from "../../../../src/app/game-model/gamesystems/SimpleGamesystem"; +import {ProductGamesystem} from "../../../../src/app/project/game-model/gamesystems/ProductGamesystem"; +import {SimpleGamesystem} from "../../../../src/app/project/game-model/gamesystems/SimpleGamesystem"; export class ProductSystemGenerationTrainer { diff --git a/e2e/game-model/scriptAccounts/ScriptAccountTest.spec.ts b/e2e/game-model/scriptAccounts/ScriptAccountTest.spec.ts index 00688ac..27aaed2 100644 --- a/e2e/game-model/scriptAccounts/ScriptAccountTest.spec.ts +++ b/e2e/game-model/scriptAccounts/ScriptAccountTest.spec.ts @@ -1,10 +1,10 @@ import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright'; import { test, expect } from '@playwright/test'; import * as PATH from 'path'; -import {GameModel} from "../../../src/app/game-model/GameModel"; -import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem"; -import {ScriptAccount} from "../../../src/app/game-model/scriptAccounts/ScriptAccount"; -import {ModelComponentType} from "../../../src/app/game-model/ModelComponentType"; +import {GameModel} from "../../../src/app/project/game-model/GameModel"; +import {Gamesystem} from "../../src/app/project/game-model/gamesystems/Gamesystem"; +import {ScriptAccount} from "../../../src/app/project/game-model/scriptAccounts/ScriptAccount"; +import {ModelComponentType} from "../../../src/app/project/game-model/ModelComponentType"; test.describe('Test ScriptAccounts', () => { diff --git a/src/app/app.component.html b/src/app/app.component.html index 85d1f15..2801b21 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,5 +1,5 @@
-
+
@@ -46,8 +51,8 @@ - - + + diff --git a/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.scss b/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.scss index 0830e19..f4b8648 100644 --- a/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.scss +++ b/src/app/editor/gamesystem-editor/state-editor/simple-state-editor/simple-state-editor.component.scss @@ -17,12 +17,6 @@ tr.example-element-row:not(.example-expanded-row):active { .example-element-row td { border-bottom-width: 0; } - -.example-element-detail { - overflow: hidden; - display: flex; -} - .example-element-diagram { min-width: 80px; border: 2px solid black; 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 3d4d1ed..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,11 +1,11 @@ import {Component, Input, OnInit} from '@angular/core'; -import {SimpleState} from "../../../../game-model/gamesystems/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/ProductState"; -import {LeafGamesystemCalculator} from "../../product-gamesystem-editor/LeafGamesystemCalculator"; +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', @@ -23,6 +23,7 @@ export class SimpleStateEditorComponent implements OnInit{ @Input() states: SimpleState[] = []; @Input() gamesystem: SimpleGamesystem | undefined + @Input() scriptAccounts: ScriptAccount[] = [] dataSource = new MatTableDataSource(); displayedColumns = ["name", "initial", "edit", "delete"]; columnsToDisplayWithExpand = [...this.displayedColumns, 'expand']; @@ -93,4 +94,13 @@ export class SimpleStateEditorComponent implements OnInit{ const filterValue = (event.target as HTMLInputElement).value; this.dataSource.filter = filterValue.trim().toLowerCase(); } + + onCreateCondition(state: SimpleState, condition: ScriptAccountCondition) { + state.addScriptAccountCondition(condition); + } + + + deleteCondition(state: SimpleState, condition: ScriptAccountCondition) { + state.removeScriptAccountCondition(condition.scriptAccount); + } } diff --git a/src/app/editor/gamesystem-editor/transition-editor/product-transition-editor/product-transition-editor.component.html b/src/app/editor/gamesystem-editor/transition-editor/product-transition-editor/product-transition-editor.component.html index e2da5c2..8861ae6 100644 --- a/src/app/editor/gamesystem-editor/transition-editor/product-transition-editor/product-transition-editor.component.html +++ b/src/app/editor/gamesystem-editor/transition-editor/product-transition-editor/product-transition-editor.component.html @@ -4,14 +4,31 @@ Filter - +
+ + + + + + + + + @@ -41,9 +58,22 @@ > + + + - - + + + + diff --git a/src/app/editor/gamesystem-editor/transition-editor/product-transition-editor/product-transition-editor.component.scss b/src/app/editor/gamesystem-editor/transition-editor/product-transition-editor/product-transition-editor.component.scss index 432fb10..c9cf5f4 100644 --- a/src/app/editor/gamesystem-editor/transition-editor/product-transition-editor/product-transition-editor.component.scss +++ b/src/app/editor/gamesystem-editor/transition-editor/product-transition-editor/product-transition-editor.component.scss @@ -2,3 +2,56 @@ width: 100%; } + +.mat-column-expand { + width: 32px; + text-align: center; +} + +table { + width: 100%; +} + +tr.example-detail-row { + height: 0; +} + +tr.example-element-row:not(.example-expanded-row):hover { + background: whitesmoke; +} + +tr.example-element-row:not(.example-expanded-row):active { + background: #efefef; +} + +.example-element-row td { + border-bottom-width: 0; +} + +.example-element-detail { + overflow: hidden; + display: flex; +} + +.example-element-diagram { + min-width: 80px; + border: 2px solid black; + padding: 8px; + font-weight: lighter; + margin: 8px 0; + height: 104px; +} + +.example-element-symbol { + font-weight: bold; + font-size: 40px; + line-height: normal; +} + +.example-element-description { + padding: 16px; +} + +.example-element-description-attribution { + opacity: 0.5; +} 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 8a22044..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,12 +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/ProductTransition"; -import {ProductState} from "../../../../game-model/gamesystems/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 @@ -20,7 +21,14 @@ class DisplayedColumnName { @Component({ selector: 'app-product-transition-editor', templateUrl: './product-transition-editor.component.html', - styleUrl: './product-transition-editor.component.scss' + styleUrl: './product-transition-editor.component.scss', + animations: [ + trigger('detailExpand', [ + state('collapsed,void', style({height: '0px', minHeight: '0'})), + state('expanded', style({height: '*'})), + transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')), + ]), + ], }) export class ProductTransitionEditorComponent implements OnInit{ @@ -30,6 +38,8 @@ export class ProductTransitionEditorComponent implements OnInit{ dataSource = new MatTableDataSource(); displayedColumns: DisplayedColumnName[] = []; columns: string[] = []; + columnsToDisplayWithExpand = [...this.columns, 'expand']; + expandedElement: ProductTransition | null = null numberLeafSystems: number = -1; ngOnInit() { @@ -40,6 +50,7 @@ export class ProductTransitionEditorComponent implements OnInit{ this.numberLeafSystems = leafGamesystems.length; this.columns = this.displayedColumns.map(column => column.internalName) + this.columnsToDisplayWithExpand = [...this.columns, 'expand'] this.dataSource.data = this.gamesystem.transitions; this.dataSource.filterPredicate = (data: ProductTransition, filter: string) => { @@ -64,7 +75,6 @@ export class ProductTransitionEditorComponent implements OnInit{ } const leafStates = LeafGamesystemCalculator.calcLeafStates(state); - console.log(leafStates) return leafStates[index]; } diff --git a/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.html b/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.html new file mode 100644 index 0000000..ea3882f --- /dev/null +++ b/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.html @@ -0,0 +1,45 @@ +
{{col.displayedName}} {{getLeafStateByIndex(transition, i).stateLabel}} + + Ending State
+
+ +
+
No data matching the filter "{{input.value}}"
+ + + + + + + + + + + + + + + + + + + + + + +
ScriptAccount + {{action.scriptAccount.componentName}} + + ScriptAccount + + {{scriptAccount.componentName}} + + + Value + {{action.changingValue}} + + Value + + + + + + + + + +
diff --git a/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.scss b/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.scss new file mode 100644 index 0000000..68b2712 --- /dev/null +++ b/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.scss @@ -0,0 +1,11 @@ +table { + width: 100%; +} + +.long-form { + width: 100%; +} + +.mat-column-edit, .mat-column-delete, .mat-column-expand { + width: 32px; +} diff --git a/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.spec.ts b/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.spec.ts new file mode 100644 index 0000000..3c4a363 --- /dev/null +++ b/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ScriptaccountActionEditorComponent } from './scriptaccount-action-editor.component'; + +describe('ScriptaccountActionEditorComponent', () => { + let component: ScriptaccountActionEditorComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ScriptaccountActionEditorComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(ScriptaccountActionEditorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); 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 new file mode 100644 index 0000000..e8392ee --- /dev/null +++ b/src/app/editor/gamesystem-editor/transition-editor/scriptaccount-action-editor/scriptaccount-action-editor.component.ts @@ -0,0 +1,57 @@ +import {Component, Input, OnInit} from '@angular/core'; +import {MatTableDataSource} from "@angular/material/table"; +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', + templateUrl: './scriptaccount-action-editor.component.html', + styleUrl: './scriptaccount-action-editor.component.scss' +}) +export class ScriptaccountActionEditorComponent implements OnInit{ + @Input() transition: Transition | undefined + @Input() scriptAccounts: ScriptAccount[] = [] + @Input() enableEditing: boolean = false; + + dataSource: MatTableDataSource = new MatTableDataSource(); + displayedColumns: string[] = ['scriptAccount', "valueChange", 'edit', 'delete']; + + editedAction: ScriptAccountAction | undefined + addedAction: ScriptAccountAction | undefined + + ngOnInit() { + this.dataSource.data = this.transition!.scriptAccountActions.map(action => action); + + if(!this.enableEditing) { + this.displayedColumns = this.displayedColumns.slice(0, -2); + } + } + + editAction(scriptAccountAction: ScriptAccountAction) { + this.editedAction = scriptAccountAction; + } + + createNewAction() { + this.addedAction = new ScriptAccountAction(new ScriptAccount("", ""), 0); + this.editedAction = this.addedAction; + + this.dataSource.data = this.dataSource.data.concat(this.addedAction); + } + + finishEditing() { + if(this.addedAction != undefined && this.addedAction.scriptAccount.componentName !== '') { + this.transition?.addScriptAccountAction(this.addedAction) + console.log(this.addedAction.scriptAccount) + this.dataSource.data = this.transition!.scriptAccountActions; + console.log(this.dataSource.data.length, this.transition!.scriptAccountActions.length) + this.addedAction = undefined; + } + this.editedAction = undefined; + } + + deleteAction(action: ScriptAccountAction) { + this.transition!.removeScriptAccountAction(action.scriptAccount) + this.dataSource.data = this.transition!.scriptAccountActions + } +} diff --git a/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.html b/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.html index 0834eb0..91f3790 100644 --- a/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.html +++ b/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.html @@ -40,7 +40,17 @@
-

Expanded Detail

+
+
+ +
+
+ +
+
+ +
@@ -48,8 +58,8 @@ - - + diff --git a/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.scss b/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.scss index 3292508..b1e5805 100644 --- a/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.scss +++ b/src/app/editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component.scss @@ -61,3 +61,16 @@ tr.example-element-row:not(.example-expanded-row):active { .mat-error { color: red; } + +.condition-action-container { + display: flex; + width: 100% +} + +.condition-container { + width: 45%; +} + +.action-container { + width: 45%; +} 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 b159e13..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,21 +1,13 @@ import {Component, Input, OnInit} from '@angular/core'; -import {GameModel} from "../../../../game-model/GameModel"; -import {SimpleGamesystem} from "../../../../game-model/gamesystems/SimpleGamesystem"; import { - MatCell, - MatCellDef, - MatColumnDef, - MatHeaderCell, - MatHeaderCellDef, MatHeaderRow, MatHeaderRowDef, MatRow, MatRowDef, - MatTable, MatTableDataSource } from "@angular/material/table"; -import {SimpleTransition} from "../../../../game-model/gamesystems/SimpleTransition"; import {animate, state, style, transition, trigger} from "@angular/animations"; -import {SimpleState} from "../../../../game-model/gamesystems/SimpleState"; -import {ProductTransition} from "../../../../game-model/gamesystems/ProductTransition"; -import {LeafGamesystemCalculator} from "../../product-gamesystem-editor/LeafGamesystemCalculator"; - +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', @@ -31,6 +23,7 @@ import {LeafGamesystemCalculator} from "../../product-gamesystem-editor/LeafGame export class SimpleTransitionEditorComponent implements OnInit { @Input() gamesystem: SimpleGamesystem | undefined + @Input() scriptAccounts: ScriptAccount[] = [] displayedColumns: string[] = ["starting-state", "ending-state", "edit", "delete"]; dataSource = new MatTableDataSource(); columnsToDisplayWithExpand = [...this.displayedColumns, 'expand']; @@ -49,6 +42,7 @@ export class SimpleTransitionEditorComponent implements OnInit { this.dataSource.filterPredicate = (data: SimpleTransition, filter: string) => { return [data.startingState, data.endingState].some((state) => state.stateLabel.toLowerCase().includes(filter)) } + console.log("TransitionEditor: ", this.scriptAccounts.length) } addTransition() { @@ -93,4 +87,14 @@ export class SimpleTransitionEditorComponent implements OnInit { const filterValue = (event.target as HTMLInputElement).value; this.dataSource.filter = filterValue.trim().toLowerCase(); } + + protected readonly transition = transition; + + onCreateCondition(transition: SimpleTransition, condition: ScriptAccountCondition) { + transition.addScriptAccountCondition(condition); + } + + deleteCondition(trasition: SimpleTransition, condition: ScriptAccountCondition) { + trasition.removeScriptAccountCondition(condition.scriptAccount); + } } 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.html b/src/app/editor/script-account-editor/script-account-editor.component.html index 0935334..406e563 100644 --- a/src/app/editor/script-account-editor/script-account-editor.component.html +++ b/src/app/editor/script-account-editor/script-account-editor.component.html @@ -1,13 +1,13 @@
MinValue - + Please enter a valid number! MaxValue - + Please enter a valid number! 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 271352a..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 { @@ -22,8 +22,8 @@ export class MyErrorStateMatcher implements ErrorStateMatcher { export class ScriptAccountEditorComponent implements OnInit{ @Input("scriptAccount") scriptAccount : ScriptAccount | undefined - minCtrl: FormControl = new FormControl(0, [Validators.required, Validators.pattern('^[0-9]*$')]); - maxCtrl: FormControl = new FormControl(100, [Validators.required, Validators.pattern('^[0-9]*$')]); + minCtrl: FormControl = new FormControl(0, [Validators.required, Validators.pattern('^[-]?[0-9]*$')]); + maxCtrl: FormControl = new FormControl(100, [Validators.required, Validators.pattern('^[-]?[0-9]*$')]); matcher = new MyErrorStateMatcher(); constructor(private electronService: ElectronService) { @@ -33,15 +33,8 @@ export class ScriptAccountEditorComponent implements OnInit{ this.maxCtrl.setValue(this.scriptAccount!.maxValue); } - onKeyPress(event: KeyboardEvent) { - const input = event.key; - const isDigit = /^\d+$/.test(input); - if (!isDigit) { - event.preventDefault(); - } - } - onUpdateMinValue() { + onUpdateMinValue(event: Event) { this.scriptAccount!.minValue = Number(this.minCtrl.value); this.scriptAccount!.onModifyContent(); } diff --git a/src/app/game-model/fs/parser/SimpleGamesystemParser.ts b/src/app/game-model/fs/parser/SimpleGamesystemParser.ts deleted file mode 100644 index b36c282..0000000 --- a/src/app/game-model/fs/parser/SimpleGamesystemParser.ts +++ /dev/null @@ -1,47 +0,0 @@ -import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem"; -import {SimpleState} from "../../gamesystems/SimpleState"; -import {SimpleTransition} from "../../gamesystems/SimpleTransition"; - -export class SimpleGamesystemParser { - - static parseSimpleGamesystem(jsonObject: any) : SimpleGamesystem { - const gamesystemName = jsonObject.componentName; - const gamesystemDescription = jsonObject.componentDescription; - const simpleStates = SimpleGamesystemParser.parseSimpleStates(jsonObject) - const simpleTransitions = SimpleGamesystemParser.parseSimpleTransitions(jsonObject, simpleStates); - - const gamesystem = new SimpleGamesystem(gamesystemName, gamesystemDescription); - gamesystem.states = simpleStates; - gamesystem.transitions = simpleTransitions; - - return gamesystem; - } - - static parseSimpleStates(jsonObject: any): SimpleState[] { - const states: SimpleState[] = []; - for(let i=0; i state.stateLabel === startingStateLabel); - const endingState = states.find(state => state.stateLabel === endingStateLabel); - - if(startingState != undefined && endingState != undefined) { - transitions.push(new SimpleTransition(startingState, endingState)); - } else { - console.error("Starting or Ending State are not defined!", startingState, endingState) - } - } - return transitions; - } -} diff --git a/src/app/game-model/gamesystems/State.ts b/src/app/game-model/gamesystems/State.ts deleted file mode 100644 index d6b78de..0000000 --- a/src/app/game-model/gamesystems/State.ts +++ /dev/null @@ -1,27 +0,0 @@ -import {Transition} from "./Transition"; - -export abstract class State> { - - incomingTransitions: T[] =[]; - outgoingTransitions: T[] =[]; - - initial: boolean = false; - - addIncomingTransition(transition: T) { - this.incomingTransitions.push(transition); - } - - addOutgoingTransition(transition: T) { - this.outgoingTransitions.push(transition); - } - - removeIncomingTransition(transition: T) { - - } - - removeOutgoingTransition(transition: T) { - - } - - abstract equals(state: State>): boolean; -} diff --git a/src/app/game-model/gamesystems/Transition.ts b/src/app/game-model/gamesystems/Transition.ts deleted file mode 100644 index 5f75cbd..0000000 --- a/src/app/game-model/gamesystems/Transition.ts +++ /dev/null @@ -1,15 +0,0 @@ -import {State} from "./State"; - -export abstract class Transition> { - startingState: S - endingState: S - - - constructor(startingState: S, endingState: S) { - this.startingState = startingState; - this.endingState = endingState; - - this.startingState.addOutgoingTransition(this); - this.endingState.addIncomingTransition(this); - } -} diff --git a/src/app/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts similarity index 78% rename from src/app/game-model/GameModel.ts rename to src/app/project/game-model/GameModel.ts index 487f53f..66dd46c 100644 --- a/src/app/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -1,39 +1,34 @@ import {Gamesystem} from "./gamesystems/Gamesystem"; import {ScriptAccount} from "./scriptAccounts/ScriptAccount"; -import {Transition} from "./gamesystems/Transition"; -import {State} from "./gamesystems/State"; +import {Transition} from "./gamesystems/transitions/Transition"; +import {State} from "./gamesystems/states/State"; import {ProductGamesystem} from "./gamesystems/ProductGamesystem"; import {SimpleGamesystem} from "./gamesystems/SimpleGamesystem"; import {StorageModel} from "./fs/StorageModel"; export class GameModel { - private readonly _gameModelName: string + gameModelName: string - private _gamesystems: Gamesystem[] = []; - private _scriptAccounts: ScriptAccount[] = []; + gamesystems: Gamesystem[] = []; + scriptAccounts: ScriptAccount[] = []; constructor(gameModelName: string) { - this._gameModelName = gameModelName; - } - get gameModelName(): string { - return this._gameModelName; - } - get gamesystems(): Gamesystem[] { - return this._gamesystems; - } - get scriptAccounts(): ScriptAccount[] { - return this._scriptAccounts; + this.gameModelName = gameModelName; } addGamesystem(gamesystem: Gamesystem) { if(this.findGamesystem(gamesystem.componentName) == undefined) { - this._gamesystems.push(gamesystem); + this.gamesystems.push(gamesystem); } } removeGamesystem(gamesystem : Gamesystem) { - this._gamesystems = this._gamesystems.filter(g => g !== gamesystem); + if(gamesystem.parentGamesystem == undefined) { + this.gamesystems = this.gamesystems.filter(g => g !== gamesystem); + } else { + (gamesystem.parentGamesystem as ProductGamesystem).removeChildGamesystem(gamesystem); + } } createScriptAccount(scriptAccountName: string) { @@ -72,7 +67,7 @@ export class GameModel { removeScriptAccount(scriptAccount: ScriptAccount) { if(scriptAccount != undefined) { - this._scriptAccounts = this.scriptAccounts.filter(s => s != scriptAccount); + this.scriptAccounts = this.scriptAccounts.filter(s => s != scriptAccount); } } @@ -94,4 +89,12 @@ export class GameModel { addScriptAccount(scriptAccount: ScriptAccount) { this.scriptAccounts.push(scriptAccount); } + + generateProductSystemContents() { + this.gamesystems.forEach(gamesystem => { + if(gamesystem instanceof ProductGamesystem) { + gamesystem.generateFromChildsystems(); + } + }) + } } 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/project/game-model/fs/DeleteModel.ts b/src/app/project/game-model/fs/DeleteModel.ts new file mode 100644 index 0000000..186c583 --- /dev/null +++ b/src/app/project/game-model/fs/DeleteModel.ts @@ -0,0 +1,12 @@ +import {ModelComponentType} from "../ModelComponentType"; + +export class DeleteModel { + componentName: string + modeltype: ModelComponentType + + + constructor(componentName: string, modeltype: ModelComponentType) { + this.componentName = componentName; + this.modeltype = modeltype; + } +} diff --git a/src/app/game-model/fs/ProcessLoadedProject.ts b/src/app/project/game-model/fs/ProcessLoadedProject.ts similarity index 93% rename from src/app/game-model/fs/ProcessLoadedProject.ts rename to src/app/project/game-model/fs/ProcessLoadedProject.ts index b6fe4d1..faf6719 100644 --- a/src/app/game-model/fs/ProcessLoadedProject.ts +++ b/src/app/project/game-model/fs/ProcessLoadedProject.ts @@ -47,21 +47,23 @@ export class ProcessLoadedProject { console.log("Loaded Model should be an instance of recursivemodel") if(parsedJsonString.hasOwnProperty('states') && parsedJsonString.hasOwnProperty('transitions')) { //SimpleGamesystem - const simpleGamesystem: SimpleGamesystem = SimpleGamesystemParser.parseSimpleGamesystem(parsedJsonString); + const simpleGamesystem: SimpleGamesystem = SimpleGamesystemParser.parseSimpleGamesystem(parsedJsonString, gameModel.scriptAccounts); const parentModel: ProductGamesystem = gameModel.findGamesystem(recursiveLoadModel.parentLoadModelname) as ProductGamesystem parentModel.addChildGamesystem(simpleGamesystem); + simpleGamesystem.parentGamesystem = parentModel } else { console.log("Gamesystems: ", ) //ProductGamesystem const productGamesystem: ProductGamesystem = ProductGamesystemParser.parseProductGamesystem(parsedJsonString); const parentModel: ProductGamesystem = gameModel.findGamesystem(recursiveLoadModel.parentLoadModelname) as ProductGamesystem; parentModel.addChildGamesystem(productGamesystem); + productGamesystem.parentGamesystem = parentModel } } else { //Top Gamesystem if(parsedJsonString.hasOwnProperty('states') && parsedJsonString.hasOwnProperty('transitions')) { //SimpleGamesystem - const simpleGamesystem: SimpleGamesystem = SimpleGamesystemParser.parseSimpleGamesystem(parsedJsonString); + const simpleGamesystem: SimpleGamesystem = SimpleGamesystemParser.parseSimpleGamesystem(parsedJsonString, gameModel.scriptAccounts); gameModel.addGamesystem(simpleGamesystem); } else { //ProductGamesystem 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/project/game-model/fs/parser/SimpleGamesystemParser.ts b/src/app/project/game-model/fs/parser/SimpleGamesystemParser.ts new file mode 100644 index 0000000..b20cd3d --- /dev/null +++ b/src/app/project/game-model/fs/parser/SimpleGamesystemParser.ts @@ -0,0 +1,95 @@ +import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem"; +import {SimpleState} from "../../gamesystems/states/SimpleState"; +import {SimpleTransition} from "../../gamesystems/transitions/SimpleTransition"; +import {ScriptAccount} from "../../scriptAccounts/ScriptAccount"; +import {ScriptAccountCondition} from "../../gamesystems/conditions/ScriptAccountCondition"; +import {ScriptAccountAction} from "../../gamesystems/actions/ScriptAccountAction"; + +export class SimpleGamesystemParser { + + static parseSimpleGamesystem(jsonObject: any, scriptAccounts: ScriptAccount[] = []) : SimpleGamesystem { + const gamesystemName = jsonObject.componentName; + const gamesystemDescription = jsonObject.componentDescription; + const simpleStates = SimpleGamesystemParser.parseSimpleStates(jsonObject, scriptAccounts) + const simpleTransitions = SimpleGamesystemParser.parseSimpleTransitions(jsonObject, simpleStates, scriptAccounts); + + const gamesystem = new SimpleGamesystem(gamesystemName, gamesystemDescription); + gamesystem.states = simpleStates; + gamesystem.transitions = simpleTransitions; + + return gamesystem; + } + + static parseSimpleStates(jsonObject: any, scriptAccounts: ScriptAccount[] = []): SimpleState[] { + const states: SimpleState[] = []; + for(let i=0; i scriptAccount.componentName === conditions[j].scriptAccount) + if(searchedScriptAccount != undefined) { + const scriptAccountCondition = + ScriptAccountCondition.constructScriptAccountCondition(searchedScriptAccount, conditions[j].minValue, conditions[j].maxValue) + + state.conditions.push(scriptAccountCondition!) + } + } + + states.push(state); + } + return states; + } + + + + static parseSimpleTransitions(jsonObject: any, states: SimpleState[], scriptAccounts: ScriptAccount[]): SimpleTransition[] { + const transitions: SimpleTransition[] = []; + for(let i=0; i state.stateLabel === startingStateLabel); + const endingState = states.find(state => state.stateLabel === endingStateLabel); + + const actions: ScriptAccountAction[] = [] + for(let j=0; j scriptAccount.componentName === scriptAccountName) + + if(referencedScriptAccount != undefined) { + const scriptAccountAction = new ScriptAccountAction(referencedScriptAccount!, jsonObject.transitions[i].scriptAccountActions[j].changingValue) + actions.push(scriptAccountAction) + } + } + + const conditions: ScriptAccountCondition[] = []; + for(let j=0; j scriptAccount.componentName === scriptAccountName) + + if(referencedScriptAccount != undefined) { + const minValue = jsonObject.transitions[i].scriptAccountConditions[j].minValue + const maxValue = jsonObject.transitions[i].scriptAccountConditions[j].maxValue + + const scriptAccountCondition = + ScriptAccountCondition.constructScriptAccountCondition(referencedScriptAccount, minValue, maxValue) + + conditions.push(scriptAccountCondition!) + } + } + + if(startingState != undefined && endingState != undefined) { + const simpleTransition = new SimpleTransition(startingState, endingState); + simpleTransition.scriptAccountActions = actions; + simpleTransition.scriptAccountConditions = conditions; + + transitions.push(simpleTransition); + } else { + console.error("Starting or Ending State are not defined!", startingState, endingState) + } + } + return transitions; + } +} diff --git a/src/app/game-model/fs/store/StoreProject.ts b/src/app/project/game-model/fs/store/StoreProject.ts similarity index 93% rename from src/app/game-model/fs/store/StoreProject.ts rename to src/app/project/game-model/fs/store/StoreProject.ts index 6503281..6f2cffe 100644 --- a/src/app/game-model/fs/store/StoreProject.ts +++ b/src/app/project/game-model/fs/store/StoreProject.ts @@ -53,7 +53,11 @@ export class StoreProject { return value.stateLabel } - if(key === 'incomingTransitions' || key === 'outgoingTransitions' || key === 'unsaved' || key === 'type') { + if(key === "scriptAccount") { + return value.componentName + } + + if(key === 'parentGamesystem' || key === 'incomingTransitions' || key === 'outgoingTransitions' || key === 'unsaved' || key === 'type') { return undefined; } else { return value; 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 94% rename from src/app/game-model/gamesystems/Gamesystem.ts rename to src/app/project/game-model/gamesystems/Gamesystem.ts index e182c25..2e94174 100644 --- a/src/app/game-model/gamesystems/Gamesystem.ts +++ b/src/app/project/game-model/gamesystems/Gamesystem.ts @@ -7,6 +7,7 @@ export abstract class Gamesystem extends ModelComponent{ states: S[] = []; transitions: T[] = []; + parentGamesystem: ProductGamesystem | undefined constructor(gamesystemName: string, gamesystemDescription: string) { super(gamesystemName, gamesystemDescription, ModelComponentType.GAMESYTEM); } diff --git a/src/app/game-model/gamesystems/ProductGamesystem.ts b/src/app/project/game-model/gamesystems/ProductGamesystem.ts similarity index 50% rename from src/app/game-model/gamesystems/ProductGamesystem.ts rename to src/app/project/game-model/gamesystems/ProductGamesystem.ts index 7795942..83d73ec 100644 --- a/src/app/game-model/gamesystems/ProductGamesystem.ts +++ b/src/app/project/game-model/gamesystems/ProductGamesystem.ts @@ -1,17 +1,17 @@ import {Gamesystem} from "./Gamesystem"; -import {ProductState} from "./ProductState"; -import {ProductTransition} from "./ProductTransition"; -import {State} from "./State"; -import {Transition} from "./Transition"; -import {SimpleState} from "./SimpleState"; +import {ProductState} from "./states/ProductState"; +import {ProductTransition} from "./transitions/ProductTransition"; +import {State} from "./states/State"; +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"; export class ProductGamesystem extends Gamesystem { innerGamesystems: Gamesystem, Transition>[] = []; - parentGamesystem: ProductGamesystem | undefined static constructFromSimpleGamesystem(simpleGamesystem: SimpleGamesystem, gameModel: GameModel) { const productGamesystem = new ProductGamesystem(simpleGamesystem.componentName, simpleGamesystem.componentDescription); @@ -20,12 +20,14 @@ export class ProductGamesystem extends Gamesystem 0) { simpleGamesystem.componentName += "(Child)"; productGamesystem.addChildGamesystem(simpleGamesystem); + simpleGamesystem.parentGamesystem = productGamesystem } if(parentGamesystem != undefined) { parentGamesystem.removeChildGamesystem(simpleGamesystem); parentGamesystem.addChildGamesystem(productGamesystem); + productGamesystem.parentGamesystem = parentGamesystem } else { gameModel.removeGamesystem(simpleGamesystem); gameModel.addGamesystem(productGamesystem); @@ -100,20 +102,56 @@ export class ProductGamesystem extends Gamesystem, rightInnerState: State, left_temp: boolean) { + const combinedStateConditions: ScriptAccountCondition[] = leftInnerState.conditions.concat(rightInnerState.conditions) + for(let i=0; i[] = []; if(!left_temp) { innerStates = [leftInnerState, rightInnerState]; @@ -147,6 +258,9 @@ export class ProductGamesystem extends Gamesystem productInitial = productInitial && innerState.initial) + binary_productState!.initial = productInitial + binary_productState.conditions = combinedStateConditions + return binary_productState!; } @@ -154,8 +268,8 @@ export class ProductGamesystem extends Gamesystem, Transition>) { - this.innerGamesystems = this.innerGamesystems.filter(childSystem => childSystem != gamesystem); + removeChildGamesystem(gamesystem: Gamesystem, Transition>) { + this.innerGamesystems = this.innerGamesystems.filter(childSystem => childSystem.componentName !== gamesystem.componentName); } findProductStateByInnerStates(innerStates: State[]) { @@ -183,4 +297,6 @@ export class ProductGamesystem extends Gamesystem s.equals(state)) != undefined; } + + } diff --git a/src/app/game-model/gamesystems/SimpleGamesystem.ts b/src/app/project/game-model/gamesystems/SimpleGamesystem.ts similarity index 82% rename from src/app/game-model/gamesystems/SimpleGamesystem.ts rename to src/app/project/game-model/gamesystems/SimpleGamesystem.ts index d5b4f1f..9b04b03 100644 --- a/src/app/game-model/gamesystems/SimpleGamesystem.ts +++ b/src/app/project/game-model/gamesystems/SimpleGamesystem.ts @@ -1,15 +1,13 @@ import {Gamesystem} from "./Gamesystem"; -import {SimpleState} from "./SimpleState"; -import {SimpleTransition} from "./SimpleTransition"; -import {State} from "./State"; -import {Transition} from "./Transition"; -import {ProductState} from "./ProductState"; -import {ProductTransition} from "./ProductTransition"; +import {SimpleState} from "./states/SimpleState"; +import {SimpleTransition} from "./transitions/SimpleTransition"; +import {State} from "./states/State"; +import {Transition} from "./transitions/Transition"; +import {ProductState} from "./states/ProductState"; +import {ProductTransition} from "./transitions/ProductTransition"; import {ProductGamesystem} from "./ProductGamesystem"; export class SimpleGamesystem extends Gamesystem { - parentGamesystem: ProductGamesystem | undefined - createState(label: string, description: string): SimpleState | undefined { diff --git a/src/app/project/game-model/gamesystems/actions/ScriptAccountAction.ts b/src/app/project/game-model/gamesystems/actions/ScriptAccountAction.ts new file mode 100644 index 0000000..f2d88f6 --- /dev/null +++ b/src/app/project/game-model/gamesystems/actions/ScriptAccountAction.ts @@ -0,0 +1,22 @@ +import {ScriptAccount} from "../../scriptAccounts/ScriptAccount"; +import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition"; + +export class ScriptAccountAction { + scriptAccount: ScriptAccount + changingValue: number = 0; + + + constructor(scriptAccount: ScriptAccount, changingValue: number) { + this.scriptAccount = scriptAccount; + this.changingValue = changingValue; + } + + + combineActions(otherAction: ScriptAccountAction) { + if(otherAction.scriptAccount === this.scriptAccount) { + return new ScriptAccountAction(this.scriptAccount, this.changingValue + otherAction.changingValue) + } else { + return undefined; + } + } +} diff --git a/src/app/project/game-model/gamesystems/conditions/ScriptAccountCondition.ts b/src/app/project/game-model/gamesystems/conditions/ScriptAccountCondition.ts new file mode 100644 index 0000000..ecc1b26 --- /dev/null +++ b/src/app/project/game-model/gamesystems/conditions/ScriptAccountCondition.ts @@ -0,0 +1,41 @@ +import {ScriptAccount} from "../../scriptAccounts/ScriptAccount"; +export class ScriptAccountCondition { + scriptAccount: ScriptAccount + minValue: number + maxValue: number + + + private constructor(scriptAccount: ScriptAccount, minValue: number, maxValue: number) { + this.scriptAccount = scriptAccount; + this.minValue = minValue; + this.maxValue = maxValue; + } + + static constructScriptAccountCondition(scriptAccount: ScriptAccount, minValue: number, maxValue: number) { + if(scriptAccount == undefined || minValue == undefined || maxValue == undefined || minValue > maxValue) return undefined + return new ScriptAccountCondition(scriptAccount, minValue, maxValue) + } + + extendCondition(condition: ScriptAccountCondition) { + if(!this.isContradicting(condition) && this.scriptAccount === condition.scriptAccount) { + this.minValue = Math.min(this.minValue, condition.minValue); + this.maxValue = Math.max(this.maxValue, condition.maxValue); + } + } + + combineCondition(condition: ScriptAccountCondition) { + if(condition.scriptAccount === this.scriptAccount) { + const scriptAccount = new ScriptAccountCondition(this.scriptAccount, this.minValue, this.maxValue); + scriptAccount.extendCondition(condition); + return scriptAccount; + } + return undefined; + } + + isContradicting(condition: ScriptAccountCondition) { + return condition.scriptAccount === this.scriptAccount && + (this.maxValue < condition.minValue || this.minValue > condition.maxValue) + } + + +} diff --git a/src/app/game-model/gamesystems/ProductState.ts b/src/app/project/game-model/gamesystems/states/ProductState.ts similarity index 91% rename from src/app/game-model/gamesystems/ProductState.ts rename to src/app/project/game-model/gamesystems/states/ProductState.ts index 4831c3d..8a4c504 100644 --- a/src/app/game-model/gamesystems/ProductState.ts +++ b/src/app/project/game-model/gamesystems/states/ProductState.ts @@ -1,7 +1,7 @@ -import {ProductTransition} from "./ProductTransition"; +import {ProductTransition} from "../transitions/ProductTransition"; import {State} from "./State"; import {SimpleState} from "./SimpleState"; -import {Transition} from "./Transition"; +import {Transition} from "../transitions/Transition"; export class ProductState extends State { innerStates: State[] = []; diff --git a/src/app/game-model/gamesystems/SimpleState.ts b/src/app/project/game-model/gamesystems/states/SimpleState.ts similarity index 80% rename from src/app/game-model/gamesystems/SimpleState.ts rename to src/app/project/game-model/gamesystems/states/SimpleState.ts index e570ece..259f8fe 100644 --- a/src/app/game-model/gamesystems/SimpleState.ts +++ b/src/app/project/game-model/gamesystems/states/SimpleState.ts @@ -1,6 +1,6 @@ import {State} from "./State"; -import {SimpleTransition} from "./SimpleTransition"; -import {Transition} from "./Transition"; +import {SimpleTransition} from "../transitions/SimpleTransition"; +import {Transition} from "../transitions/Transition"; export class SimpleState extends State { stateLabel: string = ""; diff --git a/src/app/project/game-model/gamesystems/states/State.ts b/src/app/project/game-model/gamesystems/states/State.ts new file mode 100644 index 0000000..d1848f5 --- /dev/null +++ b/src/app/project/game-model/gamesystems/states/State.ts @@ -0,0 +1,50 @@ +import {Transition} from "../transitions/Transition"; +import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition"; +import {ScriptAccount} from "../../scriptAccounts/ScriptAccount"; + +export abstract class State> { + + incomingTransitions: T[] =[]; + outgoingTransitions: T[] =[]; + + initial: boolean = false; + + conditions: ScriptAccountCondition[] = []; + + addIncomingTransition(transition: T) { + this.incomingTransitions.push(transition); + } + + addOutgoingTransition(transition: T) { + this.outgoingTransitions.push(transition); + } + + removeIncomingTransition(transition: T) { + + } + + removeOutgoingTransition(transition: T) { + + } + + addScriptAccountCondition(scriptAccountCondition: ScriptAccountCondition) { + const existingScriptAccountCondition = this.findScriptAccountConditionByScriptAccount(scriptAccountCondition.scriptAccount); + if(existingScriptAccountCondition != undefined) { + if(!existingScriptAccountCondition.isContradicting(scriptAccountCondition)) { + existingScriptAccountCondition.extendCondition(scriptAccountCondition) + } + } else { + this.conditions.push(scriptAccountCondition); + } + } + + removeScriptAccountCondition(scriptAccount: ScriptAccount) { + this.conditions = this.conditions.filter(condition => condition.scriptAccount !== scriptAccount); + } + + findScriptAccountConditionByScriptAccount(scriptAccount: ScriptAccount): ScriptAccountCondition | undefined { + return this.conditions.find(condition => condition.scriptAccount === scriptAccount); + } + + abstract equals(state: State>): boolean; +} diff --git a/src/app/game-model/gamesystems/ProductTransition.ts b/src/app/project/game-model/gamesystems/transitions/ProductTransition.ts similarity index 84% rename from src/app/game-model/gamesystems/ProductTransition.ts rename to src/app/project/game-model/gamesystems/transitions/ProductTransition.ts index ebd0be5..04f86f0 100644 --- a/src/app/game-model/gamesystems/ProductTransition.ts +++ b/src/app/project/game-model/gamesystems/transitions/ProductTransition.ts @@ -1,5 +1,5 @@ import {Transition} from "./Transition"; -import {ProductState} from "./ProductState"; +import {ProductState} from "../states/ProductState"; export class ProductTransition extends Transition { diff --git a/src/app/game-model/gamesystems/SimpleTransition.ts b/src/app/project/game-model/gamesystems/transitions/SimpleTransition.ts similarity index 68% rename from src/app/game-model/gamesystems/SimpleTransition.ts rename to src/app/project/game-model/gamesystems/transitions/SimpleTransition.ts index e7356ed..2ddc912 100644 --- a/src/app/game-model/gamesystems/SimpleTransition.ts +++ b/src/app/project/game-model/gamesystems/transitions/SimpleTransition.ts @@ -1,4 +1,4 @@ -import {SimpleState} from "./SimpleState"; +import {SimpleState} from "../states/SimpleState"; import {Transition} from "./Transition"; export class SimpleTransition extends Transition { diff --git a/src/app/project/game-model/gamesystems/transitions/Transition.ts b/src/app/project/game-model/gamesystems/transitions/Transition.ts new file mode 100644 index 0000000..e4a5e39 --- /dev/null +++ b/src/app/project/game-model/gamesystems/transitions/Transition.ts @@ -0,0 +1,60 @@ +import {State} from "../states/State"; +import {ScriptAccountAction} from "../actions/ScriptAccountAction"; +import {ScriptAccount} from "../../scriptAccounts/ScriptAccount"; +import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition"; + +export abstract class Transition> { + startingState: S + endingState: S + + scriptAccountActions: ScriptAccountAction[] = []; + scriptAccountConditions: ScriptAccountCondition[] = []; + + constructor(startingState: S, endingState: S) { + this.startingState = startingState; + this.endingState = endingState; + + this.startingState.addOutgoingTransition(this); + this.endingState.addIncomingTransition(this); + } + + addScriptAccountAction(scriptAccountAction: ScriptAccountAction) { + if(scriptAccountAction != undefined) { + const searchedScriptAccount = this.findScriptAccountActionByScriptAccount(scriptAccountAction.scriptAccount); + if(searchedScriptAccount == undefined) { + this.scriptAccountActions.push(scriptAccountAction) + } else { + searchedScriptAccount.changingValue += scriptAccountAction.changingValue; + } + } + } + + removeScriptAccountAction(scriptAccount: ScriptAccount) { + if(scriptAccount != undefined) { + this.scriptAccountActions = this.scriptAccountActions.filter(sA => sA.scriptAccount.componentName !== scriptAccount.componentName); + } + } + + findScriptAccountActionByScriptAccount(scriptAccount: ScriptAccount) { + return this.scriptAccountActions.find(sA => sA.scriptAccount.componentName === scriptAccount.componentName); + } + + addScriptAccountCondition(scriptAccountCondition: ScriptAccountCondition) { + const existingScriptAccountCondition = this.findScriptAccountConditionByScriptAccount(scriptAccountCondition.scriptAccount); + if(existingScriptAccountCondition != undefined) { + if(!existingScriptAccountCondition.isContradicting(scriptAccountCondition)) { + existingScriptAccountCondition.extendCondition(scriptAccountCondition) + } + } else { + this.scriptAccountConditions.push(scriptAccountCondition); + } + } + + removeScriptAccountCondition(scriptAccount: ScriptAccount) { + this.scriptAccountConditions = this.scriptAccountConditions.filter(condition => condition.scriptAccount !== scriptAccount); + } + + findScriptAccountConditionByScriptAccount(scriptAccount: ScriptAccount): ScriptAccountCondition | undefined { + return this.scriptAccountConditions.find(condition => condition.scriptAccount === scriptAccount); + } +} 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..72538c9 --- /dev/null +++ b/src/app/project/parser/ScriptAccountParser.ts @@ -0,0 +1,20 @@ +import {StoreComponent} from "../../../../app/storage/StoreComponent"; +import {ScriptAccount} from "../game-model/scriptAccounts/ScriptAccount"; + +export class ScriptAccountParser { + + public static parseScriptAccounts(storedScriptAccounts: StoreComponent[]): ScriptAccount[] { + const scriptAccounts: ScriptAccount[] = [] + storedScriptAccounts.forEach(scriptAccount => { + scriptAccounts.push(this.parseScriptAccount(scriptAccount)) + }) + return scriptAccounts; + } + + private 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/project/parser/gamesystemParser/GamesystemParser.ts b/src/app/project/parser/gamesystemParser/GamesystemParser.ts new file mode 100644 index 0000000..e085bba --- /dev/null +++ b/src/app/project/parser/gamesystemParser/GamesystemParser.ts @@ -0,0 +1,87 @@ +import {StoreComponent} from "../../../../../app/storage/StoreComponent"; +import {Gamesystem} from "../../game-model/gamesystems/Gamesystem"; +import {ParsedParentGamesystems} from "./ParsedParentGamesystems"; +import {ProductGamesystem} from "../../game-model/gamesystems/ProductGamesystem"; +import {SimpleGamesystem} from "../../game-model/gamesystems/SimpleGamesystem"; +import {StateParser} from "./StateParser"; +import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; +import {TransitionParser} from "./TransitionParser"; + +export class GamesystemParser { + + private parsedParentGamesystems: ParsedParentGamesystems[] = [] + private parsedGamesystems: Gamesystem[] = [] + + private scriptAccounts: ScriptAccount[] + + + constructor(scriptAccounts: ScriptAccount[]) { + this.scriptAccounts = scriptAccounts; + } + + + public parseStoredGamesystems(storedGamesystems: StoreComponent[]): Gamesystem[] { + storedGamesystems.forEach(storedGamesystem => { + this.parseGamesystem(storedGamesystem) + }) + + return this.computeGamesystemStructure(); + } + + private parseGamesystem(storedGamesystem: StoreComponent) { + const parsedGamesystemData = JSON.parse(storedGamesystem.jsonString) + let parsedSystem: Gamesystem + if(parsedGamesystemData.childsystems != undefined) { + parsedSystem = this.parseProductGamesystem(parsedGamesystemData) + } else { + parsedSystem = this.parseSimpleGamesystem(parsedGamesystemData) + } + this.parsedGamesystems.push(parsedSystem); + } + + parseSimpleGamesystem(gamesystemData: any): SimpleGamesystem { + const simpleGamesystem = new SimpleGamesystem(gamesystemData.componentName, gamesystemData.componentDescription) + + const stateParser = new StateParser(this.scriptAccounts); + simpleGamesystem.states = stateParser.parseStates(gamesystemData.states) + + const transitionParser = new TransitionParser(simpleGamesystem.states, this.scriptAccounts) + simpleGamesystem.transitions = transitionParser.parseTransitions(gamesystemData.transitions) + return simpleGamesystem + } + + parseProductGamesystem(gamesystemData: any) { + const productGamesystem = new ProductGamesystem(gamesystemData.componentName, gamesystemData.componentDescription); + const childsystemNames: string[] = [] + for(let i=0; i[] { + const topGamesystems: Gamesystem[] = [] + this.parsedGamesystems.forEach(parsedGamesystem => { + const searchedParentsystem = this.findParentsystem(parsedGamesystem.componentName) + if(searchedParentsystem != undefined) { + searchedParentsystem.addChildGamesystem(parsedGamesystem) + parsedGamesystem.parentGamesystem = searchedParentsystem + } else { + topGamesystems.push(parsedGamesystem) + } + }) + return topGamesystems + } + + findParentsystem(childsystemName: string) { + for(let i=0; i scriptAccount.componentName === scriptAccountName); + } +} diff --git a/src/app/project/parser/gamesystemParser/ScriptAccountConditionParser.ts b/src/app/project/parser/gamesystemParser/ScriptAccountConditionParser.ts new file mode 100644 index 0000000..7d7198c --- /dev/null +++ b/src/app/project/parser/gamesystemParser/ScriptAccountConditionParser.ts @@ -0,0 +1,39 @@ +import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; +import {ScriptAccountCondition} from "../../game-model/gamesystems/conditions/ScriptAccountCondition"; +import {max, min} from "rxjs"; + +export class ScriptAccountConditionParser { + + private scriptAccounts: ScriptAccount[] + + + constructor(scriptAccounts: ScriptAccount[]) { + this.scriptAccounts = scriptAccounts; + } + + parseStoredConditions(conditionData: any): ScriptAccountCondition[] { + const conditions: ScriptAccountCondition[] = [] + for(let i=0; i scriptAccount.componentName === scriptAccountName); + } +} diff --git a/src/app/project/parser/gamesystemParser/StateParser.ts b/src/app/project/parser/gamesystemParser/StateParser.ts new file mode 100644 index 0000000..8da602a --- /dev/null +++ b/src/app/project/parser/gamesystemParser/StateParser.ts @@ -0,0 +1,39 @@ +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"; + +export class StateParser { + + private conditionParser + + + constructor(scriptAccounts: ScriptAccount[]) { + this.conditionParser = new ScriptAccountConditionParser(scriptAccounts) + } + + public parseStates(stateData: any): SimpleState[] { + const parsedStates: SimpleState[] = [] + for(let i=0; i state.stateLabel === stateLabel); + } +} diff --git a/src/app/project/serializer/GamesystemSerializer.ts b/src/app/project/serializer/GamesystemSerializer.ts new file mode 100644 index 0000000..8ffcafc --- /dev/null +++ b/src/app/project/serializer/GamesystemSerializer.ts @@ -0,0 +1,109 @@ +import {Gamesystem} from "../game-model/gamesystems/Gamesystem"; +import {StoreComponent} from "../../../../app/storage/StoreComponent"; +import {SimpleGamesystem} from "../game-model/gamesystems/SimpleGamesystem"; +import {ProductGamesystem} from "../game-model/gamesystems/ProductGamesystem"; +import {SerializeConstants} from "./SerializeConstants"; +import {ModelComponentType} from "../game-model/ModelComponentType"; + +export class GamesystemSerializer { + + private static IGNORED_SIMPLE_ATTRIBUTES = ["parentGamesystem", 'incomingTransitions', "outgoingTransitions", "unsaved", "type"] + + public static serializeGamesystems(gamesystems: Gamesystem[]): StoreComponent[] { + let storedGamesystems: StoreComponent[] = [] + gamesystems.forEach(gamesystem => storedGamesystems = storedGamesystems.concat(this.serializeSingleGamesystem(gamesystem))) + return storedGamesystems + } + + private static serializeSingleGamesystem(gamesystem: Gamesystem): StoreComponent[] { + if(gamesystem instanceof SimpleGamesystem) { + console.log("Simple Gamesystem") + return [this.serializeSimpleGamesystem(gamesystem as SimpleGamesystem)] + } else { + return this.serializeProductGamesystem(gamesystem as ProductGamesystem) + } + } + + private static serializeSimpleGamesystem(simpleGamesystem: SimpleGamesystem): StoreComponent { + const fileName = this.computeSimpleGamesystemPath(simpleGamesystem); + if(simpleGamesystem.componentName === "Weather(Child)") { + console.log(fileName) + } + const jsonString = JSON.stringify(simpleGamesystem, (key, value) => { + + if(this.IGNORED_SIMPLE_ATTRIBUTES.includes(key)) { + return undefined + } else if(key === 'startingState' || key === 'endingState') { + return value.stateLabel + } else if(key === 'scriptAccount') { + return value.componentName + } else { + return value; + } + }, SerializeConstants.JSON_INDENT) + + return new StoreComponent(jsonString, fileName, ModelComponentType.GAMESYTEM) + } + + private static serializeProductGamesystem(productGamesystem: ProductGamesystem): StoreComponent[] { + const storedGamesystems: StoreComponent[] = [] + + const fileName = this.computeProductGamesystemPath(productGamesystem) + const innerGamesystemJsonArray: {'componentName': string}[] = [] + productGamesystem.innerGamesystems.forEach(innerGamesystem => { + innerGamesystemJsonArray.push({ + 'componentName': innerGamesystem.componentName + }) + + const storedChildsystems = this.serializeSingleGamesystem(innerGamesystem); + storedChildsystems.forEach(storedChildsystem => storedGamesystems.push(storedChildsystem)) + }) + + const jsonString = { + 'componentName': productGamesystem.componentName, + 'componentDescription': productGamesystem.componentDescription, + 'childsystems': innerGamesystemJsonArray + } + + const storedProductsystem = new StoreComponent(JSON.stringify(jsonString, null, SerializeConstants.JSON_INDENT), fileName, ModelComponentType.GAMESYTEM) + storedGamesystems.push(storedProductsystem) + + return storedGamesystems; + } + + private static computeSimpleGamesystemPath(simpleGamesystem: SimpleGamesystem): string { + if(simpleGamesystem.parentGamesystem == undefined) { + return simpleGamesystem.componentName + } else { + const pathElements: string[] = [simpleGamesystem.componentName] + let currentGamesystem: ProductGamesystem | undefined = simpleGamesystem.parentGamesystem + while(currentGamesystem != undefined) { + pathElements.unshift(currentGamesystem.componentName) + currentGamesystem = currentGamesystem.parentGamesystem + } + let output = "" + for(let i=0; i storeComponents.push(this.serializeSingleScriptAccount(scriptAccount))) + return storeComponents; + } + + private static serializeSingleScriptAccount(scriptAccount: ScriptAccount): StoreComponent { + const fileName = scriptAccount.componentName + const jsonString = JSON.stringify(scriptAccount, (key, value) => { + if(key === 'unsaved' || key === 'type') { + return undefined + } else { + return value; + } + }, SerializeConstants.JSON_INDENT) + return new StoreComponent(jsonString, fileName, ModelComponentType.SCRIPTACCOUNT); + } +} diff --git a/src/app/project/serializer/SerializeConstants.ts b/src/app/project/serializer/SerializeConstants.ts new file mode 100644 index 0000000..cc7e432 --- /dev/null +++ b/src/app/project/serializer/SerializeConstants.ts @@ -0,0 +1,3 @@ +export class SerializeConstants { + public static JSON_INDENT = 4 +} 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 4c07292..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,21 +1,13 @@ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {Gamesystem} from "../../game-model/gamesystems/Gamesystem"; -import {State} from "../../game-model/gamesystems/State"; -import {Transition} from "../../game-model/gamesystems/Transition"; -import {ProductGamesystem} from "../../game-model/gamesystems/ProductGamesystem"; import {FlatTreeControl} from "@angular/cdk/tree"; -import { - MatTree, - MatTreeFlatDataSource, - MatTreeFlattener, - MatTreeNode, MatTreeNodeDef, - MatTreeNodePadding, MatTreeNodeToggle -} from "@angular/material/tree"; -import {MatIcon} from "@angular/material/icon"; -import {MatIconButton} from "@angular/material/button"; -import {SimpleGamesystem} from "../../game-model/gamesystems/SimpleGamesystem"; -import {GameModel} from "../../game-model/GameModel"; +import {MatTreeFlatDataSource, MatTreeFlattener} from "@angular/material/tree"; 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 { @@ -100,7 +92,20 @@ export class GamescriptOverviewComponent implements OnInit { } } + getSelectedGamesystem() { + if(this.selectedGamesystem != undefined) { + return this.gameModel!.findGamesystem(this.selectedGamesystem!.name); + } else { + return undefined; + } + } + refresh() { this.dataSource.data = this.gameModel!.gamesystems; + this.resetSelectedGamesystem() + } + + resetSelectedGamesystem() { + this.selectedGamesystem = undefined } } 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', diff --git a/src/styles.css b/src/styles.css index 2fd855a..4f3f4b3 100644 --- a/src/styles.css +++ b/src/styles.css @@ -17,3 +17,7 @@ body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; } background-color: #4f5459 !important; color: white; } + +.icon-btn-primary { + color: #3c95f8; +} diff --git a/testModel/gamesystems/Testsystem.json b/testModel/gamesystems/Testsystem.json new file mode 100644 index 0000000..654df19 --- /dev/null +++ b/testModel/gamesystems/Testsystem.json @@ -0,0 +1,37 @@ +{ + "componentName": "Testsystem", + "componentDescription": "", + "states": [ + { + "initial": false, + "conditions": [], + "stateLabel": "A", + "stateDescription": "" + }, + { + "initial": false, + "conditions": [], + "stateLabel": "B", + "stateDescription": "" + } + ], + "transitions": [ + { + "scriptAccountActions": [ + { + "changingValue": 5, + "scriptAccount": "New ScriptAccount" + } + ], + "scriptAccountConditions": [ + { + "scriptAccount": "Temperature", + "minValue": 0, + "maxValue": "10" + } + ], + "startingState": "A", + "endingState": "B" + } + ] +} \ No newline at end of file diff --git a/testModel/gamesystems/Weathersystem/Season.json b/testModel/gamesystems/Weathersystem/Season.json new file mode 100644 index 0000000..a815ccb --- /dev/null +++ b/testModel/gamesystems/Weathersystem/Season.json @@ -0,0 +1,80 @@ +{ + "componentName": "Season", + "componentDescription": "Ein simples Gamesystem zur Modellierung verschiedener Jahreszeiten und deren Übergänge", + "states": [ + { + "initial": true, + "conditions": [ + { + "scriptAccount": "Temperature", + "minValue": 0, + "maxValue": "10" + } + ], + "stateLabel": "Frühling", + "stateDescription": "" + }, + { + "initial": false, + "conditions": [ + { + "scriptAccount": "Temperature", + "minValue": "10", + "maxValue": "30" + } + ], + "stateLabel": "Sommer", + "stateDescription": "" + }, + { + "initial": false, + "conditions": [ + { + "scriptAccount": "Temperature", + "minValue": "10", + "maxValue": "20" + } + ], + "stateLabel": "Herbst", + "stateDescription": "" + }, + { + "initial": false, + "conditions": [ + { + "scriptAccount": "Temperature", + "minValue": "-10", + "maxValue": "10" + } + ], + "stateLabel": "Winter", + "stateDescription": "" + } + ], + "transitions": [ + { + "scriptAccountActions": [], + "scriptAccountConditions": [], + "startingState": "Frühling", + "endingState": "Sommer" + }, + { + "scriptAccountActions": [], + "scriptAccountConditions": [], + "startingState": "Sommer", + "endingState": "Herbst" + }, + { + "scriptAccountActions": [], + "scriptAccountConditions": [], + "startingState": "Herbst", + "endingState": "Winter" + }, + { + "scriptAccountActions": [], + "scriptAccountConditions": [], + "startingState": "Winter", + "endingState": "Frühling" + } + ] +} \ No newline at end of file diff --git a/testModel/gamesystems/Weathersystem/Weather.json b/testModel/gamesystems/Weathersystem/Weather.json new file mode 100644 index 0000000..b9de825 --- /dev/null +++ b/testModel/gamesystems/Weathersystem/Weather.json @@ -0,0 +1,80 @@ +{ + "componentName": "Weather", + "componentDescription": "A small Gamesystem about local weather events", + "states": [ + { + "initial": true, + "conditions": [], + "stateLabel": "Sonne", + "stateDescription": "" + }, + { + "initial": false, + "conditions": [ + { + "scriptAccount": "Temperature", + "minValue": 0, + "maxValue": "30" + } + ], + "stateLabel": "Regen", + "stateDescription": "" + }, + { + "initial": false, + "conditions": [], + "stateLabel": "Wolke", + "stateDescription": "" + }, + { + "initial": false, + "conditions": [ + { + "scriptAccount": "Temperature", + "minValue": "-5", + "maxValue": 0 + } + ], + "stateLabel": "Schnee", + "stateDescription": "" + } + ], + "transitions": [ + { + "scriptAccountActions": [], + "scriptAccountConditions": [], + "startingState": "Sonne", + "endingState": "Wolke" + }, + { + "scriptAccountActions": [], + "scriptAccountConditions": [], + "startingState": "Wolke", + "endingState": "Sonne" + }, + { + "scriptAccountActions": [], + "scriptAccountConditions": [], + "startingState": "Wolke", + "endingState": "Regen" + }, + { + "scriptAccountActions": [], + "scriptAccountConditions": [], + "startingState": "Regen", + "endingState": "Wolke" + }, + { + "scriptAccountActions": [], + "scriptAccountConditions": [], + "startingState": "Wolke", + "endingState": "Schnee" + }, + { + "scriptAccountActions": [], + "scriptAccountConditions": [], + "startingState": "Schnee", + "endingState": "Wolke" + } + ] +} \ No newline at end of file diff --git a/testModel/gamesystems/Weathersystem/Weathersystem.json b/testModel/gamesystems/Weathersystem/Weathersystem.json new file mode 100644 index 0000000..df066e7 --- /dev/null +++ b/testModel/gamesystems/Weathersystem/Weathersystem.json @@ -0,0 +1 @@ +{"componentName":"Weathersystem","componentDescription":"Ein Wettersystem, dass sich aus normalem Wetter (Sonne, Regen, Wolke, Schnee, Sturm etc.) und zusätzlich den Jahreszeiten (Frühling, Sommer, Herbst, Winter, etc.) zusammensetzt.","childsystems":[{"componentName":"Season"},{"componentName":"Weather"}]} \ No newline at end of file diff --git a/testModel/script-accounts/Luftfeuchtigkeit.json b/testModel/script-accounts/Luftfeuchtigkeit.json index b948f4b..b4593b2 100644 --- a/testModel/script-accounts/Luftfeuchtigkeit.json +++ b/testModel/script-accounts/Luftfeuchtigkeit.json @@ -1,8 +1,6 @@ { - "unsaved": false, "componentName": "Luftfeuchtigkeit", "componentDescription": "", - "type": 0, "minValue": 0, "maxValue": 100 } \ No newline at end of file diff --git a/testModel/script-accounts/New ScriptAccount.json b/testModel/script-accounts/New ScriptAccount.json new file mode 100644 index 0000000..c4a4176 --- /dev/null +++ b/testModel/script-accounts/New ScriptAccount.json @@ -0,0 +1,6 @@ +{ + "componentName": "New ScriptAccount", + "componentDescription": "", + "minValue": 0, + "maxValue": 100 +} \ No newline at end of file diff --git a/testModel/script-accounts/Temperature.json b/testModel/script-accounts/Temperature.json index c53736b..91a3a6c 100644 --- a/testModel/script-accounts/Temperature.json +++ b/testModel/script-accounts/Temperature.json @@ -1,8 +1,6 @@ { - "unsaved": false, "componentName": "Temperature", "componentDescription": "", - "type": 0, - "minValue": 0, - "maxValue": 100 + "minValue": -30, + "maxValue": 50 } \ No newline at end of file