@pkmn/engine 0.1.0-dev.02b7f810 → 0.1.0-dev.09d1baec

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 (60) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +103 -69
  3. package/build/pkg/addon.d.ts +2 -2
  4. package/build/pkg/addon.js +8 -7
  5. package/build/pkg/addon.js.map +1 -1
  6. package/build/pkg/data/ids.json +12 -12
  7. package/build/pkg/data/layout.json +27 -5
  8. package/build/pkg/data/protocol.json +69 -12
  9. package/build/pkg/data.d.ts +3 -2
  10. package/build/pkg/data.js.map +1 -1
  11. package/build/pkg/gen1.d.ts +5 -4
  12. package/build/pkg/gen1.js +49 -33
  13. package/build/pkg/gen1.js.map +1 -1
  14. package/build/pkg/index.d.ts +17 -13
  15. package/build/pkg/index.js.map +1 -1
  16. package/build/pkg/protocol.d.ts +4 -2
  17. package/build/pkg/protocol.js +61 -40
  18. package/build/pkg/protocol.js.map +1 -1
  19. package/build/test/display.js +31 -13
  20. package/build/test/display.js.map +1 -1
  21. package/build/tools/debug.js +3 -1
  22. package/build/tools/debug.js.map +1 -1
  23. package/build.zig +159 -124
  24. package/package.json +56 -25
  25. package/src/bin/install-pkmn-engine +24 -19
  26. package/src/lib/common/battle.zig +17 -0
  27. package/src/lib/common/data.zig +19 -31
  28. package/src/lib/common/debug.zig +21 -11
  29. package/src/lib/common/js.zig +118 -0
  30. package/src/lib/common/optional.zig +67 -0
  31. package/src/lib/common/options.zig +12 -3
  32. package/src/lib/common/protocol.zig +932 -395
  33. package/src/lib/common/rational.zig +357 -0
  34. package/src/lib/common/rng.zig +29 -20
  35. package/src/lib/common/util.zig +12 -0
  36. package/src/lib/gen1/README.md +285 -182
  37. package/src/lib/gen1/calc.zig +426 -0
  38. package/src/lib/gen1/chance.zig +1060 -0
  39. package/src/lib/gen1/data/moves.zig +202 -190
  40. package/src/lib/gen1/data/species.zig +4 -4
  41. package/src/lib/gen1/data/types.zig +10 -10
  42. package/src/lib/gen1/data.zig +106 -92
  43. package/src/lib/gen1/helpers.zig +577 -32
  44. package/src/lib/gen1/mechanics.zig +1117 -818
  45. package/src/lib/gen2/README.md +105 -85
  46. package/src/lib/gen2/calc.zig +143 -0
  47. package/src/lib/gen2/chance.zig +1314 -0
  48. package/src/lib/gen2/data/items.zig +14 -20
  49. package/src/lib/gen2/data/moves.zig +664 -570
  50. package/src/lib/gen2/data/species.zig +2 -2
  51. package/src/lib/gen2/data/types.zig +137 -34
  52. package/src/lib/gen2/data.zig +134 -96
  53. package/src/lib/gen2/generated.zig +806 -0
  54. package/src/lib/gen2/helpers.zig +16 -22
  55. package/src/lib/gen2/mechanics.zig +3506 -12
  56. package/src/lib/node.zig +131 -0
  57. package/src/lib/pkmn.zig +91 -9
  58. package/src/lib/wasm.zig +13 -0
  59. package/src/lib/binding/node.zig +0 -229
  60. package/src/lib/binding/wasm.zig +0 -10
package/build.zig CHANGED
@@ -1,16 +1,23 @@
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
- .source_file = .{ .path = dirname ++ "/src/lib/pkmn.zig" },
13
- .dependencies = &.{.{ .name = "build_options", .module = build_options.createModule() }},
19
+ .root_source_file = .{ .path = dirname ++ "/src/lib/pkmn.zig" },
20
+ .imports = &.{.{ .name = "build_options", .module = build_options.createModule() }},
14
21
  });
15
22
  }
16
23
 
