game-data-gen 2.3.0 → 3.0.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
@@ -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 a very easy syntax (I tried JSON, didn't feel it)
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,44 @@ npx game-data-gen <input-file-path> <optional-output-file-path>
33
33
 
34
34
  ## Example
35
35
 
36
- Create a plain text file somewhere in your source code (without a file extension).
36
+ Create a Markdown file somewhere in your source code (without a file extension).
37
37
 
38
- For example `src/data/game`:
38
+ For example `src/data.md`:
39
39
 
40
- ```
41
- game group
42
- activeEntities array entity
43
- activeEntityIds array number
44
- playerId number
45
-
46
- vector struct
47
- x number
48
- y number
49
-
50
- entity struct
51
- position vector
52
- velocity vector
53
- health number
54
- items array number
55
- isActive boolean
56
-
57
- entities aos 2048 entity
58
-
59
- particle soa 10_000
60
- type string
61
- pos Vector
40
+ ```md
41
+ # game group
42
+ - activeEntities array entity
43
+ - activeEntityIds array number
44
+ - playerId number
45
+
46
+ # vector struct
47
+ - x number
48
+ - y number
49
+
50
+ # entity struct
51
+ - position vector
52
+ - velocity vector
53
+ <!-- stats -->
54
+ - health number
55
+ <!-- inventory -->
56
+ - items array number
57
+ <!-- flags -->
58
+ - isActive boolean
59
+
60
+ # entities aos 2048 entity
61
+
62
+ # particle soa 10_000
63
+ - type string
64
+ - pos Vector
62
65
  ```
63
66
 
64
67
  Run the package with (consider making this a script in your package.json):
65
68
 
66
69
  ```shell
67
- npx game-data-gen src/data/game
70
+ npx game-data-gen src/data.md
68
71
  ```
69
72
 
70
- 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.
73
+ 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
74
 
72
75
  ```typescript
73
76
  /*
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(index: number) {`);
31
- output.push(` zero${capitalize(type)}(${name}[index])`);
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)}(value: ${getTypeName(fieldType, fieldArrayType)}) {`);
41
- output.push(` ${fieldName} = value`);
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)}(idx: number) {`);
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}[idx] = ""`);
77
+ output.push(` ${fieldName}[i] = ""`);
78
78
  break;
79
79
  case ArrayType.NUMBER:
80
- output.push(` ${fieldName}[idx] = 0`);
80
+ output.push(` ${fieldName}[i] = 0`);
81
81
  break;
82
82
  case ArrayType.BOOLEAN:
83
- output.push(` ${fieldName}[idx] = false`);
83
+ output.push(` ${fieldName}[i] = false`);
84
84
  break;
85
85
  default:
86
- output.push(` zero${capitalize(fieldType)}(${fieldName}[idx])`);
86
+ output.push(` zero${capitalize(fieldType)}(${fieldName}[i])`);
87
87
  }
88
88
  }
89
89
  output.push("}");
package/dist/main.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ var _a;
2
3
  import fs from "node:fs";
3
4
  import { Type } from "./consts.js";
4
5
  import { addArrayOfStructures } from "./lib/aos.js";
@@ -6,18 +7,24 @@ import { addGroup } from "./lib/group.js";
6
7
  import { addStructureOfArrays } from "./lib/soa.js";
7
8
  import { addStruct } from "./lib/struct.js";
8
9
  const inputFile = process.argv[2];
9
- const outputFile = process.argv[3] || `${inputFile}.ts`;
10
+ const outputFile = process.argv[3] || `${inputFile.replace(/\.md$/, "")}.ts`;
10
11
  const input = fs.readFileSync(inputFile, "utf-8");
11
12
  const output = [];
12
13
  output.push("/*");
13
14
  output.push(` * Generated with game-data-gen on ${new Date().toLocaleString()}. DO NOT MODIFY THIS FILE!`);
14
15
  output.push(" */");
15
- const blocks = input.trim().split("\n\n");
16
+ const blocks = input
17
+ .split("\n")
18
+ .filter((line) => !line.startsWith("<!--"))
19
+ .join("\n")
20
+ .trim()
21
+ .split("\n\n");
16
22
  for (const block of blocks) {
17
- const fields = block.split("\n");
18
- const header = fields.shift();
23
+ const lines = block.split("\n");
24
+ const header = (_a = lines.shift()) === null || _a === void 0 ? void 0 : _a.replace(/^#\s*/, "");
19
25
  if (!header)
20
26
  continue;
27
+ const fields = lines.map((line) => line.replace(/^-\s*/, ""));
21
28
  const [_, type] = header.split(" ");
22
29
  switch (type) {
23
30
  case Type.STRUCT:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "game-data-gen",
3
- "version": "2.3.0",
3
+ "version": "3.0.0",
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": {