@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.
Files changed (45) hide show
  1. package/README.md +52 -24
  2. package/build/pkg/addon.d.ts +7 -0
  3. package/build/pkg/addon.js +111 -0
  4. package/build/pkg/addon.js.map +1 -0
  5. package/build/pkg/data/layout.json +1 -1
  6. package/build/pkg/data.d.ts +1 -2
  7. package/build/pkg/data.js +3 -5
  8. package/build/pkg/data.js.map +1 -1
  9. package/build/pkg/gen1.d.ts +5 -4
  10. package/build/pkg/gen1.js +43 -24
  11. package/build/pkg/gen1.js.map +1 -1
  12. package/build/pkg/index.d.ts +15 -12
  13. package/build/pkg/index.js.map +1 -1
  14. package/build/pkg/protocol.d.ts +4 -2
  15. package/build/pkg/protocol.js +4 -2
  16. package/build/pkg/protocol.js.map +1 -1
  17. package/build/test/display.js +400 -0
  18. package/build/test/display.js.map +1 -0
  19. package/build/tools/debug.js +133 -0
  20. package/build/tools/debug.js.map +1 -0
  21. package/build.zig +30 -39
  22. package/package.json +45 -34
  23. package/src/bin/install-pkmn-engine +47 -28
  24. package/src/bin/pkmn-debug +62 -0
  25. package/src/lib/binding/node.zig +7 -7
  26. package/src/lib/binding/wasm.zig +3 -3
  27. package/src/lib/common/data.zig +1 -1
  28. package/src/lib/common/debug.zig +1 -0
  29. package/src/lib/common/options.zig +3 -3
  30. package/src/lib/common/protocol.zig +140 -133
  31. package/src/lib/gen1/README.md +106 -70
  32. package/src/lib/gen1/data/moves.zig +10 -10
  33. package/src/lib/gen1/data/species.zig +2 -2
  34. package/src/lib/gen1/data/types.zig +2 -2
  35. package/src/lib/gen1/data.zig +32 -28
  36. package/src/lib/gen1/helpers.zig +6 -17
  37. package/src/lib/gen1/mechanics.zig +418 -325
  38. package/src/lib/gen2/data/items.zig +3 -3
  39. package/src/lib/gen2/data/moves.zig +1 -1
  40. package/src/lib/gen2/data/species.zig +1 -1
  41. package/src/lib/gen2/data/types.zig +3 -3
  42. package/src/lib/gen2/data.zig +12 -12
  43. package/src/lib/gen2/helpers.zig +3 -3
  44. package/src/lib/pkmn.zig +7 -7
  45. package/src/test/display/pkmn.html.tmpl +368 -0
@@ -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("trace", .{ .value = Boolean.init(env, pkmn.options.trace) }),
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 options_size = @intCast(u32, gen.OPTIONS_SIZE);
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("OPTIONS_SIZE", .{ .value = Number.init(env, options_size) }),
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 = @intToEnum(pkmn.Player, Number.get(env, argv[1], u8));
108
- const request = @intToEnum(pkmn.Choice.Type, Number.get(env, argv[2], u8));
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.OPTIONS_SIZE);
111
+ assert(len == gen.CHOICES_SIZE);
112
112
  assert(data != null);
113
113
 
114
- var out = @ptrCast([*]pkmn.Choice, data.?)[0..gen.OPTIONS_SIZE];
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
  }
@@ -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 TRACE = pkmn.options.trace;
5
+ export const LOG = pkmn.options.log;
6
6
 
7
- export const GEN1_OPTIONS_SIZE =
8
- std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.OPTIONS_SIZE)) catch unreachable;
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;
@@ -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(Player, ~@intFromEnum(self));
14
14
  }
15
15
 
16
16
  /// Return's an identifier for the player's Pokémon at the one-indexed `id`.
@@ -58,6 +58,7 @@ fn inspect(value: anytype) void {
58
58
  @compileError(err);
59
59
  },
60
60
  },
61
+ .Optional => stderr.print("{?}", .{value}) catch return,
61
62
  else => stderr.print("{}", .{value}) catch return,
62
63
  }
63
64
  }
@@ -3,7 +3,7 @@ const root = @import("root");
3
3
 
4
4
  pub const Options = struct {
5
5
  showdown: ?bool = null,
6
- trace: ?bool = null,
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 trace logging is enabled.
15
- pub const trace = get("trace", false);
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);