diff --git a/app/SaveProject.js b/app/SaveProject.js
new file mode 100644
index 0000000..6e6d440
--- /dev/null
+++ b/app/SaveProject.js
@@ -0,0 +1,30 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.SaveProject = void 0;
+const fs = require("fs");
+const path = require("node:path");
+class SaveProject {
+ static saveProject(projectDir, storageModels) {
+ const directoryPath = 'testModel/';
+ if (!fs.existsSync(directoryPath)) {
+ fs.mkdirSync(directoryPath, { recursive: true });
+ }
+ storageModels.forEach(storageModel => {
+ const modelDir = path.join(directoryPath, storageModel.storageDir);
+ if (!fs.existsSync(modelDir)) {
+ fs.mkdirSync(modelDir, { recursive: true });
+ }
+ const filePath = path.join(directoryPath, storageModel.storageDir, 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);
+ }
+ });
+ });
+ }
+}
+exports.SaveProject = SaveProject;
+//# sourceMappingURL=SaveProject.js.map
\ No newline at end of file
diff --git a/app/SaveProject.ts b/app/SaveProject.ts
new file mode 100644
index 0000000..9368adc
--- /dev/null
+++ b/app/SaveProject.ts
@@ -0,0 +1,29 @@
+import {StorageModel} from "../src/app/game-model/StorageModel";
+import * as fs from "fs";
+import * as path from "node:path";
+
+
+export class SaveProject {
+ static saveProject(projectDir: string, storageModels: StorageModel[]) {
+ const directoryPath = 'testModel/'
+ if(!fs.existsSync(directoryPath)) {
+ fs.mkdirSync(directoryPath, {recursive: true});
+ }
+
+ storageModels.forEach(storageModel => {
+ const modelDir = path.join(directoryPath, storageModel.storageDir);
+ if(!fs.existsSync(modelDir)) {
+ fs.mkdirSync(modelDir, {recursive: true});
+ }
+
+ const filePath = path.join(directoryPath, storageModel.storageDir, 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);
+ }
+ })
+ })
+ }
+}
diff --git a/app/main.ts b/app/main.ts
index 5a25dde..d27f239 100644
--- a/app/main.ts
+++ b/app/main.ts
@@ -1,8 +1,9 @@
-import {app, BrowserWindow, screen, Menu, ipcMain, ipcRenderer} from 'electron';
+import {app, BrowserWindow, screen, Menu, ipcMain, ipcRenderer, globalShortcut} 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/StorageModel";
+import {SaveProject} from "./SaveProject";
let win: BrowserWindow | null = null;
const args = process.argv.slice(1),
@@ -94,26 +95,8 @@ function createWindow(): BrowserWindow {
})
ipcMain.on('save-model', (event, storageModels: StorageModel[]) => {
- const directoryPath = 'testModel/'
- if(!fs.existsSync(directoryPath)) {
- fs.mkdirSync(directoryPath, {recursive: true});
- }
-
- storageModels.forEach(storageModel => {
- const modelDir = path.join(directoryPath, storageModel.storageDir);
- if(!fs.existsSync(modelDir)) {
- fs.mkdirSync(modelDir, {recursive: true});
- }
-
- const filePath = path.join(directoryPath, storageModel.storageDir, 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);
- }
- })
- })
+ console.log("Save Model")
+ SaveProject.saveProject(projectDirectory, storageModels);
})
const menuTemplate = [
@@ -171,7 +154,11 @@ try {
}
});
-
+ app.whenReady().then(() => {
+ globalShortcut.register('CommandOrControl+S', () => {
+ saveProject();
+ })
+ })
} catch (e) {
// Catch Error
@@ -188,6 +175,5 @@ function openProject() {
}
function saveProject() {
- console.log("Clicked SaveProject")
win!.webContents.send('get-project-data')
}
diff --git a/src/app/editor/editor.component.html b/src/app/editor/editor.component.html
index 59dcd6f..b43ce41 100644
--- a/src/app/editor/editor.component.html
+++ b/src/app/editor/editor.component.html
@@ -10,7 +10,7 @@
-
diff --git a/src/app/game-model/GameModel.ts b/src/app/game-model/GameModel.ts
index 2c6a350..a396a92 100644
--- a/src/app/game-model/GameModel.ts
+++ b/src/app/game-model/GameModel.ts
@@ -100,6 +100,8 @@ export class GameModel {
jsonString: scriptAccountJson,
storageDir: "script-accounts"
})
+
+ console.log(scriptAccount)
})
return storageModels;
diff --git a/src/app/game-model/scriptAccounts/ScriptAccount.ts b/src/app/game-model/scriptAccounts/ScriptAccount.ts
index 57556e7..62b0636 100644
--- a/src/app/game-model/scriptAccounts/ScriptAccount.ts
+++ b/src/app/game-model/scriptAccounts/ScriptAccount.ts
@@ -10,6 +10,7 @@ export class ScriptAccount extends ModelComponent{
}
save(): string {
+ this.unsaved = false;
return JSON.stringify(this, null, SaveComponent.JSON_INDENT)
}
}
diff --git a/testModel/script-accounts/Temperature.json b/testModel/script-accounts/Temperature.json
index c53736b..56a6930 100644
--- a/testModel/script-accounts/Temperature.json
+++ b/testModel/script-accounts/Temperature.json
@@ -1,7 +1,7 @@
{
"unsaved": false,
"componentName": "Temperature",
- "componentDescription": "",
+ "componentDescription": "ddada",
"type": 0,
"minValue": 0,
"maxValue": 100
diff --git a/testModel/scriptAccounts/Temperature.json b/testModel/scriptAccounts/Temperature.json
deleted file mode 100644
index c53736b..0000000
--- a/testModel/scriptAccounts/Temperature.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "unsaved": false,
- "componentName": "Temperature",
- "componentDescription": "",
- "type": 0,
- "minValue": 0,
- "maxValue": 100
-}
\ No newline at end of file