issue-15 #21
16
app/main.ts
16
app/main.ts
@ -2,6 +2,9 @@ import {app, BrowserWindow, dialog, globalShortcut, ipcMain, Menu, screen} from
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import {GameModelLoader} from "./storage/loader/GameModelLoader";
|
||||
import {StoredGameModel} from "./storage/StoredGameModel";
|
||||
import {ScriptAccountStorage} from "./storage/storing/ScriptAccountStoring";
|
||||
import {ModelComponentFileDirectory} from "./storage/ModelComponentFileDirectory";
|
||||
|
||||
let win: BrowserWindow | null = null;
|
||||
const args = process.argv.slice(1),
|
||||
@ -92,10 +95,9 @@ 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)
|
||||
@ -129,7 +131,6 @@ function createWindow(): BrowserWindow {
|
||||
]
|
||||
const menu = Menu.buildFromTemplate(menuTemplate);
|
||||
Menu.setApplicationMenu(menu)
|
||||
loadDevProjectAtStart()
|
||||
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
loadDevProjectAtStart()
|
||||
@ -211,6 +212,11 @@ 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)
|
||||
}
|
||||
|
||||
/*function deleteComponent(component: DeleteModel) {
|
||||
console.log("Delete Component")
|
||||
if(component.modeltype == ModelComponentType.SCRIPTACCOUNT) {
|
||||
|
33
app/storage/storing/ScriptAccountStoring.js
Normal file
33
app/storage/storing/ScriptAccountStoring.js
Normal file
@ -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
|
36
app/storage/storing/ScriptAccountStoring.ts
Normal file
36
app/storage/storing/ScriptAccountStoring.ts
Normal file
@ -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')
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@
|
||||
<button mat-menu-item (click)="openGamesystemsOverview()">{{ModelComponentTypeUtillities.toString(ModelComponentType.GAMESYTEM)}}</button>
|
||||
</mat-menu>
|
||||
</div>
|
||||
<app-script-account-overview *ngIf="openContent == ModelComponentType.SCRIPTACCOUNT" #scriptAccountOverview [gameModel]="projectService.gameModel" (onOpenScriptAccount)="openModelComponent($event)"></app-script-account-overview>
|
||||
<app-script-account-overview *ngIf="openContent == ModelComponentType.SCRIPTACCOUNT" #scriptAccountOverview [gameModel]="gameModel" (onOpenScriptAccount)="openModelComponent($event)"></app-script-account-overview>
|
||||
<app-gamescript-overview *ngIf="openContent == ModelComponentType.GAMESYTEM" #gamesystemOverview [gameModel]="gameModel" (openGamesystemEditor)="openModelComponent($event)"></app-gamescript-overview>
|
||||
</mat-drawer>
|
||||
|
||||
|
@ -17,6 +17,8 @@ import {StoredGameModel} from "../../app/storage/StoredGameModel";
|
||||
import {GamesystemParser} from "./project/parser/gamesystemParser/GamesystemParser";
|
||||
import {ScriptAccountParser} from "./project/parser/ScriptAccountParser";
|
||||
import {ElectronService} from "./core/services";
|
||||
import {ScriptAccountSerializer} from "./project/serializer/ScriptAccountSerializer";
|
||||
import {StoreComponent} from "../../app/storage/StoreComponent";
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@ -162,11 +164,19 @@ export class AppComponent implements OnInit{
|
||||
gameModel.scriptAccounts = scriptAccounts
|
||||
gameModel.gamesystems = gamesystems
|
||||
|
||||
console.log(gameModel.scriptAccounts)
|
||||
|
||||
this.gameModel = gameModel;
|
||||
}
|
||||
|
||||
onSaveProject() {
|
||||
const storedScriptAccounts = ScriptAccountSerializer.serializeScriptAccounts(this.gameModel!.scriptAccounts)
|
||||
const storedGamesystems: StoreComponent[] = [];
|
||||
const storeModel = new StoredGameModel(this.gameModel!.gameModelName, storedScriptAccounts, storedGamesystems)
|
||||
|
||||
if(this.electronService.isElectron) {
|
||||
this.electronService.ipcRenderer.send('save-model', storeModel)
|
||||
}
|
||||
}
|
||||
|
||||
openScriptAccountsOverview() {
|
||||
|
@ -7,13 +7,13 @@ import {SimpleGamesystem} from "./gamesystems/SimpleGamesystem";
|
||||
import {StorageModel} from "./fs/StorageModel";
|
||||
|
||||
export class GameModel {
|
||||
private readonly _gameModelName: string
|
||||
gameModelName: string
|
||||
|
||||
gamesystems: Gamesystem<any, any>[] = [];
|
||||
scriptAccounts: ScriptAccount[] = [];
|
||||
|
||||
constructor(gameModelName: string) {
|
||||
this._gameModelName = gameModelName;
|
||||
this.gameModelName = gameModelName;
|
||||
}
|
||||
|
||||
addGamesystem(gamesystem: Gamesystem<any, any>) {
|
||||
|
25
src/app/project/serializer/ScriptAccountSerializer.ts
Normal file
25
src/app/project/serializer/ScriptAccountSerializer.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import {ScriptAccount} from "../game-model/scriptAccounts/ScriptAccount";
|
||||
import {StoreComponent} from "../../../../app/storage/StoreComponent";
|
||||
import {SerializeConstants} from "./SerializeConstants";
|
||||
import {ModelComponentType} from "../game-model/ModelComponentType";
|
||||
|
||||
export class ScriptAccountSerializer {
|
||||
|
||||
public static serializeScriptAccounts(scriptAccounts: ScriptAccount[]): StoreComponent[] {
|
||||
const storeComponents: StoreComponent[] = []
|
||||
scriptAccounts.forEach(scriptAccount => 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);
|
||||
}
|
||||
}
|
3
src/app/project/serializer/SerializeConstants.ts
Normal file
3
src/app/project/serializer/SerializeConstants.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export class SerializeConstants {
|
||||
public static JSON_INDENT = 4
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"componentName": "Temperature",
|
||||
"componentDescription": "",
|
||||
"minValue": -50,
|
||||
"minValue": -30,
|
||||
"maxValue": 50
|
||||
}
|
Loading…
Reference in New Issue
Block a user