game-data-gen 1.1.0 → 1.2.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.
Files changed (3) hide show
  1. package/README.md +3 -1
  2. package/dist/main.js +43 -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
@@ -30,6 +30,15 @@ for (const block of blocks) {
30
30
  const [fieldName, fieldType, fieldArrayType, fieldLength] = field.split(" ");
31
31
  const length = baseLength || fieldLength || "";
32
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;
33
42
  case "array" /* ARRAY */:
34
43
  {
35
44
  switch (fieldArrayType) {
@@ -73,13 +82,36 @@ for (const block of blocks) {
73
82
  break;
74
83
  }
75
84
  }
85
+ for (const field of fields) {
86
+ const [fieldName, fieldType] = field.split(" ");
87
+ switch (fieldType) {
88
+ case "string" /* STRING */:
89
+ case "boolean" /* BOOLEAN */:
90
+ case "number" /* NUMBER */:
91
+ output.push("");
92
+ output.push(`/** Set the value of the ${fieldName} field within the ${name} ${getTypeName(type)}. */`);
93
+ output.push(`export function set${capitalize(fieldName)}(value: ${fieldType}) {`);
94
+ output.push(` ${fieldName} = value`);
95
+ output.push("}");
96
+ break;
97
+ }
98
+ }
76
99
  if (type === "soa" /* SOA */) {
77
100
  output.push("");
78
101
  output.push(`/** Zero an index within the ${name} ${getTypeName(type)}. */`);
79
102
  output.push(`export function zero${capitalize(name)}(idx: number) {`);
80
103
  for (const field of fields) {
81
- const [fieldName, fieldType, fieldArrayType] = field.split(" ");
82
- zeroIndex(fieldName, fieldType, fieldArrayType, "idx");
104
+ const [fieldName, _, fieldArrayType] = field.split(" ");
105
+ switch (fieldArrayType) {
106
+ case "string" /* STRING */:
107
+ output.push(` ${fieldName}[idx] = ""`);
108
+ break;
109
+ case "boolean" /* BOOLEAN */:
110
+ output.push(` ${fieldName}[idx] = false`);
111
+ break;
112
+ default:
113
+ output.push(` ${fieldName}[idx] = 0`);
114
+ }
83
115
  }
84
116
  output.push("}");
85
117
  }
@@ -102,26 +134,17 @@ for (const block of blocks) {
102
134
  }
103
135
  output.push("}");
104
136
  }
105
- function zeroIndex(name, type, arrayType, variableName) {
106
- switch (type) {
107
- case "array" /* ARRAY */:
108
- {
109
- switch (arrayType) {
110
- case "string" /* STRING */:
111
- output.push(` ${name}[${variableName}] = ""`);
112
- break;
113
- case "boolean" /* BOOLEAN */:
114
- output.push(` ${name}[${variableName}] = false`);
115
- break;
116
- default:
117
- output.push(` ${name}[${variableName}] = 0`);
118
- }
119
- }
120
- break;
121
- }
122
- }
123
137
  function zeroField(name, type, arrayType, length) {
124
138
  switch (type) {
139
+ case "string" /* STRING */:
140
+ output.push(` ${name} = ""`);
141
+ break;
142
+ case "boolean" /* BOOLEAN */:
143
+ output.push(` ${name} = false`);
144
+ break;
145
+ case "number" /* NUMBER */:
146
+ output.push(` ${name} = 0`);
147
+ break;
125
148
  case "array" /* ARRAY */:
126
149
  {
127
150
  switch (arrayType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "game-data-gen",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
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",