@@ -25,27 +32,32 @@ pub fn build(b: *std.Build) !void {
25
32
  const wasm_stack_size =
26
33
  b.option(u64, "wasm-stack-size", "The size of WASM stack") orelse std.wasm.page_size;
27
34
  const dynamic = b.option(bool, "dynamic", "Build a dynamic library") orelse false;
28
- const strip = b.option(bool, "strip", "Strip debugging symbols from binary") orelse false;
29
- const pic = b.option(bool, "pic", "Force position independent code") orelse false;
35
+ const strip = b.option(bool, "strip", "Strip debugging symbols from binary");
36
+ const pic = b.option(bool, "pic", "Force position independent code");
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,23 +66,23 @@ 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,
57
- .root_source_file = .{ .path = "src/lib/binding/node.zig" },
69
+ .root_source_file = .{ .path = "src/lib/node.zig" },
58
70
  .optimize = optimize,
59
71
  .target = target,
72
+ .strip = strip,
73
+ .pic = pic,
60
74
  });
61
- lib.addOptions("build_options", options);
62
- lib.setMainPkgPath("./");
63
- lib.addSystemIncludePath(headers);
75
+ lib.root_module.addOptions("build_options", options);
76
+ lib.addSystemIncludePath(.{ .path = headers });
64
77
  lib.linkLibC();
65
78
  if (node_import_lib) |il| {
66
- lib.addObjectFile(il);
67
- } else if ((try std.zig.system.NativeTargetInfo.detect(target)).target.os.tag == .windows) {
79
+ lib.addObjectFile(.{ .path = il });
80
+ } else if (target.result.os.tag == .windows) {
68
81
  try std.io.getStdErr().writeAll("Must provide --node-import-library path on Windows\n");
69
82
  std.process.exit(1);
70
83
  }
71
84
  lib.linker_allow_shlib_undefined = true;
72
85
  maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
73
- if (pic) lib.force_pic = pic;
74
86
  // Always emit to build/lib because this is where the driver code expects to find it
75
87
  // TODO(ziglang/zig#2231): using the following used to work (though was hacky):
76
88
  //
