s2cfgtojson 2.1.1 → 2.1.3
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 +19 -36
- package/Struct.test.mts +6 -6
- package/package.json +1 -1
- package/types.mts +1744 -0
package/Struct.mts
CHANGED
|
@@ -1,33 +1,12 @@
|
|
|
1
|
-
export type Value = Omit<Struct, "toTs"> | string | boolean | number;
|
|
2
1
|
const defaultEntries = new Set(["_isArray", "_useAsterisk"]);
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export type GetTsType<In extends Struct, E = In["entries"]> = {
|
|
7
|
-
[key in Exclude<keyof E, keyof DefaultEntries>]: E[key] extends Struct
|
|
8
|
-
? GetTsType<E[key]>
|
|
9
|
-
: E[key];
|
|
10
|
-
};
|
|
11
|
-
type RKey<In> = Exclude<keyof In, keyof DefaultEntries>;
|
|
12
|
-
|
|
13
|
-
export type GetStructType<In> =
|
|
14
|
-
In extends Array<any>
|
|
15
|
-
? Struct<{ [key: number]: GetStructType<In[number]> }>
|
|
16
|
-
: In extends Record<any, any>
|
|
17
|
-
? Struct<{ [key in RKey<In>]: GetStructType<In[key]> }>
|
|
18
|
-
: In extends string
|
|
19
|
-
? string
|
|
20
|
-
: In extends number
|
|
21
|
-
? number
|
|
22
|
-
: In extends boolean
|
|
23
|
-
? boolean
|
|
24
|
-
: never;
|
|
2
|
+
export * from "./types.mts";
|
|
3
|
+
import { DefaultEntries, Value, Entries, Struct as IStruct } from "./types.mts";
|
|
25
4
|
|
|
26
5
|
/**
|
|
27
6
|
* This file is part of the Stalker 2 Modding Tools project.
|
|
28
7
|
* This is a base class for all structs.
|
|
29
8
|
*/
|
|
30
|
-
export abstract class Struct<T extends Entries = {}> {
|
|
9
|
+
export abstract class Struct<T extends Entries = {}> implements IStruct<T> {
|
|
31
10
|
isRoot?: boolean;
|
|
32
11
|
refurl?: string;
|
|
33
12
|
refkey?: string | number;
|
|
@@ -226,18 +205,22 @@ export abstract class Struct<T extends Entries = {}> {
|
|
|
226
205
|
throw new Error(`Invalid key-value pair: ${line}`);
|
|
227
206
|
}
|
|
228
207
|
const key = match[1].trim();
|
|
229
|
-
let value: string | number = match[3].trim();
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
208
|
+
let value: string | number | boolean = match[3].trim();
|
|
209
|
+
if (value === "true" || value === "false") {
|
|
210
|
+
value = value === "true";
|
|
211
|
+
} else {
|
|
212
|
+
try {
|
|
213
|
+
// understand 0.1f / 1. / 0.f / .1 / .1f -> ((\d*)\.?(\d+)|(\d+)\.?(\d*))f?
|
|
214
|
+
const matches = value.match(/^(\d*)\.?(\d*)f?$/);
|
|
215
|
+
const first = matches[1];
|
|
216
|
+
const second = matches[2];
|
|
217
|
+
if (first || second) {
|
|
218
|
+
value = parseFloat(`${first || 0}${second ? `.${second}` : ""}`);
|
|
219
|
+
} else {
|
|
220
|
+
value = JSON.parse(value);
|
|
221
|
+
}
|
|
222
|
+
} catch (e) {}
|
|
223
|
+
}
|
|
241
224
|
Struct.addEntry(parent, key, value, index);
|
|
242
225
|
};
|
|
243
226
|
let index = 0;
|
package/Struct.test.mts
CHANGED
|
@@ -83,13 +83,13 @@ struct.end`,
|
|
|
83
83
|
TriggeredCooldowns : struct.begin
|
|
84
84
|
[0] : struct.begin
|
|
85
85
|
CooldownTag = Ability.Cooldown.RunAttack
|
|
86
|
-
Duration = 50
|
|
86
|
+
Duration = 50
|
|
87
87
|
struct.end
|
|
88
88
|
struct.end
|
|
89
89
|
Effects : struct.begin
|
|
90
90
|
[0] : struct.begin
|
|
91
91
|
EffectPrototypeSID = MutantMediumAttackCameraShake
|
|
92
|
-
Chance = 1
|
|
92
|
+
Chance = 1
|
|
93
93
|
struct.end
|
|
94
94
|
struct.end
|
|
95
95
|
struct.end`;
|
|
@@ -129,8 +129,8 @@ struct.end`;
|
|
|
129
129
|
[0] : struct.begin
|
|
130
130
|
ItemPrototypeSID = DutyArmor_3_U1
|
|
131
131
|
Weight = 1
|
|
132
|
-
MinDurability = 1
|
|
133
|
-
MaxDurability = 1
|
|
132
|
+
MinDurability = 1
|
|
133
|
+
MaxDurability = 1
|
|
134
134
|
struct.end
|
|
135
135
|
struct.end
|
|
136
136
|
struct.end
|
|
@@ -176,8 +176,8 @@ struct.end`;
|
|
|
176
176
|
[0] : struct.begin
|
|
177
177
|
ItemPrototypeSID = DutyMask_1
|
|
178
178
|
Weight = 2
|
|
179
|
-
MinDurability = 1
|
|
180
|
-
MaxDurability = 1
|
|
179
|
+
MinDurability = 1
|
|
180
|
+
MaxDurability = 1
|
|
181
181
|
struct.end
|
|
182
182
|
struct.end
|
|
183
183
|
struct.end
|