@pkmn/engine 0.1.0-dev.729b1e87 → 0.1.0-dev.7b099504
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 +52 -24
- package/build/pkg/addon.d.ts +7 -0
- package/build/pkg/addon.js +111 -0
- package/build/pkg/addon.js.map +1 -0
- package/build/pkg/data.d.ts +1 -2
- package/build/pkg/data.js +3 -5
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.d.ts +3 -3
- package/build/pkg/gen1.js +11 -13
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +11 -10
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.js +1 -1
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +396 -0
- package/build/test/display.js.map +1 -0
- package/build/tools/debug.js +133 -0
- package/build/tools/debug.js.map +1 -0
- package/build.zig +24 -34
- package/package.json +41 -30
- package/src/bin/install-pkmn-engine +60 -33
- package/src/bin/pkmn-debug +62 -0
- package/src/lib/binding/node.zig +5 -5
- package/src/lib/binding/wasm.zig +3 -3
- package/src/lib/common/debug.zig +1 -0
- package/src/lib/common/options.zig +3 -3
- package/src/lib/common/protocol.zig +38 -38
- package/src/lib/gen1/README.md +65 -39
- package/src/lib/gen1/data.zig +7 -7
- package/src/lib/gen1/helpers.zig +10 -11
- package/src/lib/gen1/mechanics.zig +416 -301
- package/src/lib/gen2/data.zig +4 -4
- package/src/lib/pkmn.zig +7 -7
- package/src/test/display/pkmn.html.tmpl +368 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.run = exports.display = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const data_1 = require("@pkmn/data");
|
|
29
|
+
const pkg_1 = require("../pkg");
|
|
30
|
+
const addon = __importStar(require("../pkg/addon"));
|
|
31
|
+
const data_2 = require("../pkg/data");
|
|
32
|
+
const gen1 = __importStar(require("../pkg/gen1"));
|
|
33
|
+
const display_1 = require("../test/display");
|
|
34
|
+
class SpeciesNames {
|
|
35
|
+
gen;
|
|
36
|
+
battle;
|
|
37
|
+
constructor(gen, battle) {
|
|
38
|
+
this.gen = gen;
|
|
39
|
+
this.battle = battle;
|
|
40
|
+
}
|
|
41
|
+
get p1() {
|
|
42
|
+
const [p1] = Array.from(this.battle.sides);
|
|
43
|
+
const team = Array.from(p1.pokemon)
|
|
44
|
+
.sort((a, b) => a.position - b.position)
|
|
45
|
+
.map(p => ({ species: p.stored.species }));
|
|
46
|
+
return new pkg_1.SideInfo(this.gen, { name: 'Player 1', team });
|
|
47
|
+
}
|
|
48
|
+
get p2() {
|
|
49
|
+
const [, p2] = Array.from(this.battle.sides);
|
|
50
|
+
const team = Array.from(p2.pokemon)
|
|
51
|
+
.sort((a, b) => a.position - b.position)
|
|
52
|
+
.map(p => ({ species: p.stored.species }));
|
|
53
|
+
return new pkg_1.SideInfo(this.gen, { name: 'Player 2', team });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function display(gens, data, error, seed) {
|
|
57
|
+
if (!data.length)
|
|
58
|
+
throw new Error('Invalid input');
|
|
59
|
+
const view = data_2.Data.view(data);
|
|
60
|
+
let offset = 0;
|
|
61
|
+
const showdown = !!view.getUint8(offset++);
|
|
62
|
+
const gen = gens.get(view.getUint8(offset++));
|
|
63
|
+
const lookup = data_2.Lookup.get(gen);
|
|
64
|
+
const size = data_2.LAYOUT[gen.num - 1].sizes.Battle;
|
|
65
|
+
const deserialize = (buf) => {
|
|
66
|
+
// We don't care about the native addon, we just need to load it so other checks don't fail
|
|
67
|
+
void addon.supports(true);
|
|
68
|
+
switch (gen.num) {
|
|
69
|
+
case 1: return new gen1.Battle(lookup, data_2.Data.view(buf), { showdown });
|
|
70
|
+
default: throw new Error(`Unsupported gen: ${gen.num}`);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const battle = deserialize(data.subarray(offset, offset += size));
|
|
74
|
+
const names = new SpeciesNames(gen, battle);
|
|
75
|
+
const log = new pkg_1.Log(gen, lookup, names);
|
|
76
|
+
let partial = undefined;
|
|
77
|
+
const frames = [];
|
|
78
|
+
while (offset < view.byteLength) {
|
|
79
|
+
partial = { parsed: [] };
|
|
80
|
+
const it = log.parse(data_2.Data.view(data.subarray(offset)))[Symbol.iterator]();
|
|
81
|
+
let r = it.next();
|
|
82
|
+
while (!r.done) {
|
|
83
|
+
partial.parsed.push(r.value);
|
|
84
|
+
r = it.next();
|
|
85
|
+
}
|
|
86
|
+
offset += r.value;
|
|
87
|
+
if (offset >= view.byteLength)
|
|
88
|
+
break;
|
|
89
|
+
partial.battle = deserialize(data.subarray(offset, offset += size));
|
|
90
|
+
if (offset >= view.byteLength)
|
|
91
|
+
break;
|
|
92
|
+
partial.result = pkg_1.Result.decode(data[offset++]);
|
|
93
|
+
if (offset >= view.byteLength)
|
|
94
|
+
break;
|
|
95
|
+
partial.c1 = pkg_1.Choice.decode(data[offset++]);
|
|
96
|
+
if (offset >= view.byteLength)
|
|
97
|
+
break;
|
|
98
|
+
partial.c2 = pkg_1.Choice.decode(data[offset++]);
|
|
99
|
+
frames.push(partial);
|
|
100
|
+
partial = undefined;
|
|
101
|
+
}
|
|
102
|
+
return (0, display_1.render)(gen, showdown, error, seed, frames, partial);
|
|
103
|
+
}
|
|
104
|
+
exports.display = display;
|
|
105
|
+
async function run(gens) {
|
|
106
|
+
let input;
|
|
107
|
+
if (process.argv.length > 2) {
|
|
108
|
+
if (process.argv.length > 3) {
|
|
109
|
+
console.error('Invalid input');
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
input = fs.readFileSync(process.argv[2]);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
let length = 0;
|
|
116
|
+
const result = [];
|
|
117
|
+
for await (const chunk of process.stdin) {
|
|
118
|
+
result.push(chunk);
|
|
119
|
+
length += chunk.length;
|
|
120
|
+
}
|
|
121
|
+
input = Buffer.concat(result, length);
|
|
122
|
+
}
|
|
123
|
+
process.stdout.write(display(gens, input));
|
|
124
|
+
}
|
|
125
|
+
exports.run = run;
|
|
126
|
+
if (require.main === module) {
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
128
|
+
run(new data_1.Generations(require('@pkmn/sim').Dex)).catch(err => {
|
|
129
|
+
console.error(err.message);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=debug.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/tools/debug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AAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAC7C,CAAC;AAlBD,kBAkBC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;IAC3B,8DAA8D;IAC9D,GAAG,CAAC,IAAI,kBAAW,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACzD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ"}
|
package/build.zig
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
2
|
const builtin = @import("builtin");
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
pub const Options = struct { showdown: ?bool = null, trace: ?bool = null };
|
|
4
|
+
pub const Options = struct { showdown: ?bool = null, log: ?bool = null };
|
|
7
5
|
|
|
8
6
|
pub fn module(b: *std.Build, options: Options) *std.Build.Module {
|
|
9
7
|
const dirname = comptime std.fs.path.dirname(@src().file) orelse ".";
|
|
10
8
|
const build_options = b.addOptions();
|
|
11
9
|
build_options.addOption(?bool, "showdown", options.showdown);
|
|
12
|
-
build_options.addOption(?bool, "
|
|
10
|
+
build_options.addOption(?bool, "log", options.log);
|
|
13
11
|
return b.createModule(.{
|
|
14
12
|
.source_file = .{ .path = dirname ++ "/src/lib/pkmn.zig" },
|
|
15
13
|
.dependencies = &.{.{ .name = "build_options", .module = build_options.createModule() }},
|
|
@@ -29,8 +27,9 @@ pub fn build(b: *std.Build) !void {
|
|
|
29
27
|
const dynamic = b.option(bool, "dynamic", "Build a dynamic library") orelse false;
|
|
30
28
|
const strip = b.option(bool, "strip", "Strip debugging symbols from binary") orelse false;
|
|
31
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;
|
|
32
31
|
|
|
33
|
-
const cmd = b.findProgram(
|
|
32
|
+
const cmd = b.findProgram(&.{"strip"}, &.{}) catch null;
|
|
34
33
|
|
|
35
34
|
var parser = std.json.Parser.init(b.allocator, false);
|
|
36
35
|
defer parser.deinit();
|
|
@@ -43,11 +42,11 @@ pub fn build(b: *std.Build) !void {
|
|
|
43
42
|
|
|
44
43
|
const showdown =
|
|
45
44
|
b.option(bool, "showdown", "Enable Pokémon Showdown compatibility mode") orelse false;
|
|
46
|
-
const
|
|
45
|
+
const log = b.option(bool, "log", "Enable protocol message logging") orelse false;
|
|
47
46
|
|
|
48
47
|
const options = b.addOptions();
|
|
49
48
|
options.addOption(?bool, "showdown", showdown);
|
|
50
|
-
options.addOption(?bool, "
|
|
49
|
+
options.addOption(?bool, "log", log);
|
|
51
50
|
|
|
52
51
|
const name = if (showdown) "pkmn-showdown" else "pkmn";
|
|
53
52
|
|
|
@@ -66,7 +65,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
66
65
|
lib.linkLibC();
|
|
67
66
|
if (node_import_lib) |il| {
|
|
68
67
|
lib.addObjectFile(il);
|
|
69
|
-
} else if ((try NativeTargetInfo.detect(target)).target.os.tag == .windows) {
|
|
68
|
+
} else if ((try std.zig.system.NativeTargetInfo.detect(target)).target.os.tag == .windows) {
|
|
70
69
|
try std.io.getStdErr().writeAll("Must provide --node-import-library path on Windows\n");
|
|
71
70
|
std.process.exit(1);
|
|
72
71
|
}
|
|
@@ -74,14 +73,14 @@ pub fn build(b: *std.Build) !void {
|
|
|
74
73
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
75
74
|
if (pic) lib.force_pic = pic;
|
|
76
75
|
// 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
|
|
76
|
+
// TODO(ziglang/zig#2231): using the following used to work (though was hacky):
|
|
78
77
|
//
|
|
79
78
|
// lib.emit_bin = .{ .emit_to = b.fmt("build/lib/{s}", .{addon}) };
|
|
80
79
|
// b.getInstallStep().dependOn(&lib.step);
|
|
81
80
|
//
|
|
82
81
|
// But ziglang/zig#14647 broke this so we now need to do an install() and then manually
|
|
83
82
|
// rename the file ourself in install-pkmn-engine
|
|
84
|
-
|
|
83
|
+
b.installArtifact(lib);
|
|
85
84
|
} else if (wasm) {
|
|
86
85
|
const lib = b.addSharedLibrary(.{
|
|
87
86
|
.name = name,
|
|
@@ -98,19 +97,16 @@ pub fn build(b: *std.Build) !void {
|
|
|
98
97
|
lib.rdynamic = true;
|
|
99
98
|
lib.strip = strip;
|
|
100
99
|
if (pic) lib.force_pic = pic;
|
|
101
|
-
const opt = b.findProgram(
|
|
102
|
-
&[_][]const u8{"wasm-opt"},
|
|
103
|
-
&[_][]const u8{"./node_modules/.bin"},
|
|
104
|
-
) catch null;
|
|
100
|
+
const opt = b.findProgram(&.{"wasm-opt"}, &.{"./node_modules/.bin"}) catch null;
|
|
105
101
|
if (optimize != .Debug and opt != null) {
|
|
106
102
|
const out = b.fmt("build/lib/{s}.wasm", .{name});
|
|
107
|
-
const sh = b.addSystemCommand(
|
|
103
|
+
const sh = b.addSystemCommand(&.{ opt.?, "-O4" });
|
|
108
104
|
sh.addArtifactArg(lib);
|
|
109
105
|
sh.addArg("-o");
|
|
110
106
|
sh.addFileSourceArg(.{ .path = out });
|
|
111
107
|
b.getInstallStep().dependOn(&sh.step);
|
|
112
108
|
}
|
|
113
|
-
|
|
109
|
+
b.installArtifact(lib);
|
|
114
110
|
} else if (dynamic) {
|
|
115
111
|
const lib = b.addSharedLibrary(.{
|
|
116
112
|
.name = name,
|
|
@@ -124,7 +120,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
124
120
|
lib.addIncludePath("src/include");
|
|
125
121
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
126
122
|
if (pic) lib.force_pic = pic;
|
|
127
|
-
|
|
123
|
+
b.installArtifact(lib);
|
|
128
124
|
c = true;
|
|
129
125
|
} else {
|
|
130
126
|
const lib = b.addStaticLibrary(.{
|
|
@@ -139,7 +135,8 @@ pub fn build(b: *std.Build) !void {
|
|
|
139
135
|
lib.bundle_compiler_rt = true;
|
|
140
136
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
141
137
|
if (pic) lib.force_pic = pic;
|
|
142
|
-
lib.
|
|
138
|
+
if (emit_asm) lib.emit_asm = .emit;
|
|
139
|
+
b.installArtifact(lib);
|
|
143
140
|
c = true;
|
|
144
141
|
}
|
|
145
142
|
|
|
@@ -188,7 +185,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
188
185
|
.general = config,
|
|
189
186
|
.tool = .{
|
|
190
187
|
.showdown = showdown,
|
|
191
|
-
.
|
|
188
|
+
.log = log,
|
|
192
189
|
.tests = if (tests.build) tests else null,
|
|
193
190
|
.exes = &exes,
|
|
194
191
|
},
|
|
@@ -210,7 +207,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
210
207
|
const lint_exe =
|
|
211
208
|
b.addExecutable(.{ .name = "lint", .root_source_file = .{ .path = "src/tools/lint.zig" } });
|
|
212
209
|
if (tests.build) tests.step.dependOn(&lint_exe.step);
|
|
213
|
-
const lint =
|
|
210
|
+
const lint = b.addRunArtifact(lint_exe);
|
|
214
211
|
|
|
215
212
|
b.step("benchmark", "Run benchmark code").dependOn(&benchmark.step);
|
|
216
213
|
b.step("fuzz", "Run fuzz tester").dependOn(&fuzz.step);
|
|
@@ -235,7 +232,7 @@ fn maybeStrip(
|
|
|
235
232
|
if (mac and artifact.isDynamicLibrary()) return;
|
|
236
233
|
// Assuming GNU strip, which complains "illegal pathname found in archive member"...
|
|
237
234
|
if (!mac and artifact.isStaticLibrary()) return;
|
|
238
|
-
const sh = b.addSystemCommand(
|
|
235
|
+
const sh = b.addSystemCommand(&.{ cmd.?, if (mac) "-x" else "-s" });
|
|
239
236
|
sh.addArtifactArg(artifact);
|
|
240
237
|
step.dependOn(&sh.step);
|
|
241
238
|
}
|
|
@@ -248,7 +245,7 @@ const Config = struct {
|
|
|
248
245
|
cmd: ?[]const u8,
|
|
249
246
|
};
|
|
250
247
|
|
|
251
|
-
const TESTS =
|
|
248
|
+
const TESTS = .{
|
|
252
249
|
"src/lib/common/test.zig",
|
|
253
250
|
"src/lib/gen1/test.zig",
|
|
254
251
|
"src/lib/gen2/test.zig",
|
|
@@ -261,11 +258,8 @@ const TestStep = struct {
|
|
|
261
258
|
pub fn create(b: *std.Build, options: *std.Build.OptionsStep, config: Config) *TestStep {
|
|
262
259
|
const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
|
|
263
260
|
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
261
|
const test_filter =
|
|
266
262
|
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
263
|
|
|
270
264
|
const self = b.allocator.create(TestStep) catch @panic("OOM");
|
|
271
265
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
|
|
@@ -279,21 +273,17 @@ const TestStep = struct {
|
|
|
279
273
|
.root_source_file = .{ .path = path },
|
|
280
274
|
.optimize = config.optimize,
|
|
281
275
|
.target = config.target,
|
|
276
|
+
.filter = test_filter,
|
|
282
277
|
});
|
|
283
278
|
tests.setMainPkgPath("./");
|
|
284
|
-
tests.setFilter(test_filter);
|
|
285
279
|
tests.addOptions("build_options", options);
|
|
286
280
|
tests.single_threaded = true;
|
|
287
281
|
maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
|
|
288
282
|
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
|
-
}
|
|
293
283
|
if (coverage) |c| {
|
|
294
284
|
tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
|
|
295
285
|
}
|
|
296
|
-
self.step.dependOn(
|
|
286
|
+
self.step.dependOn(&b.addRunArtifact(tests).step);
|
|
297
287
|
}
|
|
298
288
|
return self;
|
|
299
289
|
}
|
|
@@ -303,7 +293,7 @@ const ToolConfig = struct {
|
|
|
303
293
|
general: Config,
|
|
304
294
|
tool: struct {
|
|
305
295
|
showdown: bool,
|
|
306
|
-
|
|
296
|
+
log: bool,
|
|
307
297
|
tests: ?*TestStep,
|
|
308
298
|
name: ?[]const u8 = null,
|
|
309
299
|
exes: *std.ArrayList(*std.Build.CompileStep),
|
|
@@ -324,14 +314,14 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
|
|
|
324
314
|
});
|
|
325
315
|
exe.addModule("pkmn", module(b, .{
|
|
326
316
|
.showdown = config.tool.showdown,
|
|
327
|
-
.
|
|
317
|
+
.log = config.tool.log,
|
|
328
318
|
}));
|
|
329
319
|
exe.single_threaded = true;
|
|
330
320
|
if (config.general.pic) exe.force_pic = config.general.pic;
|
|
331
321
|
if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
|
|
332
322
|
config.tool.exes.append(exe) catch @panic("OOM");
|
|
333
323
|
|
|
334
|
-
const run =
|
|
324
|
+
const run = b.addRunArtifact(exe);
|
|
335
325
|
maybeStrip(b, exe, &run.step, config.general.strip, config.general.cmd);
|
|
336
326
|
if (b.args) |args| run.addArgs(args);
|
|
337
327
|
|
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.7b099504",
|
|
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,6 +9,28 @@
|
|
|
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",
|
|
@@ -17,78 +39,66 @@
|
|
|
17
39
|
"src/lib/common/options.zig",
|
|
18
40
|
"src/lib/common/protocol.zig",
|
|
19
41
|
"src/lib/common/rng.zig",
|
|
42
|
+
"src/lib/gen1/data.zig",
|
|
20
43
|
"src/lib/gen1/data/moves.zig",
|
|
21
44
|
"src/lib/gen1/data/species.zig",
|
|
22
45
|
"src/lib/gen1/data/types.zig",
|
|
23
|
-
"src/lib/gen1/data.zig",
|
|
24
46
|
"src/lib/gen1/helpers.zig",
|
|
25
47
|
"src/lib/gen1/mechanics.zig",
|
|
48
|
+
"src/lib/gen2/data.zig",
|
|
26
49
|
"src/lib/gen2/data/items.zig",
|
|
27
50
|
"src/lib/gen2/data/moves.zig",
|
|
28
51
|
"src/lib/gen2/data/species.zig",
|
|
29
52
|
"src/lib/gen2/data/types.zig",
|
|
30
|
-
"src/lib/gen2/data.zig",
|
|
31
53
|
"src/lib/gen2/helpers.zig",
|
|
32
54
|
"src/lib/gen2/mechanics.zig",
|
|
33
55
|
"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"
|
|
56
|
+
"src/test/display/pkmn.html.tmpl"
|
|
49
57
|
],
|
|
50
58
|
"engines": {
|
|
51
59
|
"node": ">=16.0.0"
|
|
52
60
|
},
|
|
53
61
|
"bin": {
|
|
54
|
-
"install-pkmn-engine": "src/bin/install-pkmn-engine"
|
|
62
|
+
"install-pkmn-engine": "src/bin/install-pkmn-engine",
|
|
63
|
+
"pkmn-debug": "src/bin/pkmn-debug"
|
|
55
64
|
},
|
|
56
65
|
"publishConfig": {
|
|
57
66
|
"access": "public"
|
|
58
67
|
},
|
|
59
68
|
"dependencies": {
|
|
60
|
-
"@pkmn/data": "^0.7.
|
|
69
|
+
"@pkmn/data": "^0.7.38",
|
|
61
70
|
"@pkmn/protocol": "^0.6.11"
|
|
62
71
|
},
|
|
63
72
|
"devDependencies": {
|
|
64
|
-
"@pkmn/eslint-config": "^3.0.0
|
|
73
|
+
"@pkmn/eslint-config": "^3.0.0",
|
|
65
74
|
"@pkmn/img": "^0.2.8",
|
|
66
75
|
"@pkmn/sets": "^5.0.4",
|
|
67
|
-
"@pkmn/sim": "0.7.
|
|
76
|
+
"@pkmn/sim": "0.7.38",
|
|
68
77
|
"@types/html-minifier": "^4.0.2",
|
|
69
78
|
"@types/jest": "^29.5.0",
|
|
70
79
|
"@types/minimist": "^1.2.2",
|
|
71
80
|
"@types/mustache": "^4.2.2",
|
|
72
81
|
"@types/node": "^18.15.11",
|
|
73
|
-
"@vitest/coverage-c8": "^0.
|
|
82
|
+
"@vitest/coverage-c8": "^0.30.1",
|
|
74
83
|
"binaryen": "^112.0.0",
|
|
75
|
-
"eslint": "^8.
|
|
84
|
+
"eslint": "^8.38.0",
|
|
76
85
|
"html-minifier": "^4.0.0",
|
|
77
|
-
"json-stringify-pretty-compact": "
|
|
86
|
+
"json-stringify-pretty-compact": "4.0.0",
|
|
78
87
|
"minimist": "^1.2.8",
|
|
79
88
|
"mustache": "^4.2.0",
|
|
80
89
|
"source-map-support": "^0.5.21",
|
|
81
90
|
"trakr": "^0.2.0",
|
|
82
|
-
"typescript": "^5.0.
|
|
83
|
-
"vitest": "^0.
|
|
91
|
+
"typescript": "^5.0.4",
|
|
92
|
+
"vitest": "^0.30.1"
|
|
84
93
|
},
|
|
85
94
|
"scripts": {
|
|
86
|
-
"lint": "eslint --cache src --ext ts,js && eslint src/bin
|
|
87
|
-
"fix": "eslint --fix src --ext ts,js && eslint --fix src/bin
|
|
95
|
+
"lint": "eslint --cache src --ext ts,js && eslint src/bin/*",
|
|
96
|
+
"fix": "eslint --fix src --ext ts,js && eslint --fix src/bin/*",
|
|
88
97
|
"compile": "tsc -p .",
|
|
89
98
|
"build": "npm run compile",
|
|
90
99
|
"test": "vitest src/pkg",
|
|
91
100
|
"test:integration": "vitest src/test",
|
|
101
|
+
"debug": "npm run compile && node build/tools/debug",
|
|
92
102
|
"fuzz": "npm run compile && node build/test/fuzz",
|
|
93
103
|
"generate": "npm run compile && node build/tools/generate",
|
|
94
104
|
"release": "npm run compile && node build/tools/release",
|
|
@@ -151,7 +161,8 @@
|
|
|
151
161
|
},
|
|
152
162
|
{
|
|
153
163
|
"files": [
|
|
154
|
-
"src/test/*.test.ts"
|
|
164
|
+
"src/test/*.test.ts",
|
|
165
|
+
"src/test/regression/*.test.ts"
|
|
155
166
|
],
|
|
156
167
|
"rules": {
|
|
157
168
|
"jest/no-standalone-expect": "off"
|