@@ -79,62 +91,86 @@ 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
- const lib = b.addSharedLibrary(.{
96
+ const exe = b.addExecutable(.{
85
97
  .name = name,
86
- .root_source_file = .{ .path = "src/lib/binding/wasm.zig" },
98
+ .root_source_file = .{ .path = "src/lib/wasm.zig" },
87
99
  .optimize = switch (optimize) {
88
100
  .ReleaseFast, .ReleaseSafe => .ReleaseSmall,
89
101
  else => optimize,
90
102
  },
91
- .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
103
+ .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
104
+ .strip = strip,
105
+ .pic = pic,
92
106
  });
93
- lib.addOptions("build_options", options);
94
- lib.setMainPkgPath("./");
95
- lib.stack_size = wasm_stack_size;
96
- lib.rdynamic = true;
97
- lib.strip = strip;
98
- if (pic) lib.force_pic = pic;
107
+ exe.root_module.addOptions("build_options", options);
108
+ exe.root_module.export_symbol_names = &[_][]const u8{
109
+ "SHOWDOWN",
110
+ "LOG",
111
+ "CHANCE",
112
+ "CALC",
113
+ "GEN1_CHOICES_SIZE",
114
+ "GEN1_LOGS_SIZE",
115
+ };
116
+ exe.entry = .disabled;
117
+ exe.stack_size = wasm_stack_size;
99
118
  const opt = b.findProgram(&.{"wasm-opt"}, &.{"./node_modules/.bin"}) catch null;
100
119
  if (optimize != .Debug and opt != null) {
101
120
  const out = b.fmt("build/lib/{s}.wasm", .{name});
102
121
  const sh = b.addSystemCommand(&.{ opt.?, "-O4" });
103
- sh.addArtifactArg(lib);
122
+ sh.addArtifactArg(exe);
104
123
  sh.addArg("-o");
105
- sh.addFileSourceArg(.{ .path = out });
124
+ sh.addFileArg(.{ .path = out });
106
125
  b.getInstallStep().dependOn(&sh.step);
126
+ } else {
127
+ b.getInstallStep().dependOn(&b.addInstallArtifact(exe, .{
128
+ .dest_dir = .{ .override = std.Build.InstallDir{ .lib = {} } },
129
+ }).step);
107
130
  }
108
- lib.install();
109
131
  } else if (dynamic) {
110
132
  const lib = b.addSharedLibrary(.{
111
133
  .name = name,
112
- .root_source_file = .{ .path = "src/lib/binding/c.zig" },
113
- .version = try std.builtin.Version.parse(version),
134
+ .root_source_file = .{ .path = "src/lib/c.zig" },
135
+ .version = try std.SemanticVersion.parse(version),
114
136
  .optimize = optimize,
115
137
  .target = target,
138
+ .strip = strip,
139
+ .pic = pic,
116
140
  });
117
- lib.addOptions("build_options", options);
118
- lib.setMainPkgPath("./");
119
- lib.addIncludePath("src/include");
141
+ lib.root_module.addOptions("build_options", options);
142
+ lib.addIncludePath(.{ .path = "src/include" });
120
143
  maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
121
- if (pic) lib.force_pic = pic;
122
- lib.install();
144
+ b.installArtifact(lib);
123
145
  c = true;
124
146
  } else {
125
147
  const lib = b.addStaticLibrary(.{
126
148
  .name = name,
127
- .root_source_file = .{ .path = "src/lib/binding/c.zig" },
149
+ .root_source_file = .{ .path = "src/lib/c.zig" },
128
150
  .optimize = optimize,
129
151
  .target = target,
152
+ .strip = strip,
153
+ .pic = pic,
130
154
  });
131
- lib.addOptions("build_options", options);
132
- lib.setMainPkgPath("./");
133
- lib.addIncludePath("src/include");
155
+ lib.root_module.addOptions("build_options", options);
156
+ lib.addIncludePath(.{ .path = "src/include" });
134
157
  lib.bundle_compiler_rt = true;
135
158
  maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
136
- if (pic) lib.force_pic = pic;
137
- lib.install();
159
+ if (emit_asm) {
160
+ b.getInstallStep().dependOn(&b.addInstallFileWithDir(
161
+ lib.getEmittedAsm(),
162
+ .prefix,
163
+ b.fmt("{s}.s", .{name}),
164
+ ).step);
165
+ }
166
+ if (emit_ll) {
167
+ b.getInstallStep().dependOn(&b.addInstallFileWithDir(
168
+ lib.getEmittedLlvmIr(),
169
+ .prefix,
170
+ b.fmt("{s}.ll", .{name}),
171
+ ).step);
172
+ }
173
+ b.installArtifact(lib);
138
174
  c = true;
139
175
  }
140
176
 
@@ -176,14 +212,20 @@ pub fn build(b: *std.Build) !void {
176
212
  .strip = strip,
177
213
  .cmd = cmd,
178
214
  };
215
+
216
+ // TODO: tests can be run multiple times due to @imports
179
217
  const tests = TestStep.create(b, options, config);
180
218
 
181
- var exes = std.ArrayList(*std.Build.CompileStep).init(b.allocator);
219
+ var exes = std.ArrayList(*std.Build.Step.Compile).init(b.allocator);
182
220
  const tools: ToolConfig = .{
221
+ .options = .{
222
+ .showdown = showdown,
223
+ .log = log,
224
+ .chance = chance,
225
+ .calc = calc,
226
+ },
183
227
  .general = config,
184
228
  .tool = .{
185
- .showdown = showdown,
186
- .trace = trace,
187
229
  .tests = if (tests.build) tests else null,
188
230
  .exes = &exes,
189
231
  },
@@ -192,39 +234,42 @@ pub fn build(b: *std.Build) !void {
192
234
  var benchmark_config = tools;
193
235
  benchmark_config.general.optimize = .ReleaseFast;
194
236
  benchmark_config.general.strip = true;
195
- const benchmark = tool(b, "src/test/benchmark.zig", benchmark_config);
237
+ const benchmark = try tool(b, "src/test/benchmark.zig", benchmark_config);
196
238
 
197
239
  var fuzz_config = tools;
198
240
  fuzz_config.general.strip = false;
199
241
  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);
242
+ const fuzz = try tool(b, "src/test/fuzz.zig", fuzz_config);
243
+
244
+ const analyze = try tool(b, "src/tools/analyze.zig", tools);
245
+ const dump = try tool(b, "src/tools/dump.zig", tools);
246
+ const transitions = try tool(b, "src/tools/transitions.zig", tools);
247
+
248
+ // FIXME: serde randomly fails to build in some release configurations
249
+ var hack = tools;
250
+ if (optimize != .Debug) hack.tool.tests = null;
251
+ const serde = try tool(b, "src/tools/serde.zig", hack);
252
+
253
+ if (analyze) |t| b.step("analyze", "Run LLVM analysis tool").dependOn(&t.step);
254
+ if (benchmark) |t| b.step("benchmark", "Run benchmark code").dependOn(&t.step);
255
+ if (dump) |t| b.step("dump", "Run protocol dump tool").dependOn(&t.step);
256
+ if (fuzz) |t| b.step("fuzz", "Run fuzz tester").dependOn(&t.step);
257
+ if (serde) |t| b.step("serde", "Run serialization/deserialization tool").dependOn(&t.step);
215
258
  b.step("test", "Run all tests").dependOn(&tests.step);
216
259
  b.step("tools", "Install tools").dependOn(&ToolsStep.create(b, &exes).step);
260
+ if (transitions) |t| {
261
+ b.step("transitions", "Visualize transitions algorithm search").dependOn(&t.step);
262
+ }
217
263
  }
218
264
 
219
265
  fn maybeStrip(
220
266
  b: *std.Build,
221
- artifact: *std.Build.CompileStep,
267
+ artifact: *std.Build.Step.Compile,
222
268
  step: *std.Build.Step,
223
- strip: bool,
269
+ strip: ?bool,
224
270
  cmd: ?[]const u8,
225
271
  ) void {
226
- artifact.strip = strip;
227
- if (!strip or cmd == null) return;
272
+ if (!(strip orelse false) or cmd == null) return;
228
273
  // Using `strip -r -u` for dynamic libraries is supposed to work on macOS but doesn't...
229
274
  const mac = builtin.os.tag == .macos;
230
275
  if (mac and artifact.isDynamicLibrary()) return;
@@ -236,97 +281,87 @@ fn maybeStrip(
236
281
  }
237
282
 
238
283
  const Config = struct {
239
- target: std.zig.CrossTarget,
284
+ target: std.Build.ResolvedTarget,
240
285
  optimize: std.builtin.OptimizeMode,
241
- pic: bool,
242
- strip: bool,
286
+ pic: ?bool,
287
+ strip: ?bool,
243
288
  cmd: ?[]const u8,
244
289
  };
245
290
 
246
- const TESTS = .{
247
- "src/lib/common/test.zig",
248
- "src/lib/gen1/test.zig",
249
- "src/lib/gen2/test.zig",
250
- };
251
-
252
291
  const TestStep = struct {
253
292
  step: std.Build.Step,
254
293
  build: bool,
255
294
 
256
- pub fn create(b: *std.Build, options: *std.Build.OptionsStep, config: Config) *TestStep {
295
+ pub fn create(b: *std.Build, options: *std.Build.Step.Options, config: Config) *TestStep {
257
296
  const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
258
297
  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
298
  const test_filter =
261
299
  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
300
 
265
301
  const self = b.allocator.create(TestStep) catch @panic("OOM");
266
302
  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);
303
+ self.* = .{ .step = step, .build = test_filter == null };
304
+
305
+ const path = test_file orelse "src/lib/test.zig";
306
+ const tests = b.addTest(.{
307
+ .name = b.fmt("{s}-{s}", .{
308
+ std.fs.path.basename(std.fs.path.dirname(path).?),
309
+ std.fs.path.stem(std.fs.path.basename(path)),
310
+ }),
311
+ .root_source_file = .{ .path = path },
312
+ .optimize = config.optimize,
313
+ .target = config.target,
314
+ .filter = test_filter,
315
+ .single_threaded = true,
316
+ .strip = config.strip,
317
+ .pic = config.pic,
318
+ });
319
+ tests.root_module.addOptions("build_options", options);
320
+ maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
321
+ if (coverage) |c| {
322
+ tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
292
323
  }
324
+ self.step.dependOn(&b.addRunArtifact(tests).step);
325
+
293
326
  return self;
294
327
  }
295
328
  };
296
329
 
297
330
  const ToolConfig = struct {
331
+ options: Options,
298
332
  general: Config,
299
333
  tool: struct {
300
- showdown: bool,
301
- trace: bool,
302
334
  tests: ?*TestStep,
303
335
  name: ?[]const u8 = null,
304
- exes: *std.ArrayList(*std.Build.CompileStep),
336
+ exes: *std.ArrayList(*std.Build.Step.Compile),
305
337
  },
306
338
  };
307
339
 
308
- fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep {
340
+ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.Step.Run {
341
+ std.fs.cwd().access(path, .{}) catch |err| switch (err) {
342
+ error.FileNotFound => return null,
343
+ else => |e| return e,
344
+ };
309
345
  var name = config.tool.name orelse std.fs.path.basename(path);
310
346
  const index = std.mem.lastIndexOfScalar(u8, name, '.');
311
347
  if (index) |i| name = name[0..i];
312
- if (config.tool.showdown) name = b.fmt("{s}-showdown", .{name});
348
+ if (config.options.showdown orelse false) name = b.fmt("{s}-showdown", .{name});
313
349
 
314
350
  const exe = b.addExecutable(.{
315
351
  .name = name,
316
352
  .root_source_file = .{ .path = path },
317
353
  .target = config.general.target,
318
354
  .optimize = config.general.optimize,
355
+ .single_threaded = true,
356
+ .strip = config.general.strip,
357
+ .pic = config.general.pic,
319
358
  });
320
- exe.addModule("pkmn", module(b, .{
321
- .showdown = config.tool.showdown,
322
- .trace = config.tool.trace,
323
- }));
324
- exe.single_threaded = true;
325
- if (config.general.pic) exe.force_pic = config.general.pic;
359
+ exe.root_module.addImport("pkmn", module(b, config.options));
360
+
326
361
  if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
327
362
  config.tool.exes.append(exe) catch @panic("OOM");
328
363
 
329
- const run = exe.run();
364
+ const run = b.addRunArtifact(exe);
330
365
  maybeStrip(b, exe, &run.step, config.general.strip, config.general.cmd);
331
366
  if (b.args) |args| run.addArgs(args);
332
367
 
@@ -336,11 +371,11 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
336
371
  const ToolsStep = struct {
337
372
  step: std.Build.Step,
338
373
 
339
- pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.CompileStep)) *ToolsStep {
374
+ pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.Step.Compile)) *ToolsStep {
340
375
  const self = b.allocator.create(ToolsStep) catch @panic("OOM");
341
376
  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);
377
+ self.* = .{ .step = step };
378
+ for (exes.items) |t| self.step.dependOn(&b.addInstallArtifact(t, .{}).step);
344
379
  return self;
345
380
  }
346
381
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pkmn/engine",
3
- "version": "0.1.0-dev.02b7f810",
3
+ "version": "0.1.0-dev.09d1baec",
4
4
  "description": "A minimal, complete, Pokémon battle simulation engine optimized for performance",
5
5
  "repository": "github:pkmn/engine",
6
6
  "license": "MIT",
@@ -32,27 +32,37 @@
32
32
  "build/tools/debug.js.map",
33
33
  "build/tools/debug.js",
34
34
  "src/bin/install-pkmn-engine",
35
- "src/lib/binding/node.zig",
36
- "src/lib/binding/wasm.zig",
35
+ "src/lib/common/battle.zig",
37
36
  "src/lib/common/data.zig",
38
37
  "src/lib/common/debug.zig",
38
+ "src/lib/common/js.zig",
39
+ "src/lib/common/optional.zig",
39
40
  "src/lib/common/options.zig",
40
41
  "src/lib/common/protocol.zig",
42
+ "src/lib/common/rational.zig",
41
43
  "src/lib/common/rng.zig",
44
+ "src/lib/common/util.zig",
45
+ "src/lib/gen1/calc.zig",
46
+ "src/lib/gen1/chance.zig",
42
47
  "src/lib/gen1/data.zig",
43
48
  "src/lib/gen1/data/moves.zig",
44
49
  "src/lib/gen1/data/species.zig",
45
50
  "src/lib/gen1/data/types.zig",
46
51
  "src/lib/gen1/helpers.zig",
47
52
  "src/lib/gen1/mechanics.zig",
53
+ "src/lib/gen2/calc.zig",
54
+ "src/lib/gen2/chance.zig",
48
55
  "src/lib/gen2/data.zig",
49
56
  "src/lib/gen2/data/items.zig",
50
57
  "src/lib/gen2/data/moves.zig",
51
58
  "src/lib/gen2/data/species.zig",
52
59
  "src/lib/gen2/data/types.zig",
60
+ "src/lib/gen2/generated.zig",
53
61
  "src/lib/gen2/helpers.zig",
54
62
  "src/lib/gen2/mechanics.zig",
63
+ "src/lib/node.zig",
55
64
  "src/lib/pkmn.zig",
65
+ "src/lib/wasm.zig",
56
66
  "src/test/display/pkmn.html.tmpl"
57
67
  ],
