@pkmn/engine 0.1.0-dev.9a0c07c3 → 0.1.0-dev.9f75c7ae

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 (55) hide show
  1. package/README.md +71 -60
  2. package/build/pkg/addon.d.ts +7 -0
  3. package/build/pkg/addon.js +112 -0
  4. package/build/pkg/addon.js.map +1 -0
  5. package/build/pkg/data/ids.json +12 -12
  6. package/build/pkg/data/layout.json +27 -5
  7. package/build/pkg/data/protocol.json +69 -12
  8. package/build/pkg/data.d.ts +2 -2
  9. package/build/pkg/gen1.d.ts +5 -4
  10. package/build/pkg/gen1.js +49 -33
  11. package/build/pkg/gen1.js.map +1 -1
  12. package/build/pkg/index.d.ts +15 -12
  13. package/build/pkg/index.js.map +1 -1
  14. package/build/pkg/protocol.d.ts +4 -2
  15. package/build/pkg/protocol.js +60 -39
  16. package/build/pkg/protocol.js.map +1 -1
  17. package/build/test/display.js +31 -13
  18. package/build/test/display.js.map +1 -1
  19. package/build.zig +112 -87
  20. package/package.json +45 -20
  21. package/src/bin/install-pkmn-engine +11 -6
  22. package/src/bin/pkmn-debug +34 -7
  23. package/src/lib/binding/node.zig +47 -142
  24. package/src/lib/binding/wasm.zig +6 -4
  25. package/src/lib/common/battle.zig +17 -0
  26. package/src/lib/common/data.zig +19 -31
  27. package/src/lib/common/debug.zig +21 -11
  28. package/src/lib/common/js.zig +118 -0
  29. package/src/lib/common/optional.zig +67 -0
  30. package/src/lib/common/options.zig +12 -3
  31. package/src/lib/common/protocol.zig +788 -246
  32. package/src/lib/common/rational.zig +353 -0
  33. package/src/lib/common/rng.zig +24 -15
  34. package/src/lib/common/util.zig +12 -0
  35. package/src/lib/gen1/README.md +292 -182
  36. package/src/lib/gen1/calc.zig +426 -0
  37. package/src/lib/gen1/chance.zig +1060 -0
  38. package/src/lib/gen1/data/moves.zig +202 -190
  39. package/src/lib/gen1/data/species.zig +4 -4
  40. package/src/lib/gen1/data/types.zig +10 -10
  41. package/src/lib/gen1/data.zig +90 -76
  42. package/src/lib/gen1/helpers.zig +577 -32
  43. package/src/lib/gen1/mechanics.zig +1032 -712
  44. package/src/lib/gen2/README.md +106 -85
  45. package/src/lib/gen2/calc.zig +143 -0
  46. package/src/lib/gen2/chance.zig +1314 -0
  47. package/src/lib/gen2/data/items.zig +14 -20
  48. package/src/lib/gen2/data/moves.zig +664 -570
  49. package/src/lib/gen2/data/species.zig +2 -2
  50. package/src/lib/gen2/data/types.zig +137 -34
  51. package/src/lib/gen2/data.zig +125 -89
  52. package/src/lib/gen2/generated.zig +815 -0
  53. package/src/lib/gen2/helpers.zig +16 -22
  54. package/src/lib/gen2/mechanics.zig +3149 -12
  55. package/src/lib/pkmn.zig +68 -9
package/build.zig CHANGED
@@ -1,13 +1,20 @@
1
1
  const std = @import("std");
2
2
  const builtin = @import("builtin");
3
3
 
4
- pub const Options = struct { showdown: ?bool = null, trace: ?bool = null };
4
+ pub const Options = struct {
5
+ showdown: ?bool = null,
6
+ log: ?bool = null,
7
+ chance: ?bool = null,
8
+ calc: ?bool = null,
9
+ };
5
10
 
