s2cfgtojson 3.2.5 → 3.2.6

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/Struct.mts CHANGED
@@ -51,6 +51,7 @@ export class Struct {
51
51
  : createDynamicClassInstance(
52
52
  this.__internal__.rawName || this.constructor.name,
53
53
  );
54
+ patch.__internal__.isRoot = this.__internal__.isRoot;
54
55
 
55
56
  function markAsbPatch(s: Struct) {
56
57
  s.__internal__.bpatch = true;
@@ -146,7 +147,7 @@ export class Struct {
146
147
  this.__internal__ = new Refs(this.__internal__);
147
148
  }
148
149
 
149
- let text: string = this.__internal__.rawName
150
+ let text: string = this.__internal__.isRoot
150
151
  ? `${this.__internal__.rawName} : `
151
152
  : "";
152
153
  text += "struct.begin";
@@ -161,7 +162,7 @@ export class Struct {
161
162
  text += this.entries()
162
163
  .map(([key, value]) => {
163
164
  const nameAlreadyRendered =
164
- value instanceof Struct && value.__internal__.rawName;
165
+ value instanceof Struct && value.__internal__.isRoot;
165
166
  const useAsterisk =
166
167
  this.__internal__.isArray && this.__internal__.useAsterisk;
167
168
  let keyOrIndex = "";
@@ -192,6 +193,7 @@ export class Refs implements DefaultEntries {
192
193
  bskipref?: boolean;
193
194
  bpatch?: boolean;
194
195
  isArray?: boolean;
196
+ isRoot?: boolean;
195
197
  useAsterisk?: boolean;
196
198
 
197
199
  constructor(ref?: string | Refs) {
@@ -228,7 +230,7 @@ export class Refs implements DefaultEntries {
228
230
  }
229
231
 
230
232
  const structHeadRegex = new RegExp(
231
- `^\s*(.*)\\s*:\\s*struct\\.begin\\s*({\\s*((${KEYWORDS.join("|")})\\s*(=.+)?)\\s*})?`,
233
+ `^\s*((.*)\\s*:)?\\s*struct\\.begin\\s*({\\s*((${KEYWORDS.join("|")})\\s*(=.+)?)\\s*})?`,
232
234
  );
233
235
 
234
236
  function parseHead(line: string, index: number): Struct {
@@ -237,9 +239,9 @@ function parseHead(line: string, index: number): Struct {
237
239
  throw new Error(`Invalid struct head: ${line}`);
238
240
  }
239
241
 
240
- const dummy = createDynamicClassInstance(match[1].trim(), index);
242
+ const dummy = createDynamicClassInstance(match[2]?.trim() || "", index);
241
243
  if (match[3]) {
242
- const parsed = new Refs(match[3]);
244
+ const parsed = new Refs(match[4]);
243
245
  dummy.__internal__.refurl = parsed.refurl;
244
246
  dummy.__internal__.refkey = parsed.refkey;
245
247
  dummy.__internal__.bskipref = parsed.bskipref;
@@ -303,6 +305,7 @@ function walk(lines: string[]) {
303
305
  );
304
306
  current[key] = newStruct;
305
307
  } else {
308
+ newStruct.__internal__.isRoot = true;
306
309
  roots.push(newStruct);
307
310
  }
308
311
  stack.push(newStruct);
package/Struct.test.mts CHANGED
@@ -12,6 +12,7 @@ import fs from "node:fs";
12
12
  class ChimeraHPFix extends Struct {
13
13
  __internal__ = {
14
14
  rawName: "ChimeraHPFix",
15
+ isRoot: true,
15
16
  bskipref: true,
16
17
  };
17
18
 
@@ -22,6 +23,7 @@ class TradePrototype extends Struct {
22
23
  rawName: "TradersDontBuyWeaponsArmor",
23
24
  refurl: "../TradePrototypes.cfg",
24
25
  refkey: 0,
26
+ isRoot: true,
25
27
  };
26
28
 
27
29
  TradeGenerators = new TradeGenerators();
@@ -78,8 +80,9 @@ struct.end`,
78
80
  describe("createDynamicClassInstance", () => {
79
81
  test("1", () => {
80
82
  const instance = createDynamicClassInstance("DynamicClass");
83
+ instance.__internal__.isRoot = true;
84
+
81
85
  expect(instance).toBeInstanceOf(Struct);
82
- expect(instance.__internal__.rawName).toBe("DynamicClass");
83
86
  expect(instance.toString()).toBe(
84
87
  `DynamicClass : struct.begin\n\nstruct.end`,
85
88
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s2cfgtojson",
3
- "version": "3.2.5",
3
+ "version": "3.2.6",
4
4
  "description": "Converts Stalker 2 Cfg file into POJOs",
5
5
  "keywords": [
6
6
  "stalker",