@pkmn/engine 0.1.0-dev.deda8593 → 0.1.0-dev.e0a786f8

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 (79) hide show
  1. package/README.md +9 -6
  2. package/build/pkg/addon/browser.d.ts +3 -0
  3. package/build/pkg/addon/browser.js +47 -0
  4. package/build/pkg/addon/browser.js.map +1 -0
  5. package/build/pkg/addon/node.d.ts +3 -0
  6. package/build/pkg/addon/node.js +110 -0
  7. package/build/pkg/addon/node.js.map +1 -0
  8. package/build/pkg/addon/wasm.d.ts +2 -0
  9. package/build/pkg/addon/wasm.js +53 -0
  10. package/build/pkg/addon/wasm.js.map +1 -0
  11. package/build/pkg/addon.d.ts +25 -3
  12. package/build/pkg/addon.js +34 -65
  13. package/build/pkg/addon.js.map +1 -1
  14. package/build/pkg/data/layout.json +15 -2
  15. package/build/pkg/data/protocol.json +23 -9
  16. package/build/pkg/data.d.ts +23 -1
  17. package/build/pkg/data.js.map +1 -1
  18. package/build/pkg/gen1.d.ts +15 -18
  19. package/build/pkg/gen1.js +28 -19
  20. package/build/pkg/gen1.js.map +1 -1
  21. package/build/pkg/index.d.ts +40 -90
  22. package/build/pkg/index.js +23 -70
  23. package/build/pkg/index.js.map +1 -1
  24. package/build/pkg/protocol.d.ts +20 -1
  25. package/build/pkg/protocol.js +105 -103
  26. package/build/pkg/protocol.js.map +1 -1
  27. package/build/tools/debug.js +52 -76
  28. package/build/tools/debug.js.map +1 -1
  29. package/build/tools/display/debug.jsx +152 -0
  30. package/build/tools/display/debug.jsx.map +1 -0
  31. package/build/tools/display/index.js +152 -0
  32. package/build/tools/display/index.js.map +1 -0
  33. package/build/tools/display/ui.jsx +359 -0
  34. package/build/tools/display/ui.jsx.map +1 -0
  35. package/build/tools/display/util.js +33 -0
  36. package/build/tools/display/util.js.map +1 -0
  37. package/build.zig +330 -85
  38. package/package.json +54 -135
  39. package/src/bin/install-pkmn-engine +10 -7
  40. package/src/bin/pkmn-debug +1 -1
  41. package/src/lib/bindings/c.zig +255 -0
  42. package/src/lib/bindings/node.zig +121 -0
  43. package/src/lib/bindings/wasm.zig +59 -0
  44. package/src/lib/common/array.zig +77 -0
  45. package/src/lib/common/data.zig +8 -8
  46. package/src/lib/common/debug.zig +39 -8
  47. package/src/lib/common/js.zig +4 -2
  48. package/src/lib/common/optional.zig +13 -9
  49. package/src/lib/common/options.zig +4 -0
  50. package/src/lib/common/protocol.zig +45 -44
  51. package/src/lib/common/rational.zig +323 -157
  52. package/src/lib/common/rng.zig +5 -7
  53. package/src/lib/common/util.zig +60 -1
  54. package/src/lib/gen1/calc.zig +527 -161
  55. package/src/lib/gen1/chance.zig +366 -240
  56. package/src/lib/gen1/data/moves.zig +2 -4
  57. package/src/lib/gen1/data/species.zig +1 -3
  58. package/src/lib/gen1/data/types.zig +1 -2
  59. package/src/lib/gen1/data.zig +35 -38
  60. package/src/lib/gen1/helpers.zig +17 -554
  61. package/src/lib/gen1/mechanics.zig +280 -193
  62. package/src/lib/gen2/calc.zig +37 -27
  63. package/src/lib/gen2/chance.zig +90 -503
  64. package/src/lib/gen2/data/items.zig +1 -3
  65. package/src/lib/gen2/data/moves.zig +2 -4
  66. package/src/lib/gen2/data/species.zig +1 -3
  67. package/src/lib/gen2/data/types.zig +1 -2
  68. package/src/lib/gen2/data.zig +26 -29
  69. package/src/lib/gen2/generated.zig +18 -23
  70. package/src/lib/gen2/helpers.zig +9 -18
  71. package/src/lib/gen2/mechanics.zig +88 -115
  72. package/src/lib/node.zig +3 -116
  73. package/src/lib/pkmn.zig +14 -7
  74. package/src/lib/wasm.zig +13 -9
  75. package/src/tools/display/dom.ts +93 -0
  76. package/src/tools/display/ui.css +354 -0
  77. package/build/test/display.js +0 -400
  78. package/build/test/display.js.map +0 -1
  79. package/src/test/display/pkmn.html.tmpl +0 -368
