@pkmn/engine 0.1.0-dev.1da0f17c → 0.1.0-dev.207fa86a

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pkmn/engine",
3
- "version": "0.1.0-dev.1da0f17c",
3
+ "version": "0.1.0-dev.207fa86a",
4
4
  "description": "A minimal, complete, Pokémon battle simulation engine optimized for performance",
5
5
  "repository": "github:pkmn/engine",
6
6
  "license": "MIT",
@@ -9,96 +9,85 @@
9
9
  "types": "build/pkg/index.d.ts",
10
10
  "files": [
11
11
  "build.zig",
12
- "build/pkg/data.d.ts",
13
- "build/pkg/data.js.map",
14
- "build/pkg/addon.d.ts",
15
- "build/pkg/addon.js.map",
16
- "build/pkg/addon.js",
17
- "build/pkg/data.js",
18
- "build/pkg/data/ids.json",
19
- "build/pkg/data/layout.json",
20
- "build/pkg/data/protocol.json",
21
- "build/pkg/gen1.d.ts",
22
- "build/pkg/gen1.js.map",
23
- "build/pkg/gen1.js",
24
- "build/pkg/index.d.ts",
25
- "build/pkg/index.js.map",
26
- "build/pkg/index.js",
27
- "build/pkg/protocol.d.ts",
28
- "build/pkg/protocol.js.map",
29
- "build/pkg/protocol.js",
30
- "build/test/display.js.map",
31
- "build/test/display.js",
32
- "build/tools/debug.js.map",
33
- "build/tools/debug.js",
34
12
  "src/bin/install-pkmn-engine",
35
13
  "src/lib/binding/node.zig",
36
14
  "src/lib/binding/wasm.zig",
37
15
  "src/lib/common/data.zig",
38
- "src/lib/common/debug.zig",
39
16
  "src/lib/common/options.zig",
40
17
  "src/lib/common/protocol.zig",
41
18
  "src/lib/common/rng.zig",
42
- "src/lib/gen1/data.zig",
43
19
  "src/lib/gen1/data/moves.zig",
44
20
  "src/lib/gen1/data/species.zig",
45
21
  "src/lib/gen1/data/types.zig",
22
+ "src/lib/gen1/data.zig",
46
23
  "src/lib/gen1/helpers.zig",
47
24
  "src/lib/gen1/mechanics.zig",
48
- "src/lib/gen2/data.zig",
49
25
  "src/lib/gen2/data/items.zig",
50
26
  "src/lib/gen2/data/moves.zig",
51
27
  "src/lib/gen2/data/species.zig",
52
28
  "src/lib/gen2/data/types.zig",
29
+ "src/lib/gen2/data.zig",
53
30
  "src/lib/gen2/helpers.zig",
54
31
  "src/lib/gen2/mechanics.zig",
55
32
  "src/lib/pkmn.zig",
56
- "src/test/display/pkmn.html.tmpl"
33
+ "build/pkg/data/ids.json",
34
+ "build/pkg/data/layout.json",
35
+ "build/pkg/data/protocol.json",
36
+ "build/pkg/data.d.ts",
37
+ "build/pkg/data.js",
38
+ "build/pkg/data.js.map",
39
+ "build/pkg/gen1.d.ts",
40
+ "build/pkg/gen1.js",
41
+ "build/pkg/gen1.js.map",
42
+ "build/pkg/index.d.ts",
43
+ "build/pkg/index.js",
44
+ "build/pkg/index.js.map",
45
+ "build/pkg/protocol.d.ts",
46
+ "build/pkg/protocol.js",
47
+ "build/pkg/protocol.js.map"
57
48
  ],
58
49
  "engines": {
59
50
  "node": ">=16.0.0"
60
51
  },
61
52
  "bin": {
62
- "install-pkmn-engine": "src/bin/install-pkmn-engine",
63
- "pkmn-debug": "src/bin/pkmn-debug"
53
+ "install-pkmn-engine": "src/bin/install-pkmn-engine"
64
54
  },
65
55
  "publishConfig": {
66
56
  "access": "public"
67
57
  },
68
58
  "dependencies": {
69
- "@pkmn/data": "^0.7.37",
59
+ "@pkmn/data": "^0.7.33",
70
60
  "@pkmn/protocol": "^0.6.11"
71
61
  },