58
68
  "engines": {
@@ -66,30 +76,31 @@
66
76
  "access": "public"
67
77
  },
68
78
  "dependencies": {
69
- "@pkmn/data": "^0.7.36",
70
- "@pkmn/protocol": "^0.6.11"
79
+ "@pkmn/data": "^0.8.6",
80
+ "@pkmn/protocol": "^0.6.19"
71
81
  },
72
82
  "devDependencies": {
73
- "@pkmn/eslint-config": "^3.0.0",
74
- "@pkmn/img": "^0.2.8",
75
- "@pkmn/sets": "^5.0.4",
76
- "@pkmn/sim": "0.7.36",
77
- "@types/html-minifier": "^4.0.2",
78
- "@types/jest": "^29.5.0",
79
- "@types/minimist": "^1.2.2",
80
- "@types/mustache": "^4.2.2",
81
- "@types/node": "^18.15.11",
82
- "@vitest/coverage-c8": "^0.29.8",
83
- "binaryen": "^112.0.0",
84
- "eslint": "^8.37.0",
83
+ "@pkmn/eslint-config": "^6.5.0",
84
+ "@pkmn/img": "^0.2.23",
85
+ "@pkmn/sets": "^5.1.0",
86
+ "@pkmn/sim": "0.8.6",
87
+ "@types/html-minifier": "^4.0.5",
88
+ "@types/jest": "^29.5.11",
89
+ "@types/minimist": "^1.2.5",
90
+ "@types/mustache": "^4.2.5",
91
+ "@types/node": "^20.11.5",
92
+ "@vitest/coverage-v8": "^1.2.1",
93
+ "binaryen": "^116.0.0",
94
+ "eslint": "^8.56.0",
85
95
  "html-minifier": "^4.0.0",
86
- "json-stringify-pretty-compact": "3.0.0",
96
+ "json-stringify-pretty-compact": "4.0.0",
87
97
  "minimist": "^1.2.8",
88
98
  "mustache": "^4.2.0",
89
99
  "source-map-support": "^0.5.21",
100
+ "table": "^6.8.1",
90
101
  "trakr": "^0.2.0",
91
- "typescript": "^5.0.3",
92
- "vitest": "^0.29.8"
102
+ "typescript": "^5.3.3",
103
+ "vitest": "^1.2.1"
93
104
  },
