game-data-gen 2.3.0 → 3.0.1
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 +45 -38
- package/dist/lib/aos.js +2 -2
- package/dist/lib/group.js +2 -2
- package/dist/lib/soa.js +5 -5
- package/dist/main.js +10 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ If you're making a game in Javascript then you might (this was actually me):
|
|
|
16
16
|
|
|
17
17
|
This library:
|
|
18
18
|
|
|
19
|
-
- creates data structures based on
|
|
19
|
+
- creates data structures based on Markdown file (see example below)
|
|
20
20
|
- each data structure gets associated functions to zero out its memory so it can be reused
|
|
21
21
|
|
|
22
22
|
## Installation
|
|
@@ -33,41 +33,48 @@ npx game-data-gen <input-file-path> <optional-output-file-path>
|
|
|
33
33
|
|
|
34
34
|
## Example
|
|
35
35
|
|
|
36
|
-
Create a
|
|
36
|
+
Create a Markdown file somewhere in your source code (without a file extension).
|
|
37
37
|
|
|
38
|
-
For example `src/data
|
|
38
|
+
For example `src/data.md`:
|
|
39
39
|
|
|
40
|
-
```
|
|
41
|
-
game group
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
40
|
+
```md
|
|
41
|
+
# game group
|
|
42
|
+
|
|
43
|
+
- activeEntities array entity
|
|
44
|
+
- activeEntityIds array number
|
|
45
|
+
- playerId number
|
|
46
|
+
|
|
47
|
+
# vector struct
|
|
48
|
+
|
|
49
|
+
- x number
|
|
50
|
+
- y number
|
|
51
|
+
|
|
52
|
+
# entity struct
|
|
53
|
+
|
|
54
|
+
- position vector
|
|
55
|
+
- velocity vector
|
|
56
|
+
<!-- stats -->
|
|
57
|
+
- health number
|
|
58
|
+
<!-- inventory -->
|
|
59
|
+
- items array number
|
|
60
|
+
<!-- flags -->
|
|
61
|
+
- isActive boolean
|
|
62
|
+
|
|
63
|
+
# entities aos 2048 entity
|
|
64
|
+
|
|
65
|
+
# particle soa 10_000
|
|
66
|
+
|
|
67
|
+
- type string
|
|
68
|
+
- pos Vector
|
|
62
69
|
```
|
|
63
70
|
|
|
64
71
|
Run the package with (consider making this a script in your package.json):
|
|
65
72
|
|
|
66
73
|
```shell
|
|
67
|
-
npx game-data-gen src/data
|
|
74
|
+
npx game-data-gen src/data.md
|
|
68
75
|
```
|
|
69
76
|
|
|
70
|
-
This will create or update the `src/data
|
|
77
|
+
This will create or update the `src/data.ts` file (see below). The data and functions can then be imported from this file into your code.
|
|
71
78
|
|
|
72
79
|
```typescript
|
|
73
80
|
/*
|
|
@@ -81,18 +88,18 @@ export let activeEntityIds = new Array<number>()
|
|
|
81
88
|
export let playerId = 0
|
|
82
89
|
|
|
83
90
|
/** Set the value of the activeEntities field within the game group. */
|
|
84
|
-
export function setActiveEntities(
|
|
85
|
-
activeEntities =
|
|
91
|
+
export function setActiveEntities(v: Array<Entity>) {
|
|
92
|
+
activeEntities = v
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
/** Set the value of the activeEntityIds field within the game group. */
|
|
89
|
-
export function setActiveEntityIds(
|
|
90
|
-
activeEntityIds =
|
|
96
|
+
export function setActiveEntityIds(v: Array<number>) {
|
|
97
|
+
activeEntityIds = v
|
|
91
98
|
}
|
|
92
99
|
|
|
93
100
|
/** Set the value of the playerId field within the game group. */
|
|
94
|
-
export function setPlayerId(
|
|
95
|
-
playerId =
|
|
101
|
+
export function setPlayerId(v: number) {
|
|
102
|
+
playerId = v
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
/** Zero the activeEntities field within the game group. */
|
|
@@ -224,8 +231,8 @@ export function zeroEntities() {
|
|
|
224
231
|
}
|
|
225
232
|
|
|
226
233
|
/** Zero an object at a specific index within the entities array of structures. */
|
|
227
|
-
export function zeroEntitiesAt(
|
|
228
|
-
zeroEntity(entities[
|
|
234
|
+
export function zeroEntitiesAt(i: number) {
|
|
235
|
+
zeroEntity(entities[i])
|
|
229
236
|
}
|
|
230
237
|
|
|
231
238
|
/*
|
|
@@ -240,9 +247,9 @@ export const type = new Array(10_000).fill("")
|
|
|
240
247
|
export const pos = Array.from({ length: 10_000 }, createVector)
|
|
241
248
|
|
|
242
249
|
/** Zero an index within the particle structure of arrays. */
|
|
243
|
-
export function zeroParticle(
|
|
244
|
-
type[
|
|
245
|
-
zeroVector(pos[
|
|
250
|
+
export function zeroParticle(i: number) {
|
|
251
|
+
type[i] = ""
|
|
252
|
+
zeroVector(pos[i])
|
|
246
253
|
}
|
|
247
254
|
|
|
248
255
|
/** Zero the type field within the particle structure of arrays. */
|
package/dist/lib/aos.js
CHANGED
|
@@ -27,7 +27,7 @@ function addArrayOfStructuresZeroFunction(name, type, length, output) {
|
|
|
27
27
|
function addArrayOfStructuresZeroAtIndexFunction(name, type, output) {
|
|
28
28
|
output.push("");
|
|
29
29
|
output.push(`/** Zero an object at a specific index within the ${name} array of structures. */`);
|
|
30
|
-
output.push(`export function zero${capitalize(name)}At(
|
|
31
|
-
output.push(` zero${capitalize(type)}(${name}[
|
|
30
|
+
output.push(`export function zero${capitalize(name)}At(i: number) {`);
|
|
31
|
+
output.push(` zero${capitalize(type)}(${name}[i])`);
|
|
32
32
|
output.push("}");
|
|
33
33
|
}
|
package/dist/lib/group.js
CHANGED
|
@@ -37,8 +37,8 @@ function addFieldSetFunction(name, field, output) {
|
|
|
37
37
|
const [fieldName, fieldType, fieldArrayType] = field.split(" ");
|
|
38
38
|
output.push("");
|
|
39
39
|
output.push(`/** Set the value of the ${fieldName} field within the ${name} group. */`);
|
|
40
|
-
output.push(`export function set${capitalize(fieldName)}(
|
|
41
|
-
output.push(` ${fieldName} =
|
|
40
|
+
output.push(`export function set${capitalize(fieldName)}(v: ${getTypeName(fieldType, fieldArrayType)}) {`);
|
|
41
|
+
output.push(` ${fieldName} = v`);
|
|
42
42
|
output.push("}");
|
|
43
43
|
}
|
|
44
44
|
function addFieldZeroFunction(name, field, output) {
|
package/dist/lib/soa.js
CHANGED
|
@@ -69,21 +69,21 @@ function zeroField(name, type, output) {
|
|
|
69
69
|
function addFieldZeroAtIndexFunction(name, fields, output) {
|
|
70
70
|
output.push("");
|
|
71
71
|
output.push(`/** Zero an index within the ${name} structure of arrays. */`);
|
|
72
|
-
output.push(`export function zero${capitalize(name)}(
|
|
72
|
+
output.push(`export function zero${capitalize(name)}(i: number) {`);
|
|
73
73
|
for (const field of fields) {
|
|
74
74
|
const [fieldName, fieldType] = field.split(" ");
|
|
75
75
|
switch (fieldType) {
|
|
76
76
|
case ArrayType.STRING:
|
|
77
|
-
output.push(` ${fieldName}[
|
|
77
|
+
output.push(` ${fieldName}[i] = ""`);
|
|
78
78
|
break;
|
|
79
79
|
case ArrayType.NUMBER:
|
|
80
|
-
output.push(` ${fieldName}[
|
|
80
|
+
output.push(` ${fieldName}[i] = 0`);
|
|
81
81
|
break;
|
|
82
82
|
case ArrayType.BOOLEAN:
|
|
83
|
-
output.push(` ${fieldName}[
|
|
83
|
+
output.push(` ${fieldName}[i] = false`);
|
|
84
84
|
break;
|
|
85
85
|
default:
|
|
86
|
-
output.push(` zero${capitalize(fieldType)}(${fieldName}[
|
|
86
|
+
output.push(` zero${capitalize(fieldType)}(${fieldName}[i])`);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
output.push("}");
|
package/dist/main.js
CHANGED
|
@@ -6,13 +6,21 @@ import { addGroup } from "./lib/group.js";
|
|
|
6
6
|
import { addStructureOfArrays } from "./lib/soa.js";
|
|
7
7
|
import { addStruct } from "./lib/struct.js";
|
|
8
8
|
const inputFile = process.argv[2];
|
|
9
|
-
const outputFile = process.argv[3] || `${inputFile}.ts`;
|
|
9
|
+
const outputFile = process.argv[3] || `${inputFile.replace(/\.md$/, "")}.ts`;
|
|
10
10
|
const input = fs.readFileSync(inputFile, "utf-8");
|
|
11
11
|
const output = [];
|
|
12
12
|
output.push("/*");
|
|
13
13
|
output.push(` * Generated with game-data-gen on ${new Date().toLocaleString()}. DO NOT MODIFY THIS FILE!`);
|
|
14
14
|
output.push(" */");
|
|
15
|
-
const blocks = input
|
|
15
|
+
const blocks = input
|
|
16
|
+
.replace(/^# (.+)\n\n- /gm, "$1\n")
|
|
17
|
+
.replace(/^# /gm, "")
|
|
18
|
+
.replace(/^- /gm, "")
|
|
19
|
+
.split("\n")
|
|
20
|
+
.filter((line) => !line.startsWith("<!--"))
|
|
21
|
+
.join("\n")
|
|
22
|
+
.trim()
|
|
23
|
+
.split("\n\n");
|
|
16
24
|
for (const block of blocks) {
|
|
17
25
|
const fields = block.split("\n");
|
|
18
26
|
const header = fields.shift();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "game-data-gen",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"game-data-gen": "dist/main.js"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
-
"start": "tsc && node dist/main.js tests/data",
|
|
12
|
+
"start": "tsc && node dist/main.js tests/data.md",
|
|
13
13
|
"build": "biome check && tsc"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|