@pkmn/engine 0.1.0-dev.900756a9 → 0.1.0-dev.9257876b

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.
@@ -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,9 +85,8 @@ 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];
89
+ const buf = @as([*]u8, @ptrCast(data.?))[0..gen.LOGS_SIZE];
91
90
  var stream: pkmn.protocol.ByteStream = .{ .buffer = buf };
92
91
  // TODO: extract out
93
92
  var opts = pkmn.battle.options(
@@ -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
@@ -91,7 +91,7 @@ pub const gen1 = struct {
91
91
  /// battle `update`.
92
92
  pub const Summaries = @import("gen1/calc.zig").Summaries;
93
93
  /// Information relevant to damage calculation that occured during a Generation I
94
- /// battle `update` for a single player.
94
+ /// battle `update` for a single player.
95
95
  pub const Summary = @import("gen1/calc.zig").Summary;
96
96
  /// Null object pattern implementation of Generation I `Calc` which does nothing,
97
97
  /// though damage calculator support should additionally be turned off
@@ -102,12 +102,35 @@ pub const gen1 = struct {
102
102
  pub const helpers = @import("gen1/helpers.zig");
103
103
  };
104
104
 
105
+ /// TODO
106
+ pub const gen2 = struct {
107
+ pub usingnamespace @import("gen2/data.zig");
108
+ pub const Chance = @import("gen2/chance.zig").Chance;
109
+ pub const chance = struct {
110
+ pub const Actions = @import("gen2/chance.zig").Actions;
111
+ pub const Action = @import("gen2/chance.zig").Action;
112
+ pub const Durations = @import("gen2/chance.zig").Durations;
113
+ pub const Duration = @import("gen2/chance.zig").Duration;
114
+ pub const NULL = @import("gen2/chance.zig").NULL;
115
+ };
116
+ pub const Calc = @import("gen2/calc.zig").Calc;
117
+ pub const calc = if (options.internal) struct {
118
+ pub usingnamespace @import("gen2/calc.zig");
119
+ } else struct {
120
+ pub const Overrides = @import("gen2/calc.zig").Overrides;
121
+ pub const Summaries = @import("gen2/calc.zig").Summaries;
122
+ pub const Summary = @import("gen2/calc.zig").Summary;
123
+ pub const NULL = @import("gen2/calc.zig").NULL;
124
+ };
125
+ pub const helpers = @import("gen2/helpers.zig");
126
+ };
127
+
105
128
  // Internal APIs used by other pkmn libraries, not actually part of the public API.
106
129
  // NOTE: `pub usingnamespace struct { ... }` here results in a (false?) dependency loop
107
130
  pub const js = if (options.internal) struct {
108
131
  pub usingnamespace @import("common/js.zig");
109
132
  } else struct {};
110
133
  pub const bindings = if (options.internal) struct {
111
- pub const node = @import("binding/node.zig");
112
- pub const wasm = @import("binding/wasm.zig");
134
+ pub const node = @import("node.zig");
135
+ pub const wasm = @import("wasm.zig");
113
136
  } else struct {};
@@ -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;