94
105
  "scripts": {
95
106
  "lint": "eslint --cache src --ext ts,js && eslint src/bin/*",
@@ -111,7 +122,7 @@
111
122
  "ignorePatterns": [
112
123
  "dist/",
113
124
  "node_modules/",
114
- "src/examples/zig",
125
+ "examples/zig",
115
126
  "build/"
116
127
  ],
117
128
  "env": {
@@ -127,10 +138,18 @@
127
138
  "parserOptions": {
128
139
  "project": [
129
140
  "./tsconfig.json",
130
- "./src/examples/js/tsconfig.json"
141
+ "./examples/js/tsconfig.json"
131
142
  ]
132
143
  }
133
144
  },
145
+ {
146
+ "files": [
147
+ "src/test/display.ts"
148
+ ],
149
+ "rules": {
150
+ "@typescript-eslint/no-unnecessary-type-assertion": "off"
151
+ }
152
+ },
134
153
  {
135
154
  "files": [
136
155
  "src/pkg/index.ts",
@@ -140,7 +159,8 @@
140
159
  "rules": {
141
160
  "no-control-regex": "off",
142
161
  "@typescript-eslint/no-empty-interface": "off",
143
- "@typescript-eslint/no-shadow": "off"
162
+ "@typescript-eslint/no-shadow": "off",
163
+ "@typescript-eslint/no-unsafe-declaration-merging": "off"
144
164
  }
145
165
  },
146
166
  {
@@ -156,12 +176,23 @@
156
176
  "src/test/benchmark*.ts"
157
177
  ],
158
178
  "rules": {
159
- "@typescript-eslint/no-unused-vars": "off"
179
+ "@typescript-eslint/no-unused-vars": "off",
180
+ "@typescript-eslint/no-redundant-type-constituents": "off"
181
+ }
182
+ },
183
+ {
184
+ "files": [
185
+ "src/pkg/protocol.test.ts"
186
+ ],
187
+ "rules": {
188
+ "jest/no-standalone-expect": "off",
189
+ "jest/no-conditional-expect": "off"
160
190
  }
161
191
  },
162
192
  {
163
193
  "files": [
164
- "src/test/*.test.ts"
194
+ "src/test/*.test.ts",
195
+ "src/test/regression/*.test.ts"
165
196
  ],
166
197
  "rules": {
167
198
  "jest/no-standalone-expect": "off"