issue-12 #14
30
app/SaveProject.js
Normal file
30
app/SaveProject.js
Normal file
@ -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
|
29
app/SaveProject.ts
Normal file
29
app/SaveProject.ts
Normal file
@ -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);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
32
app/main.ts
32
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')
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
<app-model-component-editor [modelComponent]="modelComponent" (onModelNameUpdated)="onModelNameUpdate()"></app-model-component-editor>
|
||||
<app-script-account-editor *ngIf="modelComponent.type === ModelComponentType.SCRIPTACCOUNT"
|
||||
[scriptAccount]="convertModelComponentToScriptAccount(modelComponent)"></app-script-account-editor>
|
||||
<app-gamesystem-editor *ngIf="modelComponent.type == ModelComponentType.GAMESYTEM"
|
||||
<app-gamesystem-editor *ngIf="modelComponent.type === ModelComponentType.GAMESYTEM"
|
||||
[gamesystem]="convertModelComponentToGamesystem(modelComponent)"
|
||||
(onOpenGamesystemEditor)="openGameModelComponent($event)"></app-gamesystem-editor>
|
||||
|
||||
|
@ -100,6 +100,8 @@ export class GameModel {
|
||||
jsonString: scriptAccountJson,
|
||||
storageDir: "script-accounts"
|
||||
})
|
||||
|
||||
console.log(scriptAccount)
|
||||
})
|
||||
|
||||
return storageModels;
|
||||
|
@ -10,6 +10,7 @@ export class ScriptAccount extends ModelComponent{
|
||||
}
|
||||
|
||||
save(): string {
|
||||
this.unsaved = false;
|
||||
return JSON.stringify(this, null, SaveComponent.JSON_INDENT)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"unsaved": false,
|
||||
"componentName": "Temperature",
|
||||
"componentDescription": "",
|
||||
"componentDescription": "ddada",
|
||||
"type": 0,
|
||||
"minValue": 0,
|
||||
"maxValue": 100
|
||||
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"unsaved": false,
|
||||
"componentName": "Temperature",
|
||||
"componentDescription": "",
|
||||
"type": 0,
|
||||
"minValue": 0,
|
||||
"maxValue": 100
|
||||
}
|
Loading…
Reference in New Issue
Block a user