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 +8 -6
- package/dist/consts.js +21 -0
- package/dist/lib/aos.js +32 -0
- package/dist/lib/fields.js +102 -0
- package/dist/lib/group.js +14 -0
- package/dist/lib/soa.js +38 -0
- package/dist/lib/struct.js +99 -0
- package/dist/lib/utils.js +34 -0
- package/dist/main.js +44 -5
- package/package.json +4 -7
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`
|
|
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` (
|
|
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
|
|
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 = {}));
|
package/dist/lib/aos.js
ADDED
|
@@ -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
|
+
}
|
package/dist/lib/soa.js
ADDED
|
@@ -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
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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.
|
|
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": "
|
|
13
|
-
"build": "
|
|
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
|
}
|