@@ -1,22 +1,22 @@
1
- const std = @import("std");
2
-
3
- const pkmn = @import("../pkmn.zig");
4
-
1
+ const chance = @import("chance.zig");
5
2
  const common = @import("../common/data.zig");
3
+ const Optional = @import("../common/optional.zig").Optional;
4
+ const pkmn = @import("../pkmn.zig");
5
+ const std = @import("std");
6
6
  const util = @import("../common/util.zig");
7
7
 
8
- const chance = @import("chance.zig");
9
-
8
+ const Action = chance.Action;
9
+ const Actions = chance.Actions;
10
10
  const assert = std.debug.assert;
11
-
11
+ const Criticals = chance.Criticals;
12
+ const Damages = chance.Damages;
12
13
  const enabled = pkmn.options.calc;
13
-
14
+ const isPointerTo = util.isPointerTo;
14
15
  const Player = common.Player;
15
-
16
16
  const PointerType = util.PointerType;
17
17
 
18
- const Actions = chance.Actions;
19
- const Action = chance.Action;
18
+ const Int = if (@hasField(std.builtin.Type, "int")) .int else .Int;
19
+ const Enum = if (@hasField(std.builtin.Type, "enum")) .@"enum" else .Enum;
20
20
 
21
21
  /// Information relevant to damage calculation that occured during a Generation II battle `update`.
22
22
  pub const Summaries = extern struct {
@@ -31,7 +31,7 @@ pub const Summaries = extern struct {
31
31
 
32
32
  /// Returns the `Summary` for the given `player`.
33
33
  pub fn get(self: anytype, player: Player) PointerType(@TypeOf(self), Summary) {
34
- assert(@typeInfo(@TypeOf(self)).Pointer.child == Summaries);
34
+ assert(isPointerTo(self, Summaries));
35
35
  return if (player == .P1) &self.p1 else &self.p2;
36
36
  }
37
37
  };
@@ -65,33 +65,34 @@ pub const Summary = extern struct {
65
65
  }
66
66
  };
67
67
 
68
- /// TODO
69
- pub const Overrides = extern struct {
70
- /// TODO
71
- actions: Actions = .{},
72
- };
73
-
74
68
  /// Allows for forcing the value of specific RNG events during a Generation II battle `update` via
75
69
  /// `overrides` and tracks `summaries` of information relevant to damage calculation.
76
70
  pub const Calc = struct {
77
71
  /// Overrides the normal behavior of the RNG during an `update` to force specific outcomes.
78
- overrides: Overrides = .{},
72
+ overrides: Actions = .{},
79
73
  /// Information relevant to damage calculation.
80
74
  summaries: Summaries = .{},
81
75
 
82
76
  pub fn overridden(
83
77
  self: Calc,
84
78
  player: Player,
79
+ hit: u3,
85
80
  comptime field: Action.Field,
86
- ) ?std.meta.FieldType(Action, field) {
81
+ ) ReturnType(field) {
87
82
  if (!enabled) return null;
88
83
 
89
- const overrides =
90
- if (player == .P1) self.overrides.actions.p1 else self.overrides.actions.p2;
91
- const val = @field(overrides, @tagName(field));
84
+ const val = switch (field) {
85
+ .damages => Damages.get(self.overrides.get(player).damages, hit),
86
+ .critical_hits => Criticals.get(self.overrides.get(player).critical_hits, hit),
87
+ else => val: {
88
+ assert(hit == 0);
89
+ break :val @field(self.overrides.get(player), @tagName(field));
90
+ },
91
+ };
92
+
92
93
  return if (switch (@typeInfo(@TypeOf(val))) {
93
- .Enum => val != .None,
94
- .Int => val != 0,
94
+ Enum => val != .None,
95
+ Int => val != 0,
95
96
  else => unreachable,
96
97
  }) val else null;
97
98
  }
@@ -123,9 +124,10 @@ const Null = struct {
123
124
  pub fn overridden(
124
125
  self: Null,
125
126
  player: Player,
127
+ hit: u3,
126
128
  comptime field: Action.Field,
127
- ) ?std.meta.FieldType(Action, field) {
128
- _ = .{ self, player };
129
+ ) ReturnType(field) {
130
+ _ = .{ self, player, hit };
129
131
  return null;
130
132
  }
131
133
 
@@ -141,3 +143,11 @@ const Null = struct {
141
143
  _ = .{ self, player };
142
144
  }
143
145
  };
146
+
147
+ fn ReturnType(comptime field: Action.Field) type {
148
+ return ?(switch (field) {
149
+ .damages => u8,
150
+ .critical_hits => Optional(bool),
151
+ else => std.meta.FieldType(Action, field),
152
+ });
153
+ }