s2cfgtojson 3.0.3 → 3.0.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from "./types.mts";
2
2
  export * from "./enums.mts";
3
- import { DefaultEntries, IStruct, Value } from "./types.mts";
3
+ import { DefaultEntries } from "./types.mts";
4
4
 
5
5
  const TAB = " ";
6
6
  const WILDCARD = "_wildcard";
@@ -16,7 +16,7 @@ const REMOVE_NODE = "removenode";
16
16
  * This file is part of the Stalker 2 Modding Tools project.
17
17
  * This is a base class for all structs.
18
18
  */
19
- export class Struct implements IStruct {
19
+ export class Struct {
20
20
  __internal__: Refs = new Refs();
21
21
 
22
22
  /**
@@ -103,10 +103,8 @@ export class Struct implements IStruct {
103
103
  return text;
104
104
  }
105
105
 
106
- static fromString<IntendedType extends Partial<Struct> = Struct>(
107
- text: string,
108
- ): IntendedType[] {
109
- return walk(text.trim().split("\n")) as IntendedType[];
106
+ static fromString<IntendedType>(text: string): (IntendedType & Struct)[] {
107
+ return walk(text.trim().split("\n")) as any[];
110
108
  }
111
109
  }
112
110
 
@@ -259,7 +257,7 @@ export function parseKey(key: string, parent: Struct, index: number) {
259
257
  return normKey;
260
258
  }
261
259
 
262
- function parseValue(value: string): Value {
260
+ function parseValue(value: string): string | number | boolean {
263
261
  if (value === "true" || value === "false") {
264
262
  return value === "true";
265
263
  }
@@ -274,10 +272,8 @@ function parseValue(value: string): Value {
274
272
  `${minus ? "-" : ""}${first || 0}${second ? `.${second}` : ""}`,
275
273
  );
276
274
  }
277
- return JSON.parse(value);
278
- } catch (e) {
279
- return value;
280
- }
275
+ } catch (e) {}
276
+ return value;
281
277
  }
282
278
 
283
279
  function renderStructName(name: string): string {
package/Struct.test.mts CHANGED
@@ -3,7 +3,6 @@ import {
3
3
  createDynamicClassInstance,
4
4
  ERank,
5
5
  pad,
6
- IStruct,
7
6
  Struct,
8
7
  ArmorPrototype,
9
8
  } from "./Struct.mjs";
@@ -203,7 +202,7 @@ struct.end`;
203
202
  N5 = .1f
204
203
  N6 = -2.22f
205
204
  struct.end`;
206
- const str = Struct.fromString<IStruct & { [key: `N${number}`]: number }>(
205
+ const str = Struct.fromString<{ [key: `N${number}`]: number }>(
207
206
  dynamicItemGeneratorText,
208
207
  );
209
208
  expect(str[0].N1).toBe(0.1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s2cfgtojson",
3
- "version": "3.0.3",
3
+ "version": "3.0.5",
4
4
  "description": "Converts Stalker 2 Cfg file into POJOs",
5
5
  "keywords": [
6
6
  "stalker",
package/types.mts CHANGED
@@ -69,10 +69,21 @@ import {
69
69
  import { Struct } from "./Struct.mjs";
70
70
 
71
71
  export type Internal = "__internal__";
72
- export type IStruct = {
73
- [k in Internal]: DefaultEntries;
72
+
73
+ export type DeeplyPartial<T> = {
74
+ [P in keyof T]?: T[P] extends Array<infer U>
75
+ ? Array<DeeplyPartial<U>>
76
+ : T[P] extends ReadonlyArray<infer U>
77
+ ? ReadonlyArray<DeeplyPartial<U>>
78
+ : T[P] extends object
79
+ ? DeeplyPartial<T[P]>
80
+ : T[P];
74
81
  };
75
82
 
83
+ export type DeeplyPartialStruct<T> = DeeplyPartial<
84
+ T extends Struct ? Omit<T, Internal> : T
85
+ >;
86
+
76
87
  export interface DefaultEntries {
77
88
  rawName?: string;
78
89
  refurl?: string;
@@ -84,8 +95,6 @@ export interface DefaultEntries {
84
95
  useAsterisk?: boolean;
85
96
  }
86
97
 
87
- export type Value = string | boolean | number;
88
- export type Entries = Record<string | number, Value>;
89
98
  export type GetStructType<In> =
90
99
  In extends Array<any>
91
100
  ? Struct & { [key in number]: GetStructType<In[key]> }
@@ -747,7 +756,7 @@ export type DynamicItemGenerator = GetStructType<{
747
756
  Category: EItemGenerationCategory;
748
757
  PlayerRank: ERank;
749
758
  bAllowSameCategoryGeneration: boolean;
750
- ReputationThreshold: string;
759
+ ReputationThreshold: number;
751
760
  RefreshTime: string;
752
761
  PossibleItems: {
753
762
  ItemPrototypeSID: string;