@pkmn/engine 0.1.0-dev.f3aaee39 → 0.1.0-dev.f4ba6ebd

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 (56) hide show
  1. package/LICENSE +1 -3
  2. package/README.md +46 -19
  3. package/build/pkg/addon.js +6 -7
  4. package/build/pkg/addon.js.map +1 -1
  5. package/build/pkg/data/ids.json +12 -12
  6. package/build/pkg/data/layout.json +2 -2
  7. package/build/pkg/data/protocol.json +69 -12
  8. package/build/pkg/data.d.ts +4 -4
  9. package/build/pkg/data.js.map +1 -1
  10. package/build/pkg/gen1.js +2 -2
  11. package/build/pkg/gen1.js.map +1 -1
  12. package/build/pkg/index.d.ts +3 -2
  13. package/build/pkg/index.js.map +1 -1
  14. package/build/pkg/protocol.js +61 -42
  15. package/build/pkg/protocol.js.map +1 -1
  16. package/build/test/display.js +8 -3
  17. package/build/test/display.js.map +1 -1
  18. package/build/tools/debug.js +5 -4
  19. package/build/tools/debug.js.map +1 -1
  20. package/build.zig +227 -96
  21. package/package.json +46 -23
  22. package/src/bin/install-pkmn-engine +29 -19
  23. package/src/lib/common/array.zig +77 -0
  24. package/src/lib/common/data.zig +12 -24
  25. package/src/lib/common/debug.zig +2 -2
  26. package/src/lib/common/js.zig +4 -2
  27. package/src/lib/common/optional.zig +21 -10
  28. package/src/lib/common/options.zig +2 -0
  29. package/src/lib/common/protocol.zig +807 -327
  30. package/src/lib/common/rational.zig +125 -31
  31. package/src/lib/common/rng.zig +22 -13
  32. package/src/lib/common/util.zig +50 -1
  33. package/src/lib/gen1/calc.zig +514 -135
  34. package/src/lib/gen1/chance.zig +407 -284
  35. package/src/lib/gen1/data/moves.zig +192 -180
  36. package/src/lib/gen1/data/species.zig +3 -3
  37. package/src/lib/gen1/data/types.zig +7 -7
  38. package/src/lib/gen1/data.zig +46 -57
  39. package/src/lib/gen1/helpers.zig +95 -550
  40. package/src/lib/gen1/mechanics.zig +571 -516
  41. package/src/lib/gen2/calc.zig +161 -0
  42. package/src/lib/gen2/chance.zig +905 -0
  43. package/src/lib/gen2/data/items.zig +12 -18
  44. package/src/lib/gen2/data/moves.zig +663 -569
  45. package/src/lib/gen2/data/species.zig +1 -1
  46. package/src/lib/gen2/data/types.zig +134 -31
  47. package/src/lib/gen2/data.zig +107 -79
  48. package/src/lib/gen2/generated.zig +806 -0
  49. package/src/lib/gen2/helpers.zig +49 -21
  50. package/src/lib/gen2/mechanics.zig +3563 -9
  51. package/src/lib/{binding/node.zig → node.zig} +10 -13
  52. package/src/lib/pkmn.zig +32 -15
  53. package/src/lib/{binding/wasm.zig → wasm.zig} +2 -1
  54. package/src/test/display/pkmn.html.tmpl +5 -5
  55. package/src/lib/gen1/README.md +0 -892
  56. package/src/lib/gen2/README.md +0 -308
@@ -1,7 +1,8 @@
1
1
  const std = @import("std");
2
- const pkmn = @import("../pkmn.zig");
3
2
 
4
- const js = @import("../common/js.zig");
3
+ const pkmn = @import("pkmn.zig");
4
+
5
+ const js = @import("common/js.zig");
5
6
 
6
7
  const assert = std.debug.assert;
7
8
 
@@ -19,7 +20,7 @@ export fn napi_register_module_v1(env: c.napi_env, exports: c.napi_value) c.napi
19
20
  }
20
21
 
