@pkmn/engine 0.1.0-dev.3a273268 → 0.1.0-dev.3a62fd35

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 (59) hide show
  1. package/README.md +99 -65
  2. package/build/pkg/addon.d.ts +1 -1
  3. package/build/pkg/addon.js +7 -6
  4. package/build/pkg/addon.js.map +1 -1
  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 +3 -2
  9. package/build/pkg/data.js.map +1 -1
  10. package/build/pkg/gen1.d.ts +5 -4
  11. package/build/pkg/gen1.js +48 -32
  12. package/build/pkg/gen1.js.map +1 -1
  13. package/build/pkg/index.d.ts +17 -13
  14. package/build/pkg/index.js.map +1 -1
  15. package/build/pkg/protocol.d.ts +4 -2
  16. package/build/pkg/protocol.js +61 -40
  17. package/build/pkg/protocol.js.map +1 -1
  18. package/build/test/display.js +31 -13
  19. package/build/test/display.js.map +1 -1
  20. package/build/tools/debug.js +3 -1
  21. package/build/tools/debug.js.map +1 -1
  22. package/build.zig +158 -125
  23. package/package.json +47 -24
  24. package/src/bin/install-pkmn-engine +24 -19
  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 +932 -395
  32. package/src/lib/common/rational.zig +357 -0
  33. package/src/lib/common/rng.zig +29 -20
  34. package/src/lib/common/util.zig +12 -0
  35. package/src/lib/gen1/README.md +285 -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 +101 -87
  42. package/src/lib/gen1/helpers.zig +577 -32
  43. package/src/lib/gen1/mechanics.zig +1048 -737
  44. package/src/lib/gen2/README.md +105 -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 +130 -92
  52. package/src/lib/gen2/generated.zig +806 -0
  53. package/src/lib/gen2/helpers.zig +16 -22
  54. package/src/lib/gen2/mechanics.zig +3506 -12
  55. package/src/lib/node.zig +131 -0
  56. package/src/lib/pkmn.zig +88 -6
  57. package/src/lib/wasm.zig +13 -0
  58. package/src/lib/binding/node.zig +0 -229
  59. 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,28 +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");
30
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;
31
39
 
32
40
  const cmd = b.findProgram(&.{"strip"}, &.{}) catch null;
33
41
 
34
- var parser = std.json.Parser.init(b.allocator, false);
35
- defer parser.deinit();
36
- var tree = try parser.parse(@embedFile("package.json"));
37
- defer tree.deinit();
38
- const version = tree.root.Object.get("version").?.String;
39
- const description = tree.root.Object.get("description").?.String;
40
- 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, ":");
41
48
  std.debug.assert(std.mem.eql(u8, repository.first(), "github"));
42
49
 
43
50
  const showdown =
44
51
  b.option(bool, "showdown", "Enable Pokémon Showdown compatibility mode") orelse false;
45
- 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;
46
55
 
47
56
  const options = b.addOptions();
48
57
  options.addOption(?bool, "showdown", showdown);
49
- options.addOption(?bool, "trace", trace);
58
+ options.addOption(?bool, "log", log);
59
+ options.addOption(?bool, "chance", chance);
60
+ options.addOption(?bool, "calc", calc);
50
61
 
51
62
  const name = if (showdown) "pkmn-showdown" else "pkmn";
52
63
 
@@ -55,23 +66,23 @@ pub fn build(b: *std.Build) !void {
55
66
  const addon = b.fmt("{s}.node", .{name});
56
67
  const lib = b.addSharedLibrary(.{
57
68
  .name = addon,
58
- .root_source_file = .{ .path = "src/lib/binding/node.zig" },
69
+ .root_source_file = .{ .path = "src/lib/node.zig" },
59
70
  .optimize = optimize,
60
71
  .target = target,
72
+ .strip = strip,
73
+ .pic = pic,
61
74
  });
62
- lib.addOptions("build_options", options);
63
- lib.setMainPkgPath("./");
64
- lib.addSystemIncludePath(headers);
75
+ lib.root_module.addOptions("build_options", options);
76
+ lib.addSystemIncludePath(.{ .path = headers });
65
77
  lib.linkLibC();
66
78
  if (node_import_lib) |il| {
67
- lib.addObjectFile(il);
68
- } 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) {
69
81
  try std.io.getStdErr().writeAll("Must provide --node-import-library path on Windows\n");
70
82
  std.process.exit(1);
71
83
  }
72
84
  lib.linker_allow_shlib_undefined = true;
73
85
  maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
74
- if (pic) lib.force_pic = pic;
75
86
  // Always emit to build/lib because this is where the driver code expects to find it
76
87
  // TODO(ziglang/zig#2231): using the following used to work (though was hacky):
