game-data-gen 2.0.0 → 2.1.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/README.md CHANGED
@@ -42,7 +42,7 @@ fieldName fieldType fieldArrayType? fieldArrayLength?
42
42
 
43
43
  The name of the data structure.
44
44
 
45
- `type` (optional)
45
+ `type`
46
46
 
47
47
  Supported data structure types:
48
48
 
@@ -57,6 +57,10 @@ The length of the arrays within the Structure of Arrays data structure.
57
57
 
58
58
  If no length is given to the type and no length is given to a field it is considered a dynamic array and zeroing will set the array's length back to zero (emptying it).
59
59
 
60
+ `struct` (optional, required if type=aos)
61
+
62
+ The struct to use for this Array of Structures.
63
+
60
64
  `fieldName`
61
65
 
62
66
  The name of one of the fields within the data structure.
@@ -69,8 +73,9 @@ Supported field types:
69
73
  - number
70
74
  - boolean
71
75
  - array
76
+ - a struct (see entity struct in example below)
72
77
 
73
- `fieldArrayType` (optional, required if fieldType=array)
78
+ `fieldArrayType` (required if fieldType=array)
74
79
 
75
80
  Supported array field types:
76
81
 
@@ -84,9 +89,6 @@ The length of the array field, leave empty to use a dynamically sized array inst
84
89
 
85
90
  In case of a Structure of Arrays data structure (type=soa), setting the length on the type instead is recommended so that all arrays have the same length.
86
91
 
87
- `struct` (optional, required if type=aos)
88
-
89
- The defined struct to use for this Array of Structures.
90
92
 
91
93
  ## Example
92
94
 
@@ -121,7 +123,7 @@ Run the package with (consider making this a script in your package.json):
121
123
  npx game-data-gen src/data/game
122
124
  ```
123
125
 
124
- This will create or update the `src/data/game.ts` file which you can then import into your code:
126
+ This will create or update the `src/data/game.ts` file (see below). The data and functions can then be imported from this file into your code.
125
127
 
126
128
  ```typescript
