@pkmn/engine 0.1.0-dev.02b7f810 → 0.1.0-dev.047d6e71

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 -3
  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 +160 -127
  24. package/package.json +56 -26
  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 +942 -403
  33. package/src/lib/common/rational.zig +357 -0
  34. package/src/lib/common/rng.zig +35 -26
  35. package/src/lib/common/util.zig +12 -0
  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 +5 -5
  40. package/src/lib/gen1/data/types.zig +10 -10
  41. package/src/lib/gen1/data.zig +106 -92
  42. package/src/lib/gen1/helpers.zig +577 -32
  43. package/src/lib/gen1/mechanics.zig +1153 -818
  44. package/src/lib/gen2/calc.zig +143 -0
  45. package/src/lib/gen2/chance.zig +1314 -0
  46. package/src/lib/gen2/data/items.zig +14 -20
  47. package/src/lib/gen2/data/moves.zig +664 -570
  48. package/src/lib/gen2/data/species.zig +2 -2
  49. package/src/lib/gen2/data/types.zig +137 -34
  50. package/src/lib/gen2/data.zig +134 -96
  51. package/src/lib/gen2/generated.zig +806 -0
  52. package/src/lib/gen2/helpers.zig +16 -22
  53. package/src/lib/gen2/mechanics.zig +3591 -12
  54. package/src/lib/node.zig +131 -0
  55. package/src/lib/pkmn.zig +91 -9
  56. package/src/lib/wasm.zig +13 -0
  57. package/src/lib/binding/node.zig +0 -229
  58. package/src/lib/binding/wasm.zig +0 -10
  59. package/src/lib/gen1/README.md +0 -791
  60. package/src/lib/gen2/README.md +0 -309
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,87 +66,111 @@ 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
- // TODO(ziglang/zig#2231): using the following used to work (though was hacky):
87
+ // TODO: ziglang/zig#2231 - using the following used to work (though was hacky):
76
88
  //
77
89
  // lib.emit_bin = .{ .emit_to = b.fmt("build/lib/{s}", .{addon}) };
78
90
  // b.getInstallStep().dependOn(&lib.step);
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
 