72
62
  "devDependencies": {
73
- "@pkmn/eslint-config": "^3.0.0",
63
+ "@pkmn/eslint-config": "^3.0.0-alpha.0",
74
64
  "@pkmn/img": "^0.2.8",
75
65
  "@pkmn/sets": "^5.0.4",
76
- "@pkmn/sim": "0.7.37",
66
+ "@pkmn/sim": "0.7.33",
77
67
  "@types/html-minifier": "^4.0.2",
78
68
  "@types/jest": "^29.5.0",
79
69
  "@types/minimist": "^1.2.2",
80
70
  "@types/mustache": "^4.2.2",
81
71
  "@types/node": "^18.15.11",
82
- "@vitest/coverage-c8": "^0.30.1",
72
+ "@vitest/coverage-c8": "^0.29.8",
83
73
  "binaryen": "^112.0.0",
84
- "eslint": "^8.38.0",
74
+ "eslint": "^8.37.0",
85
75
  "html-minifier": "^4.0.0",
86
- "json-stringify-pretty-compact": "4.0.0",
76
+ "json-stringify-pretty-compact": "3.0.0",
87
77
  "minimist": "^1.2.8",
88
78
  "mustache": "^4.2.0",
89
79
  "source-map-support": "^0.5.21",
90
80
  "trakr": "^0.2.0",
91
- "typescript": "^5.0.4",
92
- "vitest": "^0.30.1"
81
+ "typescript": "^5.0.2",
82
+ "vitest": "^0.29.8"
93
83
  },
94
84
  "scripts": {
95
- "lint": "eslint --cache src --ext ts,js && eslint src/bin/*",
96
- "fix": "eslint --fix src --ext ts,js && eslint --fix src/bin/*",
85
+ "lint": "eslint --cache src --ext ts,js && eslint src/bin/install-pkmn-engine",
86
+ "fix": "eslint --fix src --ext ts,js && eslint --fix src/bin/install-pkmn-engine",
97
87
  "compile": "tsc -p .",
98
88
  "build": "npm run compile",
99
89
  "test": "vitest src/pkg",
100
90
  "test:integration": "vitest src/test",
101
- "debug": "npm run compile && node build/tools/debug",
102
91
  "fuzz": "npm run compile && node build/test/fuzz",
103
92
  "generate": "npm run compile && node build/tools/generate",
104
93
  "release": "npm run compile && node build/tools/release",
@@ -199,4 +188,4 @@
199
188
  }
200
189
  ]
201
190
  }
202
- }
191
+ }
@@ -10,15 +10,13 @@ const path = require('path');
10
10
  const {pipeline} = require('stream/promises');
11
11
  const tty = require('tty');
12
12
 
13
- const ZIG_VERSION = {major: 0, minor: 11, patch: 0, dev: 2560};
13
+ const ZIG_VERSION = {major: 0, minor: 11, patch: 0, dev: 2168};
14
14
  const DEV = ZIG_VERSION.dev ? `-dev.${ZIG_VERSION.dev}` : '';
15
15
  const VERSION = `${ZIG_VERSION.major}.${ZIG_VERSION.minor}.${ZIG_VERSION.patch}${DEV}`;
16
16
  const INDEX = 'https://ziglang.org/download/index.json';
17
17
  const ROOT = path.resolve(__dirname, '..', '..');
18
- let SILENT = false;
19
18
 
20
19
  const sh = (cmd, args) => execFileSync(cmd, args, {encoding: 'utf8', cwd: ROOT});
21
- const log = (...args) => { if (!SILENT) console.log(...args); };
22
20
 
23
21
  // This is hardly the browser fetch API, but it works for our primitive needs
