issue-15 #21
17
app/storage/FileUtils.js
Normal file
17
app/storage/FileUtils.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.FileUtils = void 0;
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("node:path");
|
||||||
|
class FileUtils {
|
||||||
|
static listFilesInDirectory(directory) {
|
||||||
|
if (fs.lstatSync(directory).isDirectory()) {
|
||||||
|
return fs.readdirSync(directory).map(fileName => path.join(directory, fileName));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.FileUtils = FileUtils;
|
||||||
|
//# sourceMappingURL=FileUtils.js.map
|
11
app/storage/ModelComponentFileDirectory.js
Normal file
11
app/storage/ModelComponentFileDirectory.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.ModelComponentFileDirectory = void 0;
|
||||||
|
class ModelComponentFileDirectory {
|
||||||
|
}
|
||||||
|
exports.ModelComponentFileDirectory = ModelComponentFileDirectory;
|
||||||
|
ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME = "script-accounts";
|
||||||
|
ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME = "gamesystems";
|
||||||
|
ModelComponentFileDirectory.GAMESYSTEM_SIMPLE_DIR_NAME = "simple";
|
||||||
|
ModelComponentFileDirectory.GAMESYSTEM_PRODUCT_DIR_NAME = "product";
|
||||||
|
//# sourceMappingURL=ModelComponentFileDirectory.js.map
|
12
app/storage/StoreComponent.js
Normal file
12
app/storage/StoreComponent.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.StoreComponent = void 0;
|
||||||
|
class StoreComponent {
|
||||||
|
constructor(jsonString, fileName, componentType) {
|
||||||
|
this.jsonString = jsonString;
|
||||||
|
this.fileName = fileName;
|
||||||
|
this.componentType = componentType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.StoreComponent = StoreComponent;
|
||||||
|
//# sourceMappingURL=StoreComponent.js.map
|
11
app/storage/StoredGameModel.js
Normal file
11
app/storage/StoredGameModel.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.StoredGameModel = void 0;
|
||||||
|
class StoredGameModel {
|
||||||
|
constructor(gameModelName, loadedModels) {
|
||||||
|
this.gameModelName = gameModelName;
|
||||||
|
this.loadedModels = loadedModels;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.StoredGameModel = StoredGameModel;
|
||||||
|
//# sourceMappingURL=StoredGameModel.js.map
|
32
app/storage/loader/GameModelLoader.js
Normal file
32
app/storage/loader/GameModelLoader.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.GameModelLoader = void 0;
|
||||||
|
const StoredGameModel_1 = require("../StoredGameModel");
|
||||||
|
const path = require("node:path");
|
||||||
|
const ModelComponentFileDirectory_1 = require("../ModelComponentFileDirectory");
|
||||||
|
const ScriptAccountLoader_1 = require("./ScriptAccountLoader");
|
||||||
|
class GameModelLoader {
|
||||||
|
constructor(gameModelDir) {
|
||||||
|
this.gameModelDir = gameModelDir;
|
||||||
|
}
|
||||||
|
loadGameModel() {
|
||||||
|
const gameModelName = path.basename(this.gameModelDir);
|
||||||
|
const gameModelComponents = this.loadGameModelComponents();
|
||||||
|
return new StoredGameModel_1.StoredGameModel(gameModelName, gameModelComponents);
|
||||||
|
}
|
||||||
|
loadGameModelComponents() {
|
||||||
|
let gameModelComponents = this.loadScriptAccountComponents();
|
||||||
|
gameModelComponents = gameModelComponents.concat(this.loadGamesystems());
|
||||||
|
return gameModelComponents;
|
||||||
|
}
|
||||||
|
loadScriptAccountComponents() {
|
||||||
|
const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME);
|
||||||
|
const scriptAccountLoader = new ScriptAccountLoader_1.ScriptAccountLoader(scriptAccountDir);
|
||||||
|
return scriptAccountLoader.loadScriptAccounts();
|
||||||
|
}
|
||||||
|
loadGamesystems() {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.GameModelLoader = GameModelLoader;
|
||||||
|
//# sourceMappingURL=GameModelLoader.js.map
|
31
app/storage/loader/ScriptAccountLoader.js
Normal file
31
app/storage/loader/ScriptAccountLoader.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.ScriptAccountLoader = void 0;
|
||||||
|
const StoreComponent_1 = require("../StoreComponent");
|
||||||
|
const FileUtils_1 = require("../FileUtils");
|
||||||
|
const ModelComponentType_1 = require("../../../src/app/project/game-model/ModelComponentType");
|
||||||
|
const fs = require("fs");
|
||||||
|
class ScriptAccountLoader {
|
||||||
|
constructor(scriptAccountDir) {
|
||||||
|
this.scriptAccountDir = scriptAccountDir;
|
||||||
|
}
|
||||||
|
loadScriptAccounts() {
|
||||||
|
const scriptAccountFiles = FileUtils_1.FileUtils.listFilesInDirectory(this.scriptAccountDir);
|
||||||
|
const loadedScriptAccounts = [];
|
||||||
|
scriptAccountFiles.forEach(scriptAccountFile => {
|
||||||
|
const loadedScriptAccount = this.loadScriptAccount(scriptAccountFile);
|
||||||
|
if (loadedScriptAccount != undefined) {
|
||||||
|
loadedScriptAccounts.push(loadedScriptAccount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return loadedScriptAccounts;
|
||||||
|
}
|
||||||
|
loadScriptAccount(scriptAccountFile) {
|
||||||
|
if (scriptAccountFile.endsWith(".json")) {
|
||||||
|
const scriptAccountData = fs.readFileSync(scriptAccountFile, 'utf-8');
|
||||||
|
return new StoreComponent_1.StoreComponent(scriptAccountData, scriptAccountFile, ModelComponentType_1.ModelComponentType.SCRIPTACCOUNT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.ScriptAccountLoader = ScriptAccountLoader;
|
||||||
|
//# sourceMappingURL=ScriptAccountLoader.js.map
|
16
src/app/project/project.service.spec.ts
Normal file
16
src/app/project/project.service.spec.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ProjectService } from './project.service';
|
||||||
|
|
||||||
|
describe('ProjectService', () => {
|
||||||
|
let service: ProjectService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(ProjectService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
45
src/app/project/project.service.ts
Normal file
45
src/app/project/project.service.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import {ElectronService} from "../core/services";
|
||||||
|
import {GameModel} from "./game-model/GameModel";
|
||||||
|
import {StoredGameModel} from "../../../app/storage/StoredGameModel";
|
||||||
|
import {ScriptAccount} from "./game-model/scriptAccounts/ScriptAccount";
|
||||||
|
import {ModelComponentType} from "./game-model/ModelComponentType";
|
||||||
|
import {ScriptAccountParser} from "./parser/ScriptAccountParser";
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class ProjectService {
|
||||||
|
|
||||||
|
gameModel: GameModel = new GameModel("New GameModel")
|
||||||
|
constructor(private electronService: ElectronService) {
|
||||||
|
if(electronService.isElectron) {
|
||||||
|
electronService.ipcRenderer.on('get-project-data', (event: any, message: string) => {
|
||||||
|
this.saveProject();
|
||||||
|
})
|
||||||
|
|
||||||
|
electronService.ipcRenderer.on('open-project', (event: any, loadedProject: StoredGameModel) => {
|
||||||
|
this.loadProject(loadedProject);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
saveProject() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
loadProject(storedGameModel: StoredGameModel) {
|
||||||
|
const gameModel = new GameModel(storedGameModel.gameModelName)
|
||||||
|
storedGameModel.loadedModels.forEach(storedComponent => {
|
||||||
|
switch (storedComponent.componentType) {
|
||||||
|
case ModelComponentType.SCRIPTACCOUNT: {
|
||||||
|
const scriptAccount = ScriptAccountParser.parseScriptAccount(storedComponent);
|
||||||
|
gameModel.addScriptAccount(scriptAccount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.gameModel = gameModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user