issue-12 #14

Merged
sebastian merged 6 commits from issue-12 into main 2024-02-17 15:14:34 +01:00
8 changed files with 73 additions and 33 deletions
Showing only changes of commit d56166b245 - Show all commits

30
app/SaveProject.js Normal file
View 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
View 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);
}
})
})
}
}

View File

@ -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')
}

View File

@ -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>

View File

@ -100,6 +100,8 @@ export class GameModel {
jsonString: scriptAccountJson,
storageDir: "script-accounts"
})
console.log(scriptAccount)
})
return storageModels;

View File

@ -10,6 +10,7 @@ export class ScriptAccount extends ModelComponent{
}
save(): string {
this.unsaved = false;
return JSON.stringify(this, null, SaveComponent.JSON_INDENT)
}
}

View File

@ -1,7 +1,7 @@
{
"unsaved": false,
"componentName": "Temperature",
"componentDescription": "",
"componentDescription": "ddada",
"type": 0,
"minValue": 0,
"maxValue": 100

View File

@ -1,8 +0,0 @@
{
"unsaved": false,
"componentName": "Temperature",
"componentDescription": "",
"type": 0,
"minValue": 0,
"maxValue": 100
}