diff --git a/app/DeleteModel.js b/app/DeleteModel.js new file mode 100644 index 0000000..563c8fb --- /dev/null +++ b/app/DeleteModel.js @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DeleteTransaction = void 0; +const path = require("node:path"); +const fs = require("fs"); +class DeleteTransaction { + static deleteScriptAccount(projectDir, componentName) { + const filename = path.join(projectDir, "script-accounts", componentName + ".json"); + fs.unlinkSync(filename); + console.log("Delete ", filename); + } +} +exports.DeleteTransaction = DeleteTransaction; +//# sourceMappingURL=DeleteModel.js.map \ No newline at end of file diff --git a/app/DeleteModel.ts b/app/DeleteModel.ts new file mode 100644 index 0000000..cd00d88 --- /dev/null +++ b/app/DeleteModel.ts @@ -0,0 +1,10 @@ +import * as path from "node:path"; +import * as fs from "fs"; + +export class DeleteTransaction { + static deleteScriptAccount(projectDir: string, componentName: string) { + const filename = path.join(projectDir, "script-accounts", componentName + ".json") + fs.unlinkSync(filename) + console.log("Delete ", filename) + } +} diff --git a/app/main.ts b/app/main.ts index 0f784e9..4aa4388 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 {DeleteModel} from "../src/app/game-model/fs/DeleteModel"; +import {ModelComponentType} from "../src/app/game-model/ModelComponentType"; +import {DeleteTransaction} from "./DeleteModel"; let win: BrowserWindow | null = null; const args = process.argv.slice(1), @@ -99,6 +101,11 @@ function createWindow(): BrowserWindow { SaveProject.saveProject(projectDirectory, storageModels); }) + ipcMain.on('delete-component', (event, deletedComponent: DeleteModel) => { + console.log("Delete Model: ", deletedComponent) + deleteComponent(deletedComponent); + }) + const menuTemplate = [ { label: 'File', @@ -207,3 +214,10 @@ function openProjectFromFile(openProjectDir: string) { function saveProject() { win!.webContents.send('get-project-data') } + +function deleteComponent(component: DeleteModel) { + console.log("Delete Component") + if(component.modeltype == ModelComponentType.SCRIPTACCOUNT) { + DeleteTransaction.deleteScriptAccount(projectDirectory, component.componentName); + } +} diff --git a/src/app/app.component.ts b/src/app/app.component.ts index cdc62e8..5b3675f 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -18,6 +18,7 @@ import {LoadedProject} from "../../app/LoadedProject"; import {ProcessLoadedProject} from "./game-model/fs/ProcessLoadedProject"; import {StoreProject} from "./game-model/fs/store/StoreProject"; import {Gamesystem} from "./game-model/gamesystems/Gamesystem"; +import {DeleteModel} from "./game-model/fs/DeleteModel"; @Component({ selector: 'app-root', @@ -115,6 +116,7 @@ export class AppComponent implements OnInit{ if(res != undefined && res) { if(affectedModelComponent instanceof ScriptAccount) { this.gameModel!.removeScriptAccount(affectedModelComponent); + this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.SCRIPTACCOUNT)) } else if(affectedModelComponent instanceof Gamesystem) { this.gameModel!.removeGamesystem(affectedModelComponent); this.gamesystemOverview!.refresh() diff --git a/src/app/game-model/fs/DeleteModel.ts b/src/app/game-model/fs/DeleteModel.ts new file mode 100644 index 0000000..186c583 --- /dev/null +++ b/src/app/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/testModel/script-accounts/Temperature.json b/testModel/script-accounts/Temperature.json deleted file mode 100644 index 53db39d..0000000 --- a/testModel/script-accounts/Temperature.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "componentName": "Temperature", - "componentDescription": "", - "minValue": -50, - "maxValue": 70 -} \ No newline at end of file