@pkmn/engine 0.1.0-dev.83de29ee → 0.1.0-dev.84cc1a02
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 +22 -50
- package/build/pkg/data/layout.json +1 -1
- package/build/pkg/data.d.ts +2 -1
- package/build/pkg/data.js +5 -3
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.d.ts +4 -5
- package/build/pkg/gen1.js +24 -35
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +12 -15
- package/build/pkg/index.js.map +1 -1
- package/build.zig +31 -23
- package/package.json +29 -40
- package/src/bin/install-pkmn-engine +28 -47
- package/src/lib/binding/node.zig +5 -5
- package/src/lib/binding/wasm.zig +3 -3
- package/src/lib/common/debug.zig +0 -1
- package/src/lib/common/options.zig +3 -3
- package/src/lib/common/protocol.zig +38 -38
- package/src/lib/gen1/README.md +63 -93
- package/src/lib/gen1/data.zig +17 -19
- package/src/lib/gen1/helpers.zig +13 -11
- package/src/lib/gen1/mechanics.zig +301 -378
- package/src/lib/gen2/data.zig +4 -4
- package/src/lib/pkmn.zig +7 -7
- package/build/pkg/addon.d.ts +0 -7
- package/build/pkg/addon.js +0 -111
- package/build/pkg/addon.js.map +0 -1
- package/build/test/display.js +0 -401
- package/build/test/display.js.map +0 -1
- package/build/tools/debug.js +0 -133
- package/build/tools/debug.js.map +0 -1
- package/src/bin/pkmn-debug +0 -62
- package/src/test/display/pkmn.html.tmpl +0 -368
package/build.zig
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
2
|
const builtin = @import("builtin");
|
|
3
3
|
|
|
4
|
-
pub const Options = struct { showdown: ?bool = null,
|
|
4
|
+
pub const Options = struct { showdown: ?bool = null, trace: ?bool = null };
|
|
5
5
|
|
|
6
6
|
pub fn module(b: *std.Build, options: Options) *std.Build.Module {
|
|
7
7
|
const dirname = comptime std.fs.path.dirname(@src().file) orelse ".";
|
|
8
8
|
const build_options = b.addOptions();
|
|
9
9
|
build_options.addOption(?bool, "showdown", options.showdown);
|
|
10
|
-
build_options.addOption(?bool, "
|
|
10
|
+
build_options.addOption(?bool, "trace", options.trace);
|
|
11
11
|
return b.createModule(.{
|
|
12
12
|
.source_file = .{ .path = dirname ++ "/src/lib/pkmn.zig" },
|
|
13
13
|
.dependencies = &.{.{ .name = "build_options", .module = build_options.createModule() }},
|
|
@@ -27,9 +27,8 @@ pub fn build(b: *std.Build) !void {
|
|
|
27
27
|
const dynamic = b.option(bool, "dynamic", "Build a dynamic library") orelse false;
|
|
28
28
|
const strip = b.option(bool, "strip", "Strip debugging symbols from binary") orelse false;
|
|
29
29
|
const pic = b.option(bool, "pic", "Force position independent code") orelse false;
|
|
30
|
-
const emit_asm = b.option(bool, "emit-asm", "Output .s (assembly code)") orelse false;
|
|
31
30
|
|
|
32
|
-
const cmd = b.findProgram(
|
|
31
|
+
const cmd = b.findProgram(&[_][]const u8{"strip"}, &[_][]const u8{}) catch null;
|
|
33
32
|
|
|
34
33
|
var parser = std.json.Parser.init(b.allocator, false);
|
|
35
34
|
defer parser.deinit();
|
|
@@ -42,11 +41,11 @@ pub fn build(b: *std.Build) !void {
|
|
|
42
41
|
|
|
43
42
|
const showdown =
|
|
44
43
|
b.option(bool, "showdown", "Enable Pokémon Showdown compatibility mode") orelse false;
|
|
45
|
-
const
|
|
44
|
+
const trace = b.option(bool, "trace", "Enable trace logs") orelse false;
|
|
46
45
|
|
|
47
46
|
const options = b.addOptions();
|
|
48
47
|
options.addOption(?bool, "showdown", showdown);
|
|
49
|
-
options.addOption(?bool, "
|
|
48
|
+
options.addOption(?bool, "trace", trace);
|
|
50
49
|
|
|
51
50
|
const name = if (showdown) "pkmn-showdown" else "pkmn";
|
|
52
51
|
|
|
@@ -73,14 +72,14 @@ pub fn build(b: *std.Build) !void {
|
|
|
73
72
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
74
73
|
if (pic) lib.force_pic = pic;
|
|
75
74
|
// Always emit to build/lib because this is where the driver code expects to find it
|
|
76
|
-
// TODO(ziglang/zig#2231): using the following used to work (though
|
|
75
|
+
// TODO(ziglang/zig#2231): using the following used to work (though be hacky):
|
|
77
76
|
//
|
|
78
77
|
// lib.emit_bin = .{ .emit_to = b.fmt("build/lib/{s}", .{addon}) };
|
|
79
78
|
// b.getInstallStep().dependOn(&lib.step);
|
|
80
79
|
//
|
|
81
80
|
// But ziglang/zig#14647 broke this so we now need to do an install() and then manually
|
|
82
81
|
// rename the file ourself in install-pkmn-engine
|
|
83
|
-
|
|
82
|
+
lib.install();
|
|
84
83
|
} else if (wasm) {
|
|
85
84
|
const lib = b.addSharedLibrary(.{
|
|
86
85
|
.name = name,
|
|
@@ -97,16 +96,19 @@ pub fn build(b: *std.Build) !void {
|
|
|
97
96
|
lib.rdynamic = true;
|
|
98
97
|
lib.strip = strip;
|
|
99
98
|
if (pic) lib.force_pic = pic;
|
|
100
|
-
const opt = b.findProgram(
|
|
99
|
+
const opt = b.findProgram(
|
|
100
|
+
&[_][]const u8{"wasm-opt"},
|
|
101
|
+
&[_][]const u8{"./node_modules/.bin"},
|
|
102
|
+
) catch null;
|
|
101
103
|
if (optimize != .Debug and opt != null) {
|
|
102
104
|
const out = b.fmt("build/lib/{s}.wasm", .{name});
|
|
103
|
-
const sh = b.addSystemCommand(
|
|
105
|
+
const sh = b.addSystemCommand(&[_][]const u8{ opt.?, "-O4" });
|
|
104
106
|
sh.addArtifactArg(lib);
|
|
105
107
|
sh.addArg("-o");
|
|
106
108
|
sh.addFileSourceArg(.{ .path = out });
|
|
107
109
|
b.getInstallStep().dependOn(&sh.step);
|
|
108
110
|
}
|
|
109
|
-
|
|
111
|
+
lib.install();
|
|
110
112
|
} else if (dynamic) {
|
|
111
113
|
const lib = b.addSharedLibrary(.{
|
|
112
114
|
.name = name,
|
|
@@ -120,7 +122,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
120
122
|
lib.addIncludePath("src/include");
|
|
121
123
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
122
124
|
if (pic) lib.force_pic = pic;
|
|
123
|
-
|
|
125
|
+
lib.install();
|
|
124
126
|
c = true;
|
|
125
127
|
} else {
|
|
126
128
|
const lib = b.addStaticLibrary(.{
|
|
@@ -135,8 +137,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
135
137
|
lib.bundle_compiler_rt = true;
|
|
136
138
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
137
139
|
if (pic) lib.force_pic = pic;
|
|
138
|
-
|
|
139
|
-
b.installArtifact(lib);
|
|
140
|
+
lib.install();
|
|
140
141
|
c = true;
|
|
141
142
|
}
|
|
142
143
|
|
|
@@ -185,7 +186,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
185
186
|
.general = config,
|
|
186
187
|
.tool = .{
|
|
187
188
|
.showdown = showdown,
|
|
188
|
-
.
|
|
189
|
+
.trace = trace,
|
|
189
190
|
.tests = if (tests.build) tests else null,
|
|
190
191
|
.exes = &exes,
|
|
191
192
|
},
|
|
@@ -207,7 +208,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
207
208
|
const lint_exe =
|
|
208
209
|
b.addExecutable(.{ .name = "lint", .root_source_file = .{ .path = "src/tools/lint.zig" } });
|
|
209
210
|
if (tests.build) tests.step.dependOn(&lint_exe.step);
|
|
210
|
-
const lint =
|
|
211
|
+
const lint = lint_exe.run();
|
|
211
212
|
|
|
212
213
|
b.step("benchmark", "Run benchmark code").dependOn(&benchmark.step);
|
|
213
214
|
b.step("fuzz", "Run fuzz tester").dependOn(&fuzz.step);
|
|
@@ -232,7 +233,7 @@ fn maybeStrip(
|
|
|
232
233
|
if (mac and artifact.isDynamicLibrary()) return;
|
|
233
234
|
// Assuming GNU strip, which complains "illegal pathname found in archive member"...
|
|
234
235
|
if (!mac and artifact.isStaticLibrary()) return;
|
|
235
|
-
const sh = b.addSystemCommand(
|
|
236
|
+
const sh = b.addSystemCommand(&[_][]const u8{ cmd.?, if (mac) "-x" else "-s" });
|
|
236
237
|
sh.addArtifactArg(artifact);
|
|
237
238
|
step.dependOn(&sh.step);
|
|
238
239
|
}
|
|
@@ -245,7 +246,7 @@ const Config = struct {
|
|
|
245
246
|
cmd: ?[]const u8,
|
|
246
247
|
};
|
|
247
248
|
|
|
248
|
-
const TESTS =
|
|
249
|
+
const TESTS = [_][]const u8{
|
|
249
250
|
"src/lib/common/test.zig",
|
|
250
251
|
"src/lib/gen1/test.zig",
|
|
251
252
|
"src/lib/gen2/test.zig",
|
|
@@ -258,8 +259,11 @@ const TestStep = struct {
|
|
|
258
259
|
pub fn create(b: *std.Build, options: *std.Build.OptionsStep, config: Config) *TestStep {
|
|
259
260
|
const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
|
|
260
261
|
const test_file = b.option([]const u8, "test-file", "Input file for test");
|
|
262
|
+
const test_bin = b.option([]const u8, "test-bin", "Emit test binary to");
|
|
261
263
|
const test_filter =
|
|
262
264
|
b.option([]const u8, "test-filter", "Skip tests that do not match filter");
|
|
265
|
+
const test_no_exec =
|
|
266
|
+
b.option(bool, "test-no-exec", "Compiles test binary without running it") orelse false;
|
|
263
267
|
|
|
264
268
|
const self = b.allocator.create(TestStep) catch @panic("OOM");
|
|
265
269
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
|
|
@@ -273,17 +277,21 @@ const TestStep = struct {
|
|
|
273
277
|
.root_source_file = .{ .path = path },
|
|
274
278
|
.optimize = config.optimize,
|
|
275
279
|
.target = config.target,
|
|
276
|
-
.filter = test_filter,
|
|
277
280
|
});
|
|
278
281
|
tests.setMainPkgPath("./");
|
|
282
|
+
tests.setFilter(test_filter);
|
|
279
283
|
tests.addOptions("build_options", options);
|
|
280
284
|
tests.single_threaded = true;
|
|
281
285
|
maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
|
|
282
286
|
if (config.pic) tests.force_pic = config.pic;
|
|
287
|
+
if (test_bin) |bin| {
|
|
288
|
+
tests.name = std.fs.path.basename(bin);
|
|
289
|
+
if (std.fs.path.dirname(bin)) |dir| tests.setOutputDir(dir);
|
|
290
|
+
}
|
|
283
291
|
if (coverage) |c| {
|
|
284
292
|
tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
|
|
285
293
|
}
|
|
286
|
-
self.step.dependOn(&
|
|
294
|
+
self.step.dependOn(if (test_no_exec) &tests.step else &tests.run().step);
|
|
287
295
|
}
|
|
288
296
|
return self;
|
|
289
297
|
}
|
|
@@ -293,7 +301,7 @@ const ToolConfig = struct {
|
|
|
293
301
|
general: Config,
|
|
294
302
|
tool: struct {
|
|
295
303
|
showdown: bool,
|
|
296
|
-
|
|
304
|
+
trace: bool,
|
|
297
305
|
tests: ?*TestStep,
|
|
298
306
|
name: ?[]const u8 = null,
|
|
299
307
|
exes: *std.ArrayList(*std.Build.CompileStep),
|
|
@@ -314,14 +322,14 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
|
|
|
314
322
|
});
|
|
315
323
|
exe.addModule("pkmn", module(b, .{
|
|
316
324
|
.showdown = config.tool.showdown,
|
|
317
|
-
.
|
|
325
|
+
.trace = config.tool.trace,
|
|
318
326
|
}));
|
|
319
327
|
exe.single_threaded = true;
|
|
320
328
|
if (config.general.pic) exe.force_pic = config.general.pic;
|
|
321
329
|
if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
|
|
322
330
|
config.tool.exes.append(exe) catch @panic("OOM");
|
|
323
331
|
|
|
324
|
-
const run =
|
|
332
|
+
const run = exe.run();
|
|
325
333
|
maybeStrip(b, exe, &run.step, config.general.strip, config.general.cmd);
|
|
326
334
|
if (b.args) |args| run.addArgs(args);
|
|
327
335
|
|
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.84cc1a02",
|
|
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,28 +9,6 @@
|
|
|
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",
|
|
34
12
|
"src/bin/install-pkmn-engine",
|
|
35
13
|
"src/lib/binding/node.zig",
|
|
36
14
|
"src/lib/binding/wasm.zig",
|
|
@@ -39,66 +17,78 @@
|
|
|
39
17
|
"src/lib/common/options.zig",
|
|
40
18
|
"src/lib/common/protocol.zig",
|
|
41
19
|
"src/lib/common/rng.zig",
|
|
42
|
-
"src/lib/gen1/data.zig",
|
|
43
20
|
"src/lib/gen1/data/moves.zig",
|
|
44
21
|
"src/lib/gen1/data/species.zig",
|
|
45
22
|
"src/lib/gen1/data/types.zig",
|
|
23
|
+
"src/lib/gen1/data.zig",
|
|
46
24
|
"src/lib/gen1/helpers.zig",
|
|
47
25
|
"src/lib/gen1/mechanics.zig",
|
|
48
|
-
"src/lib/gen2/data.zig",
|
|
49
26
|
"src/lib/gen2/data/items.zig",
|
|
50
27
|
"src/lib/gen2/data/moves.zig",
|
|
51
28
|
"src/lib/gen2/data/species.zig",
|
|
52
29
|
"src/lib/gen2/data/types.zig",
|
|
30
|
+
"src/lib/gen2/data.zig",
|
|
53
31
|
"src/lib/gen2/helpers.zig",
|
|
54
32
|
"src/lib/gen2/mechanics.zig",
|
|
55
33
|
"src/lib/pkmn.zig",
|
|
56
|
-
"
|
|
34
|
+
"build/pkg/data/ids.json",
|
|
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"
|
|
57
49
|
],
|
|
58
50
|
"engines": {
|
|
59
51
|
"node": ">=16.0.0"
|
|
60
52
|
},
|
|
61
53
|
"bin": {
|
|
62
|
-
"install-pkmn-engine": "src/bin/install-pkmn-engine"
|
|
63
|
-
"pkmn-debug": "src/bin/pkmn-debug"
|
|
54
|
+
"install-pkmn-engine": "src/bin/install-pkmn-engine"
|
|
64
55
|
},
|
|
65
56
|
"publishConfig": {
|
|
66
57
|
"access": "public"
|
|
67
58
|
},
|
|
68
59
|
"dependencies": {
|
|
69
|
-
"@pkmn/data": "^0.7.
|
|
60
|
+
"@pkmn/data": "^0.7.35",
|
|
70
61
|
"@pkmn/protocol": "^0.6.11"
|
|
71
62
|
},
|
|
72
63
|
"devDependencies": {
|
|
73
64
|
"@pkmn/eslint-config": "^3.0.0",
|
|
74
65
|
"@pkmn/img": "^0.2.8",
|
|
75
66
|
"@pkmn/sets": "^5.0.4",
|
|
76
|
-
"@pkmn/sim": "0.7.
|
|
67
|
+
"@pkmn/sim": "0.7.35",
|
|
77
68
|
"@types/html-minifier": "^4.0.2",
|
|
78
69
|
"@types/jest": "^29.5.0",
|
|
79
70
|
"@types/minimist": "^1.2.2",
|
|
80
71
|
"@types/mustache": "^4.2.2",
|
|
81
72
|
"@types/node": "^18.15.11",
|
|
82
|
-
"@vitest/coverage-c8": "^0.
|
|
73
|
+
"@vitest/coverage-c8": "^0.29.8",
|
|
83
74
|
"binaryen": "^112.0.0",
|
|
84
|
-
"eslint": "^8.
|
|
75
|
+
"eslint": "^8.37.0",
|
|
85
76
|
"html-minifier": "^4.0.0",
|
|
86
|
-
"json-stringify-pretty-compact": "
|
|
77
|
+
"json-stringify-pretty-compact": "3.0.0",
|
|
87
78
|
"minimist": "^1.2.8",
|
|
88
79
|
"mustache": "^4.2.0",
|
|
89
80
|
"source-map-support": "^0.5.21",
|
|
90
81
|
"trakr": "^0.2.0",
|
|
91
|
-
"typescript": "^5.0.
|
|
92
|
-
"vitest": "^0.
|
|
82
|
+
"typescript": "^5.0.3",
|
|
83
|
+
"vitest": "^0.29.8"
|
|
93
84
|
},
|
|
94
85
|
"scripts": {
|
|
95
|
-
"lint": "eslint --cache src --ext ts,js && eslint src/bin
|
|
96
|
-
"fix": "eslint --fix src --ext ts,js && eslint --fix src/bin
|
|
86
|
+
"lint": "eslint --cache src --ext ts,js && eslint src/bin/install-pkmn-engine",
|
|
87
|
+
"fix": "eslint --fix src --ext ts,js && eslint --fix src/bin/install-pkmn-engine",
|
|
97
88
|
"compile": "tsc -p .",
|
|
98
89
|
"build": "npm run compile",
|
|
99
90
|
"test": "vitest src/pkg",
|
|
100
91
|
"test:integration": "vitest src/test",
|
|
101
|
-
"debug": "npm run compile && node build/tools/debug",
|
|
102
92
|
"fuzz": "npm run compile && node build/test/fuzz",
|
|
103
93
|
"generate": "npm run compile && node build/tools/generate",
|
|
104
94
|
"release": "npm run compile && node build/tools/release",
|
|
@@ -161,8 +151,7 @@
|
|
|
161
151
|
},
|
|
162
152
|
{
|
|
163
153
|
"files": [
|
|
164
|
-
"src/test/*.test.ts"
|
|
165
|
-
"src/test/regression/*.test.ts"
|
|
154
|
+
"src/test/*.test.ts"
|
|
166
155
|
],
|
|
167
156
|
"rules": {
|
|
168
157
|
"jest/no-standalone-expect": "off"
|
|
@@ -10,15 +10,13 @@ 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: 11, patch: 0, dev:
|
|
13
|
+
const ZIG_VERSION = {major: 0, minor: 11, patch: 0, dev: 2168};
|
|
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';
|
|
17
17
|
const ROOT = path.resolve(__dirname, '..', '..');
|
|
18
|
-
let SILENT = false;
|
|
19
18
|
|
|
20
19
|
const sh = (cmd, args) => execFileSync(cmd, args, {encoding: 'utf8', cwd: ROOT});
|
|
21
|
-
const log = (...args) => { if (!SILENT) console.log(...args); };
|
|
22
20
|
|
|
23
21
|
// This is hardly the browser fetch API, but it works for our primitive needs
|
|
24
22
|
const fetch = url => new Promise((resolve, reject) => {
|
|
@@ -63,7 +61,7 @@ const unpack7 = (input, output) => new Promise((resolve, reject) => {
|
|
|
63
61
|
require.resolve('7zip-min');
|
|
64
62
|
} catch (err) {
|
|
65
63
|
if (err.code !== 'MODULE_NOT_FOUND') throw err;
|
|
66
|
-
log('Installing 7zip-min package locally to unpack the archive...');
|
|
64
|
+
console.log('Installing 7zip-min package locally to unpack the archive...');
|
|
67
65
|
sh('npm', ['install', '7zip-min', '--no-audit', '--no-save']);
|
|
68
66
|
}
|
|
69
67
|
|
|
@@ -85,7 +83,7 @@ const unpack = async (input, output) => {
|
|
|
85
83
|
sh('tar', ['xf', input, '-C', output]);
|
|
86
84
|
return;
|
|
87
85
|
} catch {
|
|
88
|
-
log('tar command not found, falling back to 7z');
|
|
86
|
+
console.log('tar command not found, falling back to 7z');
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
89
|
// Try to use a 7z binary if we can, and only install 7zip-min as a last resort
|
|
@@ -122,10 +120,10 @@ const find = zig => {
|
|
|
122
120
|
(!ZIG_VERSION.dev || (dev && dev >= ZIG_VERSION.dev)));
|
|
123
121
|
|
|
124
122
|
if (compatible) {
|
|
125
|
-
log('Found existing compatible Zig executable:', zig_exe);
|
|
123
|
+
console.log('Found existing compatible Zig executable:', zig_exe);
|
|
126
124
|
return zig_exe;
|
|
127
125
|
} else {
|
|
128
|
-
log(`Existing Zig executable is not compatible (${version} < ${VERSION}):`, zig_exe);
|
|
126
|
+
console.log(`Existing Zig executable is not compatible (${version} < ${VERSION}):`, zig_exe);
|
|
129
127
|
}
|
|
130
128
|
} catch (err) {
|
|
131
129
|
if (err.code !== 'ENOENT') throw err;
|
|
@@ -170,11 +168,11 @@ const install = async () => {
|
|
|
170
168
|
let base = path.basename(url);
|
|
171
169
|
const archive = path.join(dir, path.basename(url));
|
|
172
170
|
|
|
173
|
-
log(`Downloading Zig tarball from ${url} to ${archive}`);
|
|
171
|
+
console.log(`Downloading Zig tarball from ${url} to ${archive}`);
|
|
174
172
|
try {
|
|
175
173
|
await download(url, archive, release.shasum);
|
|
176
174
|
|
|
177
|
-
log(`Extracting tarball and installing to ${dir}`);
|
|
175
|
+
console.log(`Extracting tarball and installing to ${dir}`);
|
|
178
176
|
await unpack(archive, dir);
|
|
179
177
|
if (archive.endsWith('.zip')) {
|
|
180
178
|
base = base.slice(0, -4);
|
|
@@ -189,17 +187,17 @@ const install = async () => {
|
|
|
189
187
|
} catch (err) {
|
|
190
188
|
if (err.code !== 'ENOENT') throw err;
|
|
191
189
|
}
|
|
192
|
-
log(`Zig${version === 'master' ? '' : ` v${version}`} executable:`, zig,
|
|
190
|
+
console.log(`Zig${version === 'master' ? '' : ` v${version}`} executable:`, zig,
|
|
193
191
|
'(this version of Zig will be retained to speed up future updates)');
|
|
194
192
|
const [pre, post] = tty.isatty(1) ? ['\x1b[1m\x1b[35m', '\x1b[0m'] : ['', ''];
|
|
195
|
-
log(
|
|
193
|
+
console.log(
|
|
196
194
|
`${pre}Consider moving the ${path.dirname(zig)} directory and adding it to your PATH`,
|
|
197
195
|
`to use Zig on other projects, or delete this if you wish to save space.${post}`
|
|
198
196
|
);
|
|
199
197
|
|
|
200
198
|
return zig;
|
|
201
199
|
} finally {
|
|
202
|
-
log(`Cleaning up ${archive}`);
|
|
200
|
+
console.log(`Cleaning up ${archive}`);
|
|
203
201
|
try { fs.rmSync(archive); } catch {}
|
|
204
202
|
}
|
|
205
203
|
};
|
|
@@ -208,17 +206,17 @@ const install = async () => {
|
|
|
208
206
|
const downloadHeaders = async () => {
|
|
209
207
|
const include = path.resolve(process.execPath, '..', '..', 'include', 'node');
|
|
210
208
|
if (fs.existsSync(path.join(include, 'node.h'))) {
|
|
211
|
-
log('Node headers:', include);
|
|
209
|
+
console.log('Node headers:', include);
|
|
212
210
|
return include;
|
|
213
211
|
}
|
|
214
212
|
|
|
215
213
|
const dir = path.join(ROOT, 'build', 'include');
|
|
216
214
|
const dest = path.join(dir, 'node');
|
|
217
215
|
if (fs.existsSync(path.join(dest, 'node.h'))) {
|
|
218
|
-
log('Node headers:', dest);
|
|
216
|
+
console.log('Node headers:', dest);
|
|
219
217
|
return dest;
|
|
220
218
|
} else {
|
|
221
|
-
log(`Could not find Node headers at ${include}, downloading...`);
|
|
219
|
+
console.log(`Could not find Node headers at ${include}, downloading...`);
|
|
222
220
|
}
|
|
223
221
|
|
|
224
222
|
try {
|
|
@@ -231,14 +229,14 @@ const downloadHeaders = async () => {
|
|
|
231
229
|
const targz = path.join(dir, path.basename(url));
|
|
232
230
|
const unpacked = path.join(dir, `node-${process.version}`, 'include');
|
|
233
231
|
|
|
234
|
-
log(`Downloading Node headers from ${url} to ${targz}`);
|
|
232
|
+
console.log(`Downloading Node headers from ${url} to ${targz}`);
|
|
235
233
|
|
|
236
234
|
try {
|
|
237
235
|
await download(url, targz);
|
|
238
236
|
await unpack(targz, dir);
|
|
239
237
|
fs.renameSync(path.join(unpacked, 'node'), dest);
|
|
240
238
|
|
|
241
|
-
log('Node headers:', dest);
|
|
239
|
+
console.log('Node headers:', dest);
|
|
242
240
|
|
|
243
241
|
return dest;
|
|
244
242
|
} finally {
|
|
@@ -250,7 +248,7 @@ const downloadHeaders = async () => {
|
|
|
250
248
|
const downloadImportLib = async () => {
|
|
251
249
|
const library = path.resolve(process.execPath, '..', 'node.lib');
|
|
252
250
|
if (fs.existsSync(path.join(library, 'node.h'))) {
|
|
253
|
-
log('Node import library:', library);
|
|
251
|
+
console.log('Node import library:', library);
|
|
254
252
|
return library;
|
|
255
253
|
}
|
|
256
254
|
|
|
@@ -258,10 +256,10 @@ const downloadImportLib = async () => {
|
|
|
258
256
|
const url = new URL('./win-x64/node.lib', process.release.headersUrl).href;
|
|
259
257
|
const dest = path.join(dir, path.basename(url));
|
|
260
258
|
if (fs.existsSync(path.join(dest))) {
|
|
261
|
-
log('Node import library:', dest);
|
|
259
|
+
console.log('Node import library:', dest);
|
|
262
260
|
return dest;
|
|
263
261
|
} else {
|
|
264
|
-
log(`Could not find Node import library at ${library}, downloading...`);
|
|
262
|
+
console.log(`Could not find Node import library at ${library}, downloading...`);
|
|
265
263
|
}
|
|
266
264
|
|
|
267
265
|
try {
|
|
@@ -270,41 +268,24 @@ const downloadImportLib = async () => {
|
|
|
270
268
|
if (err.code !== 'EEXIST') throw err;
|
|
271
269
|
}
|
|
272
270
|
|
|
273
|
-
log(`Downloading Node import library from ${url} to ${dest}`);
|
|
271
|
+
console.log(`Downloading Node import library from ${url} to ${dest}`);
|
|
274
272
|
await download(url, dest);
|
|
275
|
-
log('Node import library:', dest);
|
|
273
|
+
console.log('Node import library:', dest);
|
|
276
274
|
|
|
277
275
|
return dest;
|
|
278
276
|
};
|
|
279
277
|
|
|
280
278
|
(async () => {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
switch (process.argv[i]) {
|
|
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
|
-
}
|
|
300
|
-
}
|
|
301
|
-
if (error) {
|
|
279
|
+
const options = (process.argv[2] || '').startsWith('--options=')
|
|
280
|
+
? process.argv[2].slice(10).split(' ') : undefined;
|
|
281
|
+
if (process.argv.length > 3 ||
|
|
282
|
+
process.argv.length === 3 && !(process.argv[2] === '--zig' || options)) {
|
|
302
283
|
console.error('Invalid arguments');
|
|
303
284
|
process.exit(1);
|
|
304
285
|
}
|
|
305
286
|
|
|
306
287
|
const zig = await install();
|
|
307
|
-
if (
|
|
288
|
+
if (process.argv[2] === '--zig') process.exit(0);
|
|
308
289
|
|
|
309
290
|
let tmp;
|
|
310
291
|
try {
|
|
@@ -337,13 +318,13 @@ const downloadImportLib = async () => {
|
|
|
337
318
|
if (!options) {
|
|
338
319
|
const addon = require(copy);
|
|
339
320
|
if (addon.options.showdown) opts.push('-Dshowdown');
|
|
340
|
-
if (addon.options.
|
|
321
|
+
if (addon.options.trace) opts.push('-Dtrace');
|
|
341
322
|
}
|
|
342
323
|
} else if (!options) {
|
|
343
324
|
const addon = await WebAssembly.instantiate(fs.readFileSync(copy));
|
|
344
325
|
const values = new Uint8Array(addon.instance.exports.memory.buffer);
|
|
345
326
|
if (values[addon.instance.exports.SHOWDOWN.value]) opts.push('-Dshowdown');
|
|
346
|
-
if (values[addon.instance.exports.
|
|
327
|
+
if (values[addon.instance.exports.TRACE.value]) opts.push('-Dtrace');
|
|
347
328
|
}
|
|
348
329
|
const key = `${type} ${opts.sort().join(' ')}`;
|
|
349
330
|
if (!configs.has(key)) configs.set(key, {type, options: opts});
|
|
@@ -374,7 +355,7 @@ const downloadImportLib = async () => {
|
|
|
374
355
|
opts.includes('-Dshowdown') || opts.includes('-Dshowdown=true') ? '-showdown' : '';
|
|
375
356
|
const flags = opts.length ? ` (${opts.join(' ')})` : '';
|
|
376
357
|
const artifact = path.join('build', 'lib', `pkmn${suffix}.${config.type}`);
|
|
377
|
-
log(`Building ${artifact}${flags}`);
|
|
358
|
+
console.log(`Building ${artifact}${flags}`);
|
|
378
359
|
sh(zig, args);
|
|
379
360
|
// TODO: ziglang/zig#14647 broke emit_to so we get to rename the file ourselves...
|
|
380
361
|
if (config.type === 'node') {
|
package/src/lib/binding/node.zig
CHANGED
|
@@ -21,7 +21,7 @@ fn options(env: c.napi_env) c.napi_value {
|
|
|
21
21
|
var object = Object.init(env);
|
|
22
22
|
const properties = [_]c.napi_property_descriptor{
|
|
23
23
|
Property.init("showdown", .{ .value = Boolean.init(env, pkmn.options.showdown) }),
|
|
24
|
-
Property.init("
|
|
24
|
+
Property.init("trace", .{ .value = Boolean.init(env, pkmn.options.trace) }),
|
|
25
25
|
};
|
|
26
26
|
assert(c.napi_define_properties(env, object, properties.len, &properties) == c.napi_ok);
|
|
27
27
|
return object;
|
|
@@ -34,11 +34,11 @@ fn bindings(env: c.napi_env) c.napi_value {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
fn bind(env: c.napi_env, gen: anytype) c.napi_value {
|
|
37
|
-
const
|
|
37
|
+
const options_size = @intCast(u32, gen.OPTIONS_SIZE);
|
|
38
38
|
const logs_size = @intCast(u32, gen.LOGS_SIZE);
|
|
39
39
|
var object = Object.init(env);
|
|
40
40
|
const properties = [_]c.napi_property_descriptor{
|
|
41
|
-
Property.init("
|
|
41
|
+
Property.init("OPTIONS_SIZE", .{ .value = Number.init(env, options_size) }),
|
|
42
42
|
Property.init("LOGS_SIZE", .{ .value = Number.init(env, logs_size) }),
|
|
43
43
|
Property.init("update", .{ .method = update(gen) }),
|
|
44
44
|
Property.init("choices", .{ .method = choices(gen) }),
|
|
@@ -108,10 +108,10 @@ fn choices(gen: anytype) c.napi_callback {
|
|
|
108
108
|
const request = @intToEnum(pkmn.Choice.Type, Number.get(env, argv[2], u8));
|
|
109
109
|
|
|
110
110
|
assert(c.napi_get_arraybuffer_info(env, argv[3], &data, &len) == c.napi_ok);
|
|
111
|
-
assert(len == gen.
|
|
111
|
+
assert(len == gen.OPTIONS_SIZE);
|
|
112
112
|
assert(data != null);
|
|
113
113
|
|
|
114
|
-
var out = @ptrCast([*]pkmn.Choice, data.?)[0..gen.
|
|
114
|
+
var out = @ptrCast([*]pkmn.Choice, data.?)[0..gen.OPTIONS_SIZE];
|
|
115
115
|
const n = battle.choices(player, request, out);
|
|
116
116
|
return Number.init(env, @bitCast(u8, n));
|
|
117
117
|
}
|
package/src/lib/binding/wasm.zig
CHANGED
|
@@ -2,9 +2,9 @@ const std = @import("std");
|
|
|
2
2
|
const pkmn = @import("../pkmn.zig");
|
|
3
3
|
|
|
4
4
|
export const SHOWDOWN = pkmn.options.showdown;
|
|
5
|
-
export const
|
|
5
|
+
export const TRACE = pkmn.options.trace;
|
|
6
6
|
|
|
7
|
-
export const
|
|
8
|
-
std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.
|
|
7
|
+
export const GEN1_OPTIONS_SIZE =
|
|
8
|
+
std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.OPTIONS_SIZE)) catch unreachable;
|
|
9
9
|
export const GEN1_LOGS_SIZE =
|
|
10
10
|
std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.LOGS_SIZE)) catch unreachable;
|
package/src/lib/common/debug.zig
CHANGED
|
@@ -3,7 +3,7 @@ const root = @import("root");
|
|
|
3
3
|
|
|
4
4
|
pub const Options = struct {
|
|
5
5
|
showdown: ?bool = null,
|
|
6
|
-
|
|
6
|
+
trace: ?bool = null,
|
|
7
7
|
advance: ?bool = null,
|
|
8
8
|
ebc: ?bool = null,
|
|
9
9
|
internal: ?bool = null,
|
|
@@ -11,8 +11,8 @@ pub const Options = struct {
|
|
|
11
11
|
|
|
12
12
|
/// Whether or not Pokémon Showdown compatibility mode is enabled.
|
|
13
13
|
pub const showdown = get("showdown", false);
|
|
14
|
-
/// Whether or not protocol
|
|
15
|
-
pub const
|
|
14
|
+
/// Whether or not protocol trace logging is enabled.
|
|
15
|
+
pub const trace = get("trace", false);
|
|
16
16
|
|
|
17
17
|
pub const advance = get("advance", true);
|
|
18
18
|
pub const ebc = get("ebc", true);
|