ConceptCreator/src/app/game-model/fs/store/StoreProject.ts
Sebastian Böckelmann e873688cb7
All checks were successful
E2E Testing / test (push) Successful in 1m28s
Save Gamesystems and Ignore save status and type of saved gamemodelcomponent
2024-02-17 10:13:32 +01:00

85 lines
3.2 KiB
TypeScript

import {StorageModel} from "../StorageModel";
import {GameModel} from "../../GameModel";
import {ScriptAccount} from "../../scriptAccounts/ScriptAccount";
import {Gamesystem} from "../../gamesystems/Gamesystem";
import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem";
import {ModelComponent} from "../../ModelComponent";
import {ProductGamesystem} from "../../gamesystems/ProductGamesystem";
export class StoreProject {
static JSON_INDENT = 4
static storeProject(gameModel: GameModel): StorageModel[] {
let storageModels: StorageModel[] = [];
storageModels = storageModels.concat(this.storeScriptAccounts(gameModel.scriptAccounts));
storageModels = storageModels.concat(this.storeGamesystems(gameModel.gamesystems));
return storageModels;
}
static storeScriptAccounts(scriptAcccounts: ScriptAccount[]): StorageModel[] {
const storedScriptAccounts: StorageModel[] = [];
scriptAcccounts.forEach(scriptAccount => {
storedScriptAccounts.push({
fileName: scriptAccount.componentName,
jsonString: JSON.stringify(scriptAccount, (key,value) => {
if(key === 'unsaved' || key === 'type') {
return undefined
} else {
return value;
}
}, StoreProject.JSON_INDENT),
storageRootDir: "script-accounts",
storagePath: []
})
scriptAccount.onSaveContent();
})
return storedScriptAccounts;
}
static storeGamesystems(gamesystems: Gamesystem<any, any>[]): StorageModel[] {
let storedGamesystems: StorageModel[] = [];
gamesystems.forEach(gamesystem => {
const storageModels: StorageModel[] = StoreProject.storeIndividualGamesystem(gamesystem, []);
storedGamesystems = storedGamesystems.concat(storageModels);
})
return storedGamesystems;
}
static storeIndividualGamesystem(gamesystem: Gamesystem<any, any>, storagePath: string[]): StorageModel[] {
if(gamesystem instanceof SimpleGamesystem) {
return [new StorageModel(JSON.stringify(gamesystem, (key, value) => {
if(key === 'startingState' || key === 'endingState') {
return value.stateLabel
}
if(key === 'incomingTransitions' || key === 'outgoingTransitions' || key === 'unsaved' || key === 'type') {
return undefined;
} else {
return value;
}
}, this.JSON_INDENT), gamesystem.componentName, storagePath, "gamesystems")];
} else if(gamesystem instanceof ProductGamesystem) {
const storageModels: StorageModel[] = [];
//Root-StorageModel
storagePath.push(gamesystem.componentName);
(gamesystem as ProductGamesystem).innerGamesystems.forEach(innerGamesystem => {
const innerStorageModels: StorageModel[] = StoreProject.storeIndividualGamesystem(innerGamesystem, storagePath)
innerStorageModels.forEach(storageModel => storageModels.push(storageModel))
})
const productData = {
'componentName': gamesystem.componentName,
'componentDescription': gamesystem.componentDescription
}
storageModels.push(new StorageModel(JSON.stringify(productData, null, this.JSON_INDENT), gamesystem.componentName, storagePath, "gamesystems"))
return storageModels;
} else {
return [];
}
}
}