77
88
  //
@@ -80,63 +91,86 @@ pub fn build(b: *std.Build) !void {
80
91
  //
81
92
  // But ziglang/zig#14647 broke this so we now need to do an install() and then manually
82
93
  // rename the file ourself in install-pkmn-engine
83
- lib.install();
94
+ b.installArtifact(lib);
84
95
  } else if (wasm) {
85
- const lib = b.addSharedLibrary(.{
96
+ const exe = b.addExecutable(.{
86
97
  .name = name,
87
- .root_source_file = .{ .path = "src/lib/binding/wasm.zig" },
98
+ .root_source_file = .{ .path = "src/lib/wasm.zig" },
88
99
  .optimize = switch (optimize) {
89
100
  .ReleaseFast, .ReleaseSafe => .ReleaseSmall,
90
101
  else => optimize,
91
102
  },
92
- .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
103
+ .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
104
+ .strip = strip,
105
+ .pic = pic,
93
106
  });
94
- lib.addOptions("build_options", options);
95
- lib.setMainPkgPath("./");
96
- lib.stack_size = wasm_stack_size;
97
- lib.rdynamic = true;
98
- lib.strip = strip;
99
- 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;
100
118
  const opt = b.findProgram(&.{"wasm-opt"}, &.{"./node_modules/.bin"}) catch null;
101
119
  if (optimize != .Debug and opt != null) {
102
120
  const out = b.fmt("build/lib/{s}.wasm", .{name});
103
121
  const sh = b.addSystemCommand(&.{ opt.?, "-O4" });
104
- sh.addArtifactArg(lib);
122
+ sh.addArtifactArg(exe);
105
123
  sh.addArg("-o");
106
- sh.addFileSourceArg(.{ .path = out });
124
+ sh.addFileArg(.{ .path = out });
107
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);
108
130
  }
109
- lib.install();
110
131
  } else if (dynamic) {
111
132
  const lib = b.addSharedLibrary(.{
112
133
  .name = name,
113
- .root_source_file = .{ .path = "src/lib/binding/c.zig" },
114
- .version = try std.builtin.Version.parse(version),
134
+ .root_source_file = .{ .path = "src/lib/c.zig" },
135
+ .version = try std.SemanticVersion.parse(version),
115
136
  .optimize = optimize,
116
137
  .target = target,
138
+ .strip = strip,
139
+ .pic = pic,
117
140
  });
118
- lib.addOptions("build_options", options);
119
- lib.setMainPkgPath("./");
120
- lib.addIncludePath("src/include");
141
+ lib.root_module.addOptions("build_options", options);
142
+ lib.addIncludePath(.{ .path = "src/include" });
121
143
  maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
122
- if (pic) lib.force_pic = pic;
123
- lib.install();
144
+ b.installArtifact(lib);
124
145
  c = true;
125
146
  } else {
126
147
  const lib = b.addStaticLibrary(.{
127
148
  .name = name,
128
- .root_source_file = .{ .path = "src/lib/binding/c.zig" },
149
+ .root_source_file = .{ .path = "src/lib/c.zig" },
129
150
  .optimize = optimize,
130
151
  .target = target,
152
+ .strip = strip,
153
+ .pic = pic,
131
154
  });
132
- lib.addOptions("build_options", options);
133
- lib.setMainPkgPath("./");
134
- lib.addIncludePath("src/include");
155
+ lib.root_module.addOptions("build_options", options);
156
+ lib.addIncludePath(.{ .path = "src/include" });
135
157
  lib.bundle_compiler_rt = true;
136
158
  maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
137
- if (pic) lib.force_pic = pic;
138
- if (emit_asm) lib.emit_asm = .emit;
139
- 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);
140
174
  c = true;
141
175
  }
142
176
 
@@ -178,14 +212,20 @@ pub fn build(b: *std.Build) !void {
178
212
  .strip = strip,
179
213
  .cmd = cmd,
180
214
  };
215
+
216
+ // TODO: tests can be run multiple times due to @imports
181
217
  const tests = TestStep.create(b, options, config);
182
218
 
