@pkmn/engine 0.1.0-dev.d716e940 → 0.1.0-dev.da4a0515
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 +90 -56
- package/build/pkg/addon.js +9 -9
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data/ids.json +12 -12
- package/build/pkg/data/layout.json +26 -4
- package/build/pkg/data/protocol.json +69 -12
- package/build/pkg/data.d.ts +4 -4
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.js +15 -18
- 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 +61 -42
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +2 -2
- package/build/test/display.js.map +1 -1
- package/build/tools/debug.js +5 -4
- package/build/tools/debug.js.map +1 -1
- package/build.zig +154 -116
- package/package.json +53 -24
- package/src/bin/install-pkmn-engine +35 -22
- package/src/lib/common/battle.zig +17 -0
- package/src/lib/common/data.zig +19 -31
- package/src/lib/common/debug.zig +20 -11
- package/src/lib/common/js.zig +118 -0
- package/src/lib/common/optional.zig +67 -0
- package/src/lib/common/options.zig +9 -0
- package/src/lib/common/protocol.zig +906 -367
- package/src/lib/common/rational.zig +357 -0
- package/src/lib/common/rng.zig +35 -26
- package/src/lib/common/util.zig +12 -0
- package/src/lib/gen1/calc.zig +426 -0
- package/src/lib/gen1/chance.zig +1061 -0
- package/src/lib/gen1/data/moves.zig +202 -190
- package/src/lib/gen1/data/species.zig +5 -5
- package/src/lib/gen1/data/types.zig +10 -10
- package/src/lib/gen1/data.zig +99 -87
- package/src/lib/gen1/helpers.zig +599 -23
- package/src/lib/gen1/mechanics.zig +978 -710
- package/src/lib/gen2/calc.zig +143 -0
- package/src/lib/gen2/chance.zig +1315 -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 +130 -92
- package/src/lib/gen2/generated.zig +806 -0
- package/src/lib/gen2/helpers.zig +16 -22
- package/src/lib/gen2/mechanics.zig +3591 -12
- package/src/lib/node.zig +131 -0
- package/src/lib/pkmn.zig +84 -2
- package/src/lib/wasm.zig +13 -0
- package/src/lib/binding/node.zig +0 -229
- package/src/lib/binding/wasm.zig +0 -10
- package/src/lib/gen1/README.md +0 -812
- 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 {
|
|
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
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
|
-
.
|
|
13
|
-
.
|
|
19
|
+
.root_source_file = .{ .cwd_relative = 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")
|
|
29
|
-
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");
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
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.splitSequence(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
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
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,25 +66,25 @@ 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 = .
|
|
69
|
+
.root_source_file = b.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.
|
|
64
|
-
lib.addSystemIncludePath(headers);
|
|
75
|
+
lib.root_module.addOptions("build_options", options);
|
|
76
|
+
lib.addSystemIncludePath(b.path(headers));
|
|
65
77
|
lib.linkLibC();
|
|
66
78
|
if (node_import_lib) |il| {
|
|
67
|
-
lib.addObjectFile(il);
|
|
68
|
-
} else if (
|
|
79
|
+
lib.addObjectFile(b.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
|
-
// TODO
|
|
87
|
+
// TODO: ziglang/zig#2231 - using the following used to work (though was hacky):
|
|
77
88
|
//
|
|
78
89
|
// lib.emit_bin = .{ .emit_to = b.fmt("build/lib/{s}", .{addon}) };
|
|
79
90
|
// b.getInstallStep().dependOn(&lib.step);
|
|
@@ -82,74 +93,101 @@ pub fn build(b: *std.Build) !void {
|
|
|
82
93
|
// rename the file ourself in install-pkmn-engine
|
|
83
94
|
b.installArtifact(lib);
|
|
84
95
|
} else if (wasm) {
|
|
85
|
-
const
|
|
96
|
+
const exe = b.addExecutable(.{
|
|
86
97
|
.name = name,
|
|
87
|
-
.root_source_file = .
|
|
98
|
+
.root_source_file = b.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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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(
|
|
122
|
+
sh.addArtifactArg(exe);
|
|
105
123
|
sh.addArg("-o");
|
|
106
|
-
sh.
|
|
124
|
+
sh.addFileArg(b.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
|
-
b.installArtifact(lib);
|
|
110
131
|
} else if (dynamic) {
|
|
111
132
|
const lib = b.addSharedLibrary(.{
|
|
112
133
|
.name = name,
|
|
113
|
-
.root_source_file = .
|
|
114
|
-
.version = try std.
|
|
134
|
+
.root_source_file = b.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.
|
|
120
|
-
lib.addIncludePath("src/include");
|
|
141
|
+
lib.root_module.addOptions("build_options", options);
|
|
142
|
+
lib.addIncludePath(b.path("src/include"));
|
|
121
143
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
122
|
-
if (pic) lib.force_pic = pic;
|
|
123
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 = .
|
|
149
|
+
.root_source_file = b.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.
|
|
134
|
-
lib.addIncludePath("src/include");
|
|
155
|
+
lib.root_module.addOptions("build_options", options);
|
|
156
|
+
lib.addIncludePath(b.path("src/include"));
|
|
135
157
|
lib.bundle_compiler_rt = true;
|
|
136
158
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
137
|
-
if (
|
|
138
|
-
|
|
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
|
+
}
|
|
139
173
|
b.installArtifact(lib);
|
|
140
174
|
c = true;
|
|
141
175
|
}
|
|
142
176
|
|
|
143
177
|
if (c) {
|
|
144
178
|
const header = b.addInstallFileWithDir(
|
|
145
|
-
.
|
|
179
|
+
b.path("src/include/pkmn.h"),
|
|
146
180
|
.header,
|
|
147
181
|
"pkmn.h",
|
|
148
182
|
);
|
|
149
183
|
b.getInstallStep().dependOn(&header.step);
|
|
150
184
|
|
|
151
185
|
const pc = b.fmt("lib{s}.pc", .{name});
|
|
152
|
-
const file = try
|
|
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
|
+
);
|
|
153
191
|
const pkgconfig_file = try std.fs.cwd().createFile(file, .{});
|
|
154
192
|
|
|
155
193
|
const dirname = comptime std.fs.path.dirname(@src().file) orelse ".";
|
|
@@ -178,14 +216,20 @@ pub fn build(b: *std.Build) !void {
|
|
|
178
216
|
.strip = strip,
|
|
179
217
|
.cmd = cmd,
|
|
180
218
|
};
|
|
219
|
+
|
|
220
|
+
// TODO: tests can be run multiple times due to @imports
|
|
181
221
|
const tests = TestStep.create(b, options, config);
|
|
182
222
|
|
|
183
|
-
var exes = std.ArrayList(*std.Build.
|
|
223
|
+
var exes = std.ArrayList(*std.Build.Step.Compile).init(b.allocator);
|
|
184
224
|
const tools: ToolConfig = .{
|
|
185
|
-
.
|
|
186
|
-
.tool = .{
|
|
225
|
+
.options = .{
|
|
187
226
|
.showdown = showdown,
|
|
188
227
|
.log = log,
|
|
228
|
+
.chance = chance,
|
|
229
|
+
.calc = calc,
|
|
230
|
+
},
|
|
231
|
+
.general = config,
|
|
232
|
+
.tool = .{
|
|
189
233
|
.tests = if (tests.build) tests else null,
|
|
190
234
|
.exes = &exes,
|
|
191
235
|
},
|
|
@@ -194,39 +238,42 @@ pub fn build(b: *std.Build) !void {
|
|
|
194
238
|
var benchmark_config = tools;
|
|
195
239
|
benchmark_config.general.optimize = .ReleaseFast;
|
|
196
240
|
benchmark_config.general.strip = true;
|
|
197
|
-
const benchmark = tool(b, "src/test/benchmark.zig", benchmark_config);
|
|
241
|
+
const benchmark = try tool(b, "src/test/benchmark.zig", benchmark_config);
|
|
198
242
|
|
|
199
243
|
var fuzz_config = tools;
|
|
200
244
|
fuzz_config.general.strip = false;
|
|
201
245
|
fuzz_config.tool.name = "fuzz";
|
|
202
|
-
const fuzz = tool(b, "src/test/
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
b.step("
|
|
214
|
-
b.step("
|
|
215
|
-
b.step("
|
|
216
|
-
b.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);
|
|
217
262
|
b.step("test", "Run all tests").dependOn(&tests.step);
|
|
218
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
|
+
}
|
|
219
267
|
}
|
|
220
268
|
|
|
221
269
|
fn maybeStrip(
|
|
222
270
|
b: *std.Build,
|
|
223
|
-
artifact: *std.Build.
|
|
271
|
+
artifact: *std.Build.Step.Compile,
|
|
224
272
|
step: *std.Build.Step,
|
|
225
|
-
strip: bool,
|
|
273
|
+
strip: ?bool,
|
|
226
274
|
cmd: ?[]const u8,
|
|
227
275
|
) void {
|
|
228
|
-
|
|
229
|
-
if (!strip or cmd == null) return;
|
|
276
|
+
if (!(strip orelse false) or cmd == null) return;
|
|
230
277
|
// Using `strip -r -u` for dynamic libraries is supposed to work on macOS but doesn't...
|
|
231
278
|
const mac = builtin.os.tag == .macos;
|
|
232
279
|
if (mac and artifact.isDynamicLibrary()) return;
|
|
@@ -238,86 +285,77 @@ fn maybeStrip(
|
|
|
238
285
|
}
|
|
239
286
|
|
|
240
287
|
const Config = struct {
|
|
241
|
-
target: std.
|
|
288
|
+
target: std.Build.ResolvedTarget,
|
|
242
289
|
optimize: std.builtin.OptimizeMode,
|
|
243
|
-
pic: bool,
|
|
244
|
-
strip: bool,
|
|
290
|
+
pic: ?bool,
|
|
291
|
+
strip: ?bool,
|
|
245
292
|
cmd: ?[]const u8,
|
|
246
293
|
};
|
|
247
294
|
|
|
248
|
-
const TESTS = .{
|
|
249
|
-
"src/lib/common/test.zig",
|
|
250
|
-
"src/lib/gen1/test.zig",
|
|
251
|
-
"src/lib/gen2/test.zig",
|
|
252
|
-
};
|
|
253
|
-
|
|
254
295
|
const TestStep = struct {
|
|
255
296
|
step: std.Build.Step,
|
|
256
297
|
build: bool,
|
|
257
298
|
|
|
258
|
-
pub fn create(b: *std.Build, options: *std.Build.
|
|
299
|
+
pub fn create(b: *std.Build, options: *std.Build.Step.Options, config: Config) *TestStep {
|
|
259
300
|
const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
|
|
260
|
-
const test_file = b.option([]const u8, "test-file", "Input file for test");
|
|
261
301
|
const test_filter =
|
|
262
302
|
b.option([]const u8, "test-filter", "Skip tests that do not match filter");
|
|
263
303
|
|
|
264
304
|
const self = b.allocator.create(TestStep) catch @panic("OOM");
|
|
265
305
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
|
|
266
|
-
self.* =
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
tests.
|
|
281
|
-
maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
|
|
282
|
-
if (config.pic) tests.force_pic = config.pic;
|
|
283
|
-
if (coverage) |c| {
|
|
284
|
-
tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
|
|
285
|
-
}
|
|
286
|
-
self.step.dependOn(&b.addRunArtifact(tests).step);
|
|
306
|
+
self.* = .{ .step = step, .build = test_filter == null };
|
|
307
|
+
|
|
308
|
+
const tests = b.addTest(.{
|
|
309
|
+
.root_source_file = b.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 });
|
|
287
321
|
}
|
|
322
|
+
self.step.dependOn(&b.addRunArtifact(tests).step);
|
|
323
|
+
|
|
288
324
|
return self;
|
|
289
325
|
}
|
|
290
326
|
};
|
|
291
327
|
|
|
292
328
|
const ToolConfig = struct {
|
|
329
|
+
options: Options,
|
|
293
330
|
general: Config,
|
|
294
331
|
tool: struct {
|
|
295
|
-
showdown: bool,
|
|
296
|
-
log: bool,
|
|
297
332
|
tests: ?*TestStep,
|
|
298
333
|
name: ?[]const u8 = null,
|
|
299
|
-
exes: *std.ArrayList(*std.Build.
|
|
334
|
+
exes: *std.ArrayList(*std.Build.Step.Compile),
|
|
300
335
|
},
|
|
301
336
|
};
|
|
302
337
|
|
|
303
|
-
fn tool(b: *std.Build, path: []const u8, config: ToolConfig)
|
|
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
|
+
};
|
|
304
343
|
var name = config.tool.name orelse std.fs.path.basename(path);
|
|
305
344
|
const index = std.mem.lastIndexOfScalar(u8, name, '.');
|
|
306
345
|
if (index) |i| name = name[0..i];
|
|
307
|
-
if (config.
|
|
346
|
+
if (config.options.showdown orelse false) name = b.fmt("{s}-showdown", .{name});
|
|
308
347
|
|
|
309
348
|
const exe = b.addExecutable(.{
|
|
310
349
|
.name = name,
|
|
311
|
-
.root_source_file = .
|
|
350
|
+
.root_source_file = b.path(path),
|
|
312
351
|
.target = config.general.target,
|
|
313
352
|
.optimize = config.general.optimize,
|
|
353
|
+
.single_threaded = true,
|
|
354
|
+
.strip = config.general.strip,
|
|
355
|
+
.pic = config.general.pic,
|
|
314
356
|
});
|
|
315
|
-
exe.
|
|
316
|
-
|
|
317
|
-
.log = config.tool.log,
|
|
318
|
-
}));
|
|
319
|
-
exe.single_threaded = true;
|
|
320
|
-
if (config.general.pic) exe.force_pic = config.general.pic;
|
|
357
|
+
exe.root_module.addImport("pkmn", module(b, config.options));
|
|
358
|
+
|
|
321
359
|
if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
|
|
322
360
|
config.tool.exes.append(exe) catch @panic("OOM");
|
|
323
361
|
|
|
@@ -331,11 +369,11 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
|
|
|
331
369
|
const ToolsStep = struct {
|
|
332
370
|
step: std.Build.Step,
|
|
333
371
|
|
|
334
|
-
pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.
|
|
372
|
+
pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.Step.Compile)) *ToolsStep {
|
|
335
373
|
const self = b.allocator.create(ToolsStep) catch @panic("OOM");
|
|
336
374
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Install tools", .owner = b });
|
|
337
|
-
self.* =
|
|
338
|
-
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);
|
|
339
377
|
return self;
|
|
340
378
|
}
|
|
341
379
|
};
|
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.da4a0515",
|
|
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/
|
|
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.
|
|
70
|
-
"@pkmn/protocol": "^0.6.
|
|
78
|
+
"@pkmn/data": "^0.9.9",
|
|
79
|
+
"@pkmn/protocol": "^0.6.25"
|
|
71
80
|
},
|
|
72
81
|
"devDependencies": {
|
|
73
|
-
"@pkmn/eslint-config": "^
|
|
74
|
-
"@pkmn/img": "^0.2.
|
|
75
|
-
"@pkmn/sets": "^5.
|
|
76
|
-
"@pkmn/sim": "0.
|
|
77
|
-
"@types/html-minifier": "^4.0.
|
|
78
|
-
"@types/jest": "^29.5.
|
|
79
|
-
"@types/minimist": "^1.2.
|
|
80
|
-
"@types/mustache": "^4.2.
|
|
81
|
-
"@types/node": "^
|
|
82
|
-
"@vitest/coverage-
|
|
83
|
-
"binaryen": "^
|
|
84
|
-
"eslint": "
|
|
82
|
+
"@pkmn/eslint-config": "^7.5.0",
|
|
83
|
+
"@pkmn/img": "^0.2.30",
|
|
84
|
+
"@pkmn/sets": "^5.1.2",
|
|
85
|
+
"@pkmn/sim": "0.9.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.14.10",
|
|
91
|
+
"@vitest/coverage-v8": "^2.0.2",
|
|
92
|
+
"binaryen": "^118.0.0",
|
|
93
|
+
"eslint": "<=8",
|
|
85
94
|
"html-minifier": "^4.0.0",
|
|
86
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.2",
|
|
90
100
|
"trakr": "^0.2.0",
|
|
91
|
-
"typescript": "^5.
|
|
92
|
-
"vitest": "^0.
|
|
101
|
+
"typescript": "^5.5.3",
|
|
102
|
+
"vitest": "^2.0.2"
|
|
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
|
-
"
|
|
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
|
-
"./
|
|
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,7 +175,17 @@
|
|
|
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
|
{
|