This commit is contained in:
parent
36e4a68e54
commit
0884709603
@ -6,6 +6,8 @@ import {StoredGameModel} from "./storage/StoredGameModel";
|
|||||||
import {ScriptAccountStorage} from "./storage/storing/ScriptAccountStoring";
|
import {ScriptAccountStorage} from "./storage/storing/ScriptAccountStoring";
|
||||||
import {ModelComponentFileDirectory} from "./storage/ModelComponentFileDirectory";
|
import {ModelComponentFileDirectory} from "./storage/ModelComponentFileDirectory";
|
||||||
import {GamesystemStorage} from "./storage/storing/GamesystemStorage";
|
import {GamesystemStorage} from "./storage/storing/GamesystemStorage";
|
||||||
|
import {Character} from "../src/app/project/game-model/characters/Character";
|
||||||
|
import {CharacterStorage} from "./storage/storing/CharacterStorage";
|
||||||
|
|
||||||
let win: BrowserWindow | null = null;
|
let win: BrowserWindow | null = null;
|
||||||
const args = process.argv.slice(1),
|
const args = process.argv.slice(1),
|
||||||
@ -225,6 +227,9 @@ function recieveGameModelToStore(gameModel: StoredGameModel) {
|
|||||||
|
|
||||||
const gamesystemStorage = new GamesystemStorage(path.join(projectDirectory, ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME))
|
const gamesystemStorage = new GamesystemStorage(path.join(projectDirectory, ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME))
|
||||||
gamesystemStorage.storeGamesystems(gameModel.storedGamesystems)
|
gamesystemStorage.storeGamesystems(gameModel.storedGamesystems)
|
||||||
|
|
||||||
|
const characterStorage = new CharacterStorage(path.join(projectDirectory, ModelComponentFileDirectory.CHARACTER_DIR_NAME))
|
||||||
|
characterStorage.storeCharacters(gameModel.storedCharacters)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*function deleteComponent(component: DeleteModel) {
|
/*function deleteComponent(component: DeleteModel) {
|
||||||
|
@ -19,6 +19,11 @@ class FileUtils {
|
|||||||
(0, fs_1.mkdirSync)(parentDirectory, { recursive: true });
|
(0, fs_1.mkdirSync)(parentDirectory, { recursive: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static prepareDirectoryFroWriting(directoryFile) {
|
||||||
|
if (!fs.existsSync(directoryFile)) {
|
||||||
|
(0, fs_1.mkdirSync)(directoryFile, { recursive: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
static removeFiles(files) {
|
static removeFiles(files) {
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
if (fs.lstatSync(file).isDirectory()) {
|
if (fs.lstatSync(file).isDirectory()) {
|
||||||
|
@ -21,6 +21,12 @@ export class FileUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static prepareDirectoryFroWriting(directoryFile: string) {
|
||||||
|
if(!fs.existsSync(directoryFile)) {
|
||||||
|
mkdirSync(directoryFile, {recursive: true})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static removeFiles(files: string[]) {
|
public static removeFiles(files: string[]) {
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
if(fs.lstatSync(file).isDirectory()) {
|
if(fs.lstatSync(file).isDirectory()) {
|
||||||
|
@ -6,6 +6,5 @@ class ModelComponentFileDirectory {
|
|||||||
exports.ModelComponentFileDirectory = ModelComponentFileDirectory;
|
exports.ModelComponentFileDirectory = ModelComponentFileDirectory;
|
||||||
ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME = "script-accounts";
|
ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME = "script-accounts";
|
||||||
ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME = "gamesystems";
|
ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME = "gamesystems";
|
||||||
ModelComponentFileDirectory.GAMESYSTEM_SIMPLE_DIR_NAME = "simple";
|
ModelComponentFileDirectory.CHARACTER_DIR_NAME = "characters";
|
||||||
ModelComponentFileDirectory.GAMESYSTEM_PRODUCT_DIR_NAME = "product";
|
|
||||||
//# sourceMappingURL=ModelComponentFileDirectory.js.map
|
//# sourceMappingURL=ModelComponentFileDirectory.js.map
|
@ -1,6 +1,5 @@
|
|||||||
export class ModelComponentFileDirectory {
|
export class ModelComponentFileDirectory {
|
||||||
public static SCRIPTACCOUNT_DIR_NAME = "script-accounts"
|
public static SCRIPTACCOUNT_DIR_NAME = "script-accounts"
|
||||||
public static GAMESYSTEM_DIR_NAME = "gamesystems";
|
public static GAMESYSTEM_DIR_NAME = "gamesystems";
|
||||||
public static GAMESYSTEM_SIMPLE_DIR_NAME = "simple";
|
public static CHARACTER_DIR_NAME = "characters";
|
||||||
public static GAMESYSTEM_PRODUCT_DIR_NAME = "product";
|
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.StoredGameModel = void 0;
|
exports.StoredGameModel = void 0;
|
||||||
class StoredGameModel {
|
class StoredGameModel {
|
||||||
constructor(gameModelName, storedScriptAccounts, storedGamesystems) {
|
constructor(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters) {
|
||||||
this.gameModelName = gameModelName;
|
this.gameModelName = gameModelName;
|
||||||
this.storedGamesystems = storedGamesystems;
|
this.storedGamesystems = storedGamesystems;
|
||||||
this.storedScriptAccounts = storedScriptAccounts;
|
this.storedScriptAccounts = storedScriptAccounts;
|
||||||
|
this.storedCharacters = storedCharacters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.StoredGameModel = StoredGameModel;
|
exports.StoredGameModel = StoredGameModel;
|
||||||
|
@ -5,11 +5,14 @@ export class StoredGameModel {
|
|||||||
|
|
||||||
storedGamesystems: StoreComponent[]
|
storedGamesystems: StoreComponent[]
|
||||||
storedScriptAccounts: StoreComponent[]
|
storedScriptAccounts: StoreComponent[]
|
||||||
|
storedCharacters: StoreComponent[]
|
||||||
|
|
||||||
|
|
||||||
constructor(gameModelName: string, storedScriptAccounts: StoreComponent[], storedGamesystems: StoreComponent[]) {
|
constructor(gameModelName: string, storedScriptAccounts: StoreComponent[], storedGamesystems: StoreComponent[],
|
||||||
|
storedCharacters: StoreComponent[]) {
|
||||||
this.gameModelName = gameModelName;
|
this.gameModelName = gameModelName;
|
||||||
this.storedGamesystems = storedGamesystems;
|
this.storedGamesystems = storedGamesystems;
|
||||||
this.storedScriptAccounts = storedScriptAccounts;
|
this.storedScriptAccounts = storedScriptAccounts;
|
||||||
|
this.storedCharacters = storedCharacters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ class GameModelLoader {
|
|||||||
const gameModelName = path.basename(this.gameModelDir);
|
const gameModelName = path.basename(this.gameModelDir);
|
||||||
const storedScriptAccounts = this.loadScriptAccountComponents();
|
const storedScriptAccounts = this.loadScriptAccountComponents();
|
||||||
const storedGamesystems = this.loadGamesystems();
|
const storedGamesystems = this.loadGamesystems();
|
||||||
return new StoredGameModel_1.StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems);
|
return new StoredGameModel_1.StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, []);
|
||||||
}
|
}
|
||||||
loadScriptAccountComponents() {
|
loadScriptAccountComponents() {
|
||||||
const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME);
|
const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME);
|
||||||
|
@ -20,7 +20,7 @@ export class GameModelLoader {
|
|||||||
const storedScriptAccounts = this.loadScriptAccountComponents();
|
const storedScriptAccounts = this.loadScriptAccountComponents();
|
||||||
const storedGamesystems = this.loadGamesystems();
|
const storedGamesystems = this.loadGamesystems();
|
||||||
|
|
||||||
return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems);
|
return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadScriptAccountComponents() {
|
private loadScriptAccountComponents() {
|
||||||
|
32
app/storage/storing/CharacterStorage.js
Normal file
32
app/storage/storing/CharacterStorage.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.CharacterStorage = void 0;
|
||||||
|
const FileUtils_1 = require("../FileUtils");
|
||||||
|
const path = require("node:path");
|
||||||
|
const fs = require("fs");
|
||||||
|
class CharacterStorage {
|
||||||
|
constructor(characterDir) {
|
||||||
|
this.characterDir = characterDir;
|
||||||
|
FileUtils_1.FileUtils.prepareDirectoryFroWriting(characterDir);
|
||||||
|
}
|
||||||
|
storeCharacters(storedCharacters) {
|
||||||
|
this.persistDeletedCharacters(storedCharacters);
|
||||||
|
storedCharacters.forEach(storedCharacter => this.storeSingleCharacter(storedCharacter));
|
||||||
|
}
|
||||||
|
persistDeletedCharacters(existingCharacters) {
|
||||||
|
const scriptAccountFiles = FileUtils_1.FileUtils.listFilesInDirectory(this.characterDir);
|
||||||
|
scriptAccountFiles.forEach(characterFile => {
|
||||||
|
const scriptAccountFileName = path.parse(path.basename(characterFile)).name;
|
||||||
|
if (existingCharacters.find(character => character.fileName === scriptAccountFileName) == undefined) {
|
||||||
|
//No scriptAccountFile was found with that nae of the file. So the scriptAccount was deleted. Remove file
|
||||||
|
fs.unlinkSync(characterFile);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
storeSingleCharacter(character) {
|
||||||
|
const completeScriptAccountFile = path.join(this.characterDir, character.fileName + ".json");
|
||||||
|
fs.writeFileSync(completeScriptAccountFile, character.jsonString, 'utf-8');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.CharacterStorage = CharacterStorage;
|
||||||
|
//# sourceMappingURL=CharacterStorage.js.map
|
35
app/storage/storing/CharacterStorage.ts
Normal file
35
app/storage/storing/CharacterStorage.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import {StoreComponent} from "../StoreComponent";
|
||||||
|
import {FileUtils} from "../FileUtils";
|
||||||
|
import * as path from "node:path";
|
||||||
|
import * as fs from "fs";
|
||||||
|
|
||||||
|
export class CharacterStorage {
|
||||||
|
private characterDir: string
|
||||||
|
|
||||||
|
|
||||||
|
constructor(characterDir: string) {
|
||||||
|
this.characterDir = characterDir;
|
||||||
|
FileUtils.prepareDirectoryFroWriting(characterDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
storeCharacters(storedCharacters: StoreComponent[]) {
|
||||||
|
this.persistDeletedCharacters(storedCharacters)
|
||||||
|
storedCharacters.forEach(storedCharacter => this.storeSingleCharacter(storedCharacter))
|
||||||
|
}
|
||||||
|
|
||||||
|
private persistDeletedCharacters(existingCharacters: StoreComponent[]) {
|
||||||
|
const scriptAccountFiles = FileUtils.listFilesInDirectory(this.characterDir);
|
||||||
|
scriptAccountFiles.forEach(characterFile => {
|
||||||
|
const scriptAccountFileName = path.parse(path.basename(characterFile)).name
|
||||||
|
if(existingCharacters.find(character => character.fileName === scriptAccountFileName) == undefined) {
|
||||||
|
//No scriptAccountFile was found with that nae of the file. So the scriptAccount was deleted. Remove file
|
||||||
|
fs.unlinkSync(characterFile)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private storeSingleCharacter(character: StoreComponent) {
|
||||||
|
const completeScriptAccountFile = path.join(this.characterDir, character.fileName + ".json")
|
||||||
|
fs.writeFileSync(completeScriptAccountFile, character.jsonString, 'utf-8')
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ const fs = require("fs");
|
|||||||
class GamesystemStorage {
|
class GamesystemStorage {
|
||||||
constructor(gamesystemRootDir) {
|
constructor(gamesystemRootDir) {
|
||||||
this.gamesystemRootDir = gamesystemRootDir;
|
this.gamesystemRootDir = gamesystemRootDir;
|
||||||
|
FileUtils_1.FileUtils.prepareDirectoryFroWriting(gamesystemRootDir);
|
||||||
}
|
}
|
||||||
storeGamesystems(gamesystems) {
|
storeGamesystems(gamesystems) {
|
||||||
const unreferencedFiles = this.detectUnusedGamesystemFiles(gamesystems);
|
const unreferencedFiles = this.detectUnusedGamesystemFiles(gamesystems);
|
||||||
|
@ -10,6 +10,7 @@ export class GamesystemStorage {
|
|||||||
|
|
||||||
constructor(gamesystemRootDir: string) {
|
constructor(gamesystemRootDir: string) {
|
||||||
this.gamesystemRootDir = gamesystemRootDir;
|
this.gamesystemRootDir = gamesystemRootDir;
|
||||||
|
FileUtils.prepareDirectoryFroWriting(gamesystemRootDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
public storeGamesystems(gamesystems: StoreComponent[]) {
|
public storeGamesystems(gamesystems: StoreComponent[]) {
|
||||||
|
@ -7,6 +7,7 @@ const fs = require("fs");
|
|||||||
class ScriptAccountStorage {
|
class ScriptAccountStorage {
|
||||||
constructor(scriptAccountDir) {
|
constructor(scriptAccountDir) {
|
||||||
this.scriptAccountDir = scriptAccountDir;
|
this.scriptAccountDir = scriptAccountDir;
|
||||||
|
FileUtils_1.FileUtils.prepareDirectoryFroWriting(this.scriptAccountDir);
|
||||||
}
|
}
|
||||||
storeScriptAccounts(scriptAccounts) {
|
storeScriptAccounts(scriptAccounts) {
|
||||||
this.persistDeletedScriptAccounts(scriptAccounts);
|
this.persistDeletedScriptAccounts(scriptAccounts);
|
||||||
|
@ -9,6 +9,7 @@ export class ScriptAccountStorage {
|
|||||||
|
|
||||||
constructor(scriptAccountDir: string) {
|
constructor(scriptAccountDir: string) {
|
||||||
this.scriptAccountDir = scriptAccountDir;
|
this.scriptAccountDir = scriptAccountDir;
|
||||||
|
FileUtils.prepareDirectoryFroWriting(this.scriptAccountDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
storeScriptAccounts(scriptAccounts: StoreComponent[]) {
|
storeScriptAccounts(scriptAccounts: StoreComponent[]) {
|
||||||
|
@ -22,6 +22,7 @@ import {StoreComponent} from "../../app/storage/StoreComponent";
|
|||||||
import {GamesystemSerializer} from "./project/serializer/GamesystemSerializer";
|
import {GamesystemSerializer} from "./project/serializer/GamesystemSerializer";
|
||||||
import {Character} from "./project/game-model/characters/Character";
|
import {Character} from "./project/game-model/characters/Character";
|
||||||
import {CharacterOverviewComponent} from "./side-overviews/character-overview/character-overview.component";
|
import {CharacterOverviewComponent} from "./side-overviews/character-overview/character-overview.component";
|
||||||
|
import {CharacterSerializer} from "./project/serializer/CharacterSerializer";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@ -215,7 +216,8 @@ export class AppComponent implements OnInit{
|
|||||||
if(this.gameModel != undefined) {
|
if(this.gameModel != undefined) {
|
||||||
const storedScriptAccounts = ScriptAccountSerializer.serializeScriptAccounts(this.gameModel.scriptAccounts)
|
const storedScriptAccounts = ScriptAccountSerializer.serializeScriptAccounts(this.gameModel.scriptAccounts)
|
||||||
const storedGamesystems: StoreComponent[] = GamesystemSerializer.serializeGamesystems(this.gameModel.gamesystems)
|
const storedGamesystems: StoreComponent[] = GamesystemSerializer.serializeGamesystems(this.gameModel.gamesystems)
|
||||||
const storeModel = new StoredGameModel(this.gameModel.gameModelName, storedScriptAccounts, storedGamesystems)
|
const storedCharacters: StoreComponent[] = CharacterSerializer.serializeCharacters(this.gameModel.characters)
|
||||||
|
const storeModel = new StoredGameModel(this.gameModel.gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters)
|
||||||
|
|
||||||
if(this.electronService.isElectron) {
|
if(this.electronService.isElectron) {
|
||||||
this.electronService.ipcRenderer.send('save-model', storeModel)
|
this.electronService.ipcRenderer.send('save-model', storeModel)
|
||||||
|
26
src/app/project/serializer/CharacterSerializer.ts
Normal file
26
src/app/project/serializer/CharacterSerializer.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import {Character} from "../game-model/characters/Character";
|
||||||
|
import {StoreComponent} from "../../../../app/storage/StoreComponent";
|
||||||
|
import {SerializeConstants} from "./SerializeConstants";
|
||||||
|
import {ModelComponentType} from "../game-model/ModelComponentType";
|
||||||
|
|
||||||
|
export class CharacterSerializer {
|
||||||
|
|
||||||
|
public static serializeCharacters(characters: Character[]): StoreComponent[] {
|
||||||
|
const storedCharacters: StoreComponent[] = []
|
||||||
|
characters.forEach(character => storedCharacters.push(this.serializeSingleCharacter(character)))
|
||||||
|
return storedCharacters;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static serializeSingleCharacter(character: Character): StoreComponent{
|
||||||
|
const fileName = character.componentName
|
||||||
|
const jsonString = JSON.stringify(character, (key, value) => {
|
||||||
|
if(key === 'unsaved' || key === 'type') {
|
||||||
|
return undefined
|
||||||
|
} else {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}, SerializeConstants.JSON_INDENT)
|
||||||
|
|
||||||
|
return new StoreComponent(jsonString, fileName, ModelComponentType.CHARACTER);
|
||||||
|
}
|
||||||
|
}
|
4
testModel/characters/Astrid Hofferson.json
Normal file
4
testModel/characters/Astrid Hofferson.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"componentName": "Astrid Hofferson",
|
||||||
|
"componentDescription": ""
|
||||||
|
}
|
4
testModel/characters/Hicks Haddock.json
Normal file
4
testModel/characters/Hicks Haddock.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"componentName": "Hicks Haddock",
|
||||||
|
"componentDescription": ""
|
||||||
|
}
|
@ -1 +1,12 @@
|
|||||||
{"componentName":"Weathersystem","componentDescription":"Ein Wettersystem, dass sich aus normalem Wetter (Sonne, Regen, Wolke, Schnee, Sturm etc.) und zusätzlich den Jahreszeiten (Frühling, Sommer, Herbst, Winter, etc.) zusammensetzt.","childsystems":[{"componentName":"Season"},{"componentName":"Weather"}]}
|
{
|
||||||
|
"componentName": "Weathersystem",
|
||||||
|
"componentDescription": "Ein Wettersystem, dass sich aus normalem Wetter (Sonne, Regen, Wolke, Schnee, Sturm etc.) und zusätzlich den Jahreszeiten (Frühling, Sommer, Herbst, Winter, etc.) zusammensetzt.",
|
||||||
|
"childsystems": [
|
||||||
|
{
|
||||||
|
"componentName": "Season"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"componentName": "Weather"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user