@etothepii/satisfactory-file-parser 0.1.7 → 0.1.9

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 CHANGED
@@ -19,7 +19,7 @@ U8 has only read support so far and only for save files, not for blueprint files
19
19
  |:--------------:|:-----------------------------|
20
20
  | <= U5 | ❌ |
21
21
  | U6 + U7 | ✅ 0.0.1 - 0.0.34 |
22
- | U8 | ⚠️ >= 0.1.5 (Reading only) |
22
+ | U8 | ⚠️ >= 0.1.9 (Reading only) |
23
23
 
24
24
 
25
25
  ## Installation via npm
@@ -5,7 +5,7 @@ import { vec3 } from "../structs/util.types";
5
5
  import { ObjectReference } from "./ObjectReference";
6
6
  import { AbstractBaseProperty } from "./Property";
7
7
  import { SaveObject } from "./SaveObject";
8
- export type SpecialAnyProperty = {} | PowerLineSpecialProperty;
8
+ export type SpecialAnyProperty = {} | PowerLineSpecialProperty | PlayerSpecialProperty;
9
9
  export type PowerLineSpecialProperty = {
10
10
  num: number;
11
11
  source: ObjectReference;
@@ -31,7 +31,7 @@ export declare class DataFields {
31
31
  constructor();
32
32
  static ParseProperties(obj: SaveObject, length: number, reader: BinaryReadable, buildVersion: number, typePath: string): void;
33
33
  static ParseAdditionalSpecialProperties(reader: BinaryReadable, typePath: string, remainingLen: number): SpecialAnyProperty;
34
- static ParseProperty(reader: BinaryReadable, buildVersion: number, propertyName: string): AbstractBaseProperty | null;
34
+ static ParseProperty(reader: BinaryReadable, buildVersion: number, propertyName: string): AbstractBaseProperty;
35
35
  static Serialize(obj: SaveObject, writer: SaveWriter, buildVersion: number, typePath: string): void;
36
36
  static SerializeAdditionalSpecialProperties(writer: ByteWriter, typePath: string, property: SpecialAnyProperty): void;
37
37
  static SerializeProperty(writer: ByteWriter, property: AbstractBaseProperty, propertyName: string, buildVersion: number): void;
@@ -8,14 +8,22 @@ class DataFields {
8
8
  }
9
9
  static ParseProperties(obj, length, reader, buildVersion, typePath) {
10
10
  const start = reader.getBufferPosition();
11
- obj.properties = [];
11
+ obj.properties = {};
12
12
  if (length === 0) {
13
13
  return;
14
14
  }
15
15
  let propertyName = reader.readString();
16
16
  while (propertyName !== 'None') {
17
- const property = DataFields.ParseProperty(reader, buildVersion, propertyName);
18
- obj.properties.push(property);
17
+ const parsedProperty = DataFields.ParseProperty(reader, buildVersion, propertyName);
18
+ if (obj.properties[propertyName]) {
19
+ if (!Array.isArray(obj.properties[propertyName])) {
20
+ obj.properties[propertyName] = [obj.properties[propertyName]];
21
+ }
22
+ obj.properties[propertyName].push(parsedProperty);
23
+ }
24
+ else {
25
+ obj.properties[propertyName] = parsedProperty;
26
+ }
19
27
  propertyName = reader.readString();
20
28
  }
21
29
  let padding = reader.readInt32();
@@ -81,9 +89,6 @@ class DataFields {
81
89
  }
82
90
  static ParseProperty(reader, buildVersion, propertyName) {
83
91
  let currentProperty = {};
84
- if (currentProperty.name === 'None') {
85
- return null;
86
- }
87
92
  const propertyType = reader.readString();
88
93
  const binarySize = reader.readInt32();
89
94
  const index = reader.readInt32();
@@ -174,7 +179,7 @@ class DataFields {
174
179
  return currentProperty;
175
180
  }
176
181
  static Serialize(obj, writer, buildVersion, typePath) {
177
- for (const property of Object.values(obj.properties)) {
182
+ for (const property of Object.values(obj.properties).flatMap(val => Array.isArray(val) ? val : [val])) {
178
183
  writer.writeString(property.name);
179
184
  DataFields.SerializeProperty(writer, property, property.name, buildVersion);
180
185
  }
@@ -2,8 +2,8 @@ import { ByteWriter } from "../../..";
2
2
  import { BinaryReadable } from "../../byte/binary-readable.interface";
3
3
  import { col4, vec3, vec4 } from "../structs/util.types";
4
4
  import { ObjectReference } from "./ObjectReference";
5
- export type Properties = {
6
- [key: string]: string | number | boolean | any;
5
+ export type PropertiesMap = {
6
+ [name: string]: AbstractBaseProperty | AbstractBaseProperty[];
7
7
  };
8
8
  export declare abstract class AbstractProperty {
9
9
  type: string;
@@ -201,7 +201,7 @@ export type FICFrameRangeStructPropertyValue = {
201
201
  };
202
202
  export type DynamicStructPropertyValue = {
203
203
  type: string;
204
- properties: Properties;
204
+ properties: PropertiesMap;
205
205
  };
206
206
  export type GENERIC_STRUCT_PROPERTY_VALUE = BasicMultipleStructPropertyValue | BasicStructPropertyValue | BoxStructPropertyValue | RailroadTrackPositionStructPropertyValue | InventoryItemStructPropertyValue | FICFrameRangeStructPropertyValue | DynamicStructPropertyValue | col4 | vec3 | vec4 | string;
207
207
  export declare class StructProperty extends AbstractBaseProperty {
@@ -933,8 +933,16 @@ const ParseDynamicStructData = (reader, buildVersion, type) => {
933
933
  const pos = reader.getBufferPosition();
934
934
  let propertyName = reader.readString();
935
935
  while (propertyName !== 'None') {
936
- const property = DataFields_1.DataFields.ParseProperty(reader, buildVersion, propertyName);
937
- data.properties.push(property);
936
+ const parsedProperty = DataFields_1.DataFields.ParseProperty(reader, buildVersion, propertyName);
937
+ if (data.properties[propertyName]) {
938
+ if (!Array.isArray(data.properties[propertyName])) {
939
+ data.properties[propertyName] = [data.properties[propertyName]];
940
+ }
941
+ data.properties[propertyName].push(parsedProperty);
942
+ }
943
+ else {
944
+ data.properties[propertyName] = parsedProperty;
945
+ }
938
946
  propertyName = reader.readString();
939
947
  }
940
948
  return data;
@@ -943,7 +951,9 @@ exports.ParseDynamicStructData = ParseDynamicStructData;
943
951
  const SerializeDynamicStructData = (writer, buildVersion, data) => {
944
952
  for (const key in data.properties) {
945
953
  writer.writeString(key);
946
- DataFields_1.DataFields.SerializeProperty(writer, data.properties[key], key, buildVersion);
954
+ for (const prop of (Array.isArray(data.properties[key]) ? data.properties[key] : [data.properties[key]])) {
955
+ DataFields_1.DataFields.SerializeProperty(writer, prop, key, buildVersion);
956
+ }
947
957
  }
948
958
  writer.writeString('None');
949
959
  };
@@ -1,7 +1,7 @@
1
1
  import { BinaryReadable } from "../../byte/binary-readable.interface";
2
2
  import { ByteWriter } from "../../byte/byte-writer.class";
3
3
  import { SpecialAnyProperty } from "./DataFields";
4
- import { AbstractBaseProperty } from "./Property";
4
+ import { PropertiesMap } from "./Property";
5
5
  export interface SaveObjectHeader {
6
6
  typePath: string;
7
7
  rootObject: string;
@@ -11,7 +11,7 @@ export declare abstract class SaveObject implements SaveObjectHeader {
11
11
  typePath: string;
12
12
  rootObject: string;
13
13
  instanceName: string;
14
- properties: AbstractBaseProperty[];
14
+ properties: PropertiesMap;
15
15
  specialProperties: SpecialAnyProperty;
16
16
  trailingData: number[];
17
17
  unknownType1: number;
@@ -7,7 +7,7 @@ class SaveObject {
7
7
  this.typePath = typePath;
8
8
  this.rootObject = rootObject;
9
9
  this.instanceName = instanceName;
10
- this.properties = [];
10
+ this.properties = {};
11
11
  this.specialProperties = {};
12
12
  this.trailingData = [];
13
13
  this.unknownType1 = 0;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@etothepii/satisfactory-file-parser",
3
3
  "author": "etothepii",
4
- "version": "0.1.7",
4
+ "version": "0.1.9",
5
5
  "description": "A file parser for satisfactory files. Includes save files and blueprint files.",
6
6
  "types": "./build/index.d.ts",
7
7
  "main": "./build/index.js",