183
- var exes = std.ArrayList(*std.Build.CompileStep).init(b.allocator);
219
+ var exes = std.ArrayList(*std.Build.Step.Compile).init(b.allocator);
184
220
  const tools: ToolConfig = .{
221
+ .options = .{
222
+ .showdown = showdown,
223
+ .log = log,
224
+ .chance = chance,
225
+ .calc = calc,
226
+ },
185
227
  .general = config,
186
228
  .tool = .{
187
- .showdown = showdown,
188
- .trace = trace,
189
229
  .tests = if (tests.build) tests else null,
190
230
  .exes = &exes,
191
231
  },
@@ -194,39 +234,42 @@ pub fn build(b: *std.Build) !void {
194
234
  var benchmark_config = tools;
195
235
  benchmark_config.general.optimize = .ReleaseFast;
196
236
  benchmark_config.general.strip = true;
197
- const benchmark = tool(b, "src/test/benchmark.zig", benchmark_config);
237
+ const benchmark = try tool(b, "src/test/benchmark.zig", benchmark_config);
198
238
 
199
239
  var fuzz_config = tools;
200
240
  fuzz_config.general.strip = false;
201
241
  fuzz_config.tool.name = "fuzz";
202
- const fuzz = tool(b, "src/test/benchmark.zig", fuzz_config);
203
-
204
- const serde = tool(b, "src/tools/serde.zig", tools);
205
- const protocol = tool(b, "src/tools/protocol.zig", tools);
206
-
207
- const lint_exe =
208
- b.addExecutable(.{ .name = "lint", .root_source_file = .{ .path = "src/tools/lint.zig" } });
209
- if (tests.build) tests.step.dependOn(&lint_exe.step);
210
- const lint = lint_exe.run();
211
-
212
- b.step("benchmark", "Run benchmark code").dependOn(&benchmark.step);
213
- b.step("fuzz", "Run fuzz tester").dependOn(&fuzz.step);
214
- b.step("lint", "Lint source files").dependOn(&lint.step);
215
- b.step("protocol", "Run protocol dump tool").dependOn(&protocol.step);
216
- 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);
217
258
  b.step("test", "Run all tests").dependOn(&tests.step);
218
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
+ }
219
263
  }
220
264
 
221
265
  fn maybeStrip(
222
266
  b: *std.Build,
223
- artifact: *std.Build.CompileStep,
267
+ artifact: *std.Build.Step.Compile,
224
268
  step: *std.Build.Step,
225
- strip: bool,
269
+ strip: ?bool,
226
270
  cmd: ?[]const u8,
227
271
  ) void {
228
- artifact.strip = strip;
229
- if (!strip or cmd == null) return;
272
+ if (!(strip orelse false) or cmd == null) return;
230
273
  // Using `strip -r -u` for dynamic libraries is supposed to work on macOS but doesn't...
231
274
  const mac = builtin.os.tag == .macos;
232
275
  if (mac and artifact.isDynamicLibrary()) return;
@@ -238,97 +281,87 @@ fn maybeStrip(
238
281
  }
239
282
 
240
283
  const Config = struct {
241
- target: std.zig.CrossTarget,
284
+ target: std.Build.ResolvedTarget,
242
285
  optimize: std.builtin.OptimizeMode,
243
- pic: bool,
244
- strip: bool,
286
+ pic: ?bool,
287
+ strip: ?bool,
245
288
  cmd: ?[]const u8,
246
289
  };
247
290
 
248
- const TESTS = .{
249
- "src/lib/common/test.zig",
250
- "src/lib/gen1/test.zig",
251
- "src/lib/gen2/test.zig",
252
- };
253
-
254
291
  const TestStep = struct {
255
292
  step: std.Build.Step,
256
293
  build: bool,
257
294
 
258
- 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 {
259
296
  const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
260
297
  const test_file = b.option([]const u8, "test-file", "Input file for test");
261
- const test_bin = b.option([]const u8, "test-bin", "Emit test binary to");
262
298
  const test_filter =
263
299
  b.option([]const u8, "test-filter", "Skip tests that do not match filter");
264
- const test_no_exec =
265
- b.option(bool, "test-no-exec", "Compiles test binary without running it") orelse false;
266
300
 
267
301
  const self = b.allocator.create(TestStep) catch @panic("OOM");
268
302
  const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
269
- self.* = TestStep{ .step = step, .build = test_filter == null };
270
-
271
- const paths: []const []const u8 =
272
- if (test_file) |t| &.{t} else if (coverage != null) &.{"src/lib/test.zig"} else &TESTS;
273
- for (paths) |path| {
274
- const tests = b.addTest(.{
275
- .name = std.fs.path.basename(std.fs.path.dirname(path).?),
276
- .root_source_file = .{ .path = path },
277
- .optimize = config.optimize,
278
- .target = config.target,
279
- });
280
- tests.setMainPkgPath("./");
281
- tests.setFilter(test_filter);
282
- tests.addOptions("build_options", options);
283
- tests.single_threaded = true;
284
- maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
285
- if (config.pic) tests.force_pic = config.pic;
286
- if (test_bin) |bin| {
287
- tests.name = std.fs.path.basename(bin);
288
- if (std.fs.path.dirname(bin)) |dir| tests.setOutputDir(dir);
289
- }
290
- if (coverage) |c| {
291
- tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
292
- }
293
- 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 });
294
323
  }
324
+ self.step.dependOn(&b.addRunArtifact(tests).step);
325
+
295
326
  return self;
296
327
  }
