s2cfgtojson 1.0.0 → 1.0.2
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 +8 -5
- package/package.json +1 -1
- package/readme.md +7 -1
package/Struct.mts
CHANGED
|
@@ -68,7 +68,9 @@ export abstract class Struct<T extends Entries = {}> {
|
|
|
68
68
|
if (Struct.isNumber(Struct.extractKeyFromBrackets(name))) {
|
|
69
69
|
return `_${name.match(/\[(\d+)]/)[1]}`; // Special case for indexed structs
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
const replacer = (text: string) =>
|
|
72
|
+
text.replace(/\W/g, "_").replace(/_+/g, "_").replace(/^_/, "");
|
|
73
|
+
return `${replacer(name[0]).replace(/\d/, "")}${replacer(name.slice(1))}`;
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
static createDynamicClass = (name: string): new () => Struct =>
|
|
@@ -76,7 +78,7 @@ export abstract class Struct<T extends Entries = {}> {
|
|
|
76
78
|
|
|
77
79
|
toString(): string {
|
|
78
80
|
let text: string;
|
|
79
|
-
text = this.isRoot ? `${
|
|
81
|
+
text = this.isRoot ? `${this._id} : ` : "";
|
|
80
82
|
text += "struct.begin";
|
|
81
83
|
const refs = ["refurl", "refkey", "bskipref"]
|
|
82
84
|
.map((k) => [k, this[k]])
|
|
@@ -158,9 +160,7 @@ export abstract class Struct<T extends Entries = {}> {
|
|
|
158
160
|
let name = Struct.parseStructName(match[1].trim());
|
|
159
161
|
|
|
160
162
|
const dummy = new (Struct.createDynamicClass(name))();
|
|
161
|
-
|
|
162
|
-
dummy._id = name;
|
|
163
|
-
}
|
|
163
|
+
dummy._id = match[1];
|
|
164
164
|
if (match[3]) {
|
|
165
165
|
const refs = match[3]
|
|
166
166
|
.split(";")
|
|
@@ -197,6 +197,9 @@ export abstract class Struct<T extends Entries = {}> {
|
|
|
197
197
|
const stack = [];
|
|
198
198
|
while (index < lines.length) {
|
|
199
199
|
const line = lines[index++].trim();
|
|
200
|
+
if (line.startsWith("#") || line.startsWith("//")) {
|
|
201
|
+
continue; // Skip comments
|
|
202
|
+
}
|
|
200
203
|
const current = stack[stack.length - 1];
|
|
201
204
|
if (line.includes("struct.begin")) {
|
|
202
205
|
const newStruct = parseHead(line);
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -18,6 +18,12 @@ A utility to convert Stalker 2 `.cfg` configuration files into structured JavaSc
|
|
|
18
18
|
- npm (or pnpm/yarn)
|
|
19
19
|
|
|
20
20
|
### Installation
|
|
21
|
+
In your project directory, run:
|
|
22
|
+
```bash
|
|
23
|
+
npm install s2cfgtojson
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or, if you checked out the repository, you can install dependencies directly:
|
|
21
27
|
```bash
|
|
22
28
|
npm install
|
|
23
29
|
```
|
|
@@ -47,7 +53,7 @@ BasePhantomAttack : struct.begin {refkey=BaseAttackAbility}
|
|
|
47
53
|
struct.end
|
|
48
54
|
`;
|
|
49
55
|
const parsed = Struct.fromString(configText)[0];
|
|
50
|
-
console.log(parsed.
|
|
56
|
+
console.log(parsed.entries.TriggeredCooldowns);
|
|
51
57
|
```
|
|
52
58
|
|
|
53
59
|
---
|