@etothepii/satisfactory-file-parser 0.0.33 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -8
- package/build/index.js +41 -51
- package/build/parser/byte/alignment.enum.js +8 -18
- package/build/parser/byte/binary-operable.interface.js +2 -12
- package/build/parser/byte/binary-readable.interface.js +2 -12
- package/build/parser/byte/byte-reader.class.js +122 -132
- package/build/parser/byte/byte-writer.class.js +133 -143
- package/build/parser/error/parser.error.js +40 -50
- package/build/parser/file.types.js +2 -12
- package/build/parser/parser.js +84 -95
- package/build/parser/satisfactory/blueprint/blueprint-reader.js +109 -119
- package/build/parser/satisfactory/blueprint/blueprint-writer.js +56 -66
- package/build/parser/satisfactory/blueprint/blueprint.types.js +2 -12
- package/build/parser/satisfactory/objects/DataFields.js +306 -307
- package/build/parser/satisfactory/objects/ObjectReference.js +14 -24
- package/build/parser/satisfactory/objects/Property.js +974 -977
- package/build/parser/satisfactory/objects/SaveComponent.js +28 -38
- package/build/parser/satisfactory/objects/SaveEntity.js +69 -75
- package/build/parser/satisfactory/objects/SaveObject.js +26 -36
- package/build/parser/satisfactory/save/asynchronous-level.class.js +60 -70
- package/build/parser/satisfactory/save/level.class.d.ts +1 -1
- package/build/parser/satisfactory/save/level.class.js +147 -128
- package/build/parser/satisfactory/save/satisfactory-save.js +10 -20
- package/build/parser/satisfactory/save/save-reader.d.ts +2 -2
- package/build/parser/satisfactory/save/save-reader.js +209 -171
- package/build/parser/satisfactory/save/save-writer.js +97 -107
- package/build/parser/satisfactory/save/save.types.js +2 -12
- package/build/parser/satisfactory/structs/util.types.d.ts +6 -0
- package/build/parser/satisfactory/structs/util.types.js +122 -96
- package/build/parser/stream/byte-stream-reader.class.js +217 -227
- package/build/parser/stream/json-stream-state-writer.js +15 -25
- package/build/parser/stream/json-stream-writable.js +72 -82
- package/build/parser/stream/json-stream-writer.js +122 -132
- package/build/parser/stream/save-stream-json-stringifier.js +29 -39
- package/build/parser/stream/save-stream-reader.class.js +106 -116
- package/build/parser/stream/save-stream-writer.class.js +90 -100
- package/build/parser/stream/stream-level.class.js +93 -103
- package/package.json +2 -2
|
@@ -1,149 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
writeString(value) {
|
|
92
|
-
if (value.length === 0) {
|
|
93
|
-
this.writeInt32(0);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (ByteWriter.IsASCIICompatible(value)) {
|
|
97
|
-
this.writeInt32(value.length + 1);
|
|
98
|
-
for (let i = 0; i < value.length; i++) {
|
|
99
|
-
this.writeByte(value.charCodeAt(i));
|
|
100
|
-
}
|
|
101
|
-
this.writeUint8(0);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
this.writeInt32(-value.length - 1);
|
|
105
|
-
for (let i = 0; i < value.length; i++) {
|
|
106
|
-
this.writeUint16(value.charCodeAt(i));
|
|
107
|
-
}
|
|
108
|
-
this.writeUint16(0);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ByteWriter = void 0;
|
|
4
|
+
const alignment_enum_1 = require("./alignment.enum");
|
|
5
|
+
class ByteWriter {
|
|
6
|
+
constructor(alignment, bufferSize = 500) {
|
|
7
|
+
this.getBufferPosition = () => this.currentByte;
|
|
8
|
+
this.getBufferSlice = (start, end) => this.bufferArray.slice(start, end);
|
|
9
|
+
this.alignment = alignment;
|
|
10
|
+
this.bufferArray = new ArrayBuffer(bufferSize);
|
|
11
|
+
this.bufferView = new DataView(this.bufferArray);
|
|
12
|
+
this.currentByte = 0;
|
|
13
|
+
}
|
|
14
|
+
skipBytes(count = 1) {
|
|
15
|
+
this.extendBufferIfNeeded(count);
|
|
16
|
+
this.currentByte += count;
|
|
17
|
+
}
|
|
18
|
+
jumpTo(pos) {
|
|
19
|
+
const count = pos - this.getBufferPosition();
|
|
20
|
+
this.skipBytes(count);
|
|
21
|
+
}
|
|
22
|
+
writeByte(value) {
|
|
23
|
+
this.extendBufferIfNeeded(1);
|
|
24
|
+
this.bufferView.setUint8(this.currentByte, value);
|
|
25
|
+
this.currentByte += 1;
|
|
26
|
+
}
|
|
27
|
+
writeBytesArray(bytes) {
|
|
28
|
+
this.writeBytes(new Uint8Array(bytes));
|
|
29
|
+
}
|
|
30
|
+
writeBytes(bytes) {
|
|
31
|
+
this.extendBufferIfNeeded(bytes.length);
|
|
32
|
+
bytes.forEach(byte => this.bufferView.setUint8(this.currentByte++, byte));
|
|
33
|
+
}
|
|
34
|
+
writeInt8(value) {
|
|
35
|
+
this.extendBufferIfNeeded(1);
|
|
36
|
+
this.bufferView.setInt8(this.currentByte, value);
|
|
37
|
+
this.currentByte += 1;
|
|
38
|
+
}
|
|
39
|
+
writeUint8(value) {
|
|
40
|
+
this.writeByte(value);
|
|
41
|
+
}
|
|
42
|
+
writeInt16(value) {
|
|
43
|
+
this.extendBufferIfNeeded(2);
|
|
44
|
+
this.bufferView.setInt16(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
45
|
+
this.currentByte += 2;
|
|
46
|
+
}
|
|
47
|
+
writeUint16(value) {
|
|
48
|
+
this.extendBufferIfNeeded(2);
|
|
49
|
+
this.bufferView.setUint16(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
50
|
+
this.currentByte += 2;
|
|
51
|
+
}
|
|
52
|
+
writeInt32(value) {
|
|
53
|
+
this.extendBufferIfNeeded(4);
|
|
54
|
+
this.bufferView.setInt32(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
55
|
+
this.currentByte += 4;
|
|
56
|
+
}
|
|
57
|
+
writeUint32(value) {
|
|
58
|
+
this.extendBufferIfNeeded(4);
|
|
59
|
+
this.bufferView.setUint32(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
60
|
+
this.currentByte += 4;
|
|
61
|
+
}
|
|
62
|
+
writeInt64(value) {
|
|
63
|
+
this.extendBufferIfNeeded(8);
|
|
64
|
+
this.bufferView.setBigInt64(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
65
|
+
this.currentByte += 8;
|
|
66
|
+
}
|
|
67
|
+
writeUint64(value) {
|
|
68
|
+
this.extendBufferIfNeeded(8);
|
|
69
|
+
this.bufferView.setBigUint64(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
70
|
+
this.currentByte += 8;
|
|
71
|
+
}
|
|
72
|
+
writeFloat(value) {
|
|
73
|
+
this.extendBufferIfNeeded(4);
|
|
74
|
+
this.bufferView.setFloat32(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
75
|
+
this.currentByte += 4;
|
|
76
|
+
}
|
|
77
|
+
writeDouble(value) {
|
|
78
|
+
this.extendBufferIfNeeded(8);
|
|
79
|
+
this.bufferView.setFloat64(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
80
|
+
this.currentByte += 8;
|
|
81
|
+
}
|
|
82
|
+
writeString(value) {
|
|
83
|
+
if (value.length === 0) {
|
|
84
|
+
this.writeInt32(0);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (ByteWriter.IsASCIICompatible(value)) {
|
|
88
|
+
this.writeInt32(value.length + 1);
|
|
89
|
+
for (let i = 0; i < value.length; i++) {
|
|
90
|
+
this.writeByte(value.charCodeAt(i));
|
|
109
91
|
}
|
|
92
|
+
this.writeUint8(0);
|
|
110
93
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this.writeInt32(writtenBytes);
|
|
116
|
-
this.jumpTo(after);
|
|
117
|
-
}
|
|
118
|
-
extendBufferIfNeeded(countNeededBytes, factor = 1.5) {
|
|
119
|
-
if (this.currentByte + countNeededBytes > this.bufferView.byteLength) {
|
|
120
|
-
this.bufferArray = ByteWriter.AppendBuffer(this.bufferArray, new ArrayBuffer(factor * this.bufferArray.byteLength));
|
|
121
|
-
this.bufferView = new DataView(this.bufferArray);
|
|
94
|
+
else {
|
|
95
|
+
this.writeInt32(-value.length - 1);
|
|
96
|
+
for (let i = 0; i < value.length; i++) {
|
|
97
|
+
this.writeUint16(value.charCodeAt(i));
|
|
122
98
|
}
|
|
99
|
+
this.writeUint16(0);
|
|
123
100
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
(num & 0x000000ff)
|
|
137
|
-
]);
|
|
138
|
-
}
|
|
139
|
-
static AppendBuffer(buffer1, buffer2) {
|
|
140
|
-
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
|
|
141
|
-
tmp.set(new Uint8Array(buffer1), 0);
|
|
142
|
-
tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
|
|
143
|
-
return tmp.buffer;
|
|
101
|
+
}
|
|
102
|
+
writeBinarySizeFromPosition(lenIndicatorPos, start) {
|
|
103
|
+
const after = this.getBufferPosition();
|
|
104
|
+
const writtenBytes = after - start;
|
|
105
|
+
this.jumpTo(lenIndicatorPos);
|
|
106
|
+
this.writeInt32(writtenBytes);
|
|
107
|
+
this.jumpTo(after);
|
|
108
|
+
}
|
|
109
|
+
extendBufferIfNeeded(countNeededBytes, factor = 1.5) {
|
|
110
|
+
if (this.currentByte + countNeededBytes > this.bufferView.byteLength) {
|
|
111
|
+
this.bufferArray = ByteWriter.AppendBuffer(this.bufferArray, new ArrayBuffer(factor * this.bufferArray.byteLength));
|
|
112
|
+
this.bufferView = new DataView(this.bufferArray);
|
|
144
113
|
}
|
|
145
|
-
;
|
|
146
114
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
115
|
+
truncateBuffer() {
|
|
116
|
+
this.bufferArray = this.bufferArray.slice(0, this.currentByte);
|
|
117
|
+
}
|
|
118
|
+
endWriting() {
|
|
119
|
+
this.truncateBuffer();
|
|
120
|
+
return this.bufferArray;
|
|
121
|
+
}
|
|
122
|
+
static ToInt32(num) {
|
|
123
|
+
return new Uint8Array([
|
|
124
|
+
(num & 0xff000000) >> 24,
|
|
125
|
+
(num & 0x00ff0000) >> 16,
|
|
126
|
+
(num & 0x0000ff00) >> 8,
|
|
127
|
+
(num & 0x000000ff)
|
|
128
|
+
]);
|
|
129
|
+
}
|
|
130
|
+
static AppendBuffer(buffer1, buffer2) {
|
|
131
|
+
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
|
|
132
|
+
tmp.set(new Uint8Array(buffer1), 0);
|
|
133
|
+
tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
|
|
134
|
+
return tmp.buffer;
|
|
135
|
+
}
|
|
136
|
+
;
|
|
137
|
+
}
|
|
138
|
+
ByteWriter.IsASCIICompatible = (value) => /^[\x00-\x7F]*$/.test(value);
|
|
139
|
+
exports.ByteWriter = ByteWriter;
|
|
@@ -1,50 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.TimeoutError = TimeoutError;
|
|
44
|
-
class UnimplementedError extends ParserError {
|
|
45
|
-
constructor(message) {
|
|
46
|
-
super('UnimplementedError', message ?? 'Unimplemented Operation.');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.UnimplementedError = UnimplementedError;
|
|
50
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnimplementedError = exports.TimeoutError = exports.CompressionLibraryError = exports.CorruptSaveError = exports.UnsupportedVersionError = exports.ParserError = void 0;
|
|
4
|
+
class ParserError extends Error {
|
|
5
|
+
constructor(name, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = name;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ParserError = ParserError;
|
|
11
|
+
class UnsupportedVersionError extends ParserError {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super('UnsupportedVersionError', message ?? 'This save version is not supported.');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.UnsupportedVersionError = UnsupportedVersionError;
|
|
17
|
+
class CorruptSaveError extends ParserError {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super('CorruptSaveError', message ?? 'This save data is most likely corrupt.');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.CorruptSaveError = CorruptSaveError;
|
|
23
|
+
class CompressionLibraryError extends ParserError {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super('CompressionLibraryError', message ?? 'Failed to compress/decompress save data.');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.CompressionLibraryError = CompressionLibraryError;
|
|
29
|
+
class TimeoutError extends ParserError {
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super('TimeoutError', message ?? 'Operation timed out.');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.TimeoutError = TimeoutError;
|
|
35
|
+
class UnimplementedError extends ParserError {
|
|
36
|
+
constructor(message) {
|
|
37
|
+
super('UnimplementedError', message ?? 'Unimplemented Operation.');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.UnimplementedError = UnimplementedError;
|
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/build/parser/parser.js
CHANGED
|
@@ -1,98 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Parser = void 0;
|
|
4
|
+
const blueprint_reader_1 = require("./satisfactory/blueprint/blueprint-reader");
|
|
5
|
+
const blueprint_writer_1 = require("./satisfactory/blueprint/blueprint-writer");
|
|
6
|
+
const level_class_1 = require("./satisfactory/save/level.class");
|
|
7
|
+
const satisfactory_save_1 = require("./satisfactory/save/satisfactory-save");
|
|
8
|
+
const save_reader_1 = require("./satisfactory/save/save-reader");
|
|
9
|
+
const save_writer_1 = require("./satisfactory/save/save-writer");
|
|
10
|
+
class Parser {
|
|
11
|
+
static WriteSave(save, onBinaryBeforeCompressing, onHeader, onChunk) {
|
|
12
|
+
const writer = new save_writer_1.SaveWriter();
|
|
13
|
+
save_writer_1.SaveWriter.WriteHeader(writer, save.header);
|
|
14
|
+
const posAfterHeader = writer.getBufferPosition();
|
|
15
|
+
save_writer_1.SaveWriter.WriteLevels(writer, save, save.header.buildVersion);
|
|
16
|
+
writer.endWriting();
|
|
17
|
+
const chunkSummary = writer.generateChunks(save.compressionInfo, posAfterHeader, onBinaryBeforeCompressing, onHeader, onChunk);
|
|
18
|
+
return chunkSummary;
|
|
5
19
|
}
|
|
6
|
-
|
|
7
|
-
|
|
20
|
+
static ParseSaveFile(file, onDecompressedSaveBody = () => { }, onProgress = () => { }) {
|
|
21
|
+
const reader = new save_reader_1.SaveReader(new Uint8Array(file).buffer, onProgress);
|
|
22
|
+
const header = reader.readHeader();
|
|
23
|
+
const save = new satisfactory_save_1.SatisfactorySave(header);
|
|
24
|
+
const inflateResult = reader.inflateChunks();
|
|
25
|
+
onDecompressedSaveBody(reader.getBuffer());
|
|
26
|
+
save.levels = reader.readLevelsU8();
|
|
27
|
+
save.compressionInfo = reader.compressionInfo;
|
|
28
|
+
save.trailingCollectedObjects = reader.trailingCollectedObjects;
|
|
29
|
+
return save;
|
|
8
30
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
writer.endWriting();
|
|
26
|
-
const chunkSummary = writer.generateChunks(save.compressionInfo, posAfterHeader, onBinaryBeforeCompressing, onHeader, onChunk);
|
|
27
|
-
return chunkSummary;
|
|
28
|
-
}
|
|
29
|
-
static ParseSaveFile(file, onDecompressedSaveBody = () => { }, onProgress = () => { }) {
|
|
30
|
-
const reader = new save_reader_1.SaveReader(new Uint8Array(file).buffer, onProgress);
|
|
31
|
-
const header = reader.readHeader();
|
|
32
|
-
const save = new satisfactory_save_1.SatisfactorySave(header);
|
|
33
|
-
const inflateResult = reader.inflateChunks();
|
|
34
|
-
onDecompressedSaveBody(reader.getBuffer());
|
|
35
|
-
const levelParseResult = reader.readLevels();
|
|
36
|
-
save.levels = reader.levels;
|
|
37
|
-
save.compressionInfo = reader.compressionInfo;
|
|
38
|
-
save.trailingCollectedObjects = reader.trailingCollectedObjects;
|
|
39
|
-
return save;
|
|
40
|
-
}
|
|
41
|
-
static WriteBlueprintFiles(blueprint, onMainFileBinaryBeforeCompressing = () => { }, onMainFileHeader = () => { }, onMainFileChunk = () => { }) {
|
|
42
|
-
const blueprintWriter = new blueprint_writer_1.BlueprintWriter();
|
|
43
|
-
blueprint_writer_1.BlueprintWriter.SerializeHeader(blueprintWriter, blueprint.header);
|
|
44
|
-
const saveBodyPos = blueprintWriter.getBufferPosition();
|
|
45
|
-
blueprint_writer_1.BlueprintWriter.SerializeObjects(blueprintWriter, blueprint.objects);
|
|
46
|
-
blueprintWriter.endWriting();
|
|
47
|
-
let binaryChunks = [];
|
|
48
|
-
let binaryHeader;
|
|
49
|
-
const mainFileChunkSummary = blueprintWriter.generateChunks(blueprint.compressionInfo, saveBodyPos, onMainFileBinaryBeforeCompressing, onMainFileHeader, onMainFileChunk);
|
|
50
|
-
const configWriter = new blueprint_writer_1.BlueprintConfigWriter();
|
|
51
|
-
blueprint_writer_1.BlueprintConfigWriter.SerializeConfig(configWriter, blueprint.config);
|
|
52
|
-
const configFileBinary = configWriter.endWriting();
|
|
53
|
-
return {
|
|
54
|
-
mainFileChunkSummary,
|
|
55
|
-
configFileBinary
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
static ParseBlueprintFiles(name, blueprintFile, blueprintConfigFile, onDecompressedBlueprintBody = () => { }) {
|
|
59
|
-
const blueprintConfigReader = new blueprint_reader_1.BlueprintConfigReader(new Uint8Array(blueprintConfigFile).buffer);
|
|
60
|
-
const config = blueprint_reader_1.BlueprintConfigReader.ParseConfig(blueprintConfigReader);
|
|
61
|
-
const blueprintReader = new blueprint_reader_1.BlueprintReader(new Uint8Array(blueprintFile).buffer);
|
|
62
|
-
const header = blueprint_reader_1.BlueprintReader.ReadHeader(blueprintReader);
|
|
63
|
-
const inflateResult = blueprintReader.inflateChunks();
|
|
64
|
-
onDecompressedBlueprintBody(inflateResult.inflatedData);
|
|
65
|
-
const blueprintObjects = blueprint_reader_1.BlueprintReader.ParseObjects(blueprintReader);
|
|
66
|
-
const blueprint = {
|
|
67
|
-
name,
|
|
68
|
-
compressionInfo: blueprintReader.compressionInfo,
|
|
69
|
-
header: header,
|
|
70
|
-
config,
|
|
71
|
-
objects: blueprintObjects
|
|
72
|
-
};
|
|
73
|
-
return blueprint;
|
|
74
|
-
}
|
|
75
|
-
static ProjectSave(save, config) {
|
|
76
|
-
return {
|
|
77
|
-
header: save.header,
|
|
78
|
-
trailingCollectedObjects: save.trailingCollectedObjects,
|
|
79
|
-
levels: save.levels.map(level => {
|
|
80
|
-
const lvl = new level_class_1.Level(level.name);
|
|
81
|
-
lvl.collectables = level.collectables;
|
|
82
|
-
lvl.objects = level.objects.filter(obj => (0, save_reader_1.projectionFilterApplies)(config, obj));
|
|
83
|
-
return lvl;
|
|
84
|
-
})
|
|
85
|
-
};
|
|
86
|
-
}
|
|
31
|
+
static WriteBlueprintFiles(blueprint, onMainFileBinaryBeforeCompressing = () => { }, onMainFileHeader = () => { }, onMainFileChunk = () => { }) {
|
|
32
|
+
const blueprintWriter = new blueprint_writer_1.BlueprintWriter();
|
|
33
|
+
blueprint_writer_1.BlueprintWriter.SerializeHeader(blueprintWriter, blueprint.header);
|
|
34
|
+
const saveBodyPos = blueprintWriter.getBufferPosition();
|
|
35
|
+
blueprint_writer_1.BlueprintWriter.SerializeObjects(blueprintWriter, blueprint.objects);
|
|
36
|
+
blueprintWriter.endWriting();
|
|
37
|
+
let binaryChunks = [];
|
|
38
|
+
let binaryHeader;
|
|
39
|
+
const mainFileChunkSummary = blueprintWriter.generateChunks(blueprint.compressionInfo, saveBodyPos, onMainFileBinaryBeforeCompressing, onMainFileHeader, onMainFileChunk);
|
|
40
|
+
const configWriter = new blueprint_writer_1.BlueprintConfigWriter();
|
|
41
|
+
blueprint_writer_1.BlueprintConfigWriter.SerializeConfig(configWriter, blueprint.config);
|
|
42
|
+
const configFileBinary = configWriter.endWriting();
|
|
43
|
+
return {
|
|
44
|
+
mainFileChunkSummary,
|
|
45
|
+
configFileBinary
|
|
46
|
+
};
|
|
87
47
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
48
|
+
static ParseBlueprintFiles(name, blueprintFile, blueprintConfigFile, onDecompressedBlueprintBody = () => { }) {
|
|
49
|
+
const blueprintConfigReader = new blueprint_reader_1.BlueprintConfigReader(new Uint8Array(blueprintConfigFile).buffer);
|
|
50
|
+
const config = blueprint_reader_1.BlueprintConfigReader.ParseConfig(blueprintConfigReader);
|
|
51
|
+
const blueprintReader = new blueprint_reader_1.BlueprintReader(new Uint8Array(blueprintFile).buffer);
|
|
52
|
+
const header = blueprint_reader_1.BlueprintReader.ReadHeader(blueprintReader);
|
|
53
|
+
const inflateResult = blueprintReader.inflateChunks();
|
|
54
|
+
onDecompressedBlueprintBody(inflateResult.inflatedData);
|
|
55
|
+
const blueprintObjects = blueprint_reader_1.BlueprintReader.ParseObjects(blueprintReader);
|
|
56
|
+
const blueprint = {
|
|
57
|
+
name,
|
|
58
|
+
compressionInfo: blueprintReader.compressionInfo,
|
|
59
|
+
header: header,
|
|
60
|
+
config,
|
|
61
|
+
objects: blueprintObjects
|
|
62
|
+
};
|
|
63
|
+
return blueprint;
|
|
64
|
+
}
|
|
65
|
+
static ProjectSave(save, config) {
|
|
66
|
+
return {
|
|
67
|
+
header: save.header,
|
|
68
|
+
trailingCollectedObjects: save.trailingCollectedObjects,
|
|
69
|
+
levels: save.levels.map(level => {
|
|
70
|
+
const lvl = new level_class_1.Level(level.name);
|
|
71
|
+
lvl.collectables = level.collectables;
|
|
72
|
+
lvl.objects = level.objects.filter(obj => (0, save_reader_1.projectionFilterApplies)(config, obj));
|
|
73
|
+
return lvl;
|
|
74
|
+
})
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
Parser.JSONStringifyModified = (obj, indent = 0) => JSON.stringify(obj, (key, value) => {
|
|
79
|
+
if (typeof value === 'bigint') {
|
|
80
|
+
return value.toString();
|
|
81
|
+
}
|
|
82
|
+
else if (value === 0 && 1 / value < 0) {
|
|
83
|
+
return '-0';
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
}, indent);
|
|
87
|
+
exports.Parser = Parser;
|