@pkmn/engine 0.1.0-dev.954f650d → 0.1.0-dev.95e81bfe
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -3
- package/README.md +37 -14
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data/ids.json +12 -12
- package/build/pkg/data/layout.json +2 -2
- package/build/pkg/data/protocol.json +69 -12
- package/build/pkg/data.d.ts +3 -2
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.js +2 -2
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +2 -1
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.js +57 -38
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js.map +1 -1
- package/build/tools/debug.js +3 -1
- package/build/tools/debug.js.map +1 -1
- package/build.zig +80 -70
- package/package.json +43 -23
- package/src/bin/install-pkmn-engine +14 -14
- package/src/lib/common/data.zig +9 -9
- package/src/lib/common/optional.zig +9 -2
- package/src/lib/common/protocol.zig +734 -318
- package/src/lib/common/rational.zig +12 -8
- package/src/lib/common/rng.zig +25 -16
- package/src/lib/gen1/README.md +28 -28
- package/src/lib/gen1/calc.zig +9 -9
- package/src/lib/gen1/chance.zig +72 -48
- package/src/lib/gen1/data/moves.zig +24 -10
- package/src/lib/gen1/data/species.zig +3 -3
- package/src/lib/gen1/data/types.zig +7 -7
- package/src/lib/gen1/data.zig +41 -41
- package/src/lib/gen1/helpers.zig +33 -48
- package/src/lib/gen1/mechanics.zig +340 -355
- package/src/lib/gen2/README.md +18 -72
- package/src/lib/gen2/calc.zig +143 -0
- package/src/lib/gen2/chance.zig +1314 -0
- package/src/lib/gen2/data/items.zig +12 -18
- package/src/lib/gen2/data/moves.zig +69 -36
- package/src/lib/gen2/data/species.zig +1 -1
- package/src/lib/gen2/data/types.zig +134 -31
- package/src/lib/gen2/data.zig +52 -44
- package/src/lib/gen2/generated.zig +806 -0
- package/src/lib/gen2/mechanics.zig +2935 -244
- package/src/lib/{binding/node.zig → node.zig} +10 -13
- package/src/lib/pkmn.zig +26 -3
- package/src/lib/{binding/wasm.zig → wasm.zig} +2 -1
package/build.zig
CHANGED
|
@@ -16,8 +16,8 @@ pub fn module(b: *std.Build, options: Options) *std.Build.Module {
|
|
|
16
16
|
build_options.addOption(?bool, "chance", options.chance);
|
|
17
17
|
build_options.addOption(?bool, "calc", options.calc);
|
|
18
18
|
return b.createModule(.{
|
|
19
|
-
.
|
|
20
|
-
.
|
|
19
|
+
.root_source_file = .{ .path = dirname ++ "/src/lib/pkmn.zig" },
|
|
20
|
+
.imports = &.{.{ .name = "build_options", .module = build_options.createModule() }},
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -32,8 +32,8 @@ pub fn build(b: *std.Build) !void {
|
|
|
32
32
|
const wasm_stack_size =
|
|
33
33
|
b.option(u64, "wasm-stack-size", "The size of WASM stack") orelse std.wasm.page_size;
|
|
34
34
|
const dynamic = b.option(bool, "dynamic", "Build a dynamic library") 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")
|
|
35
|
+
const strip = b.option(bool, "strip", "Strip debugging symbols from binary");
|
|
36
|
+
const pic = b.option(bool, "pic", "Force position independent code");
|
|
37
37
|
const emit_asm = b.option(bool, "emit-asm", "Output .s (assembly code)") orelse false;
|
|
38
38
|
const emit_ll = b.option(bool, "emit-ll", "Output .ll (LLVM IR)") orelse false;
|
|
39
39
|
|
|
@@ -66,25 +66,25 @@ pub fn build(b: *std.Build) !void {
|
|
|
66
66
|
const addon = b.fmt("{s}.node", .{name});
|
|
67
67
|
const lib = b.addSharedLibrary(.{
|
|
68
68
|
.name = addon,
|
|
69
|
-
.
|
|
70
|
-
.root_source_file = .{ .path = "src/lib/binding/node.zig" },
|
|
69
|
+
.root_source_file = .{ .path = "src/lib/node.zig" },
|
|
71
70
|
.optimize = optimize,
|
|
72
71
|
.target = target,
|
|
72
|
+
.strip = strip,
|
|
73
|
+
.pic = pic,
|
|
73
74
|
});
|
|
74
|
-
lib.addOptions("build_options", options);
|
|
75
|
+
lib.root_module.addOptions("build_options", options);
|
|
75
76
|
lib.addSystemIncludePath(.{ .path = headers });
|
|
76
77
|
lib.linkLibC();
|
|
77
78
|
if (node_import_lib) |il| {
|
|
78
79
|
lib.addObjectFile(.{ .path = il });
|
|
79
|
-
} else if (
|
|
80
|
+
} else if (target.result.os.tag == .windows) {
|
|
80
81
|
try std.io.getStdErr().writeAll("Must provide --node-import-library path on Windows\n");
|
|
81
82
|
std.process.exit(1);
|
|
82
83
|
}
|
|
83
84
|
lib.linker_allow_shlib_undefined = true;
|
|
84
85
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
85
|
-
if (pic) lib.force_pic = pic;
|
|
86
86
|
// Always emit to build/lib because this is where the driver code expects to find it
|
|
87
|
-
// TODO
|
|
87
|
+
// TODO: ziglang/zig#2231 - using the following used to work (though was hacky):
|
|
88
88
|
//
|
|
89
89
|
// lib.emit_bin = .{ .emit_to = b.fmt("build/lib/{s}", .{addon}) };
|
|
90
90
|
// b.getInstallStep().dependOn(&lib.step);
|
|
@@ -93,59 +93,69 @@ pub fn build(b: *std.Build) !void {
|
|
|
93
93
|
// rename the file ourself in install-pkmn-engine
|
|
94
94
|
b.installArtifact(lib);
|
|
95
95
|
} else if (wasm) {
|
|
96
|
-
const
|
|
96
|
+
const exe = b.addExecutable(.{
|
|
97
97
|
.name = name,
|
|
98
|
-
.
|
|
99
|
-
.root_source_file = .{ .path = "src/lib/binding/wasm.zig" },
|
|
98
|
+
.root_source_file = .{ .path = "src/lib/wasm.zig" },
|
|
100
99
|
.optimize = switch (optimize) {
|
|
101
100
|
.ReleaseFast, .ReleaseSafe => .ReleaseSmall,
|
|
102
101
|
else => optimize,
|
|
103
102
|
},
|
|
104
|
-
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
|
|
103
|
+
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
|
|
104
|
+
.strip = strip,
|
|
105
|
+
.pic = pic,
|
|
105
106
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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;
|
|
111
118
|
const opt = b.findProgram(&.{"wasm-opt"}, &.{"./node_modules/.bin"}) catch null;
|
|
112
119
|
if (optimize != .Debug and opt != null) {
|
|
113
120
|
const out = b.fmt("build/lib/{s}.wasm", .{name});
|
|
114
121
|
const sh = b.addSystemCommand(&.{ opt.?, "-O4" });
|
|
115
|
-
sh.addArtifactArg(
|
|
122
|
+
sh.addArtifactArg(exe);
|
|
116
123
|
sh.addArg("-o");
|
|
117
|
-
sh.
|
|
124
|
+
sh.addFileArg(.{ .path = out });
|
|
118
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);
|
|
119
130
|
}
|
|
120
|
-
b.installArtifact(lib);
|
|
121
131
|
} else if (dynamic) {
|
|
122
132
|
const lib = b.addSharedLibrary(.{
|
|
123
133
|
.name = name,
|
|
124
|
-
.
|
|
125
|
-
.root_source_file = .{ .path = "src/lib/binding/c.zig" },
|
|
134
|
+
.root_source_file = .{ .path = "src/lib/c.zig" },
|
|
126
135
|
.version = try std.SemanticVersion.parse(version),
|
|
127
136
|
.optimize = optimize,
|
|
128
137
|
.target = target,
|
|
138
|
+
.strip = strip,
|
|
139
|
+
.pic = pic,
|
|
129
140
|
});
|
|
130
|
-
lib.addOptions("build_options", options);
|
|
141
|
+
lib.root_module.addOptions("build_options", options);
|
|
131
142
|
lib.addIncludePath(.{ .path = "src/include" });
|
|
132
143
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
133
|
-
if (pic) lib.force_pic = pic;
|
|
134
144
|
b.installArtifact(lib);
|
|
135
145
|
c = true;
|
|
136
146
|
} else {
|
|
137
147
|
const lib = b.addStaticLibrary(.{
|
|
138
148
|
.name = name,
|
|
139
|
-
.
|
|
140
|
-
.root_source_file = .{ .path = "src/lib/binding/c.zig" },
|
|
149
|
+
.root_source_file = .{ .path = "src/lib/c.zig" },
|
|
141
150
|
.optimize = optimize,
|
|
142
151
|
.target = target,
|
|
152
|
+
.strip = strip,
|
|
153
|
+
.pic = pic,
|
|
143
154
|
});
|
|
144
|
-
lib.addOptions("build_options", options);
|
|
155
|
+
lib.root_module.addOptions("build_options", options);
|
|
145
156
|
lib.addIncludePath(.{ .path = "src/include" });
|
|
146
157
|
lib.bundle_compiler_rt = true;
|
|
147
158
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
148
|
-
if (pic) lib.force_pic = pic;
|
|
149
159
|
if (emit_asm) {
|
|
150
160
|
b.getInstallStep().dependOn(&b.addInstallFileWithDir(
|
|
151
161
|
lib.getEmittedAsm(),
|
|
@@ -206,7 +216,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
206
216
|
// TODO: tests can be run multiple times due to @imports
|
|
207
217
|
const tests = TestStep.create(b, options, config);
|
|
208
218
|
|
|
209
|
-
var exes = std.ArrayList(*std.Build.
|
|
219
|
+
var exes = std.ArrayList(*std.Build.Step.Compile).init(b.allocator);
|
|
210
220
|
const tools: ToolConfig = .{
|
|
211
221
|
.options = .{
|
|
212
222
|
.showdown = showdown,
|
|
@@ -224,41 +234,42 @@ pub fn build(b: *std.Build) !void {
|
|
|
224
234
|
var benchmark_config = tools;
|
|
225
235
|
benchmark_config.general.optimize = .ReleaseFast;
|
|
226
236
|
benchmark_config.general.strip = true;
|
|
227
|
-
const benchmark = tool(b, "src/test/benchmark.zig", benchmark_config);
|
|
237
|
+
const benchmark = try tool(b, "src/test/benchmark.zig", benchmark_config);
|
|
228
238
|
|
|
229
239
|
var fuzz_config = tools;
|
|
230
240
|
fuzz_config.general.strip = false;
|
|
231
241
|
fuzz_config.tool.name = "fuzz";
|
|
232
|
-
const fuzz = tool(b, "src/test/fuzz.zig", fuzz_config);
|
|
242
|
+
const fuzz = try tool(b, "src/test/fuzz.zig", fuzz_config);
|
|
233
243
|
|
|
234
|
-
const analyze = tool(b, "src/tools/analyze.zig", tools);
|
|
235
|
-
const dump = tool(b, "src/tools/dump.zig", tools);
|
|
236
|
-
const transitions = tool(b, "src/tools/transitions.zig", tools);
|
|
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);
|
|
237
247
|
|
|
238
248
|
// FIXME: serde randomly fails to build in some release configurations
|
|
239
249
|
var hack = tools;
|
|
240
250
|
if (optimize != .Debug) hack.tool.tests = null;
|
|
241
|
-
const serde = tool(b, "src/tools/serde.zig", hack);
|
|
251
|
+
const serde = try tool(b, "src/tools/serde.zig", hack);
|
|
242
252
|
|
|
243
|
-
b.step("analyze", "Run LLVM analysis tool").dependOn(&
|
|
244
|
-
b.step("benchmark", "Run benchmark code").dependOn(&
|
|
245
|
-
b.step("dump", "Run protocol dump tool").dependOn(&
|
|
246
|
-
b.step("fuzz", "Run fuzz tester").dependOn(&
|
|
247
|
-
b.step("serde", "Run serialization/deserialization tool").dependOn(&
|
|
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);
|
|
248
258
|
b.step("test", "Run all tests").dependOn(&tests.step);
|
|
249
259
|
b.step("tools", "Install tools").dependOn(&ToolsStep.create(b, &exes).step);
|
|
250
|
-
|
|
260
|
+
if (transitions) |t| {
|
|
261
|
+
b.step("transitions", "Visualize transitions algorithm search").dependOn(&t.step);
|
|
262
|
+
}
|
|
251
263
|
}
|
|
252
264
|
|
|
253
265
|
fn maybeStrip(
|
|
254
266
|
b: *std.Build,
|
|
255
|
-
artifact: *std.Build.
|
|
267
|
+
artifact: *std.Build.Step.Compile,
|
|
256
268
|
step: *std.Build.Step,
|
|
257
|
-
strip: bool,
|
|
269
|
+
strip: ?bool,
|
|
258
270
|
cmd: ?[]const u8,
|
|
259
271
|
) void {
|
|
260
|
-
|
|
261
|
-
if (!strip or cmd == null) return;
|
|
272
|
+
if (!(strip orelse false) or cmd == null) return;
|
|
262
273
|
// Using `strip -r -u` for dynamic libraries is supposed to work on macOS but doesn't...
|
|
263
274
|
const mac = builtin.os.tag == .macos;
|
|
264
275
|
if (mac and artifact.isDynamicLibrary()) return;
|
|
@@ -270,10 +281,10 @@ fn maybeStrip(
|
|
|
270
281
|
}
|
|
271
282
|
|
|
272
283
|
const Config = struct {
|
|
273
|
-
target: std.
|
|
284
|
+
target: std.Build.ResolvedTarget,
|
|
274
285
|
optimize: std.builtin.OptimizeMode,
|
|
275
|
-
pic: bool,
|
|
276
|
-
strip: bool,
|
|
286
|
+
pic: ?bool,
|
|
287
|
+
strip: ?bool,
|
|
277
288
|
cmd: ?[]const u8,
|
|
278
289
|
};
|
|
279
290
|
|
|
@@ -281,32 +292,26 @@ const TestStep = struct {
|
|
|
281
292
|
step: std.Build.Step,
|
|
282
293
|
build: bool,
|
|
283
294
|
|
|
284
|
-
pub fn create(b: *std.Build, options: *std.Build.
|
|
295
|
+
pub fn create(b: *std.Build, options: *std.Build.Step.Options, config: Config) *TestStep {
|
|
285
296
|
const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
|
|
286
|
-
const test_file = b.option([]const u8, "test-file", "Input file for test");
|
|
287
297
|
const test_filter =
|
|
288
298
|
b.option([]const u8, "test-filter", "Skip tests that do not match filter");
|
|
289
299
|
|
|
290
300
|
const self = b.allocator.create(TestStep) catch @panic("OOM");
|
|
291
301
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
|
|
292
|
-
self.* =
|
|
302
|
+
self.* = .{ .step = step, .build = test_filter == null };
|
|
293
303
|
|
|
294
|
-
const path = test_file orelse "src/lib/test.zig";
|
|
295
304
|
const tests = b.addTest(.{
|
|
296
|
-
.
|
|
297
|
-
std.fs.path.basename(std.fs.path.dirname(path).?),
|
|
298
|
-
std.fs.path.stem(std.fs.path.basename(path)),
|
|
299
|
-
}),
|
|
300
|
-
.main_pkg_path = .{ .path = "." },
|
|
301
|
-
.root_source_file = .{ .path = path },
|
|
305
|
+
.root_source_file = .{ .path = "src/lib/test.zig" },
|
|
302
306
|
.optimize = config.optimize,
|
|
303
307
|
.target = config.target,
|
|
304
308
|
.filter = test_filter,
|
|
309
|
+
.single_threaded = true,
|
|
310
|
+
.strip = config.strip,
|
|
311
|
+
.pic = config.pic,
|
|
305
312
|
});
|
|
306
|
-
tests.addOptions("build_options", options);
|
|
307
|
-
tests.single_threaded = true;
|
|
313
|
+
tests.root_module.addOptions("build_options", options);
|
|
308
314
|
maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
|
|
309
|
-
if (config.pic) tests.force_pic = config.pic;
|
|
310
315
|
if (coverage) |c| {
|
|
311
316
|
tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
|
|
312
317
|
}
|
|
@@ -322,11 +327,15 @@ const ToolConfig = struct {
|
|
|
322
327
|
tool: struct {
|
|
323
328
|
tests: ?*TestStep,
|
|
324
329
|
name: ?[]const u8 = null,
|
|
325
|
-
exes: *std.ArrayList(*std.Build.
|
|
330
|
+
exes: *std.ArrayList(*std.Build.Step.Compile),
|
|
326
331
|
},
|
|
327
332
|
};
|
|
328
333
|
|
|
329
|
-
fn tool(b: *std.Build, path: []const u8, config: ToolConfig)
|
|
334
|
+
fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.Step.Run {
|
|
335
|
+
std.fs.cwd().access(path, .{}) catch |err| switch (err) {
|
|
336
|
+
error.FileNotFound => return null,
|
|
337
|
+
else => |e| return e,
|
|
338
|
+
};
|
|
330
339
|
var name = config.tool.name orelse std.fs.path.basename(path);
|
|
331
340
|
const index = std.mem.lastIndexOfScalar(u8, name, '.');
|
|
332
341
|
if (index) |i| name = name[0..i];
|
|
@@ -337,11 +346,12 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
|
|
|
337
346
|
.root_source_file = .{ .path = path },
|
|
338
347
|
.target = config.general.target,
|
|
339
348
|
.optimize = config.general.optimize,
|
|
349
|
+
.single_threaded = true,
|
|
350
|
+
.strip = config.general.strip,
|
|
351
|
+
.pic = config.general.pic,
|
|
340
352
|
});
|
|
341
|
-
exe.
|
|
353
|
+
exe.root_module.addImport("pkmn", module(b, config.options));
|
|
342
354
|
|
|
343
|
-
exe.single_threaded = true;
|
|
344
|
-
if (config.general.pic) exe.force_pic = config.general.pic;
|
|
345
355
|
if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
|
|
346
356
|
config.tool.exes.append(exe) catch @panic("OOM");
|
|
347
357
|
|
|
@@ -355,10 +365,10 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
|
|
|
355
365
|
const ToolsStep = struct {
|
|
356
366
|
step: std.Build.Step,
|
|
357
367
|
|
|
358
|
-
pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.
|
|
368
|
+
pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.Step.Compile)) *ToolsStep {
|
|
359
369
|
const self = b.allocator.create(ToolsStep) catch @panic("OOM");
|
|
360
370
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Install tools", .owner = b });
|
|
361
|
-
self.* =
|
|
371
|
+
self.* = .{ .step = step };
|
|
362
372
|
for (exes.items) |t| self.step.dependOn(&b.addInstallArtifact(t, .{}).step);
|
|
363
373
|
return self;
|
|
364
374
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pkmn/engine",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.95e81bfe",
|
|
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,9 +31,6 @@
|
|
|
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",
|
|
37
34
|
"src/lib/common/battle.zig",
|
|
38
35
|
"src/lib/common/data.zig",
|
|
39
36
|
"src/lib/common/debug.zig",
|
|
@@ -52,14 +49,19 @@
|
|
|
52
49
|
"src/lib/gen1/data/types.zig",
|
|
53
50
|
"src/lib/gen1/helpers.zig",
|
|
54
51
|
"src/lib/gen1/mechanics.zig",
|
|
52
|
+
"src/lib/gen2/calc.zig",
|
|
53
|
+
"src/lib/gen2/chance.zig",
|
|
55
54
|
"src/lib/gen2/data.zig",
|
|
56
55
|
"src/lib/gen2/data/items.zig",
|
|
57
56
|
"src/lib/gen2/data/moves.zig",
|
|
58
57
|
"src/lib/gen2/data/species.zig",
|
|
59
58
|
"src/lib/gen2/data/types.zig",
|
|
59
|
+
"src/lib/gen2/generated.zig",
|
|
60
60
|
"src/lib/gen2/helpers.zig",
|
|
61
61
|
"src/lib/gen2/mechanics.zig",
|
|
62
|
+
"src/lib/node.zig",
|
|
62
63
|
"src/lib/pkmn.zig",
|
|
64
|
+
"src/lib/wasm.zig",
|
|
63
65
|
"src/test/display/pkmn.html.tmpl"
|
|
64
66
|
],
|
|
65
67
|
"engines": {
|
|
@@ -73,30 +75,31 @@
|
|
|
73
75
|
"access": "public"
|
|
74
76
|
},
|
|
75
77
|
"dependencies": {
|
|
76
|
-
"@pkmn/data": "^0.
|
|
77
|
-
"@pkmn/protocol": "^0.6.
|
|
78
|
+
"@pkmn/data": "^0.8.9",
|
|
79
|
+
"@pkmn/protocol": "^0.6.19"
|
|
78
80
|
},
|
|
79
81
|
"devDependencies": {
|
|
80
|
-
"@pkmn/eslint-config": "^
|
|
81
|
-
"@pkmn/img": "^0.2.
|
|
82
|
-
"@pkmn/sets": "^5.
|
|
83
|
-
"@pkmn/sim": "0.
|
|
84
|
-
"@types/html-minifier": "^4.0.
|
|
85
|
-
"@types/jest": "^29.5.
|
|
86
|
-
"@types/minimist": "^1.2.
|
|
87
|
-
"@types/mustache": "^4.2.
|
|
88
|
-
"@types/node": "^20.
|
|
89
|
-
"@vitest/coverage-
|
|
90
|
-
"binaryen": "^
|
|
91
|
-
"eslint": "^8.
|
|
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",
|
|
92
94
|
"html-minifier": "^4.0.0",
|
|
93
|
-
"json-stringify-pretty-compact": "
|
|
95
|
+
"json-stringify-pretty-compact": "4.0.0",
|
|
94
96
|
"minimist": "^1.2.8",
|
|
95
97
|
"mustache": "^4.2.0",
|
|
96
98
|
"source-map-support": "^0.5.21",
|
|
99
|
+
"table": "^6.8.1",
|
|
97
100
|
"trakr": "^0.2.0",
|
|
98
|
-
"typescript": "^5.
|
|
99
|
-
"vitest": "^
|
|
101
|
+
"typescript": "^5.4.2",
|
|
102
|
+
"vitest": "^1.3.1"
|
|
100
103
|
},
|
|
101
104
|
"scripts": {
|
|
102
105
|
"lint": "eslint --cache src --ext ts,js && eslint src/bin/*",
|
|
@@ -118,7 +121,7 @@
|
|
|
118
121
|
"ignorePatterns": [
|
|
119
122
|
"dist/",
|
|
120
123
|
"node_modules/",
|
|
121
|
-
"
|
|
124
|
+
"examples/zig",
|
|
122
125
|
"build/"
|
|
123
126
|
],
|
|
124
127
|
"env": {
|
|
@@ -134,10 +137,18 @@
|
|
|
134
137
|
"parserOptions": {
|
|
135
138
|
"project": [
|
|
136
139
|
"./tsconfig.json",
|
|
137
|
-
"./
|
|
140
|
+
"./examples/js/tsconfig.json"
|
|
138
141
|
]
|
|
139
142
|
}
|
|
140
143
|
},
|
|
144
|
+
{
|
|
145
|
+
"files": [
|
|
146
|
+
"src/test/display.ts"
|
|
147
|
+
],
|
|
148
|
+
"rules": {
|
|
149
|
+
"@typescript-eslint/no-unnecessary-type-assertion": "off"
|
|
150
|
+
}
|
|
151
|
+
},
|
|
141
152
|
{
|
|
142
153
|
"files": [
|
|
143
154
|
"src/pkg/index.ts",
|
|
@@ -168,6 +179,15 @@
|
|
|
168
179
|
"@typescript-eslint/no-redundant-type-constituents": "off"
|
|
169
180
|
}
|
|
170
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"
|
|
189
|
+
}
|
|
190
|
+
},
|
|
171
191
|
{
|
|
172
192
|
"files": [
|
|
173
193
|
"src/test/*.test.ts",
|
|
@@ -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:
|
|
13
|
+
const ZIG_VERSION = {major: 0, minor: 12, patch: 0, dev: 2036};
|
|
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';
|
|
@@ -283,19 +283,19 @@ const downloadImportLib = async () => {
|
|
|
283
283
|
let error = false;
|
|
284
284
|
for (let i = 2; i < process.argv.length; i++) {
|
|
285
285
|
switch (process.argv[i]) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
286
|
+
case "--silent": {
|
|
287
|
+
SILENT = true;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
case "--zig": {
|
|
291
|
+
if (options || only) error = true;
|
|
292
|
+
only = true;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
default: {
|
|
296
|
+
if (options || only || !process.argv[i].startsWith('--options=')) error = true;
|
|
297
|
+
options = process.argv[i].slice(10).split(' ');
|
|
298
|
+
}
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
if (error) {
|
package/src/lib/common/data.zig
CHANGED
|
@@ -9,12 +9,12 @@ pub const Player = enum(u1) {
|
|
|
9
9
|
P2,
|
|
10
10
|
|
|
11
11
|
/// Returns a player's opponent.
|
|
12
|
-
pub
|
|
12
|
+
pub fn foe(self: Player) Player {
|
|
13
13
|
return @enumFromInt(~@intFromEnum(self));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/// Return's an identifier for the player's Pokémon at the one-indexed `id`.
|
|
17
|
-
pub
|
|
17
|
+
pub fn ident(self: Player, id: u3) ID {
|
|
18
18
|
assert(id > 0 and id <= 6);
|
|
19
19
|
return .{ .id = id, .player = self };
|
|
20
20
|
}
|
|
@@ -22,8 +22,8 @@ pub const Player = enum(u1) {
|
|
|
22
22
|
|
|
23
23
|
test Player {
|
|
24
24
|
try expectEqual(Player.P2, Player.P1.foe());
|
|
25
|
-
try expectEqual(
|
|
26
|
-
try expectEqual(
|
|
25
|
+
try expectEqual(0b0001, @as(u8, @bitCast(Player.P1.ident(1))));
|
|
26
|
+
try expectEqual(0b1101, @as(u8, @bitCast(Player.P2.ident(5))));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/// An identifier for a specific Pokémon in battle.
|
|
@@ -35,20 +35,20 @@ pub const ID = packed struct(u8) {
|
|
|
35
35
|
_: u4 = 0,
|
|
36
36
|
|
|
37
37
|
/// Converts the identifier into a number.
|
|
38
|
-
pub
|
|
38
|
+
pub fn int(self: ID) u4 {
|
|
39
39
|
return @intCast(@as(u8, @bitCast(self)));
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/// Decodes the identifier from a number.
|
|
43
|
-
pub
|
|
43
|
+
pub fn from(id: u4) ID {
|
|
44
44
|
return @bitCast(@as(u8, id));
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
test ID {
|
|
49
|
-
try expectEqual(
|
|
50
|
-
try expectEqual(
|
|
51
|
-
const id =
|
|
49
|
+
try expectEqual(0b0001, @as(u8, @bitCast(ID{ .player = .P1, .id = 1 })));
|
|
50
|
+
try expectEqual(0b1101, @as(u8, @bitCast(ID{ .player = .P2, .id = 5 })));
|
|
51
|
+
const id: ID = .{ .player = .P2, .id = 4 };
|
|
52
52
|
try expectEqual(id, ID.from(id.int()));
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -14,6 +14,7 @@ pub fn Optional(comptime T: type) type {
|
|
|
14
14
|
var decls = [_]std.builtin.Type.Declaration{};
|
|
15
15
|
|
|
16
16
|
enumFields[0] = .{ .name = "None", .value = 0 };
|
|
17
|
+
|
|
17
18
|
inline for (fields, 1..) |field, i| {
|
|
18
19
|
assert(!std.mem.eql(u8, field.name, "None"));
|
|
19
20
|
enumFields[i] = .{
|
|
@@ -24,7 +25,7 @@ pub fn Optional(comptime T: type) type {
|
|
|
24
25
|
|
|
25
26
|
return @Type(.{
|
|
26
27
|
.Enum = .{
|
|
27
|
-
.tag_type = std.math.IntFittingRange(0, fields.len
|
|
28
|
+
.tag_type = std.math.IntFittingRange(0, fields.len),
|
|
28
29
|
.fields = &enumFields,
|
|
29
30
|
.decls = &decls,
|
|
30
31
|
.is_exhaustive = true,
|
|
@@ -45,7 +46,7 @@ test Optional {
|
|
|
45
46
|
try expect(b != .true);
|
|
46
47
|
try expect(b != .false);
|
|
47
48
|
|
|
48
|
-
const Player = @import("
|
|
49
|
+
const Player = @import("data.zig").Player;
|
|
49
50
|
try expect(@bitSizeOf(Optional(Player)) == 2);
|
|
50
51
|
|
|
51
52
|
const p: Optional(Player) = .P2;
|
|
@@ -57,4 +58,10 @@ test Optional {
|
|
|
57
58
|
try expect(q == .None);
|
|
58
59
|
try expect(q != .P1);
|
|
59
60
|
try expect(q != .P2);
|
|
61
|
+
|
|
62
|
+
const Three = enum(u2) { A, B, C };
|
|
63
|
+
try expect(@bitSizeOf(Optional(Three)) == 2);
|
|
64
|
+
|
|
65
|
+
const Four = enum(u2) { A, B, C, D };
|
|
66
|
+
try expect(@bitSizeOf(Optional(Four)) == 3);
|
|
60
67
|
}
|