@pkmn/engine 0.1.0-dev.84cc1a02 → 0.1.0-dev.942dbfa4
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/layout.json +1 -1
- 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 +5 -4
- package/build/pkg/gen1.js +43 -24
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +15 -12
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +4 -2
- package/build/pkg/protocol.js +4 -2
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +400 -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 +30 -39
- package/package.json +45 -34
- package/src/bin/install-pkmn-engine +47 -28
- package/src/bin/pkmn-debug +62 -0
- package/src/lib/binding/node.zig +7 -7
- package/src/lib/binding/wasm.zig +3 -3
- package/src/lib/common/data.zig +1 -1
- package/src/lib/common/debug.zig +1 -0
- package/src/lib/common/options.zig +3 -3
- package/src/lib/common/protocol.zig +140 -133
- package/src/lib/gen1/README.md +106 -70
- package/src/lib/gen1/data/moves.zig +10 -10
- package/src/lib/gen1/data/species.zig +2 -2
- package/src/lib/gen1/data/types.zig +2 -2
- package/src/lib/gen1/data.zig +32 -28
- package/src/lib/gen1/helpers.zig +6 -17
- package/src/lib/gen1/mechanics.zig +418 -325
- package/src/lib/gen2/data/items.zig +3 -3
- package/src/lib/gen2/data/moves.zig +1 -1
- package/src/lib/gen2/data/species.zig +1 -1
- package/src/lib/gen2/data/types.zig +3 -3
- package/src/lib/gen2/data.zig +12 -12
- package/src/lib/gen2/helpers.zig +3 -3
- package/src/lib/pkmn.zig +7 -7
- package/src/test/display/pkmn.html.tmpl +368 -0
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("log", .{ .value = Boolean.init(env, pkmn.options.log) }),
|
|
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 choices_size = @intCast(u32, gen.CHOICES_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("CHOICES_SIZE", .{ .value = Number.init(env, choices_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) }),
|
|
@@ -104,14 +104,14 @@ fn choices(gen: anytype) c.napi_callback {
|
|
|
104
104
|
var aligned = @alignCast(@alignOf(*gen.Battle(gen.PRNG)), data.?);
|
|
105
105
|
var battle = @ptrCast(*gen.Battle(gen.PRNG), aligned);
|
|
106
106
|
|
|
107
|
-
const player = @
|
|
108
|
-
const request = @
|
|
107
|
+
const player = @enumFromInt(pkmn.Player, Number.get(env, argv[1], u8));
|
|
108
|
+
const request = @enumFromInt(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.CHOICES_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.CHOICES_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 LOG = pkmn.options.log;
|
|
6
6
|
|
|
7
|
-
export const
|
|
8
|
-
std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.
|
|
7
|
+
export const GEN1_CHOICES_SIZE =
|
|
8
|
+
std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.CHOICES_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/data.zig
CHANGED
|
@@ -10,7 +10,7 @@ pub const Player = enum(u1) {
|
|
|
10
10
|
|
|
11
11
|
/// Returns a player's opponent.
|
|
12
12
|
pub inline fn foe(self: Player) Player {
|
|
13
|
-
return @
|
|
13
|
+
return @enumFromInt(Player, ~@intFromEnum(self));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/// Return's an identifier for the player's Pokémon at the one-indexed `id`.
|
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
|
+
log: ?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 message logging is enabled.
|
|
15
|
+
pub const log = get("log", false);
|
|
16
16
|
|
|
17
17
|
pub const advance = get("advance", true);
|
|
18
18
|
pub const ebc = get("ebc", true);
|