UNPKG

@etothepii/satisfactory-file-parser

Version:

A file parser for satisfactory files. Includes save files and blueprint files.

128 lines (127 loc) 5.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.JsonStreamWriter = void 0; const json_stream_state_writer_1 = require("./json-stream-state-writer"); class JsonStreamWriter extends json_stream_state_writer_1.JsonStreamStateWriter { constructor(writer) { super(async (value) => await writer.write(value), 'BEFORE_START'); this.writer = writer; this.stateMachine = { openSave: { name: 'Open Save', requiresOneOfThemToBeBefore: ['BEFORE_START'], do: async () => await this.startObject(), assignOnFinish: 'OPENED_SAVE', }, writeHeader: { name: 'Write Header', requiresOneOfThemToBeBefore: ['OPENED_SAVE'], do: async (param) => await this.writeProperty('header', Promise.resolve(JSON.stringify(param))), assignOnFinish: 'FINISHED_HEADER', }, writeCompressionInfo: { name: 'Write Compression Info', requiresOneOfThemToBeBefore: ['FINISHED_HEADER'], do: async (param) => await this.writeProperty('compressionInfo', Promise.resolve(JSON.stringify(param))), assignOnFinish: 'WROTE_COMPRESSION_INFO', }, openLevels: { name: 'Open Levels', requiresOneOfThemToBeBefore: ['WROTE_COMPRESSION_INFO'], do: async () => await this.startArray(), assignOnFinish: 'OPENED_LEVELS', }, openLevel: { name: 'Open Level', requiresOneOfThemToBeBefore: ['OPENED_LEVELS', 'FINISHED_LEVEL'], do: async (param) => { await this.writePropertyName(param); await this.startObject(); await this.writeProperty('name', Promise.resolve(param)); await this.writePropertyName('objects'); await this.startArray(); }, assignOnFinish: 'OPENED_LEVEL', }, writeObject: { name: 'Write Object', requiresOneOfThemToBeBefore: ['OPENED_LEVEL', 'WROTE_OBJECT'], do: async (param) => await this.writeValue(Promise.resolve(JSON.stringify(param))), assignOnFinish: 'WROTE_OBJECT', }, switchToCollectables: { name: 'Switch To collectables', requiresOneOfThemToBeBefore: ['OPENED_LEVEL', 'WROTE_OBJECT'], do: async () => { await this.endArray(); await this.writePropertyName('collectables'); await this.startArray(); }, assignOnFinish: 'SWITCH_TO_COLLECTABLES', }, writeCollectable: { name: 'Write Collectables', requiresOneOfThemToBeBefore: ['SWITCH_TO_COLLECTABLES'], do: async (param) => { await this.writeValue(Promise.resolve(JSON.stringify(param))); }, assignOnFinish: 'WROTE_COLLECTABLE', }, closeLevel: { name: 'Close Level', requiresOneOfThemToBeBefore: ['SWITCH_TO_COLLECTABLES', 'WROTE_COLLECTABLE'], do: async () => { await this.endArray(); await this.endObject(); }, assignOnFinish: 'FINISHED_LEVEL', }, closeLevels: { name: 'Close Levels', requiresOneOfThemToBeBefore: [], do: async () => await this.endArray(), assignOnFinish: "FINISHED_LEVELS", }, closeSave: { name: 'Close Save', requiresOneOfThemToBeBefore: ['FINISHED_LEVELS'], do: async () => await this.startObject(), assignOnFinish: 'FINISHED_SAVE', } }; } async beginSave() { await this.useTransition(this.stateMachine.openSave); } async writeHeader(header) { await this.useTransition(this.stateMachine.writeHeader, header); } async writeCompressionInfo(compressionInfo) { await this.useTransition(this.stateMachine.writeCompressionInfo, compressionInfo); } async openLevels() { await this.useTransition(this.stateMachine.openLevels); } async openLevel() { await this.useTransition(this.stateMachine.openLevel); } async writeObject(object) { await this.useTransition(this.stateMachine.writeObject, object); } async switchToCollectables() { await this.useTransition(this.stateMachine.switchToCollectables); } async writeCollectable(object) { await this.useTransition(this.stateMachine.writeCollectable, object); } async closeLevel() { await this.useTransition(this.stateMachine.closeLevel); } async closeLevels() { await this.useTransition(this.stateMachine.closeLevels); } async endSave() { await this.useTransition(this.stateMachine.closeSave); } } exports.JsonStreamWriter = JsonStreamWriter;