s2cfgtojson 3.2.5 → 3.2.7
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 +10 -5
- package/Struct.test.mts +4 -1
- package/package.json +1 -1
package/Struct.mts
CHANGED
|
@@ -51,6 +51,9 @@ export class Struct {
|
|
|
51
51
|
: createDynamicClassInstance(
|
|
52
52
|
this.__internal__.rawName || this.constructor.name,
|
|
53
53
|
);
|
|
54
|
+
patch.__internal__.isRoot = this.__internal__.isRoot;
|
|
55
|
+
patch.__internal__.isArray = this.__internal__.isArray;
|
|
56
|
+
patch.__internal__.useAsterisk = this.__internal__.useAsterisk;
|
|
54
57
|
|
|
55
58
|
function markAsbPatch(s: Struct) {
|
|
56
59
|
s.__internal__.bpatch = true;
|
|
@@ -146,7 +149,7 @@ export class Struct {
|
|
|
146
149
|
this.__internal__ = new Refs(this.__internal__);
|
|
147
150
|
}
|
|
148
151
|
|
|
149
|
-
let text: string = this.__internal__.
|
|
152
|
+
let text: string = this.__internal__.isRoot
|
|
150
153
|
? `${this.__internal__.rawName} : `
|
|
151
154
|
: "";
|
|
152
155
|
text += "struct.begin";
|
|
@@ -161,7 +164,7 @@ export class Struct {
|
|
|
161
164
|
text += this.entries()
|
|
162
165
|
.map(([key, value]) => {
|
|
163
166
|
const nameAlreadyRendered =
|
|
164
|
-
value instanceof Struct && value.__internal__.
|
|
167
|
+
value instanceof Struct && value.__internal__.isRoot;
|
|
165
168
|
const useAsterisk =
|
|
166
169
|
this.__internal__.isArray && this.__internal__.useAsterisk;
|
|
167
170
|
let keyOrIndex = "";
|
|
@@ -192,6 +195,7 @@ export class Refs implements DefaultEntries {
|
|
|
192
195
|
bskipref?: boolean;
|
|
193
196
|
bpatch?: boolean;
|
|
194
197
|
isArray?: boolean;
|
|
198
|
+
isRoot?: boolean;
|
|
195
199
|
useAsterisk?: boolean;
|
|
196
200
|
|
|
197
201
|
constructor(ref?: string | Refs) {
|
|
@@ -228,7 +232,7 @@ export class Refs implements DefaultEntries {
|
|
|
228
232
|
}
|
|
229
233
|
|
|
230
234
|
const structHeadRegex = new RegExp(
|
|
231
|
-
`^\s*(.*)\\s
|
|
235
|
+
`^\s*((.*)\\s*:)?\\s*struct\\.begin\\s*({\\s*((${KEYWORDS.join("|")})\\s*(=.+)?)\\s*})?`,
|
|
232
236
|
);
|
|
233
237
|
|
|
234
238
|
function parseHead(line: string, index: number): Struct {
|
|
@@ -237,9 +241,9 @@ function parseHead(line: string, index: number): Struct {
|
|
|
237
241
|
throw new Error(`Invalid struct head: ${line}`);
|
|
238
242
|
}
|
|
239
243
|
|
|
240
|
-
const dummy = createDynamicClassInstance(match[
|
|
244
|
+
const dummy = createDynamicClassInstance(match[2]?.trim() || "", index);
|
|
241
245
|
if (match[3]) {
|
|
242
|
-
const parsed = new Refs(match[
|
|
246
|
+
const parsed = new Refs(match[4]);
|
|
243
247
|
dummy.__internal__.refurl = parsed.refurl;
|
|
244
248
|
dummy.__internal__.refkey = parsed.refkey;
|
|
245
249
|
dummy.__internal__.bskipref = parsed.bskipref;
|
|
@@ -303,6 +307,7 @@ function walk(lines: string[]) {
|
|
|
303
307
|
);
|
|
304
308
|
current[key] = newStruct;
|
|
305
309
|
} else {
|
|
310
|
+
newStruct.__internal__.isRoot = true;
|
|
306
311
|
roots.push(newStruct);
|
|
307
312
|
}
|
|
308
313
|
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
|
);
|