297
328
  };
298
329
 
299
330
  const ToolConfig = struct {
331
+ options: Options,
300
332
  general: Config,
301
333
  tool: struct {
302
- showdown: bool,
303
- trace: bool,
304
334
  tests: ?*TestStep,
305
335
  name: ?[]const u8 = null,
306
- exes: *std.ArrayList(*std.Build.CompileStep),
336
+ exes: *std.ArrayList(*std.Build.Step.Compile),
307
337
  },
308
338
  };
309
339
 
310
- 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
+ };
311
345
  var name = config.tool.name orelse std.fs.path.basename(path);
312
346
  const index = std.mem.lastIndexOfScalar(u8, name, '.');
313
347
  if (index) |i| name = name[0..i];
314
- if (config.tool.showdown) name = b.fmt("{s}-showdown", .{name});
348
+ if (config.options.showdown orelse false) name = b.fmt("{s}-showdown", .{name});
315
349
 
316
350
  const exe = b.addExecutable(.{
317
351
  .name = name,
318
352
  .root_source_file = .{ .path = path },
319
353
  .target = config.general.target,
320
354
  .optimize = config.general.optimize,
355
+ .single_threaded = true,
356
+ .strip = config.general.strip,
357
+ .pic = config.general.pic,
321
358
  });
322
- exe.addModule("pkmn", module(b, .{
323
- .showdown = config.tool.showdown,
324
- .trace = config.tool.trace,
325
- }));
326
- exe.single_threaded = true;
327
- if (config.general.pic) exe.force_pic = config.general.pic;
359
+ exe.root_module.addImport("pkmn", module(b, config.options));
360
+
328
361
  if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
329
362
  config.tool.exes.append(exe) catch @panic("OOM");
330
363
 
331
- const run = exe.run();
364
+ const run = b.addRunArtifact(exe);
332
365
  maybeStrip(b, exe, &run.step, config.general.strip, config.general.cmd);
333
366
  if (b.args) |args| run.addArgs(args);
334
367
 
@@ -338,11 +371,11 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
338
371
  const ToolsStep = struct {
339
372
  step: std.Build.Step,
340
373
 
341
- 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 {
342
375
  const self = b.allocator.create(ToolsStep) catch @panic("OOM");
343
376
  const step = std.Build.Step.init(.{ .id = .custom, .name = "Install tools", .owner = b });
344
- self.* = ToolsStep{ .step = step };
345
- 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);
346
379
  return self;
347
380
  }
348
381
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pkmn/engine",
3
- "version": "0.1.0-dev.3a273268",
3
+ "version": "0.1.0-dev.3a62fd35",
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.1",
80
+ "@pkmn/protocol": "^0.6.17"
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.4.0",
84
+ "@pkmn/img": "^0.2.20",
85
+ "@pkmn/sets": "^5.1.0",
86
+ "@pkmn/sim": "0.8.1",
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.10.5",
92
+ "@vitest/coverage-v8": "^1.0.4",
93
+ "binaryen": "^116.0.0",
94
+ "eslint": "^8.56.0",
85
95
  "html-minifier": "^4.0.0",
86
96
  "json-stringify-pretty-compact": "3.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.0.4"
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,7 +138,7 @@
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
  },
@@ -140,7 +151,8 @@
140
151
  "rules": {
141
152
  "no-control-regex": "off",
142
153
  "@typescript-eslint/no-empty-interface": "off",
143
- "@typescript-eslint/no-shadow": "off"
154
+ "@typescript-eslint/no-shadow": "off",
155
+ "@typescript-eslint/no-unsafe-declaration-merging": "off"
144
156
  }
145
157
  },
146
158
  {
@@ -156,12 +168,23 @@
156
168
  "src/test/benchmark*.ts"
157
169
  ],
158
170
  "rules": {
159
- "@typescript-eslint/no-unused-vars": "off"
171
+ "@typescript-eslint/no-unused-vars": "off",
172
+ "@typescript-eslint/no-redundant-type-constituents": "off"
160
173
  }
161
174
  },
162
175
  {
163
176
  "files": [
164
- "src/test/*.test.ts"
177
+ "src/pkg/protocol.test.ts"
178
+ ],
179
+ "rules": {
180
+ "jest/no-standalone-expect": "off",
181
+ "jest/no-conditional-expect": "off"
182
+ }
183
+ },
184
+ {
185
+ "files": [
186
+ "src/test/*.test.ts",
187
+ "src/test/regression/*.test.ts"
165
188
  ],
166
189
  "rules": {
167
190
  "jest/no-standalone-expect": "off"