127
129
  /*
package/dist/consts.js ADDED
@@ -0,0 +1,21 @@
1
+ export var Type;
2
+ (function (Type) {
3
+ Type["SOA"] = "soa";
4
+ Type["AOS"] = "aos";
5
+ Type["STRUCT"] = "struct";
6
+ Type["GROUP"] = "group";
7
+ })(Type || (Type = {}));
8
+ export var FieldType;
9
+ (function (FieldType) {
10
+ FieldType["STRING"] = "string";
11
+ FieldType["NUMBER"] = "number";
12
+ FieldType["BOOLEAN"] = "boolean";
13
+ FieldType["ARRAY"] = "array";
14
+ FieldType["SET"] = "set";
15
+ })(FieldType || (FieldType = {}));
16
+ export var ArrayType;
17
+ (function (ArrayType) {
18
+ ArrayType["STRING"] = "string";
19
+ ArrayType["NUMBER"] = "number";
20
+ ArrayType["BOOLEAN"] = "boolean";
21
+ })(ArrayType || (ArrayType = {}));
@@ -0,0 +1,32 @@
1
+ import { addFieldMaxLengthConstant } from "./fields.js";
2
+ import { capitalize, getName } from "./utils.js";
3
+ export function addArrayOfStructures(header, output) {
4
+ const [name, , length, struct] = header.split(" ");
5
+ addFieldMaxLengthConstant(name, length, output);
6
+ addArrayOfStructuresDefinition(name, struct, length, output);
7
+ addArrayOfStructuresZeroFunction(name, struct, length, output);
8
+ addArrayOfStructuresZeroAtIndexFunction(name, struct, output);
9
+ }
10
+ function addArrayOfStructuresDefinition(name, struct, length, output) {
11
+ output.push(`/** An array of ${capitalize(struct)} objects (structures). */`);
12
+ output.push(`export const ${name} = new Array<${getName(struct)}>(${length})`);
13
+ output.push(`for (let i=0; i<${length}; i++) {`);
14
+ output.push(` ${name}[i] = create${capitalize(struct)}()`);
15
+ output.push("}");
16
+ }
17
+ function addArrayOfStructuresZeroFunction(name, struct, length, output) {
18
+ output.push("");
19
+ output.push(`/** Zero all objects within the ${name} array of structures. */`);
20
+ output.push(`export function zero${capitalize(name)}() {`);
21
+ output.push(` for (let i=0; i<${length}; i++) {`);
22
+ output.push(` zero${capitalize(struct)}(${name}[i])`);
23
+ output.push(" }");
24
+ output.push("}");
25
+ }
26
+ function addArrayOfStructuresZeroAtIndexFunction(name, struct, output) {
27
+ output.push("");
28
+ output.push(`/** Zero an object at a specific index within the ${name} array of structures. */`);
29
+ output.push(`export function zero${capitalize(struct)}At(index: number) {`);
30
+ output.push(` zero${capitalize(struct)}(${name}[index])`);
31
+ output.push("}");
32
+ }
@@ -0,0 +1,102 @@
1
+ import { ArrayType, FieldType } from "../consts.js";
2
+ import { capitalize, getName } from "./utils.js";
3
+ export function addFieldDefinition(field, baseLength, output) {
4
+ const [fieldName, fieldType, fieldArrayType, fieldLength] = field.split(" ");
5
+ const fieldArrayLength = baseLength || fieldLength || "";
6
+ switch (fieldType) {
7
+ case FieldType.STRING:
8
+ output.push(`export let ${fieldName} = ""`);
9
+ break;
10
+ case FieldType.NUMBER:
11
+ output.push(`export let ${fieldName} = 0`);
12
+ break;
13
+ case FieldType.BOOLEAN:
14
+ output.push(`export let ${fieldName} = false`);
15
+ break;
16
+ case FieldType.ARRAY:
17
+ {
18
+ switch (fieldArrayType) {
19
+ case ArrayType.STRING:
20
+ output.push(`export let ${fieldName} = new Array<string>(${fieldArrayLength})${fieldArrayLength ? '.fill("")' : ""}`);
21
+ break;
22
+ case ArrayType.NUMBER:
23
+ output.push(`export let ${fieldName} = new Array<number>(${fieldArrayLength})${fieldArrayLength ? ".fill(0)" : ""}`);
24
+ break;
25
+ case ArrayType.BOOLEAN:
26
+ output.push(`export let ${fieldName} = new Array<boolean>(${fieldArrayLength})${fieldArrayLength ? ".fill(false)" : ""}`);
27
+ break;
28
+ }
29
+ }
30
+ break;
31
+ case FieldType.SET:
32
+ output.push(`export let ${fieldName} = new Set<${getName(fieldArrayType)}>()`);
33
+ break;
34
+ default:
35
+ output.push(`export let ${fieldName} = create${capitalize(fieldType)}()`);
36
+ }
37
+ }
38
+ export function addFieldSetFunction(name, type, field, output) {
39
+ const [fieldName, fieldType, fieldArrayType] = field.split(" ");
40
+ output.push("");
41
+ output.push(`/** Set the value of the ${fieldName} field within the ${name} ${getName(type)}. */`);
42
+ output.push(`export function set${capitalize(fieldName)}(value: ${getName(fieldType, fieldArrayType)}) {`);
43
+ output.push(` ${fieldName} = value`);
44
+ output.push("}");
45
+ }
46
+ export function addFieldZeroFunction(name, type, field, baseLength, output) {
47
+ const [fieldName, fieldType, fieldArrayType, fieldLength] = field.split(" ");
48
+ const length = baseLength || fieldLength || "";
49
+ output.push("");
50
+ output.push(`/** Zero the ${fieldName} field within the ${name} ${getName(type)}. */`);
51
+ output.push(`export function zero${capitalize(fieldName)}() {`);
52
+ zeroField(fieldName, fieldType, fieldArrayType, length, output);
53
+ output.push("}");
54
+ }
55
+ export function addZeroFunction(name, type, fields, baseLength, output) {
56
+ output.push("");
57
+ output.push(`/** Zero all fields within the ${name} ${getName(type)}. */`);
58
+ output.push(`export function zero${capitalize(name)}Data() {`);
59
+ for (const field of fields) {
60
+ const [fieldName, fieldType, fieldArrayType, fieldLength] = field.split(" ");
61
+ const length = baseLength || fieldLength || "";
62
+ zeroField(fieldName, fieldType, fieldArrayType, length, output);
63
+ }
64
+ output.push("}");
65
+ }
66
+ function zeroField(name, type, arrayType, length, output) {
67
+ switch (type) {
68
+ case FieldType.STRING:
69
+ output.push(` ${name} = ""`);
70
+ break;
71
+ case FieldType.NUMBER:
72
+ output.push(` ${name} = 0`);
73
+ break;
74
+ case FieldType.BOOLEAN:
75
+ output.push(` ${name} = false`);
76
+ break;
77
+ case FieldType.ARRAY:
78
+ {
79
+ switch (arrayType) {
80
+ case ArrayType.STRING:
81
+ output.push(` ${name}.${length ? 'fill("")' : "length = 0"}`);
82
+ break;
83
+ case ArrayType.NUMBER:
84
+ output.push(` ${name}.${length ? "fill(0)" : "length = 0"}`);
85
+ break;
86
+ case ArrayType.BOOLEAN:
87
+ output.push(` ${name}.${length ? "fill(false)" : "length = 0"}`);
88
+ break;
89
+ }
90
+ }
91
+ break;
92
+ case FieldType.SET:
93
+ output.push(` ${name}.clear()`);
94
+ break;
95
+ default:
96
+ output.push(` zero${capitalize(type)}(${name})`);
97
+ }
98
+ }
99
+ export function addFieldMaxLengthConstant(name, length, output) {
100
+ output.push(`export const MAX_${name.toUpperCase()}_COUNT = ${length}`);
101
+ output.push("");
102
+ }
@@ -0,0 +1,14 @@
1
+ import { addFieldDefinition, addFieldSetFunction, addFieldZeroFunction, addZeroFunction } from "./fields.js";
2
+ export function addGroup(header, fields, output) {
3
+ const [name, type, baseLength] = header.split(" ");
4
+ for (const field of fields) {
5
+ addFieldDefinition(field, baseLength, output);
6
+ }
7
+ for (const field of fields) {
8
+ addFieldSetFunction(name, type, field, output);
9
+ }
10
+ for (const field of fields) {
11
+ addFieldZeroFunction(name, type, field, baseLength, output);
12
+ }
13
+ addZeroFunction(name, type, fields, baseLength, output);
14
+ }
@@ -0,0 +1,38 @@
1
+ import { ArrayType } from "../consts.js";
2
+ import { addFieldDefinition, addFieldMaxLengthConstant, addFieldSetFunction, addFieldZeroFunction, addZeroFunction } from "./fields.js";
3
+ import { capitalize, getName } from "./utils.js";
4
+ export function addStructureOfArrays(header, fields, output) {
5
+ const [name, type, baseLength] = header.split(" ");
6
+ addFieldMaxLengthConstant(name, baseLength, output);
7
+ for (const field of fields) {
8
+ addFieldDefinition(field, baseLength, output);
9
+ }
10
+ for (const field of fields) {
11
+ addFieldSetFunction(name, type, field, output);
12
+ }
13
+ addFieldZeroAtIndexFunction(name, type, fields, output);
14
+ for (const field of fields) {
15
+ addFieldZeroFunction(name, type, field, baseLength, output);
16
+ }
17
+ addZeroFunction(name, type, fields, baseLength, output);
18
+ }
19
+ function addFieldZeroAtIndexFunction(name, type, fields, output) {
20
+ output.push("");
21
+ output.push(`/** Zero an index within the ${name} ${getName(type)}. */`);
22
+ output.push(`export function zero${capitalize(name)}(idx: number) {`);
23
+ for (const field of fields) {
24
+ const [fieldName, _, fieldArrayType] = field.split(" ");
25
+ switch (fieldArrayType) {
26
+ case ArrayType.STRING:
27
+ output.push(` ${fieldName}[idx] = ""`);
28
+ break;
29
+ case ArrayType.NUMBER:
30
+ output.push(` ${fieldName}[idx] = 0`);
31
+ break;
32
+ case ArrayType.BOOLEAN:
33
+ output.push(` ${fieldName}[idx] = false`);
34
+ break;
35
+ }
36
+ }
37
+ output.push("}");
38
+ }
@@ -0,0 +1,99 @@
1
+ import { ArrayType, FieldType } from "../consts.js";
2
+ import { capitalize, getName } from "./utils.js";
3
+ export function addStruct(header, fields, output) {
4
+ const [name] = header.split(" ");
5
+ addStructTypeDefinition(name, fields, output);
6
+ addStructCreateFunction(name, fields, output);
7
+ addStructZeroFunction(name, fields, output);
8
+ }
9
+ function addStructTypeDefinition(name, fields, output) {
10
+ output.push(`export type ${capitalize(name)} = {`);
11
+ for (const field of fields) {
12
+ const [fieldName, fieldType, fieldArrayType] = field.split(" ");
13
+ output.push(` ${fieldName}: ${getName(fieldType, fieldArrayType)}`);
14
+ }
15
+ output.push("}");
16
+ }
17
+ function addStructCreateFunction(name, fields, output) {
18
+ output.push("");
19
+ output.push(`/** Create a new ${capitalize(name)} object. */`);
20
+ output.push(`export function create${capitalize(name)}(): ${capitalize(name)} {`);
21
+ output.push(` const obj = Object.create(null)`);
22
+ for (const field of fields) {
23
+ const [fieldName, fieldType, fieldArrayType, fieldArrayLength = ""] = field.split(" ");
24
+ switch (fieldType) {
25
+ case FieldType.STRING:
26
+ output.push(` obj.${fieldName} = ""`);
27
+ break;
28
+ case FieldType.NUMBER:
29
+ output.push(` obj.${fieldName} = 0`);
30
+ break;
31
+ case FieldType.BOOLEAN:
32
+ output.push(` obj.${fieldName} = false`);
33
+ break;
34
+ case FieldType.ARRAY:
35
+ {
36
+ switch (fieldArrayType) {
37
+ case ArrayType.STRING:
38
+ output.push(` obj.${fieldName} = new Array<string>(${fieldArrayLength})${fieldArrayLength ? '.fill("")' : ""}`);
39
+ break;
40
+ case ArrayType.NUMBER:
41
+ output.push(` obj.${fieldName} = new Array<number>(${fieldArrayLength})${fieldArrayLength ? ".fill(0)" : ""}`);
42
+ break;
43
+ case ArrayType.BOOLEAN:
44
+ output.push(` obj.${fieldName} = new Array<boolean>(${fieldArrayLength})${fieldArrayLength ? ".fill(false)" : ""}`);
45
+ break;
46
+ }
47
+ }
48
+ break;
49
+ case FieldType.SET:
50
+ output.push(` obj.${fieldName} = new Set<${getName(fieldArrayType)}>()`);
51
+ break;
52
+ default: {
53
+ output.push(` obj.${fieldName} = create${capitalize(fieldType)}()`);
54
+ }
55
+ }
56
+ }
57
+ output.push(" return obj");
58
+ output.push("}");
59
+ }
60
+ function addStructZeroFunction(name, fields, output) {
61
+ output.push("");
62
+ output.push(`/** Zero the given ${capitalize(name)} object. */`);
63
+ output.push(`export function zero${capitalize(name)}(obj: ${capitalize(name)}) {`);
64
+ for (const field of fields) {
65
+ const [fieldName, fieldType, fieldArrayType, fieldArrayLength] = field.split(" ");
66
+ switch (fieldType) {
67
+ case FieldType.STRING:
68
+ output.push(` obj.${fieldName} = ""`);
69
+ break;
70
+ case FieldType.NUMBER:
71
+ output.push(` obj.${fieldName} = 0`);
72
+ break;
73
+ case FieldType.BOOLEAN:
74
+ output.push(` obj.${fieldName} = false`);
75
+ break;
76
+ case FieldType.ARRAY:
77
+ {
78
+ switch (fieldArrayType) {
79
+ case ArrayType.STRING:
80
+ output.push(` obj.${fieldName}.${fieldArrayLength ? 'fill("")' : "length = 0"}`);
81
+ break;
82
+ case ArrayType.NUMBER:
83
+ output.push(` obj.${fieldName}.${fieldArrayLength ? "fill(0)" : "length = 0"}`);
84
+ break;
85
+ case ArrayType.BOOLEAN:
86
+ output.push(` obj.${fieldName}.${fieldArrayLength ? "fill(false)" : "length = 0"}`);
87
+ break;
88
+ }
89
+ }
90
+ break;
91
+ case FieldType.SET:
92
+ output.push(` obj.${fieldName}.clear()`);
93
+ break;
94
+ default:
95
+ output.push(` zero${capitalize(fieldType)}(obj.${fieldName})`);
96
+ }
97
+ }
98
+ output.push("}");
99
+ }
@@ -0,0 +1,34 @@
1
+ import { FieldType, Type } from "../consts.js";
2
+ /**
3
+ * Get the name based on the type of the data structure.
4
+ */
5
+ export function getName(type, arrayType = "") {
6
+ switch (type) {
7
+ case Type.SOA:
8
+ return "structure of arrays";
9
+ case Type.AOS:
10
+ return "array of structures";
11
+ case Type.STRUCT:
12
+ return "struct";
13
+ case Type.GROUP:
14
+ return "group";
15
+ case FieldType.STRING:
16
+ return "string";
17
+ case FieldType.NUMBER:
18
+ return "number";
19
+ case FieldType.BOOLEAN:
20
+ return "boolean";
21
+ case FieldType.ARRAY:
22
+ return `Array<${getName(arrayType)}>`;
23
+ case FieldType.SET:
24
+ return `Set<${getName(arrayType)}>`;
25
+ default:
26
+ return capitalize(type);
27
+ }
28
+ }
29
+ /**
30
+ * Capitalize the first letter of a string.
31
+ */
32
+ export function capitalize(str) {
33
+ return `${str.substring(0, 1).toUpperCase()}${str.substring(1)}`;
34
+ }
package/dist/main.js CHANGED
@@ -1,6 +1,45 @@
1
1
  #!/usr/bin/env node
2
- import S from"fs";function l(i){switch(i){case"soa":return"structure of arrays";case"aos":return"array of structures";case"struct":return"struct";case"group":return"group";default:return"???"}}function c(i){return`${i.substring(0,1).toUpperCase()}${i.substring(1)}`}function h(i,n,r){let[e,s,a,t]=i.split(" "),o=n||t||"";switch(s){case"string":r.push(`export let ${e} = ""`);break;case"number":r.push(`export let ${e} = 0`);break;case"boolean":r.push(`export let ${e} = false`);break;case"array":switch(a){case"string":r.push(`export const ${e} = new Array<string>(${o})${o?'.fill("")':""}`);break;case"number":r.push(`export const ${e} = new Array<number>(${o})${o?".fill(0)":""}`);break;case"boolean":r.push(`export const ${e} = new Array<boolean>(${o})${o?".fill(false)":""}`);break}break}}function d(i,n,r,e){let[s,a]=r.split(" ");switch(a){case"string":case"number":case"boolean":e.push(""),e.push(`/** Set the value of the ${s} field within the ${i} ${l(n)}. */`),e.push(`export function set${c(s)}(value: ${a}) {`),e.push(` ${s} = value`),e.push("}");break}}function p(i,n,r,e,s){let[a,t,o,A]=r.split(" "),b=e||A||"";s.push(""),s.push(`/** Zero the ${a} field within the ${i} ${l(n)}. */`),s.push(`export function zero${c(a)}() {`),N(a,t,o,b,s),s.push("}")}function $(i,n,r,e,s){s.push(""),s.push(`/** Zero all fields within the ${i} ${l(n)}. */`),s.push(`export function zero${c(i)}Data() {`);for(let a of r){let[t,o,A,b]=a.split(" ");N(t,o,A,e||b||"",s)}s.push("}")}function N(i,n,r,e,s){switch(n){case"string":s.push(` ${i} = ""`);break;case"number":s.push(` ${i} = 0`);break;case"boolean":s.push(` ${i} = false`);break;case"array":switch(r){case"string":s.push(` ${i}.${e?'fill("")':"length = 0"}`);break;case"number":s.push(` ${i}.${e?"fill(0)":"length = 0"}`);break;case"boolean":s.push(` ${i}.${e?"fill(false)":"length = 0"}`);break}break}}function g(i,n,r){r.push(`export const MAX_${i.toUpperCase()}_COUNT = ${n}`),r.push("")}function m(i,n,r){let[e,s,a]=i.split(" ");g(e,a,r);for(let t of n)h(t,a,r);for(let t of n)d(e,s,t,r);F(e,s,n,r);for(let t of n)p(e,s,t,a,r);$(e,s,n,a,r)}function F(i,n,r,e){e.push(""),e.push(`/** Zero an index within the ${i} ${l(n)}. */`),e.push(`export function zero${c(i)}(idx: number) {`);for(let s of r){let[a,t,o]=s.split(" ");switch(o){case"string":e.push(` ${a}[idx] = ""`);break;case"number":e.push(` ${a}[idx] = 0`);break;case"boolean":e.push(` ${a}[idx] = false`);break}}e.push("}")}function O(i,n,r){let[e,s,a]=i.split(" ");for(let t of n)h(t,a,r);for(let t of n)d(e,s,t,r);for(let t of n)p(e,s,t,a,r);$(e,s,n,a,r)}function R(i,n,r){let[e]=i.split(" ");w(e,n,r),E(e,n,r),B(e,n,r)}function w(i,n,r){r.push(`export type ${c(i)} = {`);for(let e of n){let[s,a,t]=e.split(" ");switch(a){case"string":r.push(` ${s}: string`);break;case"number":r.push(` ${s}: number`);break;case"boolean":r.push(` ${s}: boolean`);break;case"array":r.push(` ${s}: Array<${t}>`);break;default:r.push(` ${s}: ${c(a)}`)}}r.push("}")}function E(i,n,r){r.push(""),r.push(`/** Create a new ${c(i)} object. */`),r.push(`export function create${c(i)}(): ${c(i)} {`),r.push(" const obj = Object.create(null)");for(let e of n){let[s,a,t,o=""]=e.split(" ");switch(a){case"string":r.push(` obj.${s} = ""`);break;case"number":r.push(` obj.${s} = 0`);break;case"boolean":r.push(` obj.${s} = false`);break;case"array":switch(t){case"string":r.push(` obj.${s} = new Array<string>(${o})${o?'.fill("")':""}`);break;case"number":r.push(` obj.${s} = new Array<number>(${o})${o?".fill(0)":""}`);break;case"boolean":r.push(` obj.${s} = new Array<boolean>(${o})${o?".fill(false)":""}`);break}break;default:r.push(` obj.${s} = create${c(a)}()`)}}r.push(" return obj"),r.push("}")}function B(i,n,r){r.push(""),r.push(`/** Zero the given ${c(i)} object. */`),r.push(`export function zero${c(i)}(obj: ${c(i)}) {`);for(let e of n){let[s,a,t,o]=e.split(" ");switch(a){case"string":r.push(` obj.${s} = ""`);break;case"number":r.push(` obj.${s} = 0`);break;case"boolean":r.push(` obj.${s} = false`);break;case"array":switch(t){case"string":r.push(` obj.${s}.${o?'fill("")':"length = 0"}`);break;case"number":r.push(` obj.${s}.${o?"fill(0)":"length = 0"}`);break;case"boolean":r.push(` obj.${s}.${o?"fill(false)":"length = 0"}`);break}break;default:r.push(` zero${c(a)}(obj.${s})`)}}r.push("}")}function k(i,n){let[r,,e,s]=i.split(" ");g(r,e,n),L(r,s,e,n),j(r,s,e,n)}function L(i,n,r,e){e.push(`/** An array of ${c(n)} objects (structures). */`),e.push(`export const ${i} = new Array<${c(n)}>(${r})`),e.push(`for (let i=0; i<${r}; i++) {`),e.push(` ${i}[i] = create${c(n)}()`),e.push("}")}function j(i,n,r,e){e.push(""),e.push(`/** Zero all objects within the ${i} array of structures. */`),e.push(`export function zero${c(i)}() {`),e.push(` for (let i=0; i<${r}; i++) {`),e.push(` zero${c(n)}(${i}[i])`),e.push(" }"),e.push("}")}var x=process.argv[2],U=process.argv[3]||`${x}.ts`,G=S.readFileSync(x,"utf-8"),f=[];f.push("/*");f.push(` * Generated with game-data-gen on ${new Date().toLocaleString()}. DO NOT MODIFY THIS FILE!`);f.push(" */");var M=G.trim().split(`
3
-
4
- `);for(let i of M){let n=i.split(`
5
- `),r=n.shift();if(!r)continue;let[e,s]=r.split(" ");switch(f.push(""),f.push("/*"),f.push(` * ${"-".repeat(50)}`),f.push(` * ${e} (${l(s)})`),f.push(` * ${"-".repeat(50)}`),f.push(" */"),f.push(""),s){case"struct":R(r,n,f);break;case"group":O(r,n,f);break;case"soa":m(r,n,f);break;case"aos":k(r,f);break}}S.writeFileSync(U,f.join(`
6
- `));
2
+ import fs from "node:fs";
3
+ import { Type } from "./consts.js";
4
+ import { addArrayOfStructures } from "./lib/aos.js";
5
+ import { addGroup } from "./lib/group.js";
6
+ import { addStructureOfArrays } from "./lib/soa.js";
7
+ import { addStruct } from "./lib/struct.js";
8
+ import { getName } from "./lib/utils.js";
9
+ const inputFile = process.argv[2];
10
+ const outputFile = process.argv[3] || `${inputFile}.ts`;
11
+ const input = fs.readFileSync(inputFile, "utf-8");
12
+ const output = [];
13
+ output.push("/*");
14
+ output.push(` * Generated with game-data-gen on ${new Date().toLocaleString()}. DO NOT MODIFY THIS FILE!`);
15
+ output.push(" */");
16
+ const blocks = input.trim().split("\n\n");
17
+ for (const block of blocks) {
18
+ const fields = block.split("\n");
19
+ const header = fields.shift();
20
+ if (!header)
21
+ continue;
22
+ const [name, type] = header.split(" ");
23
+ output.push("");
24
+ output.push("/*");
25
+ output.push(` * ${"-".repeat(50)}`);
26
+ output.push(` * ${name} (${getName(type)})`);
27
+ output.push(` * ${"-".repeat(50)}`);
28
+ output.push(" */");
29
+ output.push("");
30
+ switch (type) {
31
+ case Type.STRUCT:
32
+ addStruct(header, fields, output);
33
+ break;
34
+ case Type.GROUP:
35
+ addGroup(header, fields, output);
36
+ break;
37
+ case Type.SOA:
38
+ addStructureOfArrays(header, fields, output);
39
+ break;
40
+ case Type.AOS:
41
+ addArrayOfStructures(header, output);
42
+ break;
43
+ }
44
+ }
45
+ fs.writeFileSync(outputFile, output.join("\n"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "game-data-gen",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -9,19 +9,16 @@
9
9
  "game-data-gen": "dist/main.js"
10
10
  },
11
11
  "scripts": {
12
- "start": "onchange --initial 'src/**/*.ts' 'tests/*' -- tsx src/main.ts tests/data",
13
- "build": "tsc && esbuild src/main.ts --bundle --minify --platform=node --format=esm --target=es6 --outdir=dist --banner:js='#!/usr/bin/env node'",
14
- "test": "npm run build && npx game-data-gen tests/data"
12
+ "start": "tsc && node dist/main.js tests/data",
13
+ "build": "biome check && tsc"
15
14
  },
16
15
  "repository": {
17
16
  "type": "git",
18
17
  "url": "git+https://github.com/patrickswijgman/game-data-gen.git"
19
18
  },
20
19
  "devDependencies": {
20
+ "@biomejs/biome": "^2.4.11",
21
21
  "@types/node": "^24.12.2",
22
- "esbuild": "^0.28.0",
23
- "onchange": "^7.1.0",
24
- "tsx": "^4.21.0",
25
22
  "typescript": "^6.0.2"
26
23
  }
27
24
  }