@pkmn/engine 0.1.0-dev.30c63015 → 0.1.0-dev.3393edb3
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 +41 -14
- package/build/pkg/addon/browser.d.ts +3 -0
- package/build/pkg/addon/browser.js +43 -0
- package/build/pkg/addon/browser.js.map +1 -0
- package/build/pkg/addon/node.d.ts +3 -0
- package/build/pkg/addon/node.js +96 -0
- package/build/pkg/addon/node.js.map +1 -0
- package/build/pkg/addon.d.ts +2 -0
- package/build/pkg/addon.js +35 -58
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data.d.ts +27 -5
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.js +1 -1
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +24 -10
- package/build/pkg/index.js +15 -10
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +20 -1
- package/build/pkg/protocol.js +109 -107
- package/build/pkg/protocol.js.map +1 -1
- package/build/tools/debug.js +36 -70
- package/build/tools/debug.js.map +1 -1
- package/build/tools/display/debug.jsx +141 -0
- package/build/tools/display/debug.jsx.map +1 -0
- package/build/tools/display/index.js +132 -0
- package/build/tools/display/index.js.map +1 -0
- package/build/tools/display/ui.jsx +349 -0
- package/build/tools/display/ui.jsx.map +1 -0
- package/build/tools/display/util.js +18 -0
- package/build/tools/display/util.js.map +1 -0
- package/build.zig +206 -81
- package/package.json +54 -29
- package/src/bin/install-pkmn-engine +29 -19
- package/src/bin/pkmn-debug +1 -1
- package/src/lib/common/array.zig +77 -0
- package/src/lib/common/data.zig +4 -4
- package/src/lib/common/debug.zig +32 -6
- package/src/lib/common/js.zig +4 -2
- package/src/lib/common/optional.zig +14 -10
- package/src/lib/common/options.zig +4 -0
- package/src/lib/common/protocol.zig +222 -210
- package/src/lib/common/rational.zig +121 -27
- package/src/lib/common/rng.zig +7 -7
- package/src/lib/common/util.zig +50 -1
- package/src/lib/gen1/calc.zig +666 -133
- package/src/lib/gen1/chance.zig +375 -266
- package/src/lib/gen1/data/species.zig +1 -1
- package/src/lib/gen1/data.zig +17 -16
- package/src/lib/gen1/helpers.zig +89 -538
- package/src/lib/gen1/mechanics.zig +461 -372
- package/src/lib/gen2/calc.zig +34 -16
- package/src/lib/gen2/chance.zig +84 -496
- package/src/lib/gen2/data.zig +8 -7
- package/src/lib/gen2/generated.zig +1 -3
- package/src/lib/gen2/helpers.zig +41 -13
- package/src/lib/gen2/mechanics.zig +328 -300
- package/src/lib/{binding/node.zig → node.zig} +9 -12
- package/src/lib/pkmn.zig +32 -15
- package/src/lib/{binding/wasm.zig → wasm.zig} +2 -1
- package/src/tools/display/dom.ts +96 -0
- package/src/tools/display/ui.css +351 -0
- package/build/test/display.js +0 -400
- package/build/test/display.js.map +0 -1
- package/src/lib/gen1/README.md +0 -894
- package/src/lib/gen2/README.md +0 -329
- package/src/test/display/pkmn.html.tmpl +0 -368
package/build.zig
CHANGED
|
@@ -8,6 +8,17 @@ pub const Options = struct {
|
|
|
8
8
|
calc: ?bool = null,
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
const Step = if (@hasDecl(std.Build, "Step")) std.Build.Step else .{
|
|
12
|
+
.Compile = std.Build.CompileStep,
|
|
13
|
+
.Options = std.Build.OptionsStep,
|
|
14
|
+
.Run = std.Build.RunStep,
|
|
15
|
+
};
|
|
16
|
+
const has_path = @hasField(std.Build.LazyPath, "path");
|
|
17
|
+
const root_module = @hasField(Step.Compile, "root_module");
|
|
18
|
+
const force_pic = !@hasField(std.Build.SharedLibraryOptions, "pic");
|
|
19
|
+
const ResolvedTarget =
|
|
20
|
+
if (@hasDecl(std.Build, "ResolvedTarget")) std.Build.ResolvedTarget else std.zig.CrossTarget;
|
|
21
|
+
|
|
11
22
|
pub fn module(b: *std.Build, options: Options) *std.Build.Module {
|
|
12
23
|
const dirname = comptime std.fs.path.dirname(@src().file) orelse ".";
|
|
13
24
|
const build_options = b.addOptions();
|
|
@@ -15,16 +26,20 @@ pub fn module(b: *std.Build, options: Options) *std.Build.Module {
|
|
|
15
26
|
build_options.addOption(?bool, "log", options.log);
|
|
16
27
|
build_options.addOption(?bool, "chance", options.chance);
|
|
17
28
|
build_options.addOption(?bool, "calc", options.calc);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
|
|
30
|
+
const root_source_file = .{ .cwd_relative = dirname ++ "/src/lib/pkmn.zig" };
|
|
31
|
+
const imports = &.{.{ .name = "build_options", .module = build_options.createModule() }};
|
|
32
|
+
return b.createModule(if (@hasDecl(std.Build, "CreateModuleOptions"))
|
|
33
|
+
.{ .source_file = root_source_file, .dependencies = imports }
|
|
34
|
+
else
|
|
35
|
+
.{ .root_source_file = root_source_file, .imports = imports });
|
|
22
36
|
}
|
|
23
37
|
|
|
24
38
|
pub fn build(b: *std.Build) !void {
|
|
25
39
|
const target = b.standardTargetOptions(.{});
|
|
26
40
|
const optimize = b.standardOptimizeOption(.{});
|
|
27
41
|
|
|
42
|
+
const default: ?bool = if (force_pic) false else null;
|
|
28
43
|
const node_headers = b.option([]const u8, "node-headers", "Path to node-headers");
|
|
29
44
|
const node_import_lib =
|
|
30
45
|
b.option([]const u8, "node-import-library", "Path to node import library (Windows)");
|
|
@@ -32,8 +47,8 @@ pub fn build(b: *std.Build) !void {
|
|
|
32
47
|
const wasm_stack_size =
|
|
33
48
|
b.option(u64, "wasm-stack-size", "The size of WASM stack") orelse std.wasm.page_size;
|
|
34
49
|
const dynamic = b.option(bool, "dynamic", "Build a dynamic library") orelse false;
|
|
35
|
-
const strip = b.option(bool, "strip", "Strip debugging symbols from binary") orelse
|
|
36
|
-
const pic = b.option(bool, "pic", "Force position independent code") orelse
|
|
50
|
+
const strip = b.option(bool, "strip", "Strip debugging symbols from binary") orelse default;
|
|
51
|
+
const pic = b.option(bool, "pic", "Force position independent code") orelse default;
|
|
37
52
|
const emit_asm = b.option(bool, "emit-asm", "Output .s (assembly code)") orelse false;
|
|
38
53
|
const emit_ll = b.option(bool, "emit-ll", "Output .ll (LLVM IR)") orelse false;
|
|
39
54
|
|
|
@@ -44,9 +59,15 @@ pub fn build(b: *std.Build) !void {
|
|
|
44
59
|
defer parsed.deinit();
|
|
45
60
|
const version = parsed.value.object.get("version").?.string;
|
|
46
61
|
const description = parsed.value.object.get("description").?.string;
|
|
47
|
-
var repository = std.mem.
|
|
62
|
+
var repository = std.mem.splitSequence(u8, parsed.value.object.get("repository").?.string, ":");
|
|
48
63
|
std.debug.assert(std.mem.eql(u8, repository.first(), "github"));
|
|
49
64
|
|
|
65
|
+
const fast = try std.SemanticVersion.parse("0.12.0-dev.866+3a47bc715");
|
|
66
|
+
if (optimize != .Debug and fast.order(builtin.zig_version) == .lt) {
|
|
67
|
+
std.log.warn("Release builds are ~10-20% slower than before Zig " ++
|
|
68
|
+
"v0.12.0-dev.866+3a47bc715 due to ziglang/zig#17768", .{});
|
|
69
|
+
}
|
|
70
|
+
|
|
50
71
|
const showdown =
|
|
51
72
|
b.option(bool, "showdown", "Enable Pokémon Showdown compatibility mode") orelse false;
|
|
52
73
|
const log = b.option(bool, "log", "Enable protocol message logging") orelse false;
|
|
@@ -61,30 +82,47 @@ pub fn build(b: *std.Build) !void {
|
|
|
61
82
|
|
|
62
83
|
const name = if (showdown) "pkmn-showdown" else "pkmn";
|
|
63
84
|
|
|
85
|
+
const pkmn = if (@hasDecl(std.Build, "CreateModuleOptions")) null else b.addModule("pkmn", .{
|
|
86
|
+
.root_source_file = if (has_path)
|
|
87
|
+
.{ .path = "src/lib/pkmn.zig" }
|
|
88
|
+
else
|
|
89
|
+
b.path("src/lib/pkmn.zig"),
|
|
90
|
+
.optimize = optimize,
|
|
91
|
+
.target = target,
|
|
92
|
+
.imports = &.{.{ .name = "build_options", .module = options.createModule() }},
|
|
93
|
+
});
|
|
94
|
+
|
|
64
95
|
var c = false;
|
|
65
96
|
if (node_headers) |headers| {
|
|
66
97
|
const addon = b.fmt("{s}.node", .{name});
|
|
67
|
-
const
|
|
98
|
+
const path = if (has_path) .{ .path = "src/lib/node.zig" } else b.path("src/lib/node.zig");
|
|
99
|
+
const lib = b.addSharedLibrary(if (force_pic) .{
|
|
68
100
|
.name = addon,
|
|
69
|
-
.
|
|
70
|
-
.root_source_file = .{ .path = "src/lib/binding/node.zig" },
|
|
101
|
+
.root_source_file = path,
|
|
71
102
|
.optimize = optimize,
|
|
72
103
|
.target = target,
|
|
104
|
+
} else .{
|
|
105
|
+
.name = addon,
|
|
106
|
+
.root_source_file = path,
|
|
107
|
+
.optimize = optimize,
|
|
108
|
+
.target = target,
|
|
109
|
+
.strip = strip,
|
|
110
|
+
.pic = pic,
|
|
73
111
|
});
|
|
74
|
-
lib.addOptions("build_options", options);
|
|
75
|
-
lib.addSystemIncludePath(.{ .path = headers });
|
|
112
|
+
(if (root_module) lib.root_module else lib).addOptions("build_options", options);
|
|
113
|
+
lib.addSystemIncludePath(if (has_path) .{ .path = headers } else b.path(headers));
|
|
76
114
|
lib.linkLibC();
|
|
77
115
|
if (node_import_lib) |il| {
|
|
78
|
-
lib.addObjectFile(.{ .path = il });
|
|
79
|
-
} else if (
|
|
116
|
+
lib.addObjectFile(if (has_path) .{ .path = il } else b.path(il));
|
|
117
|
+
} else if (detect(target).os.tag == .windows) {
|
|
80
118
|
try std.io.getStdErr().writeAll("Must provide --node-import-library path on Windows\n");
|
|
81
119
|
std.process.exit(1);
|
|
82
120
|
}
|
|
83
121
|
lib.linker_allow_shlib_undefined = true;
|
|
84
122
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
85
|
-
if (pic) lib.force_pic = pic;
|
|
123
|
+
if (force_pic and pic orelse false) lib.force_pic = pic;
|
|
86
124
|
// Always emit to build/lib because this is where the driver code expects to find it
|
|
87
|
-
// TODO
|
|
125
|
+
// TODO: ziglang/zig#2231 - using the following used to work (though was hacky):
|
|
88
126
|
//
|
|
89
127
|
// lib.emit_bin = .{ .emit_to = b.fmt("build/lib/{s}", .{addon}) };
|
|
90
128
|
// b.getInstallStep().dependOn(&lib.step);
|
|
@@ -93,59 +131,116 @@ pub fn build(b: *std.Build) !void {
|
|
|
93
131
|
// rename the file ourself in install-pkmn-engine
|
|
94
132
|
b.installArtifact(lib);
|
|
95
133
|
} else if (wasm) {
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
134
|
+
const entry = @hasDecl(Step.Compile, "Entry");
|
|
135
|
+
const mode = switch (optimize) {
|
|
136
|
+
.ReleaseFast, .ReleaseSafe => .ReleaseSmall,
|
|
137
|
+
else => optimize,
|
|
138
|
+
};
|
|
139
|
+
const freestanding = if (@hasDecl(std.Build, "resolveTargetQuery"))
|
|
140
|
+
b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding })
|
|
141
|
+
else
|
|
142
|
+
ResolvedTarget{ .cpu_arch = .wasm32, .os_tag = .freestanding };
|
|
143
|
+
const path = if (has_path) .{ .path = "src/lib/wasm.zig" } else b.path("src/lib/wasm.zig");
|
|
144
|
+
const bin = if (entry) bin: {
|
|
145
|
+
const exe = b.addExecutable(if (force_pic) .{
|
|
146
|
+
.name = name,
|
|
147
|
+
.root_source_file = path,
|
|
148
|
+
.optimize = mode,
|
|
149
|
+
.target = freestanding,
|
|
150
|
+
} else .{
|
|
151
|
+
.name = name,
|
|
152
|
+
.root_source_file = path,
|
|
153
|
+
.optimize = mode,
|
|
154
|
+
.target = freestanding,
|
|
155
|
+
.strip = strip,
|
|
156
|
+
.pic = pic,
|
|
157
|
+
});
|
|
158
|
+
(if (root_module) exe.root_module else exe).export_symbol_names = &[_][]const u8{
|
|
159
|
+
"SHOWDOWN",
|
|
160
|
+
"LOG",
|
|
161
|
+
"CHANCE",
|
|
162
|
+
"CALC",
|
|
163
|
+
"GEN1_CHOICES_SIZE",
|
|
164
|
+
"GEN1_LOGS_SIZE",
|
|
165
|
+
};
|
|
166
|
+
exe.entry = .disabled;
|
|
167
|
+
break :bin exe;
|
|
168
|
+
} else bin: {
|
|
169
|
+
const lib = b.addSharedLibrary(.{
|
|
170
|
+
.name = name,
|
|
171
|
+
.root_source_file = path,
|
|
172
|
+
.optimize = mode,
|
|
173
|
+
.target = freestanding,
|
|
174
|
+
});
|
|
175
|
+
lib.rdynamic = true;
|
|
176
|
+
break :bin lib;
|
|
177
|
+
};
|
|
178
|
+
bin.stack_size = wasm_stack_size;
|
|
179
|
+
if (@hasDecl(@TypeOf(bin.*), "strip")) bin.strip = strip orelse false;
|
|
180
|
+
if (force_pic and pic orelse false) bin.force_pic = pic;
|
|
181
|
+
(if (root_module) bin.root_module else bin).addOptions("build_options", options);
|
|
182
|
+
|
|
111
183
|
const opt = b.findProgram(&.{"wasm-opt"}, &.{"./node_modules/.bin"}) catch null;
|
|
112
184
|
if (optimize != .Debug and opt != null) {
|
|
113
185
|
const out = b.fmt("build/lib/{s}.wasm", .{name});
|
|
114
186
|
const sh = b.addSystemCommand(&.{ opt.?, "-O4" });
|
|
115
|
-
sh.addArtifactArg(
|
|
187
|
+
sh.addArtifactArg(bin);
|
|
116
188
|
sh.addArg("-o");
|
|
117
|
-
sh
|
|
189
|
+
if (@hasDecl(@TypeOf(sh.*), "addFileSourceArg")) {
|
|
190
|
+
sh.addFileSourceArg(if (has_path) .{ .path = out } else b.path(out));
|
|
191
|
+
} else {
|
|
192
|
+
sh.addFileArg(if (has_path) .{ .path = out } else b.path(out));
|
|
193
|
+
}
|
|
118
194
|
b.getInstallStep().dependOn(&sh.step);
|
|
195
|
+
if (!entry) b.installArtifact(bin);
|
|
196
|
+
} else if (entry) {
|
|
197
|
+
b.getInstallStep().dependOn(&b.addInstallArtifact(bin, .{
|
|
198
|
+
.dest_dir = .{ .override = std.Build.InstallDir{ .lib = {} } },
|
|
199
|
+
}).step);
|
|
119
200
|
}
|
|
120
|
-
b.installArtifact(lib);
|
|
121
201
|
} else if (dynamic) {
|
|
122
|
-
const
|
|
202
|
+
const path = if (has_path) .{ .path = "src/lib/c.zig" } else b.path("src/lib/c.zig");
|
|
203
|
+
const lib = b.addSharedLibrary(if (force_pic) .{
|
|
204
|
+
.name = name,
|
|
205
|
+
.root_source_file = path,
|
|
206
|
+
.version = try std.SemanticVersion.parse(version),
|
|
207
|
+
.optimize = optimize,
|
|
208
|
+
.target = target,
|
|
209
|
+
} else .{
|
|
123
210
|
.name = name,
|
|
124
|
-
.
|
|
125
|
-
.root_source_file = .{ .path = "src/lib/binding/c.zig" },
|
|
211
|
+
.root_source_file = path,
|
|
126
212
|
.version = try std.SemanticVersion.parse(version),
|
|
127
213
|
.optimize = optimize,
|
|
128
214
|
.target = target,
|
|
215
|
+
.strip = strip,
|
|
216
|
+
.pic = pic,
|
|
129
217
|
});
|
|
130
|
-
lib.addOptions("build_options", options);
|
|
131
|
-
lib.addIncludePath(.{ .path = "src/include" });
|
|
218
|
+
(if (root_module) lib.root_module else lib).addOptions("build_options", options);
|
|
219
|
+
lib.addIncludePath(if (has_path) .{ .path = "src/include" } else b.path("src/include"));
|
|
132
220
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
133
|
-
if (pic) lib.force_pic = pic;
|
|
221
|
+
if (force_pic and pic orelse false) lib.force_pic = pic;
|
|
134
222
|
b.installArtifact(lib);
|
|
135
223
|
c = true;
|
|
136
224
|
} else {
|
|
137
|
-
const
|
|
225
|
+
const path = if (has_path) .{ .path = "src/lib/c.zig" } else b.path("src/lib/c.zig");
|
|
226
|
+
const lib = b.addStaticLibrary(if (force_pic) .{
|
|
138
227
|
.name = name,
|
|
139
|
-
.
|
|
140
|
-
.root_source_file = .{ .path = "src/lib/binding/c.zig" },
|
|
228
|
+
.root_source_file = path,
|
|
141
229
|
.optimize = optimize,
|
|
142
230
|
.target = target,
|
|
231
|
+
} else .{
|
|
232
|
+
.name = name,
|
|
233
|
+
.root_source_file = path,
|
|
234
|
+
.optimize = optimize,
|
|
235
|
+
.target = target,
|
|
236
|
+
.strip = strip,
|
|
237
|
+
.pic = pic,
|
|
143
238
|
});
|
|
144
|
-
lib.addOptions("build_options", options);
|
|
145
|
-
lib.addIncludePath(.{ .path = "src/include" });
|
|
239
|
+
(if (root_module) lib.root_module else lib).addOptions("build_options", options);
|
|
240
|
+
lib.addIncludePath(if (has_path) .{ .path = "src/include" } else b.path("src/include"));
|
|
146
241
|
lib.bundle_compiler_rt = true;
|
|
147
242
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
148
|
-
if (pic) lib.force_pic = pic;
|
|
243
|
+
if (force_pic and pic orelse false) lib.force_pic = pic;
|
|
149
244
|
if (emit_asm) {
|
|
150
245
|
b.getInstallStep().dependOn(&b.addInstallFileWithDir(
|
|
151
246
|
lib.getEmittedAsm(),
|
|
@@ -165,15 +260,17 @@ pub fn build(b: *std.Build) !void {
|
|
|
165
260
|
}
|
|
166
261
|
|
|
167
262
|
if (c) {
|
|
168
|
-
const
|
|
169
|
-
.{ .path = "src/include/pkmn.h" }
|
|
170
|
-
|
|
171
|
-
"pkmn.h",
|
|
172
|
-
);
|
|
263
|
+
const path =
|
|
264
|
+
if (has_path) .{ .path = "src/include/pkmn.h" } else b.path("src/include/pkmn.h");
|
|
265
|
+
const header = b.addInstallFileWithDir(path, .header, "pkmn.h");
|
|
173
266
|
b.getInstallStep().dependOn(&header.step);
|
|
174
267
|
|
|
175
268
|
const pc = b.fmt("lib{s}.pc", .{name});
|
|
176
|
-
const file = try
|
|
269
|
+
const file = try std.fs.path.relative(
|
|
270
|
+
b.allocator,
|
|
271
|
+
try std.process.getCwdAlloc(b.allocator),
|
|
272
|
+
try b.cache_root.join(b.allocator, &.{pc}),
|
|
273
|
+
);
|
|
177
274
|
const pkgconfig_file = try std.fs.cwd().createFile(file, .{});
|
|
178
275
|
|
|
179
276
|
const dirname = comptime std.fs.path.dirname(@src().file) orelse ".";
|
|
@@ -206,7 +303,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
206
303
|
// TODO: tests can be run multiple times due to @imports
|
|
207
304
|
const tests = TestStep.create(b, options, config);
|
|
208
305
|
|
|
209
|
-
var exes = std.ArrayList(*
|
|
306
|
+
var exes = std.ArrayList(*Step.Compile).init(b.allocator);
|
|
210
307
|
const tools: ToolConfig = .{
|
|
211
308
|
.options = .{
|
|
212
309
|
.showdown = showdown,
|
|
@@ -214,6 +311,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
214
311
|
.chance = chance,
|
|
215
312
|
.calc = calc,
|
|
216
313
|
},
|
|
314
|
+
.module = pkmn,
|
|
217
315
|
.general = config,
|
|
218
316
|
.tool = .{
|
|
219
317
|
.tests = if (tests.build) tests else null,
|
|
@@ -254,13 +352,13 @@ pub fn build(b: *std.Build) !void {
|
|
|
254
352
|
|
|
255
353
|
fn maybeStrip(
|
|
256
354
|
b: *std.Build,
|
|
257
|
-
artifact: *
|
|
355
|
+
artifact: *Step.Compile,
|
|
258
356
|
step: *std.Build.Step,
|
|
259
|
-
strip: bool,
|
|
357
|
+
strip: ?bool,
|
|
260
358
|
cmd: ?[]const u8,
|
|
261
359
|
) void {
|
|
262
|
-
artifact.strip = strip;
|
|
263
|
-
if (!strip or cmd == null) return;
|
|
360
|
+
if (@hasDecl(@TypeOf(artifact.*), "strip")) artifact.strip = strip orelse false;
|
|
361
|
+
if (!(strip orelse false) or cmd == null) return;
|
|
264
362
|
// Using `strip -r -u` for dynamic libraries is supposed to work on macOS but doesn't...
|
|
265
363
|
const mac = builtin.os.tag == .macos;
|
|
266
364
|
if (mac and artifact.isDynamicLibrary()) return;
|
|
@@ -272,10 +370,10 @@ fn maybeStrip(
|
|
|
272
370
|
}
|
|
273
371
|
|
|
274
372
|
const Config = struct {
|
|
275
|
-
target:
|
|
373
|
+
target: ResolvedTarget,
|
|
276
374
|
optimize: std.builtin.OptimizeMode,
|
|
277
|
-
pic: bool,
|
|
278
|
-
strip: bool,
|
|
375
|
+
pic: ?bool,
|
|
376
|
+
strip: ?bool,
|
|
279
377
|
cmd: ?[]const u8,
|
|
280
378
|
};
|
|
281
379
|
|
|
@@ -283,9 +381,8 @@ const TestStep = struct {
|
|
|
283
381
|
step: std.Build.Step,
|
|
284
382
|
build: bool,
|
|
285
383
|
|
|
286
|
-
pub fn create(b: *std.Build, options: *
|
|
384
|
+
pub fn create(b: *std.Build, options: *Step.Options, config: Config) *TestStep {
|
|
287
385
|
const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
|
|
288
|
-
const test_file = b.option([]const u8, "test-file", "Input file for test");
|
|
289
386
|
const test_filter =
|
|
290
387
|
b.option([]const u8, "test-filter", "Skip tests that do not match filter");
|
|
291
388
|
|
|
@@ -293,22 +390,28 @@ const TestStep = struct {
|
|
|
293
390
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
|
|
294
391
|
self.* = .{ .step = step, .build = test_filter == null };
|
|
295
392
|
|
|
296
|
-
const path =
|
|
297
|
-
const tests = b.addTest(.{
|
|
298
|
-
.
|
|
299
|
-
std.fs.path.basename(std.fs.path.dirname(path).?),
|
|
300
|
-
std.fs.path.stem(std.fs.path.basename(path)),
|
|
301
|
-
}),
|
|
302
|
-
.main_pkg_path = .{ .path = "." },
|
|
303
|
-
.root_source_file = .{ .path = path },
|
|
393
|
+
const path = if (has_path) .{ .path = "src/lib/test.zig" } else b.path("src/lib/test.zig");
|
|
394
|
+
const tests = b.addTest(if (force_pic) .{
|
|
395
|
+
.root_source_file = path,
|
|
304
396
|
.optimize = config.optimize,
|
|
305
397
|
.target = config.target,
|
|
306
398
|
.filter = test_filter,
|
|
399
|
+
} else .{
|
|
400
|
+
.root_source_file = path,
|
|
401
|
+
.optimize = config.optimize,
|
|
402
|
+
.target = config.target,
|
|
403
|
+
.filter = test_filter,
|
|
404
|
+
.single_threaded = true,
|
|
405
|
+
.strip = config.strip,
|
|
406
|
+
.pic = config.pic,
|
|
307
407
|
});
|
|
308
|
-
tests.addOptions("build_options", options);
|
|
309
|
-
|
|
408
|
+
(if (root_module) tests.root_module else tests).addOptions("build_options", options);
|
|
409
|
+
|
|
310
410
|
maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
|
|
311
|
-
if (
|
|
411
|
+
if (force_pic) {
|
|
412
|
+
tests.single_threaded = true;
|
|
413
|
+
if (config.pic orelse false) tests.force_pic = config.pic;
|
|
414
|
+
}
|
|
312
415
|
if (coverage) |c| {
|
|
313
416
|
tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
|
|
314
417
|
}
|
|
@@ -320,15 +423,16 @@ const TestStep = struct {
|
|
|
320
423
|
|
|
321
424
|
const ToolConfig = struct {
|
|
322
425
|
options: Options,
|
|
426
|
+
module: ?*std.Build.Module,
|
|
323
427
|
general: Config,
|
|
324
428
|
tool: struct {
|
|
325
429
|
tests: ?*TestStep,
|
|
326
430
|
name: ?[]const u8 = null,
|
|
327
|
-
exes: *std.ArrayList(*
|
|
431
|
+
exes: *std.ArrayList(*Step.Compile),
|
|
328
432
|
},
|
|
329
433
|
};
|
|
330
434
|
|
|
331
|
-
fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*
|
|
435
|
+
fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*Step.Run {
|
|
332
436
|
std.fs.cwd().access(path, .{}) catch |err| switch (err) {
|
|
333
437
|
error.FileNotFound => return null,
|
|
334
438
|
else => |e| return e,
|
|
@@ -338,16 +442,32 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.RunSte
|
|
|
338
442
|
if (index) |i| name = name[0..i];
|
|
339
443
|
if (config.options.showdown orelse false) name = b.fmt("{s}-showdown", .{name});
|
|
340
444
|
|
|
341
|
-
const exe = b.addExecutable(.{
|
|
445
|
+
const exe = b.addExecutable(if (force_pic) .{
|
|
342
446
|
.name = name,
|
|
343
|
-
.root_source_file = .{ .path = path },
|
|
447
|
+
.root_source_file = if (has_path) .{ .path = path } else b.path(path),
|
|
344
448
|
.target = config.general.target,
|
|
345
449
|
.optimize = config.general.optimize,
|
|
450
|
+
} else .{
|
|
451
|
+
.name = name,
|
|
452
|
+
.root_source_file = if (has_path) .{ .path = path } else b.path(path),
|
|
453
|
+
.target = config.general.target,
|
|
454
|
+
.optimize = config.general.optimize,
|
|
455
|
+
.single_threaded = true,
|
|
456
|
+
.strip = config.general.strip,
|
|
457
|
+
.pic = config.general.pic,
|
|
346
458
|
});
|
|
347
|
-
exe.addModule("pkmn", module(b, config.options));
|
|
348
459
|
|
|
349
|
-
|
|
350
|
-
|
|
460
|
+
if (root_module) {
|
|
461
|
+
const import = if (config.module) |m| m else module(b, config.options);
|
|
462
|
+
exe.root_module.addImport("pkmn", import);
|
|
463
|
+
} else {
|
|
464
|
+
exe.addModule("pkmn", module(b, config.options));
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (force_pic) {
|
|
468
|
+
exe.single_threaded = true;
|
|
469
|
+
if (config.general.pic orelse false) exe.force_pic = config.general.pic;
|
|
470
|
+
}
|
|
351
471
|
if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
|
|
352
472
|
config.tool.exes.append(exe) catch @panic("OOM");
|
|
353
473
|
|
|
@@ -361,7 +481,7 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.RunSte
|
|
|
361
481
|
const ToolsStep = struct {
|
|
362
482
|
step: std.Build.Step,
|
|
363
483
|
|
|
364
|
-
pub fn create(b: *std.Build, exes: *std.ArrayList(*
|
|
484
|
+
pub fn create(b: *std.Build, exes: *std.ArrayList(*Step.Compile)) *ToolsStep {
|
|
365
485
|
const self = b.allocator.create(ToolsStep) catch @panic("OOM");
|
|
366
486
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Install tools", .owner = b });
|
|
367
487
|
self.* = .{ .step = step };
|
|
@@ -369,3 +489,8 @@ const ToolsStep = struct {
|
|
|
369
489
|
return self;
|
|
370
490
|
}
|
|
371
491
|
};
|
|
492
|
+
|
|
493
|
+
fn detect(target: anytype) std.Target {
|
|
494
|
+
if (@hasField(@TypeOf(target), "result")) return target.result;
|
|
495
|
+
return (std.zig.system.NativeTargetInfo.detect(target) catch unreachable).target;
|
|
496
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pkmn/engine",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.3393edb3",
|
|
4
4
|
"description": "A minimal, complete, Pokémon battle simulation engine optimized for performance",
|
|
5
5
|
"repository": "github:pkmn/engine",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"main": "build/pkg/index.js",
|
|
9
9
|
"types": "build/pkg/index.d.ts",
|
|
10
|
+
"browser": {
|
|
11
|
+
"./build/pkg/addon/node.js": "./build/pkg/addon/browser.js"
|
|
12
|
+
},
|
|
10
13
|
"files": [
|
|
11
14
|
"build.zig",
|
|
12
|
-
"build/pkg/data.d.ts",
|
|
13
|
-
"build/pkg/data.js.map",
|
|
14
15
|
"build/pkg/addon.d.ts",
|
|
15
16
|
"build/pkg/addon.js.map",
|
|
16
17
|
"build/pkg/addon.js",
|
|
18
|
+
"build/pkg/addon/browser.d.ts",
|
|
19
|
+
"build/pkg/addon/browser.js.map",
|
|
20
|
+
"build/pkg/addon/browser.js",
|
|
21
|
+
"build/pkg/addon/node.d.ts",
|
|
22
|
+
"build/pkg/addon/node.js.map",
|
|
23
|
+
"build/pkg/addon/node.js",
|
|
24
|
+
"build/pkg/data.d.ts",
|
|
25
|
+
"build/pkg/data.js.map",
|
|
17
26
|
"build/pkg/data.js",
|
|
18
27
|
"build/pkg/data/ids.json",
|
|
19
28
|
"build/pkg/data/layout.json",
|
|
@@ -27,13 +36,17 @@
|
|
|
27
36
|
"build/pkg/protocol.d.ts",
|
|
28
37
|
"build/pkg/protocol.js.map",
|
|
29
38
|
"build/pkg/protocol.js",
|
|
30
|
-
"build/test/display.js.map",
|
|
31
|
-
"build/test/display.js",
|
|
32
39
|
"build/tools/debug.js.map",
|
|
33
40
|
"build/tools/debug.js",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
41
|
+
"build/tools/display/index.js.map",
|
|
42
|
+
"build/tools/display/index.js",
|
|
43
|
+
"build/tools/display/debug.jsx.map",
|
|
44
|
+
"build/tools/display/debug.jsx",
|
|
45
|
+
"build/tools/display/ui.jsx.map",
|
|
46
|
+
"build/tools/display/ui.jsx",
|
|
47
|
+
"build/tools/display/util.js.map",
|
|
48
|
+
"build/tools/display/util.js",
|
|
49
|
+
"src/lib/common/array.zig",
|
|
37
50
|
"src/lib/common/battle.zig",
|
|
38
51
|
"src/lib/common/data.zig",
|
|
39
52
|
"src/lib/common/debug.zig",
|
|
@@ -62,8 +75,11 @@
|
|
|
62
75
|
"src/lib/gen2/generated.zig",
|
|
63
76
|
"src/lib/gen2/helpers.zig",
|
|
64
77
|
"src/lib/gen2/mechanics.zig",
|
|
78
|
+
"src/lib/node.zig",
|
|
65
79
|
"src/lib/pkmn.zig",
|
|
66
|
-
"src/
|
|
80
|
+
"src/lib/wasm.zig",
|
|
81
|
+
"src/tools/display/dom.ts",
|
|
82
|
+
"src/tools/display/ui.css"
|
|
67
83
|
],
|
|
68
84
|
"engines": {
|
|
69
85
|
"node": ">=16.0.0"
|
|
@@ -76,30 +92,37 @@
|
|
|
76
92
|
"access": "public"
|
|
77
93
|
},
|
|
78
94
|
"dependencies": {
|
|
79
|
-
"@pkmn/data": "^0.
|
|
80
|
-
"@pkmn/protocol": "^0.6.
|
|
95
|
+
"@pkmn/data": "^0.9.13",
|
|
96
|
+
"@pkmn/protocol": "^0.6.26"
|
|
81
97
|
},
|
|
82
98
|
"devDependencies": {
|
|
83
|
-
"@pkmn/eslint-config": "^
|
|
84
|
-
"@pkmn/img": "^0.2.
|
|
85
|
-
"@pkmn/sets": "^5.1.
|
|
86
|
-
"@pkmn/sim": "0.
|
|
87
|
-
"@types/html-minifier": "^4.0.
|
|
88
|
-
"@types/jest": "^29.5.
|
|
89
|
-
"@types/minimist": "^1.2.
|
|
90
|
-
"@types/mustache": "^4.2.
|
|
91
|
-
"@types/node": "^
|
|
92
|
-
"@
|
|
93
|
-
"
|
|
94
|
-
"
|
|
99
|
+
"@pkmn/eslint-config": "^8.3.0",
|
|
100
|
+
"@pkmn/img": "^0.2.32",
|
|
101
|
+
"@pkmn/sets": "^5.1.2",
|
|
102
|
+
"@pkmn/sim": "0.9.13",
|
|
103
|
+
"@types/html-minifier": "^4.0.5",
|
|
104
|
+
"@types/jest": "^29.5.12",
|
|
105
|
+
"@types/minimist": "^1.2.5",
|
|
106
|
+
"@types/mustache": "^4.2.5",
|
|
107
|
+
"@types/node": "^22.5.3",
|
|
108
|
+
"@types/react": "^18.2.45",
|
|
109
|
+
"@types/semver": "^7.5.8",
|
|
110
|
+
"@types/vscode": "^1.93.0",
|
|
111
|
+
"@vitest/coverage-v8": "^2.0.5",
|
|
112
|
+
"@vscode/vsce": "^3.1.0",
|
|
113
|
+
"binaryen": "^118.0.0",
|
|
114
|
+
"esbuild": "^0.23.1",
|
|
115
|
+
"eslint": "<=8",
|
|
95
116
|
"html-minifier": "^4.0.0",
|
|
96
|
-
"json-stringify-pretty-compact": "
|
|
117
|
+
"json-stringify-pretty-compact": "4.0.0",
|
|
97
118
|
"minimist": "^1.2.8",
|
|
98
119
|
"mustache": "^4.2.0",
|
|
120
|
+
"semver": "^7.6.3",
|
|
99
121
|
"source-map-support": "^0.5.21",
|
|
122
|
+
"table": "^6.8.2",
|
|
100
123
|
"trakr": "^0.2.0",
|
|
101
|
-
"typescript": "^5.
|
|
102
|
-
"vitest": "^0.
|
|
124
|
+
"typescript": "^5.5.4",
|
|
125
|
+
"vitest": "^2.0.5"
|
|
103
126
|
},
|
|
104
127
|
"scripts": {
|
|
105
128
|
"lint": "eslint --cache src --ext ts,js && eslint src/bin/*",
|
|
@@ -109,11 +132,13 @@
|
|
|
109
132
|
"test": "vitest src/pkg",
|
|
110
133
|
"test:integration": "vitest src/test",
|
|
111
134
|
"debug": "npm run compile && node build/tools/debug",
|
|
135
|
+
"demo": "npm run compile && node build/tools/demo",
|
|
112
136
|
"fuzz": "npm run compile && node build/test/fuzz",
|
|
113
137
|
"generate": "npm run compile && node build/tools/generate",
|
|
114
138
|
"release": "npm run compile && node build/tools/release",
|
|
115
139
|
"benchmark": "npm run compile && node build/test/benchmark",
|
|
116
140
|
"integration": "npm run compile && node build/test/integration",
|
|
141
|
+
"extension": "npm -C src/tools/vscode run build",
|
|
117
142
|
"postinstall": "node src/bin/install-pkmn-engine"
|
|
118
143
|
},
|
|
119
144
|
"eslintConfig": {
|
|
@@ -122,7 +147,8 @@
|
|
|
122
147
|
"dist/",
|
|
123
148
|
"node_modules/",
|
|
124
149
|
"examples/zig",
|
|
125
|
-
"build/"
|
|
150
|
+
"build/",
|
|
151
|
+
"extension.js"
|
|
126
152
|
],
|
|
127
153
|
"env": {
|
|
128
154
|
"es6": true,
|
|
@@ -144,7 +170,6 @@
|
|
|
144
170
|
{
|
|
145
171
|
"files": [
|
|
146
172
|
"src/pkg/index.ts",
|
|
147
|
-
"src/test/display.ts",
|
|
148
173
|
"src/test/integration.ts"
|
|
149
174
|
],
|
|
150
175
|
"rules": {
|
|
@@ -156,7 +181,7 @@
|
|
|
156
181
|
},
|
|
157
182
|
{
|
|
158
183
|
"files": [
|
|
159
|
-
"src/pkg/addon.ts"
|
|
184
|
+
"src/pkg/addon/node.ts"
|
|
160
185
|
],
|
|
161
186
|
"rules": {
|
|
162
187
|
"@typescript-eslint/no-var-requires": "off"
|