@@ -147,7 +183,11 @@ pub fn build(b: *std.Build) !void {
147
183
  b.getInstallStep().dependOn(&header.step);
148
184
 
149
185
  const pc = b.fmt("lib{s}.pc", .{name});
150
- const file = try b.cache_root.join(b.allocator, &.{pc});
186
+ const file = try std.fs.path.relative(
187
+ b.allocator,
188
+ try std.process.getCwdAlloc(b.allocator),
189
+ try b.cache_root.join(b.allocator, &.{pc}),
190
+ );
151
191
  const pkgconfig_file = try std.fs.cwd().createFile(file, .{});
152
192
 
153
193
  const dirname = comptime std.fs.path.dirname(@src().file) orelse ".";
@@ -176,14 +216,20 @@ pub fn build(b: *std.Build) !void {
176
216
  .strip = strip,
177
217
  .cmd = cmd,
178
218
  };
219
+
220
+ // TODO: tests can be run multiple times due to @imports
179
221
  const tests = TestStep.create(b, options, config);
180
222
 
181
- var exes = std.ArrayList(*std.Build.CompileStep).init(b.allocator);
223
+ var exes = std.ArrayList(*std.Build.Step.Compile).init(b.allocator);
182
224
  const tools: ToolConfig = .{
225
+ .options = .{
226
+ .showdown = showdown,
227
+ .log = log,
228
+ .chance = chance,
229
+ .calc = calc,
230
+ },
183
231
  .general = config,
184
232
  .tool = .{
185
- .showdown = showdown,
186
- .trace = trace,
187
233
  .tests = if (tests.build) tests else null,
188
234
  .exes = &exes,
189
235
  },
@@ -192,39 +238,42 @@ pub fn build(b: *std.Build) !void {
192
238
  var benchmark_config = tools;
193
239
  benchmark_config.general.optimize = .ReleaseFast;
194
240
  benchmark_config.general.strip = true;
195
- const benchmark = tool(b, "src/test/benchmark.zig", benchmark_config);
241
+ const benchmark = try tool(b, "src/test/benchmark.zig", benchmark_config);
196
242
 
197
243
  var fuzz_config = tools;
198
244
  fuzz_config.general.strip = false;
199
245
  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);
246
+ const fuzz = try tool(b, "src/test/fuzz.zig", fuzz_config);
247
+
248
+ const analyze = try tool(b, "src/tools/analyze.zig", tools);
249
+ const dump = try tool(b, "src/tools/dump.zig", tools);
250
+ const transitions = try tool(b, "src/tools/transitions.zig", tools);
251
+
252
+ // FIXME: serde randomly fails to build in some release configurations
253
+ var hack = tools;
254
+ if (optimize != .Debug) hack.tool.tests = null;
255
+ const serde = try tool(b, "src/tools/serde.zig", hack);
256
+
257
+ if (analyze) |t| b.step("analyze", "Run LLVM analysis tool").dependOn(&t.step);
258
+ if (benchmark) |t| b.step("benchmark", "Run benchmark code").dependOn(&t.step);
259
+ if (dump) |t| b.step("dump", "Run protocol dump tool").dependOn(&t.step);
260
+ if (fuzz) |t| b.step("fuzz", "Run fuzz tester").dependOn(&t.step);
261
+ if (serde) |t| b.step("serde", "Run serialization/deserialization tool").dependOn(&t.step);
215
262
  b.step("test", "Run all tests").dependOn(&tests.step);
216
263
  b.step("tools", "Install tools").dependOn(&ToolsStep.create(b, &exes).step);
264
+ if (transitions) |t| {
265
+ b.step("transitions", "Visualize transitions algorithm search").dependOn(&t.step);
266
+ }
217
267
  }
218
268
 
219
269
  fn maybeStrip(
220
270
  b: *std.Build,
221
- artifact: *std.Build.CompileStep,
271
+ artifact: *std.Build.Step.Compile,
222
272
  step: *std.Build.Step,
223
- strip: bool,
273
+ strip: ?bool,
224
274
  cmd: ?[]const u8,
225
275
  ) void {
226
- artifact.strip = strip;
227
- if (!strip or cmd == null) return;
276
+ if (!(strip orelse false) or cmd == null) return;
228
277
  // Using `strip -r -u` for dynamic libraries is supposed to work on macOS but doesn't...
229
278
  const mac = builtin.os.tag == .macos;
230
279
  if (mac and artifact.isDynamicLibrary()) return;
@@ -236,97 +285,81 @@ fn maybeStrip(
236
285
  }
237
286
 
238
287
  const Config = struct {
239
- target: std.zig.CrossTarget,
288
+ target: std.Build.ResolvedTarget,
240
289
  optimize: std.builtin.OptimizeMode,
241
- pic: bool,
242
- strip: bool,
290
+ pic: ?bool,
291
+ strip: ?bool,
243
292
  cmd: ?[]const u8,
244
293
  };
245
294
 
246
- const TESTS = .{
247
- "src/lib/common/test.zig",
248
- "src/lib/gen1/test.zig",
249
- "src/lib/gen2/test.zig",
250
- };
251
-
252
295
  const TestStep = struct {
253
296
  step: std.Build.Step,
254
297
  build: bool,
255
298
 
256
- pub fn create(b: *std.Build, options: *std.Build.OptionsStep, config: Config) *TestStep {
299
+ pub fn create(b: *std.Build, options: *std.Build.Step.Options, config: Config) *TestStep {
257
300
  const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
258
- 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
301
  const test_filter =
261
302
  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
303
 
265
304
  const self = b.allocator.create(TestStep) catch @panic("OOM");
266
305
  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);
306
+ self.* = .{ .step = step, .build = test_filter == null };
307
+
308
+ const tests = b.addTest(.{
309
+ .root_source_file = .{ .path = "src/lib/test.zig" },
310
+ .optimize = config.optimize,
311
+ .target = config.target,
312
+ .filter = test_filter,
313
+ .single_threaded = true,
314
+ .strip = config.strip,
315
+ .pic = config.pic,
316
+ });
317
+ tests.root_module.addOptions("build_options", options);
318
+ maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
319
+ if (coverage) |c| {
320
+ tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
292
321
  }
322
+ self.step.dependOn(&b.addRunArtifact(tests).step);
323
+
293
324
  return self;
294
325
  }
295
326
  };
296
327
 
297
328
  const ToolConfig = struct {
329
+ options: Options,
298
330
  general: Config,
299
331
  tool: struct {
300
- showdown: bool,
301
- trace: bool,
302
332
  tests: ?*TestStep,
303
333
  name: ?[]const u8 = null,
304
- exes: *std.ArrayList(*std.Build.CompileStep),
334
+ exes: *std.ArrayList(*std.Build.Step.Compile),
305
335
  },
306
336
  };
307
337
 
308
- fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep {
338
+ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.Step.Run {
339
+ std.fs.cwd().access(path, .{}) catch |err| switch (err) {
340
+ error.FileNotFound => return null,
341
+ else => |e| return e,
342
+ };
309
343
  var name = config.tool.name orelse std.fs.path.basename(path);
310
344
  const index = std.mem.lastIndexOfScalar(u8, name, '.');
311
345
  if (index) |i| name = name[0..i];
312
- if (config.tool.showdown) name = b.fmt("{s}-showdown", .{name});
346
+ if (config.options.showdown orelse false) name = b.fmt("{s}-showdown", .{name});
313
347
 
314
348
  const exe = b.addExecutable(.{
315
349
  .name = name,
316
350
  .root_source_file = .{ .path = path },
317
351
  .target = config.general.target,
318
352
  .optimize = config.general.optimize,
353
+ .single_threaded = true,
354
+ .strip = config.general.strip,
355
+ .pic = config.general.pic,
319
356
  });
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;
357
+ exe.root_module.addImport("pkmn", module(b, config.options));
358
+
326
359
  if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
327
360
  config.tool.exes.append(exe) catch @panic("OOM");
328
361
 
329
- const run = exe.run();
362
+ const run = b.addRunArtifact(exe);
330
363
  maybeStrip(b, exe, &run.step, config.general.strip, config.general.cmd);
331
364
  if (b.args) |args| run.addArgs(args);
332
365
 
@@ -336,11 +369,11 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
336
369
  const ToolsStep = struct {
337
370
  step: std.Build.Step,
338
371
 
339
- pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.CompileStep)) *ToolsStep {
372
+ pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.Step.Compile)) *ToolsStep {
340
373
  const self = b.allocator.create(ToolsStep) catch @panic("OOM");
341
374
  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);
375
+ self.* = .{ .step = step };
376
+ for (exes.items) |t| self.step.dependOn(&b.addInstallArtifact(t, .{}).step);
344
377
  return self;
345
378
  }
346
379
  };
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.047d6e71",
4
4
  "description": "A minimal, complete, Pokémon battle simulation engine optimized for performance",
