This commit is contained in:
parent
d56166b245
commit
78a264aa26
11
app/LoadModel.js
Normal file
11
app/LoadModel.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.LoadModel = void 0;
|
||||||
|
class LoadModel {
|
||||||
|
constructor(jsonString, modelType) {
|
||||||
|
this.jsonString = jsonString;
|
||||||
|
this.modelType = modelType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.LoadModel = LoadModel;
|
||||||
|
//# sourceMappingURL=LoadModel.js.map
|
12
app/LoadModel.ts
Normal file
12
app/LoadModel.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import {ModelComponentType} from "../src/app/game-model/ModelComponentType";
|
||||||
|
|
||||||
|
export class LoadModel {
|
||||||
|
jsonString: string
|
||||||
|
modelType: ModelComponentType
|
||||||
|
|
||||||
|
|
||||||
|
constructor(jsonString: string, modelType: ModelComponentType) {
|
||||||
|
this.jsonString = jsonString;
|
||||||
|
this.modelType = modelType;
|
||||||
|
}
|
||||||
|
}
|
11
app/LoadedProject.js
Normal file
11
app/LoadedProject.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.LoadedProject = void 0;
|
||||||
|
class LoadedProject {
|
||||||
|
constructor(projectName, loadedModels) {
|
||||||
|
this.projectName = projectName;
|
||||||
|
this.loadedModels = loadedModels;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.LoadedProject = LoadedProject;
|
||||||
|
//# sourceMappingURL=LoadedProject.js.map
|
12
app/LoadedProject.ts
Normal file
12
app/LoadedProject.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import {LoadModel} from "./LoadModel";
|
||||||
|
|
||||||
|
export class LoadedProject {
|
||||||
|
projectName: string
|
||||||
|
loadedModels: LoadModel[]
|
||||||
|
|
||||||
|
|
||||||
|
constructor(projectName: string, loadedModels: LoadModel[]) {
|
||||||
|
this.projectName = projectName;
|
||||||
|
this.loadedModels = loadedModels;
|
||||||
|
}
|
||||||
|
}
|
@ -3,18 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.SaveProject = void 0;
|
exports.SaveProject = void 0;
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("node:path");
|
const path = require("node:path");
|
||||||
|
const ModelComponentType_1 = require("../src/app/game-model/ModelComponentType");
|
||||||
|
const LoadedProject_1 = require("./LoadedProject");
|
||||||
class SaveProject {
|
class SaveProject {
|
||||||
static saveProject(projectDir, storageModels) {
|
static saveProject(projectDir, storageModels) {
|
||||||
const directoryPath = 'testModel/';
|
if (!fs.existsSync(projectDir)) {
|
||||||
if (!fs.existsSync(directoryPath)) {
|
fs.mkdirSync(projectDir, { recursive: true });
|
||||||
fs.mkdirSync(directoryPath, { recursive: true });
|
|
||||||
}
|
}
|
||||||
storageModels.forEach(storageModel => {
|
storageModels.forEach(storageModel => {
|
||||||
const modelDir = path.join(directoryPath, storageModel.storageDir);
|
const modelDir = path.join(projectDir, storageModel.storageDir);
|
||||||
if (!fs.existsSync(modelDir)) {
|
if (!fs.existsSync(modelDir)) {
|
||||||
fs.mkdirSync(modelDir, { recursive: true });
|
fs.mkdirSync(modelDir, { recursive: true });
|
||||||
}
|
}
|
||||||
const filePath = path.join(directoryPath, storageModel.storageDir, storageModel.fileName + ".json");
|
const filePath = path.join(modelDir, storageModel.fileName + ".json");
|
||||||
fs.writeFile(filePath, storageModel.jsonString, 'utf-8', (err) => {
|
fs.writeFile(filePath, storageModel.jsonString, 'utf-8', (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error writing JSON to file:', err);
|
console.error('Error writing JSON to file:', err);
|
||||||
@ -25,6 +26,27 @@ class SaveProject {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
static loadProject(projectDir) {
|
||||||
|
const loadedScriptAccounts = SaveProject.loadScriptAccounts(projectDir);
|
||||||
|
return new LoadedProject_1.LoadedProject(path.basename(projectDir), loadedScriptAccounts);
|
||||||
|
}
|
||||||
|
static loadScriptAccounts(projectDir) {
|
||||||
|
const scriptAccountDir = path.join(projectDir, "script-accounts");
|
||||||
|
if (!fs.existsSync(scriptAccountDir)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const loadedScriptAccounts = [];
|
||||||
|
const scriptAccountFileNames = fs.readdirSync(scriptAccountDir);
|
||||||
|
scriptAccountFileNames.forEach(scriptAccountFileName => {
|
||||||
|
const scriptAccountFile = path.join(scriptAccountDir, scriptAccountFileName);
|
||||||
|
const scriptAccountData = fs.readFileSync(scriptAccountFile, 'utf-8');
|
||||||
|
loadedScriptAccounts.push({
|
||||||
|
modelType: ModelComponentType_1.ModelComponentType.SCRIPTACCOUNT,
|
||||||
|
jsonString: scriptAccountData
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return loadedScriptAccounts;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.SaveProject = SaveProject;
|
exports.SaveProject = SaveProject;
|
||||||
//# sourceMappingURL=SaveProject.js.map
|
//# sourceMappingURL=SaveProject.js.map
|
@ -1,22 +1,25 @@
|
|||||||
import {StorageModel} from "../src/app/game-model/StorageModel";
|
import {StorageModel} from "../src/app/game-model/StorageModel";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from "node:path";
|
import * as path from "node:path";
|
||||||
|
import {LoadModel} from "./LoadModel";
|
||||||
|
import {ModelComponentType} from "../src/app/game-model/ModelComponentType";
|
||||||
|
import {BrowserWindow} from "electron";
|
||||||
|
import {LoadedProject} from "./LoadedProject";
|
||||||
|
|
||||||
|
|
||||||
export class SaveProject {
|
export class SaveProject {
|
||||||
static saveProject(projectDir: string, storageModels: StorageModel[]) {
|
static saveProject(projectDir: string, storageModels: StorageModel[]) {
|
||||||
const directoryPath = 'testModel/'
|
if(!fs.existsSync(projectDir)) {
|
||||||
if(!fs.existsSync(directoryPath)) {
|
fs.mkdirSync(projectDir, {recursive: true});
|
||||||
fs.mkdirSync(directoryPath, {recursive: true});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
storageModels.forEach(storageModel => {
|
storageModels.forEach(storageModel => {
|
||||||
const modelDir = path.join(directoryPath, storageModel.storageDir);
|
const modelDir = path.join(projectDir, storageModel.storageDir);
|
||||||
if(!fs.existsSync(modelDir)) {
|
if(!fs.existsSync(modelDir)) {
|
||||||
fs.mkdirSync(modelDir, {recursive: true});
|
fs.mkdirSync(modelDir, {recursive: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
const filePath = path.join(directoryPath, storageModel.storageDir, storageModel.fileName + ".json");
|
const filePath = path.join(modelDir, storageModel.fileName + ".json");
|
||||||
fs.writeFile(filePath, storageModel.jsonString ,'utf-8', (err) => {
|
fs.writeFile(filePath, storageModel.jsonString ,'utf-8', (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error writing JSON to file:', err);
|
console.error('Error writing JSON to file:', err);
|
||||||
@ -26,4 +29,33 @@ export class SaveProject {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static loadProject(projectDir: string) {
|
||||||
|
const loadedScriptAccounts: LoadModel[] = SaveProject.loadScriptAccounts(projectDir)
|
||||||
|
|
||||||
|
return new LoadedProject(path.basename(projectDir), loadedScriptAccounts);
|
||||||
|
}
|
||||||
|
|
||||||
|
static loadScriptAccounts(projectDir: string): LoadModel[] {
|
||||||
|
const scriptAccountDir = path.join(projectDir, "script-accounts");
|
||||||
|
if (!fs.existsSync(scriptAccountDir)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadedScriptAccounts: LoadModel[] = [];
|
||||||
|
|
||||||
|
const scriptAccountFileNames = fs.readdirSync(scriptAccountDir);
|
||||||
|
scriptAccountFileNames.forEach(scriptAccountFileName => {
|
||||||
|
const scriptAccountFile = path.join(scriptAccountDir, scriptAccountFileName)
|
||||||
|
const scriptAccountData: string = fs.readFileSync(scriptAccountFile, 'utf-8');
|
||||||
|
|
||||||
|
loadedScriptAccounts.push({
|
||||||
|
modelType: ModelComponentType.SCRIPTACCOUNT,
|
||||||
|
jsonString: scriptAccountData
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
return loadedScriptAccounts;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
14
app/main.ts
14
app/main.ts
@ -1,4 +1,4 @@
|
|||||||
import {app, BrowserWindow, screen, Menu, ipcMain, ipcRenderer, globalShortcut} from 'electron';
|
import {app, BrowserWindow, screen, Menu, ipcMain, dialog, globalShortcut} from 'electron';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import {json} from "node:stream/consumers";
|
import {json} from "node:stream/consumers";
|
||||||
@ -171,7 +171,19 @@ function createNewProject() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openProject() {
|
function openProject() {
|
||||||
|
const selectedPaths = dialog.showOpenDialogSync(win!, {
|
||||||
|
title: "Open Game-Model",
|
||||||
|
properties: [
|
||||||
|
"openDirectory",
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
if(selectedPaths != undefined) {
|
||||||
|
projectDirectory = selectedPaths[0];
|
||||||
|
console.log("Open Project-Directory: ", projectDirectory)
|
||||||
|
const loadedProject = SaveProject.loadProject(projectDirectory)
|
||||||
|
win!.webContents.send("open-project", loadedProject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveProject() {
|
function saveProject() {
|
||||||
|
@ -17,6 +17,9 @@ import {GamescriptOverviewComponent} from "./side-overviews/gamescript-overview/
|
|||||||
import {SimpleGamesystem} from "./game-model/gamesystems/SimpleGamesystem";
|
import {SimpleGamesystem} from "./game-model/gamesystems/SimpleGamesystem";
|
||||||
import {ProductGamesystem} from "./game-model/gamesystems/ProductGamesystem";
|
import {ProductGamesystem} from "./game-model/gamesystems/ProductGamesystem";
|
||||||
import {ProductState} from "./game-model/gamesystems/ProductState";
|
import {ProductState} from "./game-model/gamesystems/ProductState";
|
||||||
|
import {LoadModel} from "../../app/LoadModel";
|
||||||
|
import {LoadedProject} from "../../app/LoadedProject";
|
||||||
|
import {ProcessLoadedProject} from "./game-model/fs/ProcessLoadedProject";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@ -56,6 +59,10 @@ export class AppComponent implements OnInit{
|
|||||||
this.saveGameModel();
|
this.saveGameModel();
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
electronService.ipcRenderer.on('open-project', (event: any, loadedProject: LoadedProject) => {
|
||||||
|
this.gameModel = ProcessLoadedProject.processLoadedProject(loadedProject)
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
console.log('Run in browser');
|
console.log('Run in browser');
|
||||||
}
|
}
|
||||||
@ -153,7 +160,7 @@ export class AppComponent implements OnInit{
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.gameModel = new GameModel("No More");
|
/*this.gameModel = new GameModel("No More");
|
||||||
this.gameModel.createScriptAccount("Temperature");
|
this.gameModel.createScriptAccount("Temperature");
|
||||||
this.gameModel.createScriptAccount("Luftfeuchtigkeit");
|
this.gameModel.createScriptAccount("Luftfeuchtigkeit");
|
||||||
|
|
||||||
@ -175,7 +182,7 @@ export class AppComponent implements OnInit{
|
|||||||
|
|
||||||
weather_season.createState([springState!, sunnyState!]);
|
weather_season.createState([springState!, sunnyState!]);
|
||||||
|
|
||||||
this.gameModel.addGamesystem(weather_season);
|
this.gameModel.addGamesystem(weather_season);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
openScriptAccountsOverview() {
|
openScriptAccountsOverview() {
|
||||||
|
@ -106,4 +106,8 @@ export class GameModel {
|
|||||||
|
|
||||||
return storageModels;
|
return storageModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addScriptAccount(scriptAccount: ScriptAccount) {
|
||||||
|
this.scriptAccounts.push(scriptAccount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
30
src/app/game-model/fs/ProcessLoadedProject.ts
Normal file
30
src/app/game-model/fs/ProcessLoadedProject.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import {GameModel} from "../GameModel";
|
||||||
|
import {LoadedProject} from "../../../../app/LoadedProject";
|
||||||
|
import {LoadModel} from "../../../../app/LoadModel";
|
||||||
|
import {ModelComponentType} from "../ModelComponentType";
|
||||||
|
import {ScriptAccount} from "../scriptAccounts/ScriptAccount";
|
||||||
|
|
||||||
|
export class ProcessLoadedProject {
|
||||||
|
|
||||||
|
static processLoadedProject(loadedProject: LoadedProject): GameModel {
|
||||||
|
const gameModel = new GameModel(loadedProject.projectName);
|
||||||
|
loadedProject.loadedModels.forEach(loadedModel => this.processLoadedModel(gameModel, loadedModel))
|
||||||
|
return gameModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
static processLoadedModel(gameModel: GameModel, loadedModel: LoadModel) {
|
||||||
|
switch (loadedModel.modelType) {
|
||||||
|
case ModelComponentType.SCRIPTACCOUNT: this.processLoadedScriptAccount(gameModel, loadedModel); break;
|
||||||
|
case ModelComponentType.GAMESYTEM: this.processLoadedGamesystem(gameModel, loadedModel); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static processLoadedScriptAccount(gameModel: GameModel, loadedModel: LoadModel) {
|
||||||
|
const scriptAccount = new ScriptAccount("", "");
|
||||||
|
Object.assign(scriptAccount, JSON.parse(loadedModel.jsonString));
|
||||||
|
gameModel.addScriptAccount(scriptAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
static processLoadedGamesystem(gameModel: GameModel, loadedModel: LoadModel) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"unsaved": false,
|
"unsaved": false,
|
||||||
"componentName": "Temperature",
|
"componentName": "Temperature",
|
||||||
"componentDescription": "ddada",
|
"componentDescription": "",
|
||||||
"type": 0,
|
"type": 0,
|
||||||
"minValue": 0,
|
"minValue": 0,
|
||||||
"maxValue": 100
|
"maxValue": 100
|
||||||
|
Loading…
Reference in New Issue
Block a user