@pkmn/engine 0.1.0-dev.9a0c07c3 → 0.1.0-dev.a324c50f

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.
Files changed (41) hide show
  1. package/README.md +32 -29
  2. package/build/pkg/addon.d.ts +7 -0
  3. package/build/pkg/addon.js +112 -0
  4. package/build/pkg/addon.js.map +1 -0
  5. package/build/pkg/data/layout.json +25 -3
  6. package/build/pkg/gen1.d.ts +5 -4
  7. package/build/pkg/gen1.js +47 -31
  8. package/build/pkg/gen1.js.map +1 -1
  9. package/build/pkg/index.d.ts +15 -12
  10. package/build/pkg/index.js.map +1 -1
  11. package/build/pkg/protocol.d.ts +4 -2
  12. package/build/pkg/protocol.js +4 -2
  13. package/build/pkg/protocol.js.map +1 -1
  14. package/build/test/display.js +31 -13
  15. package/build/test/display.js.map +1 -1
  16. package/build.zig +49 -39
  17. package/package.json +18 -14
  18. package/src/bin/install-pkmn-engine +11 -6
  19. package/src/bin/pkmn-debug +34 -7
  20. package/src/lib/binding/node.zig +46 -141
  21. package/src/lib/binding/wasm.zig +6 -4
  22. package/src/lib/common/data.zig +11 -11
  23. package/src/lib/common/debug.zig +21 -11
  24. package/src/lib/common/options.zig +12 -3
  25. package/src/lib/common/protocol.zig +239 -178
  26. package/src/lib/common/rng.zig +10 -10
  27. package/src/lib/gen1/README.md +111 -81
  28. package/src/lib/gen1/data/moves.zig +10 -10
  29. package/src/lib/gen1/data/species.zig +2 -2
  30. package/src/lib/gen1/data/types.zig +3 -3
  31. package/src/lib/gen1/data.zig +64 -43
  32. package/src/lib/gen1/helpers.zig +439 -32
  33. package/src/lib/gen1/mechanics.zig +987 -612
  34. package/src/lib/gen2/data/items.zig +3 -3
  35. package/src/lib/gen2/data/moves.zig +1 -1
  36. package/src/lib/gen2/data/species.zig +1 -1
  37. package/src/lib/gen2/data/types.zig +3 -3
  38. package/src/lib/gen2/data.zig +37 -26
  39. package/src/lib/gen2/helpers.zig +9 -11
  40. package/src/lib/gen2/mechanics.zig +5 -4
  41. package/src/lib/pkmn.zig +68 -9
@@ -2,9 +2,11 @@ const std = @import("std");
2
2
  const pkmn = @import("../pkmn.zig");
3
3
 
4
4
  export const SHOWDOWN = pkmn.options.showdown;
5
- export const TRACE = pkmn.options.trace;
5
+ export const LOG = pkmn.options.log;
6
+ export const CHANCE = pkmn.options.chance;
7
+ export const CALC = pkmn.options.calc;
6
8
 
7
- export const GEN1_OPTIONS_SIZE =
8
- std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.OPTIONS_SIZE)) catch unreachable;
9
+ export const GEN1_CHOICES_SIZE =
10
+ std.math.ceilPowerOfTwo(u32, @as(u32, @intCast(pkmn.gen1.CHOICES_SIZE))) catch unreachable;
9
11
  export const GEN1_LOGS_SIZE =
10
- std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.LOGS_SIZE)) catch unreachable;
12
+ std.math.ceilPowerOfTwo(u32, @as(u32, @intCast(pkmn.gen1.LOGS_SIZE))) catch unreachable;
@@ -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 @intToEnum(Player, ~@enumToInt(self));
13
+ return @enumFromInt(~@intFromEnum(self));
14
14
  }
15
15
 
16
16
  /// Return's an identifier for the player's Pokémon at the one-indexed `id`.