21
22
  pub fn register(env: c.napi_env) c.napi_value {
22
- var object = js.Object.init(env);
23
+ const object = js.Object.init(env);
23
24
  const properties = [_]c.napi_property_descriptor{
24
25
  js.Property.init("options", .{ .value = options(env) }),
25
26
  js.Property.init("bindings", .{ .value = bindings(env) }),
@@ -29,7 +30,7 @@ pub fn register(env: c.napi_env) c.napi_value {
29
30
  }
30
31
 
31
32
  fn options(env: c.napi_env) c.napi_value {
32
- var object = js.Object.init(env);
33
+ const object = js.Object.init(env);
33
34
  const properties = [_]c.napi_property_descriptor{
34
35
  js.Property.init("showdown", .{ .value = js.Boolean.init(env, pkmn.options.showdown) }),
35
36
  js.Property.init("log", .{ .value = js.Boolean.init(env, pkmn.options.log) }),
@@ -41,7 +42,7 @@ fn options(env: c.napi_env) c.napi_value {
41
42
  }
42
43
 
43
44
  fn bindings(env: c.napi_env) c.napi_value {
44
- var array = js.Array.init(env, .{ .length = 1 });
45
+ const array = js.Array.init(env, .{ .length = 1 });
45
46
  js.Array.set(env, array, 0, bind(env, pkmn.gen1));
46
47
  return array;
47
48
  }
@@ -49,7 +50,7 @@ fn bindings(env: c.napi_env) c.napi_value {
49
50
  fn bind(env: c.napi_env, gen: anytype) c.napi_value {
50
51
  const choices_size: u32 = @intCast(gen.CHOICES_SIZE);
51
52
  const logs_size: u32 = @intCast(gen.LOGS_SIZE);
52
- var object = js.Object.init(env);
53
+ const object = js.Object.init(env);
53
54
  const properties = [_]c.napi_property_descriptor{
54
55
  js.Property.init("CHOICES_SIZE", .{ .value = js.Number.init(env, choices_size) }),
55
56
  js.Property.init("LOGS_SIZE", .{ .value = js.Number.init(env, logs_size) }),
@@ -72,7 +73,6 @@ fn update(gen: anytype) c.napi_callback {
72
73
  var len: usize = 0;
73
74
  assert(c.napi_get_arraybuffer_info(env, argv[0], &data, &len) == c.napi_ok);
74
75
  assert(len == @sizeOf(gen.Battle(gen.PRNG)));
75
- assert(data != null);
76
76
 
77
77
  var battle: *gen.Battle(gen.PRNG) = @alignCast(@ptrCast(data.?));
78
78
  const c1: pkmn.Choice = @bitCast(js.Number.get(env, argv[1], u8));
@@ -85,10 +85,9 @@ fn update(gen: anytype) c.napi_callback {
85
85
  else => result: {
86
86
  assert(c.napi_get_arraybuffer_info(env, argv[3], &data, &len) == c.napi_ok);
87
87
  assert(len == gen.LOGS_SIZE);
88
- assert(data != null);
89
88
 
90
- var buf = @as([*]u8, @ptrCast(data.?))[0..gen.LOGS_SIZE];
91
- var stream = pkmn.protocol.ByteStream{ .buffer = buf };
89
+ const buf = @as([*]u8, @ptrCast(data.?))[0..gen.LOGS_SIZE];
90
+ var stream: pkmn.protocol.ByteStream = .{ .buffer = buf };
92
91
  // TODO: extract out
93
92
  var opts = pkmn.battle.options(
94
93
  pkmn.protocol.FixedLog{ .writer = stream.writer() },
@@ -116,7 +115,6 @@ fn choices(gen: anytype) c.napi_callback {
116
115
  var len: usize = 0;
117
116
  assert(c.napi_get_arraybuffer_info(env, argv[0], &data, &len) == c.napi_ok);
118
117
  assert(len == @sizeOf(gen.Battle(gen.PRNG)));
119
- assert(data != null);
120
118
 
121
119
  var battle: *gen.Battle(gen.PRNG) = @alignCast(@ptrCast(data.?));
122
120
  const player: pkmn.Player = @enumFromInt(js.Number.get(env, argv[1], u8));
@@ -124,9 +122,8 @@ fn choices(gen: anytype) c.napi_callback {
124
122
 
125
123
  assert(c.napi_get_arraybuffer_info(env, argv[3], &data, &len) == c.napi_ok);
126
124
  assert(len == gen.CHOICES_SIZE);
127
- assert(data != null);
128
125
 
129
- var out = @as([*]pkmn.Choice, @ptrCast(data.?))[0..gen.CHOICES_SIZE];
126
+ const out = @as([*]pkmn.Choice, @ptrCast(data.?))[0..gen.CHOICES_SIZE];
130
127
  const n = battle.choices(player, request, out);
131
128
  return js.Number.init(env, @as(u8, @bitCast(n)));
132
129
  }
package/src/lib/pkmn.zig CHANGED
@@ -22,13 +22,16 @@ pub const Choice = @import("common/data.zig").Choice;
22
22
  /// considered terminal.
23
23
  pub const Result = @import("common/data.zig").Result;
24
24
 
25
+ // TODO
26
+ pub const Array = @import("common/array.zig").Array;
27
+ // TODO
28
+ pub const Optional = @import("common/optional.zig").Optional;
29
+
25
30
  /// Pokémon Showdown's RNG (backed by a Generation V & VI RNG).
26
31
  pub const PSRNG = @import("common/rng.zig").PSRNG;
27
32
 
28
33
  /// Namespace for helpers related to protocol message logging.
29
- pub const protocol = if (options.internal) struct {
30
- pub usingnamespace @import("common/protocol.zig");
31
- } else struct {
34
+ pub const protocol = if (options.internal) @import("common/protocol.zig") else struct {
32
35
  /// Logs protocol information to its `Writer` during a battle update when
33
36
  /// `options.log` is enabled.
34
37
  pub const Log = @import("common/protocol.zig").Log;
@@ -82,16 +85,12 @@ pub const gen1 = struct {
82
85
  /// via `overrides` and tracks `summaries` of information relevant to damage calculation.
83
86
  pub const Calc = @import("gen1/calc.zig").Calc;
84
87
  /// Namespace for types associated with supported Generation I Pokémon damage calc features.
85
- pub const calc = if (options.internal) struct {
86
- pub usingnamespace @import("gen1/calc.zig");
87
- } else struct {
88
- /// TODO
89
- pub const Overrides = @import("gen1/calc.zig").Overrides;
88
+ pub const calc = if (options.internal) @import("gen1/calc.zig") else struct {
90
89
  /// Information relevant to damage calculation that occured during a Generation I
91
90
  /// battle `update`.
92
91
  pub const Summaries = @import("gen1/calc.zig").Summaries;
93
92
  /// Information relevant to damage calculation that occured during a Generation I
94
- /// battle `update` for a single player.
93
+ /// battle `update` for a single player.
95
94
  pub const Summary = @import("gen1/calc.zig").Summary;
96
95
  /// Null object pattern implementation of Generation I `Calc` which does nothing,
97
96
  /// though damage calculator support should additionally be turned off
@@ -102,12 +101,30 @@ pub const gen1 = struct {
102
101
  pub const helpers = @import("gen1/helpers.zig");
103
102
  };
104
103
 
104
+ /// TODO
105
+ pub const gen2 = struct {
106
+ pub usingnamespace @import("gen2/data.zig");
107
+ pub const Chance = @import("gen2/chance.zig").Chance;
108
+ pub const chance = struct {
109
+ pub const Actions = @import("gen2/chance.zig").Actions;
110
+ pub const Action = @import("gen2/chance.zig").Action;
111
+ pub const Durations = @import("gen2/chance.zig").Durations;
112
+ pub const Duration = @import("gen2/chance.zig").Duration;
113
+ pub const NULL = @import("gen2/chance.zig").NULL;
114
+ };
115
+ pub const Calc = @import("gen2/calc.zig").Calc;
116
+ pub const calc = if (options.internal) @import("gen2/calc.zig") else struct {
117
+ pub const Summaries = @import("gen2/calc.zig").Summaries;
118
+ pub const Summary = @import("gen2/calc.zig").Summary;
119
+ pub const NULL = @import("gen2/calc.zig").NULL;
120
+ };
121
+ pub const helpers = @import("gen2/helpers.zig");
122
+ };
123
+
105
124
  // Internal APIs used by other pkmn libraries, not actually part of the public API.
106
125
  // NOTE: `pub usingnamespace struct { ... }` here results in a (false?) dependency loop
107
- pub const js = if (options.internal) struct {
108
- pub usingnamespace @import("common/js.zig");
109
- } else struct {};
126
+ pub const js = if (options.internal) @import("common/js.zig") else {};
110
127
  pub const bindings = if (options.internal) struct {
111
- pub const node = @import("binding/node.zig");
112
- pub const wasm = @import("binding/wasm.zig");
113
- } else struct {};
128
+ pub const node = @import("node.zig");
129
+ pub const wasm = @import("wasm.zig");
130
+ } else {};
@@ -1,5 +1,6 @@
1
1
  const std = @import("std");
2
- const pkmn = @import("../pkmn.zig");
2
+
3
+ const pkmn = @import("pkmn.zig");
3
4
 
4
5
  export const SHOWDOWN = pkmn.options.showdown;
5
6
  export const LOG = pkmn.options.log;
@@ -218,8 +218,9 @@
218
218
  border-radius: 0 4px 4px 0;
219
219
  }
220
220
  .moves ul {
221
- column-count: 2;
222
- column-gap: 2em;
221
+ display: grid;
222
+ grid-template-columns: repeat(2, auto);
223
+ gap: 0 2em;
223
224
  }
224
225
  .left {
225
226
  padding-right: 32px;
@@ -268,7 +269,7 @@
268
269
  }
269
270
  @media(max-width: 1200px) {
270
271
  .moves ul {
271
- column-count: 1;
272
+ grid-template-columns: repeat(1, auto);
272
273
  }
273
274
  }
274
275
  @media(max-width: 1100px) {
@@ -283,7 +284,7 @@
283
284
  margin-left: 5px;
284
285
  }
285
286
  .moves ul {
286
- column-count: 2;
287
+ grid-template-columns: repeat(2, auto);
287
288
  }
288
289
  .left {
289
290
  padding-right: 0;
@@ -309,7 +310,6 @@
309
310
  justify-content: center;
310
311
  }
311
312
  .moves ul {
312
- column-count: 1;
313
313
  display: inline-block;
314
314
  padding: 0;
315
315
  }