24
22
  const fetch = url => new Promise((resolve, reject) => {
@@ -63,7 +61,7 @@ const unpack7 = (input, output) => new Promise((resolve, reject) => {
63
61
  require.resolve('7zip-min');
64
62
  } catch (err) {
65
63
  if (err.code !== 'MODULE_NOT_FOUND') throw err;
66
- log('Installing 7zip-min package locally to unpack the archive...');
64
+ console.log('Installing 7zip-min package locally to unpack the archive...');
67
65
  sh('npm', ['install', '7zip-min', '--no-audit', '--no-save']);
68
66
  }
69
67
 
@@ -85,7 +83,7 @@ const unpack = async (input, output) => {
85
83
  sh('tar', ['xf', input, '-C', output]);
86
84
  return;
87
85
  } catch {
88
- log('tar command not found, falling back to 7z');
86
+ console.log('tar command not found, falling back to 7z');
89
87
  }
90
88
  }
91
89
  // Try to use a 7z binary if we can, and only install 7zip-min as a last resort
@@ -122,10 +120,10 @@ const find = zig => {
122
120
  (!ZIG_VERSION.dev || (dev && dev >= ZIG_VERSION.dev)));
123
121
 
124
122
  if (compatible) {
125
- log('Found existing compatible Zig executable:', zig_exe);
123
+ console.log('Found existing compatible Zig executable:', zig_exe);
126
124
  return zig_exe;
127
125
  } else {
128
- log(`Existing Zig executable is not compatible (${version} < ${VERSION}):`, zig_exe);
126
+ console.log(`Existing Zig executable is not compatible (${version} < ${VERSION}):`, zig_exe);
129
127
  }
130
128
  } catch (err) {
131
129
  if (err.code !== 'ENOENT') throw err;
@@ -170,11 +168,11 @@ const install = async () => {
170
168
  let base = path.basename(url);
171
169
  const archive = path.join(dir, path.basename(url));
172
170
 
173
- log(`Downloading Zig tarball from ${url} to ${archive}`);
171
+ console.log(`Downloading Zig tarball from ${url} to ${archive}`);
174
172
  try {
175
173
  await download(url, archive, release.shasum);
176
174
 
177
- log(`Extracting tarball and installing to ${dir}`);
175
+ console.log(`Extracting tarball and installing to ${dir}`);
178
176
  await unpack(archive, dir);
179
177
  if (archive.endsWith('.zip')) {
180
178
  base = base.slice(0, -4);
@@ -189,17 +187,17 @@ const install = async () => {
189
187
  } catch (err) {
190
188
  if (err.code !== 'ENOENT') throw err;
191
189
  }
192
- log(`Zig${version === 'master' ? '' : ` v${version}`} executable:`, zig,
190
+ console.log(`Zig${version === 'master' ? '' : ` v${version}`} executable:`, zig,
193
191
  '(this version of Zig will be retained to speed up future updates)');
194
192
  const [pre, post] = tty.isatty(1) ? ['\x1b[1m\x1b[35m', '\x1b[0m'] : ['', ''];
195
- log(
193
+ console.log(
196
194
  `${pre}Consider moving the ${path.dirname(zig)} directory and adding it to your PATH`,
197
195
  `to use Zig on other projects, or delete this if you wish to save space.${post}`
198
196
  );
199
197
 
200
198
  return zig;
201
199
  } finally {
202
- log(`Cleaning up ${archive}`);
200
+ console.log(`Cleaning up ${archive}`);
203
201
  try { fs.rmSync(archive); } catch {}
204
202
  }
205
203
  };
@@ -208,17 +206,17 @@ const install = async () => {
208
206
  const downloadHeaders = async () => {
209
207
  const include = path.resolve(process.execPath, '..', '..', 'include', 'node');
210
208
  if (fs.existsSync(path.join(include, 'node.h'))) {
211
- log('Node headers:', include);
209
+ console.log('Node headers:', include);
212
210
  return include;
213
211
  }
214
212
 
215
213
  const dir = path.join(ROOT, 'build', 'include');
216
- const dest = path.join(dir, 'node');
214
+ const dest = path.join(dir, `node-${process.version}`, 'include', 'node');
217
215
  if (fs.existsSync(path.join(dest, 'node.h'))) {
218
- log('Node headers:', dest);
216
+ console.log('Node headers:', dest);
219
217
  return dest;
220
218
  } else {
221
- log(`Could not find Node headers at ${include}, downloading...`);
219
+ console.log(`Could not find Node headers at ${include}, downloading...`);
222
220
  }
223
221
 
224
222
  try {
@@ -229,28 +227,20 @@ const downloadHeaders = async () => {
229
227
 
230
228
  const url = process.release.headersUrl;
231
229
  const targz = path.join(dir, path.basename(url));
232
- const unpacked = path.join(dir, `node-${process.version}`, 'include');
233
230
 
234
- log(`Downloading Node headers from ${url} to ${targz}`);
231
+ console.log(`Downloading Node headers from ${url} to ${targz}`);
232
+ await download(url, targz);
233
+ await unpack(targz, dir);
235
234
 
236
- try {
237
- await download(url, targz);
238
- await unpack(targz, dir);
239
- fs.renameSync(path.join(unpacked, 'node'), dest);
240
-
241
- log('Node headers:', dest);
235
+ console.log('Node headers:', dest);
242
236
 
243
- return dest;
244
- } finally {
245
- try { fs.rmSync(targz); } catch {}
246
- try { fs.rmSync(unpacked, {recursive: true}); } catch {}
247
- }
237
+ return dest;
248
238
  };
249
239
 
250
240
  const downloadImportLib = async () => {
251
241
  const library = path.resolve(process.execPath, '..', 'node.lib');
252
242
  if (fs.existsSync(path.join(library, 'node.h'))) {
253
- log('Node import library:', library);
243
+ console.log('Node import library:', library);
254
244
  return library;
255
245
  }
256
246
 
@@ -258,10 +248,10 @@ const downloadImportLib = async () => {
258
248
  const url = new URL('./win-x64/node.lib', process.release.headersUrl).href;
259
249
  const dest = path.join(dir, path.basename(url));
260
250
  if (fs.existsSync(path.join(dest))) {
261
- log('Node import library:', dest);
251
+ console.log('Node import library:', dest);
262
252
  return dest;
263
253
  } else {
264
- log(`Could not find Node import library at ${library}, downloading...`);
254
+ console.log(`Could not find Node import library at ${library}, downloading...`);
265
255
  }
266
256
 
267
257
  try {
@@ -270,41 +260,24 @@ const downloadImportLib = async () => {
270
260
  if (err.code !== 'EEXIST') throw err;
271
261
  }
272
262
 
273
- log(`Downloading Node import library from ${url} to ${dest}`);
263
+ console.log(`Downloading Node import library from ${url} to ${dest}`);
274
264
  await download(url, dest);
275
- log('Node import library:', dest);
265
+ console.log('Node import library:', dest);
276
266
 
277
267
  return dest;
278
268
  };
279
269
 
280
270
  (async () => {
281
- let only = false;
282
- let options = undefined;
283
- let error = false;
284
- for (let i = 2; i < process.argv.length; i++) {
285
- switch (process.argv[i]) {
286
- case "--silent": {
287
- SILENT = true;
288
- break;
289
- }
290
- case "--zig": {
291
- if (options || only) error = true;
292
- only = true;
293
- break;
294
- }
295
- default: {
296
- if (options || only || !process.argv[i].startsWith('--options=')) error = true;
297
- options = process.argv[i].slice(10).split(' ');
298
- }
299
- }
300
- }
301
- if (error) {
271
+ const options = (process.argv[2] || '').startsWith('--options=')
272
+ ? process.argv[2].slice(10).split(' ') : undefined;
273
+ if (process.argv.length > 3 ||
274
+ process.argv.length === 3 && !(process.argv[2] === '--zig' || options)) {
302
275
  console.error('Invalid arguments');
303
276
  process.exit(1);
304
277
  }
305
278
 
306
279
  const zig = await install();
307
- if (only) process.exit(0);
280
+ if (process.argv[2] === '--zig') process.exit(0);
308
281
 
309
282
  let tmp;
310
283
  try {
@@ -337,13 +310,13 @@ const downloadImportLib = async () => {
337
310
  if (!options) {
338
311
  const addon = require(copy);
339
312
  if (addon.options.showdown) opts.push('-Dshowdown');
340
- if (addon.options.log) opts.push('-Dlog');
313
+ if (addon.options.trace) opts.push('-Dtrace');
341
314
  }
342
315
  } else if (!options) {
343
316
  const addon = await WebAssembly.instantiate(fs.readFileSync(copy));
344
317
  const values = new Uint8Array(addon.instance.exports.memory.buffer);
345
318
  if (values[addon.instance.exports.SHOWDOWN.value]) opts.push('-Dshowdown');
346
- if (values[addon.instance.exports.LOG.value]) opts.push('-Dlog');
319
+ if (values[addon.instance.exports.TRACE.value]) opts.push('-Dtrace');
347
320
  }
348
321
  const key = `${type} ${opts.sort().join(' ')}`;
349
322
  if (!configs.has(key)) configs.set(key, {type, options: opts});
@@ -374,7 +347,7 @@ const downloadImportLib = async () => {
374
347
  opts.includes('-Dshowdown') || opts.includes('-Dshowdown=true') ? '-showdown' : '';
375
348
  const flags = opts.length ? ` (${opts.join(' ')})` : '';
376
349
  const artifact = path.join('build', 'lib', `pkmn${suffix}.${config.type}`);
377
- log(`Building ${artifact}${flags}`);
350
+ console.log(`Building ${artifact}${flags}`);
378
351
  sh(zig, args);
379
352
  // TODO: ziglang/zig#14647 broke emit_to so we get to rename the file ourselves...
380
353
  if (config.type === 'node') {
@@ -382,7 +355,7 @@ const downloadImportLib = async () => {
382
355
  const ext = process.platform === 'darwin'
383
356
  ? 'dylib' : process.platform === 'win32' ? 'dll' : 'so';
384
357
  const actual = path.join('build', 'lib', `${prefix}pkmn${suffix}.node.${ext}`);
385
- fs.renameSync(path.join(ROOT, actual), path.join(ROOT, artifact));
358
+ fs.renameSync(actual, artifact);
386
359
  }
387
360
  }
388
361
  })().catch(e => {
@@ -21,7 +21,7 @@ fn options(env: c.napi_env) c.napi_value {
21
21
  var object = Object.init(env);
22
22
  const properties = [_]c.napi_property_descriptor{
23
23
  Property.init("showdown", .{ .value = Boolean.init(env, pkmn.options.showdown) }),
24
- Property.init("log", .{ .value = Boolean.init(env, pkmn.options.log) }),
24
+ Property.init("trace", .{ .value = Boolean.init(env, pkmn.options.trace) }),
25
25
  };
26
26
  assert(c.napi_define_properties(env, object, properties.len, &properties) == c.napi_ok);
27
27
  return object;
@@ -34,11 +34,11 @@ fn bindings(env: c.napi_env) c.napi_value {
34
34
  }
35
35
 
36
36
  fn bind(env: c.napi_env, gen: anytype) c.napi_value {
37
- const choices_size = @intCast(u32, gen.CHOICES_SIZE);
37
+ const options_size = @intCast(u32, gen.OPTIONS_SIZE);
38
38
  const logs_size = @intCast(u32, gen.LOGS_SIZE);
39
39
  var object = Object.init(env);
40
40
  const properties = [_]c.napi_property_descriptor{
41
- Property.init("CHOICES_SIZE", .{ .value = Number.init(env, choices_size) }),
41
+ Property.init("OPTIONS_SIZE", .{ .value = Number.init(env, options_size) }),
42
42
  Property.init("LOGS_SIZE", .{ .value = Number.init(env, logs_size) }),
43
43
  Property.init("update", .{ .method = update(gen) }),
44
44
  Property.init("choices", .{ .method = choices(gen) }),
@@ -108,10 +108,10 @@ fn choices(gen: anytype) c.napi_callback {
108
108
  const request = @intToEnum(pkmn.Choice.Type, Number.get(env, argv[2], u8));
109
109
 
110
110
  assert(c.napi_get_arraybuffer_info(env, argv[3], &data, &len) == c.napi_ok);
111
- assert(len == gen.CHOICES_SIZE);
111
+ assert(len == gen.OPTIONS_SIZE);
112
112
  assert(data != null);
113
113
 
114
- var out = @ptrCast([*]pkmn.Choice, data.?)[0..gen.CHOICES_SIZE];
114
+ var out = @ptrCast([*]pkmn.Choice, data.?)[0..gen.OPTIONS_SIZE];
115
115
  const n = battle.choices(player, request, out);
116
116
  return Number.init(env, @bitCast(u8, n));
117
117
  }
@@ -2,9 +2,9 @@ const std = @import("std");
2
2
  const pkmn = @import("../pkmn.zig");
3
3
 
4
4
  export const SHOWDOWN = pkmn.options.showdown;
5
- export const LOG = pkmn.options.log;
5
+ export const TRACE = pkmn.options.trace;
6
6
 
7
- export const GEN1_CHOICES_SIZE =
8
- std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.CHOICES_SIZE)) catch unreachable;
7
+ export const GEN1_OPTIONS_SIZE =
8
+ std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.OPTIONS_SIZE)) catch unreachable;
9
9
  export const GEN1_LOGS_SIZE =
10
10
  std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.LOGS_SIZE)) catch unreachable;
@@ -3,7 +3,7 @@ const root = @import("root");
3
3
 
4
4
  pub const Options = struct {
5
5
  showdown: ?bool = null,
6
- log: ?bool = null,
6
+ trace: ?bool = null,
7
7
  advance: ?bool = null,
8
8
  ebc: ?bool = null,
9
9
  internal: ?bool = null,
@@ -11,8 +11,8 @@ pub const Options = struct {
11
11
 
12
12
  /// Whether or not Pokémon Showdown compatibility mode is enabled.
13
13
  pub const showdown = get("showdown", false);
14
- /// Whether or not protocol message logging is enabled.
15
- pub const log = get("log", false);
14
+ /// Whether or not protocol trace logging is enabled.
15
+ pub const trace = get("trace", false);
16
16
 
17
17
  pub const advance = get("advance", true);
18
18
  pub const ebc = get("ebc", true);