@@ -22,8 +22,8 @@ pub const Player = enum(u1) {
22
22
 
23
23
  test Player {
24
24
  try expectEqual(Player.P2, Player.P1.foe());
25
- try expectEqual(@as(u8, 0b0001), @bitCast(u8, Player.P1.ident(1)));
26
- try expectEqual(@as(u8, 0b1101), @bitCast(u8, Player.P2.ident(5)));
25
+ try expectEqual(@as(u8, 0b0001), @as(u8, @bitCast(Player.P1.ident(1))));
26
+ try expectEqual(@as(u8, 0b1101), @as(u8, @bitCast(Player.P2.ident(5))));
27
27
  }
28
28
 
29
29
  /// An identifier for a specific Pokémon in battle.
@@ -40,18 +40,18 @@ pub const ID = packed struct {
40
40
 
41
41
  /// Converts the identifier into a number.
42
42
  pub inline fn int(self: ID) u4 {
43
- return @intCast(u4, @bitCast(u8, self));
43
+ return @intCast(@as(u8, @bitCast(self)));
44
44
  }
45
45
 
46
46
  /// Decodes the identifier from a number.
47
47
  pub inline fn from(id: u4) ID {
48
- return @bitCast(ID, @as(u8, id));
48
+ return @bitCast(@as(u8, id));
49
49
  }
50
50
  };
51
51
 
52
52
  test ID {
53
- try expectEqual(@as(u8, 0b0001), @bitCast(u8, ID{ .player = .P1, .id = 1 }));
54
- try expectEqual(@as(u8, 0b1101), @bitCast(u8, ID{ .player = .P2, .id = 5 }));
53
+ try expectEqual(@as(u8, 0b0001), @as(u8, @bitCast(ID{ .player = .P1, .id = 1 })));
54
+ try expectEqual(@as(u8, 0b1101), @as(u8, @bitCast(ID{ .player = .P2, .id = 5 })));
55
55
  const id = ID{ .player = .P2, .id = 4 };
56
56
  try expectEqual(id, ID.from(id.int()));
57
57
  }
@@ -84,8 +84,8 @@ test Choice {
84
84
  const p2: Choice = .{ .type = .Switch, .data = 5 };
85
85
  try expectEqual(5, p2.data);
86
86
  try expectEqual(Choice.Type.Move, p1.type);
87
- try expectEqual(0b0001_0001, @bitCast(u8, p1));
88
- try expectEqual(0b0001_0110, @bitCast(u8, p2));
87
+ try expectEqual(0b0001_0001, @as(u8, @bitCast(p1)));
88
+ try expectEqual(0b0001_0110, @as(u8, @bitCast(p2)));
89
89
  }
90
90
 
91
91
  /// The result of the battle - all results other than 'None' should be considered terminal.
@@ -124,6 +124,6 @@ pub const Result = packed struct {
124
124
  };
125
125
 
126
126
  test Result {
127
- try expectEqual(0b0101_0000, @bitCast(u8, Result.Default));
128
- try expectEqual(0b1000_0000, @bitCast(u8, Result{ .p2 = .Switch }));
127
+ try expectEqual(0b0101_0000, @as(u8, @bitCast(Result.Default)));
128
+ try expectEqual(0b1000_0000, @as(u8, @bitCast(Result{ .p2 = .Switch })));
129
129
  }
@@ -10,18 +10,27 @@ pub fn print(value: anytype) void {
10
10
 
11
11
  nosuspend {
12
12
  stderr.writeAll("\x1b[41m") catch return;
13
- switch (@typeInfo(@TypeOf(value))) {
14
- .Struct => |info| {
15
- if (info.is_tuple) {
16
- inline for (info.fields, 0..) |f, i| {
17
- inspect(@field(value, f.name));
18
- if (i < info.fields.len - 1) stderr.writeAll(" ") catch return;
13
+ if (@TypeOf(@src()) == @TypeOf(value)) {
14
+ stderr.print("{s} ({s}:{d}:{d})", .{
15
+ value.fn_name,
16
+ value.file,
17
+ value.line,
18
+ value.column,
19
+ }) catch return;
20
+ } else {
21
+ switch (@typeInfo(@TypeOf(value))) {
22
+ .Struct => |info| {
23
+ if (info.is_tuple) {
24
+ inline for (info.fields, 0..) |f, i| {
25
+ inspect(@field(value, f.name));
26
+ if (i < info.fields.len - 1) stderr.writeAll(" ") catch return;
27
+ }
28
+ } else {
29
+ inspect(value);
19
30
  }
20
- } else {
21
- inspect(value);
22
- }
23
- },
24
- else => inspect(value),
31
+ },
32
+ else => inspect(value),
33
+ }
25
34
  }
26
35
  stderr.writeAll("\x1b[K\x1b[0m\n") catch return;
27
36
  }
@@ -58,6 +67,7 @@ fn inspect(value: anytype) void {
58
67
  @compileError(err);
59
68
  },
60
69
  },
70
+ .Optional => stderr.print("{?}", .{value}) catch return,
61
71
  else => stderr.print("{}", .{value}) catch return,
62
72
  }
63
73
  }
@@ -1,21 +1,30 @@
1
1
  const build_options = @import("build_options");
2
2
  const root = @import("root");
3
3
 
4
+ /// Configures the behavior of the pkmn package.
4
5
  pub const Options = struct {
5
6
  showdown: ?bool = null,
6
- trace: ?bool = null,
7
+ log: ?bool = null,
8
+ chance: ?bool = null,
9
+ calc: ?bool = null,
7
10
  advance: ?bool = null,
8
11
  ebc: ?bool = null,
12
+ key: ?bool = null,
9
13
  internal: ?bool = null,
10
14
  };
11
15
 
12
16
  /// Whether or not Pokémon Showdown compatibility mode is enabled.
13
17
  pub const showdown = get("showdown", false);
14
- /// Whether or not protocol trace logging is enabled.
15
- pub const trace = get("trace", false);
18
+ /// Whether or not protocol message logging is enabled.
19
+ pub const log = get("log", false);
20
+ /// Whether or not update probability tracking is enabled.
21
+ pub const chance = get("chance", false);
22
+ /// Whether or not damage calculator support is enabled.
23
+ pub const calc = get("calc", false);
16
24
 
17
25
  pub const advance = get("advance", true);
18
26
  pub const ebc = get("ebc", true);
27
+ pub const key = get("key", false);
19
28
  pub const internal = get("internal", false);
20
29
 
21
30
  fn get(comptime name: []const u8, default: bool) bool {