game-data-gen 1.0.3 → 1.2.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.
Files changed (3) hide show
  1. package/README.md +3 -1
  2. package/dist/main.js +33 -20
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -100,7 +100,7 @@ activeEntities array number
100
100
 
101
101
  Entity soa 2048
102
102
  posX array float32
103
- posy array float32
103
+ posY array float32
104
104
  isActive array uint8
105
105
  ```
106
106
 
@@ -137,6 +137,8 @@ export function zeroGameData() {
137
137
  * --------------------------------------------------
138
138
  */
139
139
 
140
+ export const MAX_ENTITY_COUNT = 2048;
141
+
140
142
  export const posX = new Float32Array(2048);
141
143
  export const posY = new Float32Array(2048);
142
144
  export const isActive = new Uint8Array(2048);
package/dist/main.js CHANGED
@@ -22,10 +22,23 @@ for (const block of blocks) {
22
22
  output.push(` * ${"-".repeat(50)}`);
23
23
  output.push(" */");
24
24
  output.push("");
25
+ if (type === "soa" /* SOA */) {
26
+ output.push(`export const MAX_${name.toUpperCase()}_COUNT = ${baseLength}`);
27
+ output.push("");
28
+ }
25
29
  for (const field of fields) {
26
30
  const [fieldName, fieldType, fieldArrayType, fieldLength] = field.split(" ");
27
31
  const length = baseLength || fieldLength || "";
28
32
  switch (fieldType) {
33
+ case "string" /* STRING */:
34
+ output.push(`export let ${fieldName} = ""`);
35
+ break;
36
+ case "boolean" /* BOOLEAN */:
37
+ output.push(`export let ${fieldName} = false`);
38
+ break;
39
+ case "number" /* NUMBER */:
40
+ output.push(`export let ${fieldName} = 0`);
41
+ break;
29
42
  case "array" /* ARRAY */:
30
43
  {
31
44
  switch (fieldArrayType) {
@@ -74,8 +87,17 @@ for (const block of blocks) {
74
87
  output.push(`/** Zero an index within the ${name} ${getTypeName(type)}. */`);
75
88
  output.push(`export function zero${capitalize(name)}(idx: number) {`);
76
89
  for (const field of fields) {
77
- const [fieldName, fieldType, fieldArrayType] = field.split(" ");
78
- zeroIndex(fieldName, fieldType, fieldArrayType, "idx");
90
+ const [fieldName, _, fieldArrayType] = field.split(" ");
91
+ switch (fieldArrayType) {
92
+ case "string" /* STRING */:
93
+ output.push(` ${fieldName}[idx] = ""`);
94
+ break;
95
+ case "boolean" /* BOOLEAN */:
96
+ output.push(` ${fieldName}[idx] = false`);
97
+ break;
98
+ default:
99
+ output.push(` ${fieldName}[idx] = 0`);
100
+ }
79
101
  }
80
102
  output.push("}");
81
103
  }
@@ -98,26 +120,17 @@ for (const block of blocks) {
98
120
  }
99
121
  output.push("}");
100
122
  }
101
- function zeroIndex(name, type, arrayType, variableName) {
102
- switch (type) {
103
- case "array" /* ARRAY */:
104
- {
105
- switch (arrayType) {
106
- case "string" /* STRING */:
107
- output.push(` ${name}[${variableName}] = ""`);
108
- break;
109
- case "boolean" /* BOOLEAN */:
110
- output.push(` ${name}[${variableName}] = false`);
111
- break;
112
- default:
113
- output.push(` ${name}[${variableName}] = 0`);
114
- }
115
- }
116
- break;
117
- }
118
- }
119
123
  function zeroField(name, type, arrayType, length) {
120
124
  switch (type) {
125
+ case "string" /* STRING */:
126
+ output.push(` ${name} = ""`);
127
+ break;
128
+ case "boolean" /* BOOLEAN */:
129
+ output.push(` ${name} = false`);
130
+ break;
131
+ case "number" /* NUMBER */:
132
+ output.push(` ${name} = 0`);
133
+ break;
121
134
  case "array" /* ARRAY */:
122
135
  {
123
136
  switch (arrayType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "game-data-gen",
3
- "version": "1.0.3",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -9,7 +9,7 @@
9
9
  "scripts": {
10
10
  "start": "tsx watch src/main.ts tests/data",
11
11
  "build": "tsc && esbuild src/main.ts --bundle --platform=node --format=esm --target=es6 --outdir=dist --banner:js='#!/usr/bin/env node'",
12
- "test": "npx game-data-gen src/tests/data"
12
+ "test": "npm run build && npx game-data-gen tests/data"
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",