@pkmn/engine 0.1.0-dev.4eeb346e → 0.1.0-dev.53335a32
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 +5 -33
- 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.js +1 -1
- package/build.zig +27 -17
- package/package.json +23 -33
- package/src/bin/install-pkmn-engine +31 -58
- package/src/lib/binding/node.zig +4 -4
- package/src/lib/binding/wasm.zig +2 -2
- package/src/lib/gen1/README.md +23 -32
- package/src/lib/gen1/data.zig +5 -5
- package/src/lib/gen1/mechanics.zig +237 -250
- package/src/lib/gen2/data.zig +4 -4
- package/src/lib/pkmn.zig +3 -3
- 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 -383
- 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/README.md
CHANGED
|
@@ -50,7 +50,7 @@ $ zig build --prefix /usr/local -Doptimize=ReleaseFast
|
|
|
50
50
|
|
|
51
51
|
The Zig website has [installation instructions](https://ziglang.org/learn/getting-started/) which
|
|
52
52
|
walk through how to install Zig on each platform - the engine code should work on Zig v0.11.0 dev
|
|
53
|
-
build
|
|
53
|
+
build 2168 or greater, though tracks Zig's master branch so this may change in the future if
|
|
54
54
|
breaking language changes are introduced:
|
|
55
55
|
|
|
56
56
|
`libpkmn` can be built with `-Dshowdown` to instead produce the Pokémon Showdown compatible
|
|
@@ -121,7 +121,7 @@ for each player.
|
|
|
121
121
|
Unlike [Pokémon Showdown's
|
|
122
122
|
SIM-PROTOCOL](https://github.com/smogon/pokemon-showdown/blob/master/sim/SIM-PROTOCOL.md#choice-requests)
|
|
123
123
|
which provides a rich request object at each decision point, the pkmn engine computes the possible
|
|
124
|
-
choices on demand based on the result of the previous `update` and the battle state (`
|
|
124
|
+
choices on demand based on the result of the previous `update` and the battle state (`OPTIONS_SIZE`
|
|
125
125
|
is a good size to initialize the buffer passed to `choices`). **Attempting to update the battle with
|
|
126
126
|
a choice not present in the options returned by `choices` is undefined behavior and may corrupt
|
|
127
127
|
state or cause the engine to crash.**
|
|
@@ -216,7 +216,7 @@ const std = @import("std");
|
|
|
216
216
|
const pkmn = @import("pkmn");
|
|
217
217
|
|
|
218
218
|
var random = std.rand.DefaultPrng.init(seed).random();
|
|
219
|
-
var
|
|
219
|
+
var options: [pkmn.OPTIONS_SIZE]pkmn.Choice = undefined;
|
|
220
220
|
|
|
221
221
|
var battle = ...
|
|
222
222
|
var log = ...
|
|
@@ -226,8 +226,8 @@ var c2 = pkmn.Choice{};
|
|
|
226
226
|
|
|
227
227
|
var result = try battle.update(c1, c2, log);
|
|
228
228
|
while (result.type == .None) : (result = try battle.update(c1, c2, log)) {
|
|
229
|
-
c1 =
|
|
230
|
-
c2 =
|
|
229
|
+
c1 = options[random.uintLessThan(u8, battle.choices(.P1, result.p1, &options))];
|
|
230
|
+
c2 = options[random.uintLessThan(u8, battle.choices(.P2, result.p2, &options))];
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
std.debug.print("{}\n", .{result.type});
|
|
@@ -255,34 +255,6 @@ necessarily be up-to-date/complete/correct - inclusion in this list does not imp
|
|
|
255
255
|
| **C++** | `BSL-1.0` | https://github.com/pasyg/engine-wrapper |
|
|
256
256
|
| **Python** | `MIT` | https://github.com/AnnikaCodes/PyKMN |
|
|
257
257
|
|
|
258
|
-
|
|
259
|
-
#### `pkmn-debug`
|
|
260
|
-
|
|
261
|
-
The [`@pkmn/engine`](#pkmnengine) package ships with a `pkmn-debug` tool which exists to decode the
|
|
262
|
-
binary data structures and protocols used by the engine and to output a [standalone
|
|
263
|
-
webpage](https://pkmn.cc/debug.html) that can be used for debugging. To use this tool in a folder
|
|
264
|
-
that has the `@pkmn/engine` package installed locally you can use `npx pkmn-debug`, though you may
|
|
265
|
-
also wish to install the package globally to be able to use this tool anywhere without
|
|
266
|
-
[`npx`](https://docs.npmjs.com/cli/v7/commands/npx):
|
|
267
|
-
|
|
268
|
-
```sh
|
|
269
|
-
$ npm install --global @pkmn/engine
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
By default, `pkmn-debug` expects to read [binary debug protocol](docs/PROTOCOL.md#debugging) from
|
|
273
|
-
[standard input](https://en.wikipedia.org/wiki/Standard_streams) and output HTML to standard output:
|
|
274
|
-
|
|
275
|
-
```sh
|
|
276
|
-
$ <cmd> | pkmn-debug > index.html
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
Alternatively, if a single filename argument is passed to the `pkmn-debug` it will read from that
|
|
280
|
-
instead:
|
|
281
|
-
|
|
282
|
-
```sh
|
|
283
|
-
$ pkmn-debug <file> > index.html
|
|
284
|
-
```
|
|
285
|
-
|
|
286
258
|
## Status
|
|
287
259
|
|
|
288
260
|
The engine is currently expected to be developed over multiple stages:
|
package/build/pkg/data.d.ts
CHANGED
|
@@ -26,7 +26,8 @@ export declare const LAYOUT: {
|
|
|
26
26
|
};
|
|
27
27
|
}[];
|
|
28
28
|
export declare const Data: {
|
|
29
|
-
|
|
29
|
+
buffer(data: number[]): Buffer;
|
|
30
|
+
view(data: number[]): DataView;
|
|
30
31
|
};
|
|
31
32
|
/**
|
|
32
33
|
* Translation table for encoding/decoding Pokémon Showdown string identifiers
|
package/build/pkg/data.js
CHANGED
|
@@ -27,9 +27,11 @@ for (const gen of exports.LAYOUT) {
|
|
|
27
27
|
gen.offsets.Battle.p2 = gen.offsets.Battle.sides + gen.sizes.Side;
|
|
28
28
|
}
|
|
29
29
|
exports.Data = new class {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
buffer(data) {
|
|
31
|
+
return Buffer.from(new Uint8Array(data).buffer);
|
|
32
|
+
}
|
|
33
|
+
view(data) {
|
|
34
|
+
return new DataView(this.buffer(data).buffer);
|
|
33
35
|
}
|
|
34
36
|
};
|
|
35
37
|
const LOOKUPS = [];
|
package/build/pkg/data.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/pkg/data.ts"],"names":[],"mappings":";;;;;;AAEA,+DAAsC;AACtC,qEAA6C;AAC7C,yEAAgD;AAEnC,QAAA,EAAE,GAAG,CAAC,GAAG,EAAE;IACtB,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;IACvC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC,CAAC,EAAE,CAAC;AAOQ,QAAA,GAAG,GAAG,kBAAc,CAAC;AAErB,QAAA,QAAQ,GAA+C,EAAE,CAAC;AACvE,KAAK,MAAM,IAAI,IAAI,uBAAY,EAAE;IAC/B,gBAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IACpB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,KAAK,MAAM,IAAI,IAAI,uBAAY,CAAC,IAAiC,CAAC,EAAE;QAClE,gBAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;KAC5B;CACF;AAEY,QAAA,MAAM,GAAG,qBAGpB,CAAC;AACH,KAAK,MAAM,GAAG,IAAI,cAAM,EAAE;IACxB,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IACjD,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,GAAG,CA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wBAqHC"}
|
package/build/pkg/gen1.js
CHANGED
|
@@ -50,7 +50,7 @@ class Battle {
|
|
|
50
50
|
this.config = config;
|
|
51
51
|
this.lookup = lookup;
|
|
52
52
|
this.data = data;
|
|
53
|
-
this.options = new ArrayBuffer(addon.size(0, '
|
|
53
|
+
this.options = new ArrayBuffer(addon.size(0, 'options'));
|
|
54
54
|
this.buf = config.log ? new ArrayBuffer(addon.size(0, 'log')) : undefined;
|
|
55
55
|
this.log = config.log ? new DataView(this.buf) : undefined;
|
|
56
56
|
this.cache = [undefined, undefined];
|
package/build.zig
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
2
|
const builtin = @import("builtin");
|
|
3
3
|
|
|
4
|
+
const NativeTargetInfo = std.zig.system.NativeTargetInfo;
|
|
5
|
+
|
|
4
6
|
pub const Options = struct { showdown: ?bool = null, trace: ?bool = null };
|
|
5
7
|
|
|
6
8
|
pub fn module(b: *std.Build, options: Options) *std.Build.Module {
|
|
@@ -27,9 +29,8 @@ pub fn build(b: *std.Build) !void {
|
|
|
27
29
|
const dynamic = b.option(bool, "dynamic", "Build a dynamic library") orelse false;
|
|
28
30
|
const strip = b.option(bool, "strip", "Strip debugging symbols from binary") orelse false;
|
|
29
31
|
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
32
|
|
|
32
|
-
const cmd = b.findProgram(
|
|
33
|
+
const cmd = b.findProgram(&[_][]const u8{"strip"}, &[_][]const u8{}) catch null;
|
|
33
34
|
|
|
34
35
|
var parser = std.json.Parser.init(b.allocator, false);
|
|
35
36
|
defer parser.deinit();
|
|
@@ -65,7 +66,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
65
66
|
lib.linkLibC();
|
|
66
67
|
if (node_import_lib) |il| {
|
|
67
68
|
lib.addObjectFile(il);
|
|
68
|
-
} else if ((try
|
|
69
|
+
} else if ((try NativeTargetInfo.detect(target)).target.os.tag == .windows) {
|
|
69
70
|
try std.io.getStdErr().writeAll("Must provide --node-import-library path on Windows\n");
|
|
70
71
|
std.process.exit(1);
|
|
71
72
|
}
|
|
@@ -73,14 +74,14 @@ pub fn build(b: *std.Build) !void {
|
|
|
73
74
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
74
75
|
if (pic) lib.force_pic = pic;
|
|
75
76
|
// 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
|
|
77
|
+
// TODO(ziglang/zig#2231): using the following used to work (though be hacky):
|
|
77
78
|
//
|
|
78
79
|
// lib.emit_bin = .{ .emit_to = b.fmt("build/lib/{s}", .{addon}) };
|
|
79
80
|
// b.getInstallStep().dependOn(&lib.step);
|
|
80
81
|
//
|
|
81
82
|
// But ziglang/zig#14647 broke this so we now need to do an install() and then manually
|
|
82
83
|
// rename the file ourself in install-pkmn-engine
|
|
83
|
-
|
|
84
|
+
lib.install();
|
|
84
85
|
} else if (wasm) {
|
|
85
86
|
const lib = b.addSharedLibrary(.{
|
|
86
87
|
.name = name,
|
|
@@ -97,16 +98,19 @@ pub fn build(b: *std.Build) !void {
|
|
|
97
98
|
lib.rdynamic = true;
|
|
98
99
|
lib.strip = strip;
|
|
99
100
|
if (pic) lib.force_pic = pic;
|
|
100
|
-
const opt = b.findProgram(
|
|
101
|
+
const opt = b.findProgram(
|
|
102
|
+
&[_][]const u8{"wasm-opt"},
|
|
103
|
+
&[_][]const u8{"./node_modules/.bin"},
|
|
104
|
+
) catch null;
|
|
101
105
|
if (optimize != .Debug and opt != null) {
|
|
102
106
|
const out = b.fmt("build/lib/{s}.wasm", .{name});
|
|
103
|
-
const sh = b.addSystemCommand(
|
|
107
|
+
const sh = b.addSystemCommand(&[_][]const u8{ opt.?, "-O4" });
|
|
104
108
|
sh.addArtifactArg(lib);
|
|
105
109
|
sh.addArg("-o");
|
|
106
110
|
sh.addFileSourceArg(.{ .path = out });
|
|
107
111
|
b.getInstallStep().dependOn(&sh.step);
|
|
108
112
|
}
|
|
109
|
-
|
|
113
|
+
lib.install();
|
|
110
114
|
} else if (dynamic) {
|
|
111
115
|
const lib = b.addSharedLibrary(.{
|
|
112
116
|
.name = name,
|
|
@@ -120,7 +124,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
120
124
|
lib.addIncludePath("src/include");
|
|
121
125
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
122
126
|
if (pic) lib.force_pic = pic;
|
|
123
|
-
|
|
127
|
+
lib.install();
|
|
124
128
|
c = true;
|
|
125
129
|
} else {
|
|
126
130
|
const lib = b.addStaticLibrary(.{
|
|
@@ -135,8 +139,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
135
139
|
lib.bundle_compiler_rt = true;
|
|
136
140
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
137
141
|
if (pic) lib.force_pic = pic;
|
|
138
|
-
|
|
139
|
-
b.installArtifact(lib);
|
|
142
|
+
lib.install();
|
|
140
143
|
c = true;
|
|
141
144
|
}
|
|
142
145
|
|
|
@@ -207,7 +210,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
207
210
|
const lint_exe =
|
|
208
211
|
b.addExecutable(.{ .name = "lint", .root_source_file = .{ .path = "src/tools/lint.zig" } });
|
|
209
212
|
if (tests.build) tests.step.dependOn(&lint_exe.step);
|
|
210
|
-
const lint =
|
|
213
|
+
const lint = lint_exe.run();
|
|
211
214
|
|
|
212
215
|
b.step("benchmark", "Run benchmark code").dependOn(&benchmark.step);
|
|
213
216
|
b.step("fuzz", "Run fuzz tester").dependOn(&fuzz.step);
|
|
@@ -232,7 +235,7 @@ fn maybeStrip(
|
|
|
232
235
|
if (mac and artifact.isDynamicLibrary()) return;
|
|
233
236
|
// Assuming GNU strip, which complains "illegal pathname found in archive member"...
|
|
234
237
|
if (!mac and artifact.isStaticLibrary()) return;
|
|
235
|
-
const sh = b.addSystemCommand(
|
|
238
|
+
const sh = b.addSystemCommand(&[_][]const u8{ cmd.?, if (mac) "-x" else "-s" });
|
|
236
239
|
sh.addArtifactArg(artifact);
|
|
237
240
|
step.dependOn(&sh.step);
|
|
238
241
|
}
|
|
@@ -245,7 +248,7 @@ const Config = struct {
|
|
|
245
248
|
cmd: ?[]const u8,
|
|
246
249
|
};
|
|
247
250
|
|
|
248
|
-
const TESTS =
|
|
251
|
+
const TESTS = [_][]const u8{
|
|
249
252
|
"src/lib/common/test.zig",
|
|
250
253
|
"src/lib/gen1/test.zig",
|
|
251
254
|
"src/lib/gen2/test.zig",
|
|
@@ -258,8 +261,11 @@ const TestStep = struct {
|
|
|
258
261
|
pub fn create(b: *std.Build, options: *std.Build.OptionsStep, config: Config) *TestStep {
|
|
259
262
|
const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
|
|
260
263
|
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");
|
|
261
265
|
const test_filter =
|
|
262
266
|
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;
|
|
263
269
|
|
|
264
270
|
const self = b.allocator.create(TestStep) catch @panic("OOM");
|
|
265
271
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
|
|
@@ -273,17 +279,21 @@ const TestStep = struct {
|
|
|
273
279
|
.root_source_file = .{ .path = path },
|
|
274
280
|
.optimize = config.optimize,
|
|
275
281
|
.target = config.target,
|
|
276
|
-
.filter = test_filter,
|
|
277
282
|
});
|
|
278
283
|
tests.setMainPkgPath("./");
|
|
284
|
+
tests.setFilter(test_filter);
|
|
279
285
|
tests.addOptions("build_options", options);
|
|
280
286
|
tests.single_threaded = true;
|
|
281
287
|
maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
|
|
282
288
|
if (config.pic) tests.force_pic = config.pic;
|
|
289
|
+
if (test_bin) |bin| {
|
|
290
|
+
tests.name = std.fs.path.basename(bin);
|
|
291
|
+
if (std.fs.path.dirname(bin)) |dir| tests.setOutputDir(dir);
|
|
292
|
+
}
|
|
283
293
|
if (coverage) |c| {
|
|
284
294
|
tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
|
|
285
295
|
}
|
|
286
|
-
self.step.dependOn(&
|
|
296
|
+
self.step.dependOn(if (test_no_exec) &tests.step else &tests.run().step);
|
|
287
297
|
}
|
|
288
298
|
return self;
|
|
289
299
|
}
|
|
@@ -321,7 +331,7 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
|
|
|
321
331
|
if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
|
|
322
332
|
config.tool.exes.append(exe) catch @panic("OOM");
|
|
323
333
|
|
|
324
|
-
const run =
|
|
334
|
+
const run = exe.run();
|
|
325
335
|
maybeStrip(b, exe, &run.step, config.general.strip, config.general.cmd);
|
|
326
336
|
if (b.args) |args| run.addArgs(args);
|
|
327
337
|
|
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.53335a32",
|
|
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,41 +17,54 @@
|
|
|
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",
|
|
@@ -92,13 +83,12 @@
|
|
|
92
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",
|
|
@@ -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
|
-
const dest = path.join(dir, 'node');
|
|
214
|
+
const dest = path.join(dir, `node-${process.version}`, 'include', '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 {
|
|
@@ -229,28 +227,20 @@ const downloadHeaders = async () => {
|
|
|
229
227
|
|
|
230
228
|
const url = process.release.headersUrl;
|
|
231
229
|
const targz = path.join(dir, path.basename(url));
|
|
232
|
-
const unpacked = path.join(dir, `node-${process.version}`, 'include');
|
|
233
230
|
|
|
234
|
-
log(`Downloading Node headers from ${url} to ${targz}`);
|
|
231
|
+
console.log(`Downloading Node headers from ${url} to ${targz}`);
|
|
232
|
+
await download(url, targz);
|
|
233
|
+
await unpack(targz, dir);
|
|
235
234
|
|
|
236
|
-
|
|
237
|
-
await download(url, targz);
|
|
238
|
-
await unpack(targz, dir);
|
|
239
|
-
fs.renameSync(path.join(unpacked, 'node'), dest);
|
|
240
|
-
|
|
241
|
-
log('Node headers:', dest);
|
|
235
|
+
console.log('Node headers:', dest);
|
|
242
236
|
|
|
243
|
-
|
|
244
|
-
} finally {
|
|
245
|
-
try { fs.rmSync(targz); } catch {}
|
|
246
|
-
try { fs.rmSync(unpacked, {recursive: true}); } catch {}
|
|
247
|
-
}
|
|
237
|
+
return dest;
|
|
248
238
|
};
|
|
249
239
|
|
|
250
240
|
const downloadImportLib = async () => {
|
|
251
241
|
const library = path.resolve(process.execPath, '..', 'node.lib');
|
|
252
242
|
if (fs.existsSync(path.join(library, 'node.h'))) {
|
|
253
|
-
log('Node import library:', library);
|
|
243
|
+
console.log('Node import library:', library);
|
|
254
244
|
return library;
|
|
255
245
|
}
|
|
256
246
|
|
|
@@ -258,10 +248,10 @@ const downloadImportLib = async () => {
|
|
|
258
248
|
const url = new URL('./win-x64/node.lib', process.release.headersUrl).href;
|
|
259
249
|
const dest = path.join(dir, path.basename(url));
|
|
260
250
|
if (fs.existsSync(path.join(dest))) {
|
|
261
|
-
log('Node import library:', dest);
|
|
251
|
+
console.log('Node import library:', dest);
|
|
262
252
|
return dest;
|
|
263
253
|
} else {
|
|
264
|
-
log(`Could not find Node import library at ${library}, downloading...`);
|
|
254
|
+
console.log(`Could not find Node import library at ${library}, downloading...`);
|
|
265
255
|
}
|
|
266
256
|
|
|
267
257
|
try {
|
|
@@ -270,41 +260,24 @@ const downloadImportLib = async () => {
|
|
|
270
260
|
if (err.code !== 'EEXIST') throw err;
|
|
271
261
|
}
|
|
272
262
|
|
|
273
|
-
log(`Downloading Node import library from ${url} to ${dest}`);
|
|
263
|
+
console.log(`Downloading Node import library from ${url} to ${dest}`);
|
|
274
264
|
await download(url, dest);
|
|
275
|
-
log('Node import library:', dest);
|
|
265
|
+
console.log('Node import library:', dest);
|
|
276
266
|
|
|
277
267
|
return dest;
|
|
278
268
|
};
|
|
279
269
|
|
|
280
270
|
(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) {
|
|
271
|
+
const options = (process.argv[2] || '').startsWith('--options=')
|
|
272
|
+
? process.argv[2].slice(10).split(' ') : undefined;
|
|
273
|
+
if (process.argv.length > 3 ||
|
|
274
|
+
process.argv.length === 3 && !(process.argv[2] === '--zig' || options)) {
|
|
302
275
|
console.error('Invalid arguments');
|
|
303
276
|
process.exit(1);
|
|
304
277
|
}
|
|
305
278
|
|
|
306
279
|
const zig = await install();
|
|
307
|
-
if (
|
|
280
|
+
if (process.argv[2] === '--zig') process.exit(0);
|
|
308
281
|
|
|
309
282
|
let tmp;
|
|
310
283
|
try {
|
|
@@ -374,7 +347,7 @@ const downloadImportLib = async () => {
|
|
|
374
347
|
opts.includes('-Dshowdown') || opts.includes('-Dshowdown=true') ? '-showdown' : '';
|
|
375
348
|
const flags = opts.length ? ` (${opts.join(' ')})` : '';
|
|
376
349
|
const artifact = path.join('build', 'lib', `pkmn${suffix}.${config.type}`);
|
|
377
|
-
log(`Building ${artifact}${flags}`);
|
|
350
|
+
console.log(`Building ${artifact}${flags}`);
|
|
378
351
|
sh(zig, args);
|
|
379
352
|
// TODO: ziglang/zig#14647 broke emit_to so we get to rename the file ourselves...
|
|
380
353
|
if (config.type === 'node') {
|
|
@@ -382,7 +355,7 @@ const downloadImportLib = async () => {
|
|
|
382
355
|
const ext = process.platform === 'darwin'
|
|
383
356
|
? 'dylib' : process.platform === 'win32' ? 'dll' : 'so';
|
|
384
357
|
const actual = path.join('build', 'lib', `${prefix}pkmn${suffix}.node.${ext}`);
|
|
385
|
-
fs.renameSync(
|
|
358
|
+
fs.renameSync(actual, artifact);
|
|
386
359
|
}
|
|
387
360
|
}
|
|
388
361
|
})().catch(e => {
|
package/src/lib/binding/node.zig
CHANGED
|
@@ -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
|
@@ -4,7 +4,7 @@ const pkmn = @import("../pkmn.zig");
|
|
|
4
4
|
export const SHOWDOWN = pkmn.options.showdown;
|
|
5
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;
|