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