5
5
  "repository": "github:pkmn/engine",
6
6
  "license": "MIT",
@@ -31,28 +31,37 @@
31
31
  "build/test/display.js",
32
32
  "build/tools/debug.js.map",
33
33
  "build/tools/debug.js",
34
- "src/bin/install-pkmn-engine",
35
- "src/lib/binding/node.zig",
36
- "src/lib/binding/wasm.zig",
34
+ "src/lib/common/battle.zig",
37
35
  "src/lib/common/data.zig",
38
36
  "src/lib/common/debug.zig",
37
+ "src/lib/common/js.zig",
38
+ "src/lib/common/optional.zig",
39
39
  "src/lib/common/options.zig",
40
40
  "src/lib/common/protocol.zig",
41
+ "src/lib/common/rational.zig",
41
42
  "src/lib/common/rng.zig",
43
+ "src/lib/common/util.zig",
44
+ "src/lib/gen1/calc.zig",
45
+ "src/lib/gen1/chance.zig",
42
46
  "src/lib/gen1/data.zig",
43
47
  "src/lib/gen1/data/moves.zig",
44
48
  "src/lib/gen1/data/species.zig",
45
49
  "src/lib/gen1/data/types.zig",
46
50
  "src/lib/gen1/helpers.zig",
47
51
  "src/lib/gen1/mechanics.zig",
52
+ "src/lib/gen2/calc.zig",
53
+ "src/lib/gen2/chance.zig",
48
54
  "src/lib/gen2/data.zig",
49
55
  "src/lib/gen2/data/items.zig",
50
56
  "src/lib/gen2/data/moves.zig",
51
57
  "src/lib/gen2/data/species.zig",
52
58
  "src/lib/gen2/data/types.zig",
59
+ "src/lib/gen2/generated.zig",
53
60
  "src/lib/gen2/helpers.zig",
