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); } }