s2cfgtojson 2.0.0 → 2.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.
Files changed (2) hide show
  1. package/Struct.mts +21 -7
  2. package/package.json +1 -1
package/Struct.mts CHANGED
@@ -1,7 +1,19 @@
1
1
  export type Value = Omit<Struct, "toTs"> | string | boolean | number;
2
+ const defaultEntries = new Set(["_isArray", "_useAsterisk"]);
2
3
  type DefaultEntries = { _isArray?: boolean; _useAsterisk?: boolean };
3
4
  export type Entries = Record<string | number, Value> & DefaultEntries;
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
+ export type GetStructType<In extends Record<string | number, any>> = Struct<{
12
+ [key in Exclude<keyof In, keyof DefaultEntries>]: In[key] extends In
13
+ ? GetStructType<In[key]>
14
+ : In[key];
15
+ }>;
16
+
5
17
  /**
6
18
  * This file is part of the Stalker 2 Modding Tools project.
7
19
  * This is a base class for all structs.
@@ -114,13 +126,15 @@ export abstract class Struct<T extends Entries = {}> {
114
126
  const collect = (struct: Struct) => {
115
127
  const obj = {};
116
128
  if (struct.entries) {
117
- Object.entries(struct.entries).forEach(([key, value]) => {
118
- if (value instanceof Struct) {
119
- obj[key] = collect(value);
120
- } else {
121
- obj[key] = value;
122
- }
123
- });
129
+ Object.entries(struct.entries)
130
+ .filter(([key]) => !defaultEntries.has(key))
131
+ .forEach(([key, value]) => {
132
+ if (value instanceof Struct) {
133
+ obj[key] = collect(value);
134
+ } else {
135
+ obj[key] = value;
136
+ }
137
+ });
124
138
  }
125
139
  return obj;
126
140
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s2cfgtojson",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Converts Stalker 2 Cfg file into a POJO",
5
5
  "keywords": [
6
6
  "stalker",