54
61
  "src/lib/gen2/mechanics.zig",
62
+ "src/lib/node.zig",
55
63
  "src/lib/pkmn.zig",
64
+ "src/lib/wasm.zig",
56
65
  "src/test/display/pkmn.html.tmpl"
57
66
  ],
58
67
  "engines": {
@@ -66,30 +75,31 @@
66
75
  "access": "public"
67
76
  },
68
77
  "dependencies": {
69
- "@pkmn/data": "^0.7.36",
70
- "@pkmn/protocol": "^0.6.11"
78
+ "@pkmn/data": "^0.8.9",
79
+ "@pkmn/protocol": "^0.6.19"
71
80
  },
72
81
  "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",
82
+ "@pkmn/eslint-config": "^7.1.0",
83
+ "@pkmn/img": "^0.2.25",
84
+ "@pkmn/sets": "^5.1.2",
85
+ "@pkmn/sim": "0.8.9",
86
+ "@types/html-minifier": "^4.0.5",
87
+ "@types/jest": "^29.5.12",
88
+ "@types/minimist": "^1.2.5",
89
+ "@types/mustache": "^4.2.5",
90
+ "@types/node": "^20.11.25",
91
+ "@vitest/coverage-v8": "^1.3.1",
92
+ "binaryen": "^116.0.0",
93
+ "eslint": "^8.57.0",
85
94
  "html-minifier": "^4.0.0",
86
- "json-stringify-pretty-compact": "3.0.0",
95
+ "json-stringify-pretty-compact": "4.0.0",
87
96
  "minimist": "^1.2.8",
88
97
  "mustache": "^4.2.0",
89
98
  "source-map-support": "^0.5.21",
99
+ "table": "^6.8.1",
90
100
  "trakr": "^0.2.0",
91
- "typescript": "^5.0.3",
92
- "vitest": "^0.29.8"
101
+ "typescript": "^5.4.2",
102
+ "vitest": "^1.3.1"
93
103
  },
94
104
  "scripts": {
95
105
  "lint": "eslint --cache src --ext ts,js && eslint src/bin/*",
@@ -111,7 +121,7 @@
111
121
  "ignorePatterns": [
112
122
  "dist/",
113
123
  "node_modules/",
114
- "src/examples/zig",
124
+ "examples/zig",
115
125
  "build/"
116
126
  ],
117
127
  "env": {
@@ -127,10 +137,18 @@
127
137
  "parserOptions": {
128
138
  "project": [
129
139
  "./tsconfig.json",
130
- "./src/examples/js/tsconfig.json"
140
+ "./examples/js/tsconfig.json"
131
141
  ]
132
142
  }
133
143
  },
144
+ {
145
+ "files": [
146
+ "src/test/display.ts"
147
+ ],
148
+ "rules": {
149
+ "@typescript-eslint/no-unnecessary-type-assertion": "off"
150
+ }
151
+ },
134
152
  {
135
153
  "files": [
136
154
  "src/pkg/index.ts",
@@ -140,7 +158,8 @@
140
158
  "rules": {
141
159
  "no-control-regex": "off",
142
160
  "@typescript-eslint/no-empty-interface": "off",
143
- "@typescript-eslint/no-shadow": "off"
161
+ "@typescript-eslint/no-shadow": "off",
162
+ "@typescript-eslint/no-unsafe-declaration-merging": "off"
144
163
  }
145
164
  },
146
165
  {
@@ -156,12 +175,23 @@
156
175
  "src/test/benchmark*.ts"
157
176
  ],
158
177
  "rules": {
159
- "@typescript-eslint/no-unused-vars": "off"
178
+ "@typescript-eslint/no-unused-vars": "off",
179
+ "@typescript-eslint/no-redundant-type-constituents": "off"
180
+ }
181
+ },
182
+ {
183
+ "files": [
184
+ "src/pkg/protocol.test.ts"
185
+ ],
186
+ "rules": {
187
+ "jest/no-standalone-expect": "off",
188
+ "jest/no-conditional-expect": "off"
160
189
  }
161
190
  },
162
191
  {
163
192
  "files": [
164
- "src/test/*.test.ts"
193
+ "src/test/*.test.ts",
194
+ "src/test/regression/*.test.ts"
165
195
  ],
166
196
  "rules": {
167
197
  "jest/no-standalone-expect": "off"