6
11
  pub fn module(b: *std.Build, options: Options) *std.Build.Module {
7
12
  const dirname = comptime std.fs.path.dirname(@src().file) orelse ".";
8
13
  const build_options = b.addOptions();
9
14
  build_options.addOption(?bool, "showdown", options.showdown);
10
- build_options.addOption(?bool, "trace", options.trace);
15
+ build_options.addOption(?bool, "log", options.log);
16
+ build_options.addOption(?bool, "chance", options.chance);
17
+ build_options.addOption(?bool, "calc", options.calc);
11
18
  return b.createModule(.{
12
19
  .source_file = .{ .path = dirname ++ "/src/lib/pkmn.zig" },
13
20
  .dependencies = &.{.{ .name = "build_options", .module = build_options.createModule() }},
@@ -27,25 +34,30 @@ pub fn build(b: *std.Build) !void {
27
34
  const dynamic = b.option(bool, "dynamic", "Build a dynamic library") orelse false;
28
35
  const strip = b.option(bool, "strip", "Strip debugging symbols from binary") orelse false;
29
36
  const pic = b.option(bool, "pic", "Force position independent code") orelse false;
37
+ const emit_asm = b.option(bool, "emit-asm", "Output .s (assembly code)") orelse false;
38
+ const emit_ll = b.option(bool, "emit-ll", "Output .ll (LLVM IR)") orelse false;
30
39
 
31
40
  const cmd = b.findProgram(&.{"strip"}, &.{}) catch null;
32
41
 
33
- var parser = std.json.Parser.init(b.allocator, false);
34
- defer parser.deinit();
35
- var tree = try parser.parse(@embedFile("package.json"));
36
- defer tree.deinit();
37
- const version = tree.root.Object.get("version").?.String;
38
- const description = tree.root.Object.get("description").?.String;
39
- var repository = std.mem.split(u8, tree.root.Object.get("repository").?.String, ":");
42
+ const json = @embedFile("package.json");
43
+ var parsed = try std.json.parseFromSlice(std.json.Value, b.allocator, json, .{});
44
+ defer parsed.deinit();
45
+ const version = parsed.value.object.get("version").?.string;
46
+ const description = parsed.value.object.get("description").?.string;
47
+ var repository = std.mem.split(u8, parsed.value.object.get("repository").?.string, ":");
40
48
  std.debug.assert(std.mem.eql(u8, repository.first(), "github"));
41
49
 
42
50
  const showdown =
43
51
  b.option(bool, "showdown", "Enable Pokémon Showdown compatibility mode") orelse false;
44
- const trace = b.option(bool, "trace", "Enable trace logs") orelse false;
52
+ const log = b.option(bool, "log", "Enable protocol message logging") orelse false;
53
+ const chance = b.option(bool, "chance", "Enable update probability tracking") orelse false;
54
+ const calc = b.option(bool, "calc", "Enable damage calculator support") orelse false;
45
55
 
46
56
  const options = b.addOptions();
47
57
  options.addOption(?bool, "showdown", showdown);
48
- options.addOption(?bool, "trace", trace);
58
+ options.addOption(?bool, "log", log);
59
+ options.addOption(?bool, "chance", chance);
60
+ options.addOption(?bool, "calc", calc);
49
61
 
50
62
  const name = if (showdown) "pkmn-showdown" else "pkmn";
51
63
 
@@ -54,16 +66,16 @@ pub fn build(b: *std.Build) !void {
54
66
  const addon = b.fmt("{s}.node", .{name});
55
67
  const lib = b.addSharedLibrary(.{
56
68
  .name = addon,
69
+ .main_pkg_path = .{ .path = "." },
57
70
  .root_source_file = .{ .path = "src/lib/binding/node.zig" },
58
71
  .optimize = optimize,
59
72
  .target = target,
60
73
  });
61
74
  lib.addOptions("build_options", options);
62
- lib.setMainPkgPath("./");
63
- lib.addSystemIncludePath(headers);
75
+ lib.addSystemIncludePath(.{ .path = headers });
64
76
  lib.linkLibC();
65
77
  if (node_import_lib) |il| {
66
- lib.addObjectFile(il);
78
+ lib.addObjectFile(.{ .path = il });
67
79
  } else if ((try std.zig.system.NativeTargetInfo.detect(target)).target.os.tag == .windows) {
68
80
  try std.io.getStdErr().writeAll("Must provide --node-import-library path on Windows\n");
69
81
  std.process.exit(1);
@@ -79,10 +91,11 @@ pub fn build(b: *std.Build) !void {
79
91
  //
80
92
  // But ziglang/zig#14647 broke this so we now need to do an install() and then manually
81
93
  // rename the file ourself in install-pkmn-engine
82
- lib.install();
94
+ b.installArtifact(lib);
83
95
  } else if (wasm) {
84
96
  const lib = b.addSharedLibrary(.{
85
97
  .name = name,
98
+ .main_pkg_path = .{ .path = "." },
86
99
  .root_source_file = .{ .path = "src/lib/binding/wasm.zig" },
87
100
  .optimize = switch (optimize) {
88
101
  .ReleaseFast, .ReleaseSafe => .ReleaseSmall,
@@ -91,7 +104,6 @@ pub fn build(b: *std.Build) !void {
91
104
  .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
92
105
  });
93
106
  lib.addOptions("build_options", options);
94
- lib.setMainPkgPath("./");
95
107
  lib.stack_size = wasm_stack_size;
96
108
  lib.rdynamic = true;
97
109
  lib.strip = strip;
@@ -105,36 +117,50 @@ pub fn build(b: *std.Build) !void {
105
117
  sh.addFileSourceArg(.{ .path = out });
106
118
  b.getInstallStep().dependOn(&sh.step);
107
119
  }
108
- lib.install();
120
+ b.installArtifact(lib);
109
121
  } else if (dynamic) {
110
122
  const lib = b.addSharedLibrary(.{
111
123
  .name = name,
124
+ .main_pkg_path = .{ .path = "." },
112
125
  .root_source_file = .{ .path = "src/lib/binding/c.zig" },
113
- .version = try std.builtin.Version.parse(version),
126
+ .version = try std.SemanticVersion.parse(version),
114
127
  .optimize = optimize,
115
128
  .target = target,
116
129
  });
117
130
  lib.addOptions("build_options", options);
118
- lib.setMainPkgPath("./");
119
- lib.addIncludePath("src/include");
131
+ lib.addIncludePath(.{ .path = "src/include" });
120
132
  maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
121
133
  if (pic) lib.force_pic = pic;
122
- lib.install();
134
+ b.installArtifact(lib);
123
135
  c = true;
124
136
  } else {
125
137
  const lib = b.addStaticLibrary(.{
126
138
  .name = name,
139
+ .main_pkg_path = .{ .path = "." },
127
140
  .root_source_file = .{ .path = "src/lib/binding/c.zig" },
128
141
  .optimize = optimize,
129
142
  .target = target,
130
143
  });
131
144
  lib.addOptions("build_options", options);
132
- lib.setMainPkgPath("./");
133
- lib.addIncludePath("src/include");
145
+ lib.addIncludePath(.{ .path = "src/include" });
134
146
  lib.bundle_compiler_rt = true;
135
147
  maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
136
148
  if (pic) lib.force_pic = pic;
137
- lib.install();
149
+ if (emit_asm) {
150
+ b.getInstallStep().dependOn(&b.addInstallFileWithDir(
151
+ lib.getEmittedAsm(),
152
+ .prefix,
153
+ b.fmt("{s}.s", .{name}),
154
+ ).step);
155
+ }
156
+ if (emit_ll) {
157
+ b.getInstallStep().dependOn(&b.addInstallFileWithDir(
158
+ lib.getEmittedLlvmIr(),
159
+ .prefix,
160
+ b.fmt("{s}.ll", .{name}),
161
+ ).step);
162
+ }
163
+ b.installArtifact(lib);
138
164
  c = true;
139
165
  }
140
166
 
@@ -176,14 +202,20 @@ pub fn build(b: *std.Build) !void {
176
202
  .strip = strip,
177
203
  .cmd = cmd,
178
204
  };
205
+
206
+ // TODO: tests can be run multiple times due to @imports
179
207
  const tests = TestStep.create(b, options, config);
180
208
 
181
209
  var exes = std.ArrayList(*std.Build.CompileStep).init(b.allocator);
182
210
  const tools: ToolConfig = .{
211
+ .options = .{
212
+ .showdown = showdown,
213
+ .log = log,
214
+ .chance = chance,
215
+ .calc = calc,
216
+ },
183
217
  .general = config,
184
218
  .tool = .{
185
- .showdown = showdown,
186
- .trace = trace,
187
219
  .tests = if (tests.build) tests else null,
188
220
  .exes = &exes,
189
221
  },
@@ -192,28 +224,32 @@ pub fn build(b: *std.Build) !void {
192
224
  var benchmark_config = tools;
193
225
  benchmark_config.general.optimize = .ReleaseFast;
194
226
  benchmark_config.general.strip = true;
195
- const benchmark = tool(b, "src/test/benchmark.zig", benchmark_config);
227
+ const benchmark = try tool(b, "src/test/benchmark.zig", benchmark_config);
196
228
 
197
229
  var fuzz_config = tools;
198
230
  fuzz_config.general.strip = false;
199
231
  fuzz_config.tool.name = "fuzz";
200
- const fuzz = tool(b, "src/test/benchmark.zig", fuzz_config);
201
-
202
- const serde = tool(b, "src/tools/serde.zig", tools);
203
- const protocol = tool(b, "src/tools/protocol.zig", tools);
204
-
205
- const lint_exe =
206
- b.addExecutable(.{ .name = "lint", .root_source_file = .{ .path = "src/tools/lint.zig" } });
207
- if (tests.build) tests.step.dependOn(&lint_exe.step);
208
- const lint = lint_exe.run();
209
-
210
- b.step("benchmark", "Run benchmark code").dependOn(&benchmark.step);
211
- b.step("fuzz", "Run fuzz tester").dependOn(&fuzz.step);
212
- b.step("lint", "Lint source files").dependOn(&lint.step);
213
- b.step("protocol", "Run protocol dump tool").dependOn(&protocol.step);
214
- b.step("serde", "Run serialization/deserialization tool").dependOn(&serde.step);
232
+ const fuzz = try tool(b, "src/test/fuzz.zig", fuzz_config);
233
+
234
+ const analyze = try tool(b, "src/tools/analyze.zig", tools);
235
+ const dump = try tool(b, "src/tools/dump.zig", tools);
236
+ const transitions = try tool(b, "src/tools/transitions.zig", tools);
237
+
238
+ // FIXME: serde randomly fails to build in some release configurations
239
+ var hack = tools;
240
+ if (optimize != .Debug) hack.tool.tests = null;
241
+ const serde = try tool(b, "src/tools/serde.zig", hack);
242
+
243
+ if (analyze) |t| b.step("analyze", "Run LLVM analysis tool").dependOn(&t.step);
244
+ if (benchmark) |t| b.step("benchmark", "Run benchmark code").dependOn(&t.step);
245
+ if (dump) |t| b.step("dump", "Run protocol dump tool").dependOn(&t.step);
246
+ if (fuzz) |t| b.step("fuzz", "Run fuzz tester").dependOn(&t.step);
247
+ if (serde) |t| b.step("serde", "Run serialization/deserialization tool").dependOn(&t.step);
215
248
  b.step("test", "Run all tests").dependOn(&tests.step);
216
249
  b.step("tools", "Install tools").dependOn(&ToolsStep.create(b, &exes).step);
250
+ if (transitions) |t| {
251
+ b.step("transitions", "Visualize transitions algorithm search").dependOn(&t.step);
252
+ }
217
253
  }
218
254
 
219
255
  fn maybeStrip(
@@ -243,12 +279,6 @@ const Config = struct {
243
279
  cmd: ?[]const u8,
244
280
  };
245
281
 
246
- const TESTS = .{
247
- "src/lib/common/test.zig",
248
- "src/lib/gen1/test.zig",
249
- "src/lib/gen2/test.zig",
250
- };
251
-
252
282
  const TestStep = struct {
253
283
  step: std.Build.Step,
254
284
  build: bool,
@@ -256,60 +286,57 @@ const TestStep = struct {
256
286
  pub fn create(b: *std.Build, options: *std.Build.OptionsStep, config: Config) *TestStep {
257
287
  const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
258
288
  const test_file = b.option([]const u8, "test-file", "Input file for test");
259
- const test_bin = b.option([]const u8, "test-bin", "Emit test binary to");
260
289
  const test_filter =
261
290
  b.option([]const u8, "test-filter", "Skip tests that do not match filter");
262
- const test_no_exec =
263
- b.option(bool, "test-no-exec", "Compiles test binary without running it") orelse false;
264
291
 
265
292
  const self = b.allocator.create(TestStep) catch @panic("OOM");
266
293
  const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
267
- self.* = TestStep{ .step = step, .build = test_filter == null };
268
-
269
- const paths: []const []const u8 =
270
- if (test_file) |t| &.{t} else if (coverage != null) &.{"src/lib/test.zig"} else &TESTS;
271
- for (paths) |path| {
272
- const tests = b.addTest(.{
273
- .name = std.fs.path.basename(std.fs.path.dirname(path).?),
274
- .root_source_file = .{ .path = path },
275
- .optimize = config.optimize,
276
- .target = config.target,
277
- });
278
- tests.setMainPkgPath("./");
279
- tests.setFilter(test_filter);
280
- tests.addOptions("build_options", options);
281
- tests.single_threaded = true;
282
- maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
283
- if (config.pic) tests.force_pic = config.pic;
284
- if (test_bin) |bin| {
285
- tests.name = std.fs.path.basename(bin);
286
- if (std.fs.path.dirname(bin)) |dir| tests.setOutputDir(dir);
287
- }
288
- if (coverage) |c| {
289
- tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
290
- }
291
- self.step.dependOn(if (test_no_exec) &tests.step else &tests.run().step);
294
+ self.* = .{ .step = step, .build = test_filter == null };
295
+
296
+ const path = test_file orelse "src/lib/test.zig";
297
+ const tests = b.addTest(.{
298
+ .name = b.fmt("{s}-{s}", .{
299
+ std.fs.path.basename(std.fs.path.dirname(path).?),
300
+ std.fs.path.stem(std.fs.path.basename(path)),
301
+ }),
302
+ .main_pkg_path = .{ .path = "." },
303
+ .root_source_file = .{ .path = path },
304
+ .optimize = config.optimize,
305
+ .target = config.target,
306
+ .filter = test_filter,
307
+ });
308
+ tests.addOptions("build_options", options);
309
+ tests.single_threaded = true;
310
+ maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
311
+ if (config.pic) tests.force_pic = config.pic;
312
+ if (coverage) |c| {
313
+ tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
292
314
  }
315
+ self.step.dependOn(&b.addRunArtifact(tests).step);
316
+
293
317
  return self;
294
318
  }
295
319
  };
296
320
 
297
321
  const ToolConfig = struct {
322
+ options: Options,
298
323
  general: Config,
299
324
  tool: struct {
300
- showdown: bool,
301
- trace: bool,
302
325
  tests: ?*TestStep,
303
326
  name: ?[]const u8 = null,
304
327
  exes: *std.ArrayList(*std.Build.CompileStep),
305
328
  },
306
329
  };
307
330
 
308
- fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep {
331
+ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.RunStep {
332
+ std.fs.cwd().access(path, .{}) catch |err| switch (err) {
333
+ error.FileNotFound => return null,
334
+ else => |e| return e,
335
+ };
309
336
  var name = config.tool.name orelse std.fs.path.basename(path);
310
337
  const index = std.mem.lastIndexOfScalar(u8, name, '.');
311
338
  if (index) |i| name = name[0..i];
312
- if (config.tool.showdown) name = b.fmt("{s}-showdown", .{name});
339
+ if (config.options.showdown orelse false) name = b.fmt("{s}-showdown", .{name});
313
340
 
314
341
  const exe = b.addExecutable(.{
315
342
  .name = name,
@@ -317,16 +344,14 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
317
344
  .target = config.general.target,
318
345
  .optimize = config.general.optimize,
319
346
  });
320
- exe.addModule("pkmn", module(b, .{
321
- .showdown = config.tool.showdown,
322
- .trace = config.tool.trace,
323
- }));
347
+ exe.addModule("pkmn", module(b, config.options));
348
+
324
349
  exe.single_threaded = true;
325
350
  if (config.general.pic) exe.force_pic = config.general.pic;
326
351
  if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
327
352
  config.tool.exes.append(exe) catch @panic("OOM");
328
353
 
329
- const run = exe.run();
354
+ const run = b.addRunArtifact(exe);
330
355
  maybeStrip(b, exe, &run.step, config.general.strip, config.general.cmd);
331
356
  if (b.args) |args| run.addArgs(args);
332
357
 
@@ -339,8 +364,8 @@ const ToolsStep = struct {
339
364
  pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.CompileStep)) *ToolsStep {
340
365
  const self = b.allocator.create(ToolsStep) catch @panic("OOM");
341
366
  const step = std.Build.Step.init(.{ .id = .custom, .name = "Install tools", .owner = b });
342
- self.* = ToolsStep{ .step = step };
343
- for (exes.items) |t| self.step.dependOn(&b.addInstallArtifact(t).step);
367
+ self.* = .{ .step = step };
368
+ for (exes.items) |t| self.step.dependOn(&b.addInstallArtifact(t, .{}).step);
344
369
  return self;
345
370
  }
346
371
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pkmn/engine",
3
- "version": "0.1.0-dev.9a0c07c3",
3
+ "version": "0.1.0-dev.9f75c7ae",
4
4
  "description": "A minimal, complete, Pokémon battle simulation engine optimized for performance",
5
5
  "repository": "github:pkmn/engine",
6
6
  "license": "MIT",
@@ -11,6 +11,9 @@
11
11
  "build.zig",
12
12
  "build/pkg/data.d.ts",
13
13
  "build/pkg/data.js.map",
14
+ "build/pkg/addon.d.ts",
15
+ "build/pkg/addon.js.map",
16
+ "build/pkg/addon.js",
14
17
  "build/pkg/data.js",
15
18
  "build/pkg/data/ids.json",
16
19
  "build/pkg/data/layout.json",
@@ -31,22 +34,32 @@
31
34
  "src/bin/install-pkmn-engine",
32
35
  "src/lib/binding/node.zig",
33
36
  "src/lib/binding/wasm.zig",
37
+ "src/lib/common/battle.zig",
34
38
  "src/lib/common/data.zig",
35
39
  "src/lib/common/debug.zig",
40
+ "src/lib/common/js.zig",
41
+ "src/lib/common/optional.zig",
36
42
  "src/lib/common/options.zig",
37
43
  "src/lib/common/protocol.zig",
44
+ "src/lib/common/rational.zig",
38
45
  "src/lib/common/rng.zig",
46
+ "src/lib/common/util.zig",
47
+ "src/lib/gen1/calc.zig",
48
+ "src/lib/gen1/chance.zig",
39
49
  "src/lib/gen1/data.zig",
40
50
  "src/lib/gen1/data/moves.zig",
41
51
  "src/lib/gen1/data/species.zig",
42
52
  "src/lib/gen1/data/types.zig",
43
53
  "src/lib/gen1/helpers.zig",
44
54
  "src/lib/gen1/mechanics.zig",
55
+ "src/lib/gen2/calc.zig",
56
+ "src/lib/gen2/chance.zig",
45
57
  "src/lib/gen2/data.zig",
46
58
  "src/lib/gen2/data/items.zig",
47
59
  "src/lib/gen2/data/moves.zig",
48
60
  "src/lib/gen2/data/species.zig",
49
61
  "src/lib/gen2/data/types.zig",
62
+ "src/lib/gen2/generated.zig",
50
63
  "src/lib/gen2/helpers.zig",
51
64
  "src/lib/gen2/mechanics.zig",
52
65
  "src/lib/pkmn.zig",
@@ -63,30 +76,30 @@
63
76
  "access": "public"
64
77
  },
65
78
  "dependencies": {
66
- "@pkmn/data": "^0.7.36",
67
- "@pkmn/protocol": "^0.6.11"
79
+ "@pkmn/data": "^0.7.53",
80
+ "@pkmn/protocol": "^0.6.16"
68
81
  },
69
82
  "devDependencies": {
70
- "@pkmn/eslint-config": "^3.0.0",
71
- "@pkmn/img": "^0.2.8",
72
- "@pkmn/sets": "^5.0.4",
73
- "@pkmn/sim": "0.7.36",
74
- "@types/html-minifier": "^4.0.2",
75
- "@types/jest": "^29.5.0",
76
- "@types/minimist": "^1.2.2",
77
- "@types/mustache": "^4.2.2",
78
- "@types/node": "^18.15.11",
79
- "@vitest/coverage-c8": "^0.29.8",
80
- "binaryen": "^112.0.0",
81
- "eslint": "^8.37.0",
83
+ "@pkmn/eslint-config": "^5.3.0",
84
+ "@pkmn/img": "^0.2.18",
85
+ "@pkmn/sets": "^5.1.0",
86
+ "@pkmn/sim": "0.7.53",
87
+ "@types/html-minifier": "^4.0.3",
88
+ "@types/jest": "^29.5.5",
89
+ "@types/minimist": "^1.2.3",
90
+ "@types/mustache": "^4.2.3",
91
+ "@types/node": "^20.8.2",
92
+ "@vitest/coverage-c8": "^0.33.0",
93
+ "binaryen": "^114.0.0",
94
+ "eslint": "^8.51.0",
82
95
  "html-minifier": "^4.0.0",
83
96
  "json-stringify-pretty-compact": "3.0.0",
84
97
  "minimist": "^1.2.8",
85
98
  "mustache": "^4.2.0",
86
99
  "source-map-support": "^0.5.21",
87
100
  "trakr": "^0.2.0",
88
- "typescript": "^5.0.3",
89
- "vitest": "^0.29.8"
101
+ "typescript": "^5.2.2",
102
+ "vitest": "^0.34.6"
90
103
  },
91
104
  "scripts": {
92
105
  "lint": "eslint --cache src --ext ts,js && eslint src/bin/*",
@@ -137,7 +150,8 @@
137
150
  "rules": {
138
151
  "no-control-regex": "off",
139
152
  "@typescript-eslint/no-empty-interface": "off",
140
- "@typescript-eslint/no-shadow": "off"
153
+ "@typescript-eslint/no-shadow": "off",
154
+ "@typescript-eslint/no-unsafe-declaration-merging": "off"
141
155
  }
142
156
  },
143
157
  {
@@ -153,12 +167,23 @@
153
167
  "src/test/benchmark*.ts"
154
168
  ],
155
169
  "rules": {
156
- "@typescript-eslint/no-unused-vars": "off"
170
+ "@typescript-eslint/no-unused-vars": "off",
171
+ "@typescript-eslint/no-redundant-type-constituents": "off"
157
172
  }
158
173
  },
159
174
  {
160
175
  "files": [
161
- "src/test/*.test.ts"
176
+ "src/pkg/protocol.test.ts"
177
+ ],
178
+ "rules": {
179
+ "jest/no-standalone-expect": "off",
180
+ "jest/no-conditional-expect": "off"
181
+ }
182
+ },
183
+ {
184
+ "files": [
185
+ "src/test/*.test.ts",
186
+ "src/test/regression/*.test.ts"
162
187
  ],
163
188
  "rules": {
164
189
  "jest/no-standalone-expect": "off"
@@ -10,7 +10,7 @@ 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: 2168};
13
+ const ZIG_VERSION = {major: 0, minor: 11, patch: 0};
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';
@@ -336,14 +336,18 @@ const downloadImportLib = async () => {
336
336
  node = true;
337
337
  if (!options) {
338
338
  const addon = require(copy);
339
- if (addon.options.showdown) opts.push('-Dshowdown');
340
- if (addon.options.trace) opts.push('-Dtrace');
339
+ if (addon.engine.options.showdown) opts.push('-Dshowdown');
340
+ if (addon.engine.options.log) opts.push('-Dlog');
341
+ if (addon.engine.options.chance) opts.push('-Dchance');
342
+ if (addon.engine.options.calc) opts.push('-Dcalc');
341
343
  }
342
344
  } else if (!options) {
343
345
  const addon = await WebAssembly.instantiate(fs.readFileSync(copy));
344
346
  const values = new Uint8Array(addon.instance.exports.memory.buffer);
345
347
  if (values[addon.instance.exports.SHOWDOWN.value]) opts.push('-Dshowdown');
346
- if (values[addon.instance.exports.TRACE.value]) opts.push('-Dtrace');
348
+ if (values[addon.instance.exports.LOG.value]) opts.push('-Dlog');
349
+ if (values[addon.instance.exports.CHANCE.value]) opts.push('-Dchance');
350
+ if (values[addon.instance.exports.CALC.value]) opts.push('-Dcalc');
347
351
  }
348
352
  const key = `${type} ${opts.sort().join(' ')}`;
349
353
  if (!configs.has(key)) configs.set(key, {type, options: opts});
@@ -354,8 +358,9 @@ const downloadImportLib = async () => {
354
358
  // either the default options or whatever was passed in
355
359
  if (!configs.size) {
356
360
  node = true;
357
- configs.set('node', {type: 'node', options: options || ['-Dshowdown']});
358
- configs.set('wasm', {type: 'wasm', options: options || ['-Dshowdown']});
361
+ const DEFAULT = ['-Dshowdown'];
362
+ configs.set('node', {type: 'node', options: options || DEFAULT});
363
+ configs.set('wasm', {type: 'wasm', options: options || DEFAULT});
359
364
  }
360
365
 
361
366
  const headers = node ? await downloadHeaders() : undefined;
@@ -1,34 +1,61 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- require('source-map-support').install();
4
+ try {
5
+ require('source-map-support').install();
6
+ } catch (err) {
7
+ if (err.code !== 'MODULE_NOT_FOUND') throw err;
8
+ }
5
9
 
6
10
  const {execFileSync} = require('child_process');
11
+ const {readFileSync} = require('fs');
12
+ const {join, resolve} = require('path');
7
13
 
8
- const {Generations} = require('@pkmn/data');
14
+ const ROOT = resolve(__dirname, '..', '..');
15
+ const packageJSON = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
9
16
 
10
- const {run} = require('../../build/tools/debug');
17
+ const missing = [];
18
+ for (const dep of ['@pkmn/img', 'html-minifier', 'mustache']) {
19
+ try {
20
+ require.resolve(dep);
21
+ } catch (e) {
22
+ if (e.code !== 'MODULE_NOT_FOUND') throw e;
23
+ missing.push(`${dep}@${packageJSON.devDependencies[dep]}`);
24
+ }
25
+ }
11
26
 
12
- let Dex;
27
+ let Dex = undefined;
13
28
  try {
14
29
  Dex = require('@pkmn/sim').Dex;
15
30
  } catch (err) {
16
31
  if (err.code !== 'MODULE_NOT_FOUND') throw err;
17
32
  try {
18
- require.resolve('@pkmn/dex');
33
+ Dex = require('@pkmn/dex').Dex;
19
34
  } catch (e) {
20
35
  if (e.code !== 'MODULE_NOT_FOUND') throw e;
21
- execFileSync('npm', ['install', '@pkmn/dex', '--global', '--silent']);
36
+ missing.push(`@pkmn/dex@${packageJSON.dependencies['@pkmn/data']}`);
22
37
  }
38
+ }
23
39
 
40
+ if (missing.length) {
24
41
  if (+/^v(\d+)/.exec(process.version)[1] < 16) {
25
42
  console.error('pkmn-debug requires Node v16+');
26
43
  process.exit(1);
27
44
  }
28
45
 
29
- Dex = require('@pkmn/dex').Dex;
46
+ execFileSync('npm', ['install', ...missing, '--global'], {encoding: 'utf8'});
47
+
48
+ const node_modules = execFileSync('npm', ['root', '--global'], {encoding: 'utf8'}).trim();
49
+ if (!process.env.NODE_PATH || !process.env.NODE_PATH.includes(node_modules)) {
50
+ console.error(`NODE_PATH must include npm's global node_modules directory: '${node_modules}'`);
51
+ process.exit(1);
52
+ }
30
53
  }
31
54
 
55
+ const {Generations} = require('@pkmn/data');
56
+
57
+ const {run} = require('../../build/tools/debug');
58
+
32
59
  run(new Generations(Dex)).catch(err => {
33
60
  console.error(err.message);
34
61
  process.exit(1);