s2cfgtojson 2.2.13 → 2.3.0
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 +280 -214
- package/Struct.test.mts +81 -37
- package/enums.mts +21 -6
- package/package.json +5 -4
- package/test.cfg +598 -0
- package/types.mts +17 -12
package/Struct.test.mts
CHANGED
|
@@ -1,34 +1,40 @@
|
|
|
1
1
|
import { describe, test, expect } from "vitest";
|
|
2
|
-
import { Struct } from "./Struct.mjs";
|
|
2
|
+
import { createDynamicClassInstance, ERank, pad, Struct } from "./Struct.mjs";
|
|
3
|
+
import fs from "node:fs";
|
|
3
4
|
|
|
4
5
|
class ChimeraHPFix extends Struct {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
__internal__ = {
|
|
7
|
+
rawName: "ChimeraHPFix",
|
|
8
|
+
bskipref: true,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
MaxHP = 750;
|
|
9
12
|
}
|
|
10
13
|
class TradePrototype extends Struct {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
__internal__ = {
|
|
15
|
+
rawName: "TradersDontBuyWeaponsArmor",
|
|
16
|
+
refurl: "../TradePrototypes.cfg",
|
|
17
|
+
refkey: 0,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
TradeGenerators = new TradeGenerators();
|
|
16
21
|
}
|
|
17
22
|
class TradeGenerators extends Struct {
|
|
18
|
-
|
|
19
|
-
entries = { "*": new TradeGenerator() };
|
|
23
|
+
"*" = new TradeGenerator();
|
|
20
24
|
}
|
|
21
25
|
class TradeGenerator extends Struct {
|
|
22
|
-
|
|
23
|
-
entries = { BuyLimitations: new BuyLimitations() };
|
|
26
|
+
BuyLimitations = new BuyLimitations();
|
|
24
27
|
}
|
|
28
|
+
|
|
25
29
|
class BuyLimitations extends Struct {
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
[0] = "EItemType::Weapon";
|
|
31
|
+
[1] = "EItemType::Armor";
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
describe("Struct", () => {
|
|
31
35
|
test("toString()", () => {
|
|
36
|
+
const c = new ChimeraHPFix();
|
|
37
|
+
expect(c.MaxHP).toBe(750);
|
|
32
38
|
expect(new ChimeraHPFix().toString()).toBe(
|
|
33
39
|
`ChimeraHPFix : struct.begin {bskipref}
|
|
34
40
|
MaxHP = 750
|
|
@@ -50,23 +56,16 @@ struct.end`,
|
|
|
50
56
|
});
|
|
51
57
|
|
|
52
58
|
test("pad()", () => {
|
|
53
|
-
expect(
|
|
54
|
-
expect(
|
|
59
|
+
expect(pad("test")).toBe(" test");
|
|
60
|
+
expect(pad(pad("test"))).toBe(" test");
|
|
55
61
|
});
|
|
56
62
|
|
|
57
|
-
describe("
|
|
63
|
+
describe("createDynamicClassInstance", () => {
|
|
58
64
|
test("1", () => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
BuyLimitations: {
|
|
64
|
-
"0": "EItemType::Weapon",
|
|
65
|
-
"1": "EItemType::Armor",
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
}),
|
|
65
|
+
const instance = createDynamicClassInstance("DynamicClass");
|
|
66
|
+
expect(instance).toBeInstanceOf(Struct);
|
|
67
|
+
expect(instance.toString()).toBe(
|
|
68
|
+
`DynamicClass : struct.begin\n\nstruct.end`,
|
|
70
69
|
);
|
|
71
70
|
});
|
|
72
71
|
});
|
|
@@ -197,15 +196,60 @@ struct.end`;
|
|
|
197
196
|
N5 = .1f
|
|
198
197
|
N6 = -2.22f
|
|
199
198
|
struct.end`;
|
|
200
|
-
const str = Struct.fromString<Struct
|
|
199
|
+
const str = Struct.fromString<Struct & { [key: `N${number}`]: number }>(
|
|
201
200
|
dynamicItemGeneratorText,
|
|
202
201
|
);
|
|
203
|
-
expect(str[0].
|
|
204
|
-
expect(str[0].
|
|
205
|
-
expect(str[0].
|
|
206
|
-
expect(str[0].
|
|
207
|
-
expect(str[0].
|
|
208
|
-
expect(str[0].
|
|
202
|
+
expect(str[0].N1).toBe(0.1);
|
|
203
|
+
expect(str[0].N2).toBe(1);
|
|
204
|
+
expect(str[0].N3).toBe(0);
|
|
205
|
+
expect(str[0].N4).toBe(0.1);
|
|
206
|
+
expect(str[0].N5).toBe(0.1);
|
|
207
|
+
expect(str[0].N6).toBe(-2.22);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("5", () => {
|
|
211
|
+
const testCfg = fs.readFileSync("./test.cfg", "utf-8").trim();
|
|
212
|
+
const structs = Struct.fromString(testCfg);
|
|
213
|
+
expect(structs.map((s) => s.toString()).join("\n")).toBe(testCfg);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe("fork", () => {
|
|
218
|
+
test("1", () => {
|
|
219
|
+
const a = new TradePrototype();
|
|
220
|
+
const b = a.fork() as TradePrototype;
|
|
221
|
+
|
|
222
|
+
expect(a === b).toBe(false);
|
|
223
|
+
b.TradeGenerators = new TradeGenerators().fork();
|
|
224
|
+
expect(b.toString()).toBe(
|
|
225
|
+
"TradersDontBuyWeaponsArmor : struct.begin {bpatch}\n" +
|
|
226
|
+
" TradeGenerators : struct.begin {bpatch}\n" +
|
|
227
|
+
" struct.end\n" +
|
|
228
|
+
"struct.end",
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
describe("clone", () => {
|
|
234
|
+
test("1", () => {
|
|
235
|
+
const a = new TradePrototype();
|
|
236
|
+
const b = a.clone() as TradePrototype;
|
|
237
|
+
|
|
238
|
+
expect(a === b).toBe(false);
|
|
239
|
+
expect(a.toString()).toBe(b.toString());
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
describe("removeNode", () => {
|
|
244
|
+
test("1", () => {
|
|
245
|
+
const a = new TradePrototype().fork(true);
|
|
246
|
+
expect(a.TradeGenerators[0].BuyLimitations[0]).toBe("EItemType::Weapon");
|
|
247
|
+
expect(a.TradeGenerators[0].BuyLimitations[1]).toBe("EItemType::Armor");
|
|
248
|
+
a.TradeGenerators[0].BuyLimitations.removeNode(0);
|
|
249
|
+
expect(a.TradeGenerators[0].BuyLimitations[0]).toBe("removenode");
|
|
209
250
|
});
|
|
210
251
|
});
|
|
211
252
|
});
|
|
253
|
+
|
|
254
|
+
// noinspection JSUnusedLocalSymbols
|
|
255
|
+
const MyRank: ERank = "ERank::Experienced, ERank::Veteran, ERank::Master";
|
package/enums.mts
CHANGED
|
@@ -1605,13 +1605,28 @@ export type ERadiationPreset = `ERadiationPreset::${
|
|
|
1605
1605
|
| "Strong"
|
|
1606
1606
|
| "Topaz"}`;
|
|
1607
1607
|
|
|
1608
|
-
|
|
1609
|
-
|
|
1608
|
+
type Newbie = "ERank::Newbie";
|
|
1609
|
+
type Experienced = "ERank::Experienced";
|
|
1610
|
+
type Veteran = "ERank::Veteran";
|
|
1611
|
+
type Master = "ERank::Master";
|
|
1612
|
+
type Permutations2<A, B> = A extends string
|
|
1613
|
+
? B extends string
|
|
1614
|
+
? A | B | `${A}, ${B}`
|
|
1615
|
+
: A
|
|
1616
|
+
: never;
|
|
1617
|
+
|
|
1618
|
+
type Permutations3<A, B, C> = A extends string
|
|
1619
|
+
? B extends string
|
|
1620
|
+
? C extends string
|
|
1621
|
+
? Permutations2<A, B> | Permutations2<B, C> | `${A}, ${B}, ${C}`
|
|
1622
|
+
: Permutations2<A, B>
|
|
1623
|
+
: A
|
|
1624
|
+
: never;
|
|
1625
|
+
|
|
1610
1626
|
export type ERank =
|
|
1611
|
-
|
|
|
1612
|
-
|
|
|
1613
|
-
| `${
|
|
1614
|
-
| `${_ERank}, ${_ERank}, ${_ERank}, ${_ERank}`;
|
|
1627
|
+
| Permutations3<Newbie, Experienced, Veteran>
|
|
1628
|
+
| Permutations3<Experienced, Veteran, Master>
|
|
1629
|
+
| `${Newbie}, ${Experienced}, ${Veteran}, ${Master}`;
|
|
1615
1630
|
|
|
1616
1631
|
export type ERegion = `ERegion::${
|
|
1617
1632
|
| "Bolota"
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "s2cfgtojson",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Converts Stalker 2 Cfg file into
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "Converts Stalker 2 Cfg file into POJOs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"stalker",
|
|
7
7
|
"unrealengine",
|
|
@@ -27,9 +27,10 @@
|
|
|
27
27
|
"test": "vitest"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"
|
|
30
|
+
"@types/node": "^24.5.2",
|
|
31
|
+
"prettier": "^3.6.2",
|
|
31
32
|
"typescript": "^5.8.3",
|
|
32
|
-
"
|
|
33
|
+
"vitest": "^3.2.4"
|
|
33
34
|
},
|
|
34
35
|
"engines": {
|
|
35
36
|
"node": ">=24"
|