@pkmn/engine 0.1.0-dev.84cc1a02 → 0.1.0-dev.8b83af6b

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 (46) 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 +20 -23
  26. package/src/lib/binding/wasm.zig +4 -4
  27. package/src/lib/common/data.zig +11 -11
  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 +194 -178
  31. package/src/lib/common/rng.zig +5 -5
  32. package/src/lib/gen1/README.md +106 -70
  33. package/src/lib/gen1/data/moves.zig +10 -10
  34. package/src/lib/gen1/data/species.zig +2 -2
  35. package/src/lib/gen1/data/types.zig +3 -3
  36. package/src/lib/gen1/data.zig +36 -31
  37. package/src/lib/gen1/helpers.zig +11 -22
  38. package/src/lib/gen1/mechanics.zig +460 -365
  39. package/src/lib/gen2/data/items.zig +3 -3
  40. package/src/lib/gen2/data/moves.zig +1 -1
  41. package/src/lib/gen2/data/species.zig +1 -1
  42. package/src/lib/gen2/data/types.zig +3 -3
  43. package/src/lib/gen2/data.zig +16 -15
  44. package/src/lib/gen2/helpers.zig +6 -6
  45. package/src/lib/pkmn.zig +7 -7
  46. package/src/test/display/pkmn.html.tmpl +368 -0
@@ -7,7 +7,7 @@ const options = @import("./options.zig");
7
7
  const assert = std.debug.assert;
8
8
  const print = std.debug.print;
9
9
 
10
- const trace = options.trace;
10
+ const enabled = options.log;
11
11
 
12
12
  const Player = data.Player;
13
13
  const ID = data.ID;
@@ -230,91 +230,91 @@ pub fn Log(comptime Writer: type) type {
230
230
  pub const Error = Writer.Error;
231
231
 
232
232
  pub fn move(self: Self, source: ID, m: anytype, target: ID, from: anytype) Error!void {
233
- if (!trace) return;
233
+ if (!enabled) return;
234
234
  assert(m != .None);
235
235
  try self.writer.writeAll(&.{
236
- @enumToInt(ArgType.Move),
237
- @bitCast(u8, source),
238
- @enumToInt(m),
239
- @bitCast(u8, target),
236
+ @intFromEnum(ArgType.Move),
237
+ @as(u8, @bitCast(source)),
238
+ @intFromEnum(m),
239
+ @as(u8, @bitCast(target)),
240
240
  });
241
- const none = &[_]u8{@enumToInt(Move.None)};
241
+ const none = &[_]u8{@intFromEnum(Move.None)};
242
242
  try self.writer.writeAll(switch (@typeInfo(@TypeOf(from))) {
243
243
  .Null => none,
244
244
  .Optional => if (from) |f| blk: {
245
- assert(@enumToInt(f) != 0);
246
- break :blk &[_]u8{ @enumToInt(Move.From), @enumToInt(f) };
245
+ assert(@intFromEnum(f) != 0);
246
+ break :blk &[_]u8{ @intFromEnum(Move.From), @intFromEnum(f) };
247
247
  } else none,
248
248
  else => blk: {
249
- assert(@enumToInt(from) != 0);
250
- break :blk &[_]u8{ @enumToInt(Move.From), @enumToInt(from) };
249
+ assert(@intFromEnum(from) != 0);
250
+ break :blk &[_]u8{ @intFromEnum(Move.From), @intFromEnum(from) };
251
251
  },
252
252
  });
253
253
  }
254
254
 
255
255
  pub fn switched(self: Self, ident: ID, pokemon: anytype) Error!void {
256
- if (!trace) return;
257
- try self.writer.writeAll(&.{ @enumToInt(ArgType.Switch), @bitCast(u8, ident) });
258
- try self.writer.writeAll(&.{ @enumToInt(pokemon.species), pokemon.level });
256
+ if (!enabled) return;
257
+ try self.writer.writeAll(&.{ @intFromEnum(ArgType.Switch), @as(u8, @bitCast(ident)) });
258
+ try self.writer.writeAll(&.{ @intFromEnum(pokemon.species), pokemon.level });
259
259
  try self.writer.writeIntNative(u16, pokemon.hp);
260
260
  try self.writer.writeIntNative(u16, pokemon.stats.hp);
261
261
  try self.writer.writeAll(&.{pokemon.status});
262
262
  }
263
263
 
264
264
  pub fn cant(self: Self, ident: ID, reason: Cant) Error!void {
265
- if (!trace) return;
265
+ if (!enabled) return;
266
266
  assert(reason != .Disable);
267
267
  try self.writer.writeAll(&.{
268
- @enumToInt(ArgType.Cant),
269
- @bitCast(u8, ident),
270
- @enumToInt(reason),
268
+ @intFromEnum(ArgType.Cant),
269
+ @as(u8, @bitCast(ident)),
270
+ @intFromEnum(reason),
271
271
  });
272
272
  }
273
273
 
274
274
  pub fn disabled(self: Self, ident: ID, m: anytype) Error!void {
275
- if (!trace) return;
275
+ if (!enabled) return;
276
276
  try self.writer.writeAll(&.{
277
- @enumToInt(ArgType.Cant),
278
- @bitCast(u8, ident),
279
- @enumToInt(Cant.Disable),
280
- @enumToInt(m),
277
+ @intFromEnum(ArgType.Cant),
278
+ @as(u8, @bitCast(ident)),
279
+ @intFromEnum(Cant.Disable),
280
+ @intFromEnum(m),
281
281
  });
282
282
  }
283
283
 
284
284
  pub fn faint(self: Self, ident: ID, done: bool) Error!void {
285
- if (!trace) return;
286
- try self.writer.writeAll(&.{ @enumToInt(ArgType.Faint), @bitCast(u8, ident) });
287
- if (done) try self.writer.writeByte(@enumToInt(ArgType.None));
285
+ if (!enabled) return;
286
+ try self.writer.writeAll(&.{ @intFromEnum(ArgType.Faint), @as(u8, @bitCast(ident)) });
287
+ if (done) try self.writer.writeByte(@intFromEnum(ArgType.None));
288
288
  }
289
289
 
290
290
  pub fn turn(self: Self, num: u16) Error!void {
291
- if (!trace) return;
292
- try self.writer.writeByte(@enumToInt(ArgType.Turn));
291
+ if (!enabled) return;
292
+ try self.writer.writeByte(@intFromEnum(ArgType.Turn));
293
293
  try self.writer.writeIntNative(u16, num);
294
- try self.writer.writeByte(@enumToInt(ArgType.None));
294
+ try self.writer.writeByte(@intFromEnum(ArgType.None));
295
295
  }
296
296
 
297
297
  pub fn win(self: Self, player: Player) Error!void {
298
- if (!trace) return;
298
+ if (!enabled) return;
299
299
  try self.writer.writeAll(&.{
300
- @enumToInt(ArgType.Win),
301
- @enumToInt(player),
302
- @enumToInt(ArgType.None),
300
+ @intFromEnum(ArgType.Win),
301
+ @intFromEnum(player),
302
+ @intFromEnum(ArgType.None),
303
303
  });
304
304
  }
305
305
 
306
306
  pub fn tie(self: Self) Error!void {
307
- if (!trace) return;
308
- try self.writer.writeAll(&.{ @enumToInt(ArgType.Tie), @enumToInt(ArgType.None) });
307
+ if (!enabled) return;
308
+ try self.writer.writeAll(&.{ @intFromEnum(ArgType.Tie), @intFromEnum(ArgType.None) });
309
309
  }
310
310
 
311
311
  pub fn damage(self: Self, ident: ID, pokemon: anytype, reason: Damage) Error!void {
312
- if (!trace) return;
313
- assert(@enumToInt(reason) <= @enumToInt(Damage.LeechSeed));
314
- try self.writer.writeAll(&.{ @enumToInt(ArgType.Damage), @bitCast(u8, ident) });
312
+ if (!enabled) return;
313
+ assert(@intFromEnum(reason) <= @intFromEnum(Damage.LeechSeed));
314
+ try self.writer.writeAll(&.{ @intFromEnum(ArgType.Damage), @as(u8, @bitCast(ident)) });
315
315
  try self.writer.writeIntNative(u16, pokemon.hp);
316
316
  try self.writer.writeIntNative(u16, pokemon.stats.hp);
317
- try self.writer.writeAll(&.{ pokemon.status, @enumToInt(reason) });
317
+ try self.writer.writeAll(&.{ pokemon.status, @intFromEnum(reason) });
318
318
  }
319
319
 
320
320
  pub fn damageOf(
@@ -324,221 +324,234 @@ pub fn Log(comptime Writer: type) type {
324
324
  reason: Damage,
325
325
  source: ID,
326
326
  ) Error!void {
327
- if (!trace) return;
328
- assert(@enumToInt(reason) == @enumToInt(Damage.RecoilOf));
329
- try self.writer.writeAll(&.{ @enumToInt(ArgType.Damage), @bitCast(u8, ident) });
327
+ if (!enabled) return;
328
+ assert(@intFromEnum(reason) == @intFromEnum(Damage.RecoilOf));
329
+ try self.writer.writeAll(&.{ @intFromEnum(ArgType.Damage), @as(u8, @bitCast(ident)) });
330
330
  try self.writer.writeIntNative(u16, pokemon.hp);
331
331
  try self.writer.writeIntNative(u16, pokemon.stats.hp);
332
332
  try self.writer.writeAll(&.{
333
333
  pokemon.status,
334
- @enumToInt(reason),
335
- @bitCast(u8, source),
334
+ @intFromEnum(reason),
335
+ @as(u8, @bitCast(source)),
336
336
  });
337
337
  }
338
338
 
339
339
  pub fn heal(self: Self, ident: ID, pokemon: anytype, reason: Heal) Error!void {
340
- if (!trace) return;
340
+ if (!enabled) return;
341
341
  assert(reason != .Drain);
342
- try self.writer.writeAll(&.{ @enumToInt(ArgType.Heal), @bitCast(u8, ident) });
342
+ try self.writer.writeAll(&.{ @intFromEnum(ArgType.Heal), @as(u8, @bitCast(ident)) });
343
343
  try self.writer.writeIntNative(u16, pokemon.hp);
344
344
  try self.writer.writeIntNative(u16, pokemon.stats.hp);
345
- try self.writer.writeAll(&.{ pokemon.status, @enumToInt(reason) });
345
+ try self.writer.writeAll(&.{ pokemon.status, @intFromEnum(reason) });
346
346
  }
347
347
 
348
348
  pub fn drain(self: Self, source: ID, pokemon: anytype, target: ID) Error!void {
349
- if (!trace) return;
350
- try self.writer.writeAll(&.{ @enumToInt(ArgType.Heal), @bitCast(u8, source) });
349
+ if (!enabled) return;
350
+ try self.writer.writeAll(&.{ @intFromEnum(ArgType.Heal), @as(u8, @bitCast(source)) });
351
351
  try self.writer.writeIntNative(u16, pokemon.hp);
352
352
  try self.writer.writeIntNative(u16, pokemon.stats.hp);
353
353
  try self.writer.writeAll(&.{
354
354
  pokemon.status,
355
- @enumToInt(Heal.Drain),
356
- @bitCast(u8, target),
355
+ @intFromEnum(Heal.Drain),
356
+ @as(u8, @bitCast(target)),
357
357
  });
358
358
  }
359
359
 
360
360
  pub fn status(self: Self, ident: ID, value: u8, reason: Status) Error!void {
361
- if (!trace) return;
361
+ if (!enabled) return;
362
362
  assert(reason != .From);
363
363
  try self.writer.writeAll(&.{
364
- @enumToInt(ArgType.Status),
365
- @bitCast(u8, ident),
364
+ @intFromEnum(ArgType.Status),
365
+ @as(u8, @bitCast(ident)),
366
366
  value,
367
- @enumToInt(reason),
367
+ @intFromEnum(reason),
368
368
  });
369
369
  }
370
370
 
371
371
  pub fn statusFrom(self: Self, ident: ID, value: u8, m: anytype) Error!void {
372
- if (!trace) return;
372
+ if (!enabled) return;
373
373
  try self.writer.writeAll(&.{
374
- @enumToInt(ArgType.Status),
375
- @bitCast(u8, ident),
374
+ @intFromEnum(ArgType.Status),
375
+ @as(u8, @bitCast(ident)),
376
376
  value,
377
- @enumToInt(Status.From),
378
- @enumToInt(m),
377
+ @intFromEnum(Status.From),
378
+ @intFromEnum(m),
379
379
  });
380
380
  }
381
381
 
382
382
  pub fn curestatus(self: Self, ident: ID, value: u8, reason: CureStatus) Error!void {
383
- if (!trace) return;
383
+ if (!enabled) return;
384
384
  try self.writer.writeAll(&.{
385
- @enumToInt(ArgType.CureStatus),
386
- @bitCast(u8, ident),
385
+ @intFromEnum(ArgType.CureStatus),
386
+ @as(u8, @bitCast(ident)),
387
387
  value,
388
- @enumToInt(reason),
388
+ @intFromEnum(reason),
389
389
  });
390
390
  }
391
391
 
392
392
  pub fn boost(self: Self, ident: ID, reason: Boost, num: i8) Error!void {
393
- if (!trace) return;
393
+ if (!enabled) return;
394
394
  assert(num != 0 and (reason != .Rage or num > 0));
395
395
  try self.writer.writeAll(&.{
396
- @enumToInt(ArgType.Boost),
397
- @bitCast(u8, ident),
398
- @enumToInt(reason),
399
- @intCast(u8, num + 6),
396
+ @intFromEnum(ArgType.Boost),
397
+ @as(u8, @bitCast(ident)),
398
+ @intFromEnum(reason),
399
+ @as(u8, @intCast(num + 6)),
400
400
  });
401
401
  }
402
402
 
403
403
  pub fn clearallboost(self: Self) Error!void {
404
- if (!trace) return;
405
- try self.writer.writeAll(&.{@enumToInt(ArgType.ClearAllBoost)});
404
+ if (!enabled) return;
405
+ try self.writer.writeAll(&.{@intFromEnum(ArgType.ClearAllBoost)});
406
406
  }
407
407
 
408
408
  pub fn fail(self: Self, ident: ID, reason: Fail) Error!void {
409
- if (!trace) return;
409
+ if (!enabled) return;
410
410
  try self.writer.writeAll(&.{
411
- @enumToInt(ArgType.Fail),
412
- @bitCast(u8, ident),
413
- @enumToInt(reason),
411
+ @intFromEnum(ArgType.Fail),
412
+ @as(u8, @bitCast(ident)),
413
+ @intFromEnum(reason),
414
414
  });
415
415
  }
416
416
 
417
417
  pub fn miss(self: Self, source: ID) Error!void {
418
- if (!trace) return;
419
- try self.writer.writeAll(&.{ @enumToInt(ArgType.Miss), @bitCast(u8, source) });
418
+ if (!enabled) return;
419
+ try self.writer.writeAll(&.{ @intFromEnum(ArgType.Miss), @as(u8, @bitCast(source)) });
420
420
  }
421
421
 
422
422
  pub fn hitcount(self: Self, ident: ID, num: u8) Error!void {
423
- if (!trace) return;
424
- try self.writer.writeAll(&.{ @enumToInt(ArgType.HitCount), @bitCast(u8, ident), num });
423
+ if (!enabled) return;
424
+ try self.writer.writeAll(&.{
425
+ @intFromEnum(ArgType.HitCount),
426
+ @as(u8, @bitCast(ident)),
427
+ num,
428
+ });
425
429
  }
426
430
 
427
431
  pub fn prepare(self: Self, source: ID, m: anytype) Error!void {
428
- if (!trace) return;
432
+ if (!enabled) return;
429
433
  try self.writer.writeAll(&.{
430
- @enumToInt(ArgType.Prepare),
431
- @bitCast(u8, source),
432
- @enumToInt(m),
434
+ @intFromEnum(ArgType.Prepare),
435
+ @as(u8, @bitCast(source)),
436
+ @intFromEnum(m),
433
437
  });
434
438
  }
435
439
 
436
440
  pub fn mustrecharge(self: Self, ident: ID) Error!void {
437
- if (!trace) return;
438
- try self.writer.writeAll(&.{ @enumToInt(ArgType.MustRecharge), @bitCast(u8, ident) });
441
+ if (!enabled) return;
442
+ try self.writer.writeAll(&.{
443
+ @intFromEnum(ArgType.MustRecharge),
444
+ @as(u8, @bitCast(ident)),
445
+ });
439
446
  }
440
447
 
441
448
  pub fn activate(self: Self, ident: ID, reason: Activate) Error!void {
442
- if (!trace) return;
449
+ if (!enabled) return;
443
450
  try self.writer.writeAll(&.{
444
- @enumToInt(ArgType.Activate),
445
- @bitCast(u8, ident),
446
- @enumToInt(reason),
451
+ @intFromEnum(ArgType.Activate),
452
+ @as(u8, @bitCast(ident)),
453
+ @intFromEnum(reason),
447
454
  });
448
455
  }
449
456
 
450
457
  pub fn fieldactivate(self: Self) Error!void {
451
- if (!trace) return;
452
- try self.writer.writeAll(&.{@enumToInt(ArgType.FieldActivate)});
458
+ if (!enabled) return;
459
+ try self.writer.writeAll(&.{@intFromEnum(ArgType.FieldActivate)});
453
460
  }
454
461
 
455
462
  pub fn start(self: Self, ident: ID, reason: Start) Error!void {
456
- if (!trace) return;
457
- assert(@enumToInt(reason) < @enumToInt(Start.TypeChange));
463
+ if (!enabled) return;
464
+ assert(@intFromEnum(reason) < @intFromEnum(Start.TypeChange));
458
465
  try self.writer.writeAll(&.{
459
- @enumToInt(ArgType.Start),
460
- @bitCast(u8, ident),
461
- @enumToInt(reason),
466
+ @intFromEnum(ArgType.Start),
467
+ @as(u8, @bitCast(ident)),
468
+ @intFromEnum(reason),
462
469
  });
463
470
  }
464
471
 
465
472
  pub fn typechange(self: Self, source: ID, types: anytype, target: ID) Error!void {
466
- if (!trace) return;
473
+ if (!enabled) return;
467
474
  try self.writer.writeAll(&.{
468
- @enumToInt(ArgType.Start),
469
- @bitCast(u8, source),
470
- @enumToInt(Start.TypeChange),
471
- @bitCast(u8, types),
472
- @bitCast(u8, target),
475
+ @intFromEnum(ArgType.Start),
476
+ @as(u8, @bitCast(source)),
477
+ @intFromEnum(Start.TypeChange),
478
+ @as(u8, @bitCast(types)),
479
+ @as(u8, @bitCast(target)),
473
480
  });
474
481
  }
475
482
 
476
483
  pub fn startEffect(self: Self, ident: ID, reason: Start, m: anytype) Error!void {
477
- if (!trace) return;
478
- assert(@enumToInt(reason) > @enumToInt(Start.TypeChange));
484
+ if (!enabled) return;
485
+ assert(@intFromEnum(reason) > @intFromEnum(Start.TypeChange));
479
486
  try self.writer.writeAll(&.{
480
- @enumToInt(ArgType.Start),
481
- @bitCast(u8, ident),
482
- @enumToInt(reason),
483
- @enumToInt(m),
487
+ @intFromEnum(ArgType.Start),
488
+ @as(u8, @bitCast(ident)),
489
+ @intFromEnum(reason),
490
+ @intFromEnum(m),
484
491
  });
485
492
  }
486
493
 
487
494
  pub fn end(self: Self, ident: ID, reason: End) Error!void {
488
- if (!trace) return;
495
+ if (!enabled) return;
489
496
  try self.writer.writeAll(&.{
490
- @enumToInt(ArgType.End),
491
- @bitCast(u8, ident),
492
- @enumToInt(reason),
497
+ @intFromEnum(ArgType.End),
498
+ @as(u8, @bitCast(ident)),
499
+ @intFromEnum(reason),
493
500
  });
494
501
  }
495
502
 
496
503
  pub fn ohko(self: Self) Error!void {
497
- if (!trace) return;
498
- try self.writer.writeAll(&.{@enumToInt(ArgType.OHKO)});
504
+ if (!enabled) return;
505
+ try self.writer.writeAll(&.{@intFromEnum(ArgType.OHKO)});
499
506
  }
500
507
 
501
508
  pub fn crit(self: Self, ident: ID) Error!void {
502
- if (!trace) return;
503
- try self.writer.writeAll(&.{ @enumToInt(ArgType.Crit), @bitCast(u8, ident) });
509
+ if (!enabled) return;
510
+ try self.writer.writeAll(&.{ @intFromEnum(ArgType.Crit), @as(u8, @bitCast(ident)) });
504
511
  }
505
512
 
506
513
  pub fn supereffective(self: Self, ident: ID) Error!void {
507
- if (!trace) return;
508
- try self.writer.writeAll(&.{ @enumToInt(ArgType.SuperEffective), @bitCast(u8, ident) });
514
+ if (!enabled) return;
515
+ try self.writer.writeAll(&.{
516
+ @intFromEnum(ArgType.SuperEffective),
517
+ @as(u8, @bitCast(ident)),
518
+ });
509
519
  }
510
520
 
511
521
  pub fn resisted(self: Self, ident: ID) Error!void {
512
- if (!trace) return;
513
- try self.writer.writeAll(&.{ @enumToInt(ArgType.Resisted), @bitCast(u8, ident) });
522
+ if (!enabled) return;
523
+ try self.writer.writeAll(&.{
524
+ @intFromEnum(ArgType.Resisted),
525
+ @as(u8, @bitCast(ident)),
526
+ });
514
527
  }
515
528
 
516
529
  pub fn immune(self: Self, ident: ID, reason: Immune) Error!void {
517
- if (!trace) return;
530
+ if (!enabled) return;
518
531
  try self.writer.writeAll(&.{
519
- @enumToInt(ArgType.Immune),
520
- @bitCast(u8, ident),
521
- @enumToInt(reason),
532
+ @intFromEnum(ArgType.Immune),
533
+ @as(u8, @bitCast(ident)),
534
+ @intFromEnum(reason),
522
535
  });
523
536
  }
524
537
 
525
538
  pub fn transform(self: Self, source: ID, target: ID) Error!void {
526
- if (!trace) return;
539
+ if (!enabled) return;
527
540
  try self.writer.writeAll(&.{
528
- @enumToInt(ArgType.Transform),
529
- @bitCast(u8, source),
530
- @bitCast(u8, target),
541
+ @intFromEnum(ArgType.Transform),
542
+ @as(u8, @bitCast(source)),
543
+ @as(u8, @bitCast(target)),
531
544
  });
532
545
  }
533
546
 
534
547
  pub fn laststill(self: Self) Error!void {
535
- if (!trace) return;
536
- try self.writer.writeAll(&.{@enumToInt(ArgType.LastStill)});
548
+ if (!enabled) return;
549
+ try self.writer.writeAll(&.{@intFromEnum(ArgType.LastStill)});
537
550
  }
538
551
 
539
552
  pub fn lastmiss(self: Self) Error!void {
540
- if (!trace) return;
541
- try self.writer.writeAll(&.{@enumToInt(ArgType.LastMiss)});
553
+ if (!enabled) return;
554
+ try self.writer.writeAll(&.{@intFromEnum(ArgType.LastMiss)});
542
555
  }
543
556
  };
544
557
  }
@@ -593,7 +606,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
593
606
 
594
607
  var i: usize = 0;
595
608
  while (i < a.len) {
596
- const arg = @intToEnum(ArgType, a[i]);
609
+ const arg: ArgType = @enumFromInt(a[i]);
597
610
  const name = switch (arg) {
598
611
  .None => if (color) "\x1b[2m-\x1b[0m" else "-",
599
612
  .LastStill => "|[still]",
@@ -639,17 +652,17 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
639
652
  .OHKO,
640
653
  => {},
641
654
  .Move => {
642
- const source = ID.from(@intCast(u4, a[i]));
655
+ const source = ID.from(@intCast(a[i]));
643
656
  printc(" {s}({d})", .{ @tagName(source.player), source.id }, a, b, &i, 1, color);
644
657
  printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
645
- const target = ID.from(@intCast(u4, a[i]));
658
+ const target = ID.from(@intCast(a[i]));
646
659
  printc(" {s}({d})", .{ @tagName(target.player), target.id }, a, b, &i, 1, color);
647
- const reason = @intToEnum(Move, a[i]);
660
+ const reason: Move = @enumFromInt(a[i]);
648
661
  printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
649
662
  if (reason == .From) printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
650
663
  },
651
664
  .Switch => {
652
- const id = ID.from(@intCast(u4, a[i]));
665
+ const id = ID.from(@intCast(a[i]));
653
666
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
654
667
  printc(" {s}", .{formatter(.Species, a[i])}, a, b, &i, 1, color);
655
668
  printc(" L{d}", .{a[i]}, a, b, &i, 1, color);
@@ -670,9 +683,9 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
670
683
  printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
671
684
  },
672
685
  .Cant => {
673
- const id = ID.from(@intCast(u4, a[i]));
686
+ const id = ID.from(@intCast(a[i]));
674
687
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
675
- const reason = @intToEnum(Cant, a[i]);
688
+ const reason: Cant = @enumFromInt(a[i]);
676
689
  printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
677
690
  if (reason == .Disable) {
678
691
  printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
@@ -685,7 +698,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
685
698
  .SuperEffective,
686
699
  .Resisted,
687
700
  => {
688
- const id = ID.from(@intCast(u4, a[i]));
701
+ const id = ID.from(@intCast(a[i]));
689
702
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
690
703
  },
691
704
  .Turn => {
@@ -695,9 +708,11 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
695
708
  };
696
709
  printc(" {d}", .{turn}, a, b, &i, 2, color);
697
710
  },
698
- .Win => printc(" {s}", .{@tagName(@intToEnum(Player, a[i]))}, a, b, &i, 1, color),
711
+ .Win => {
712
+ printc(" {s}", .{@tagName(@as(Player, @enumFromInt(a[i])))}, a, b, &i, 1, color);
713
+ },
699
714
  .Damage, .Heal => {
700
- var id = ID.from(@intCast(u4, a[i]));
715
+ var id = ID.from(@intCast(a[i]));
701
716
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
702
717
  switch (endian) {
703
718
  .Big => {
@@ -715,91 +730,92 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
715
730
  }
716
731
  printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
717
732
  if (arg == .Damage) {
718
- const reason = a[i];
719
- printc(" {s}", .{@tagName(@intToEnum(Damage, reason))}, a, b, &i, 1, color);
720
- if (reason == @enumToInt(Damage.RecoilOf)) {
721
- id = ID.from(@intCast(u4, a[i]));
733
+ const reason: Damage = @enumFromInt(a[i]);
734
+ printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
735
+ if (reason == .RecoilOf) {
736
+ id = ID.from(@intCast(a[i]));
722
737
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
723
738
  }
724
739
  } else {
725
- const reason = @intToEnum(Heal, a[i]);
740
+ const reason: Heal = @enumFromInt(a[i]);
726
741
  printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
727
742
  if (reason == .Drain) {
728
- id = ID.from(@intCast(u4, a[i]));
743
+ id = ID.from(@intCast(a[i]));
729
744
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
730
745
  }
731
746
  }
732
747
  },
733
748
  .Status => {
734
- const id = ID.from(@intCast(u4, a[i]));
749
+ const id = ID.from(@intCast(a[i]));
735
750
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
736
751
  printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
737
- const reason = @intToEnum(Status, a[i]);
752
+ const reason: Status = @enumFromInt(a[i]);
738
753
  printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
739
754
  if (reason == .From) printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
740
755
  },
741
756
  .CureStatus => {
742
- const id = ID.from(@intCast(u4, a[i]));
757
+ const id = ID.from(@intCast(a[i]));
743
758
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
744
759
  printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
745
- printc(" {s}", .{@tagName(@intToEnum(CureStatus, a[i]))}, a, b, &i, 1, color);
760
+ const reason: CureStatus = @enumFromInt(a[i]);
761
+ printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
746
762
  },
747
763
  .Boost => {
748
- const id = ID.from(@intCast(u4, a[i]));
764
+ const id = ID.from(@intCast(a[i]));
749
765
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
750
- printc(" {s}", .{@tagName(@intToEnum(Boost, a[i]))}, a, b, &i, 1, color);
766
+ printc(" {s}", .{@tagName(@as(Boost, @enumFromInt(a[i])))}, a, b, &i, 1, color);
751
767
  printc(" {d}", .{a[i]}, a, b, &i, 1, color);
752
768
  },
753
769
  .Fail => {
754
- const id = ID.from(@intCast(u4, a[i]));
770
+ const id = ID.from(@intCast(a[i]));
755
771
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
756
- printc(" {s}", .{@tagName(@intToEnum(Fail, a[i]))}, a, b, &i, 1, color);
772
+ printc(" {s}", .{@tagName(@as(Fail, @enumFromInt(a[i])))}, a, b, &i, 1, color);
757
773
  },
758
774
  .HitCount => {
759
- const id = ID.from(@intCast(u4, a[i]));
775
+ const id = ID.from(@intCast(a[i]));
760
776
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
761
777
  printc(" {d}", .{a[i]}, a, b, &i, 1, color);
762
778
  },
763
779
  .Prepare => {
764
- const id = ID.from(@intCast(u4, a[i]));
780
+ const id = ID.from(@intCast(a[i]));
765
781
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
766
782
  printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
767
783
  },
768
784
  .Activate => {
769
- const id = ID.from(@intCast(u4, a[i]));
785
+ const id = ID.from(@intCast(a[i]));
770
786
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
771
- printc(" {s}", .{@tagName(@intToEnum(Activate, a[i]))}, a, b, &i, 1, color);
787
+ printc(" {s}", .{@tagName(@as(Activate, @enumFromInt(a[i])))}, a, b, &i, 1, color);
772
788
  },
773
789
  .Start => {
774
- const id = ID.from(@intCast(u4, a[i]));
790
+ const id = ID.from(@intCast(a[i]));
775
791
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
776
792
  const reason = a[i];
777
- printc(" {s}", .{@tagName(@intToEnum(Start, reason))}, a, b, &i, 1, color);
778
- if (@intToEnum(Start, reason) == .TypeChange) {
779
- const types = @bitCast(gen1.Types, a[i]);
793
+ printc(" {s}", .{@tagName(@as(Start, @enumFromInt(reason)))}, a, b, &i, 1, color);
794
+ if (@as(Start, @enumFromInt(reason)) == .TypeChange) {
795
+ const types = @as(gen1.Types, @bitCast(a[i]));
780
796
  const args = .{
781
- formatter(.Type, @enumToInt(types.type1)),
782
- formatter(.Type, @enumToInt(types.type2)),
797
+ formatter(.Type, @intFromEnum(types.type1)),
798
+ formatter(.Type, @intFromEnum(types.type2)),
783
799
  };
784
800
  printc(" {s}/{s}", args, a, b, &i, 1, color);
785
- } else if (reason >= @enumToInt(Start.Disable)) {
801
+ } else if (reason >= @intFromEnum(Start.Disable)) {
786
802
  printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
787
803
  }
788
804
  },
789
805
  .End => {
790
- const id = ID.from(@intCast(u4, a[i]));
806
+ const id = ID.from(@intCast(a[i]));
791
807
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
792
- printc(" {s}", .{@tagName(@intToEnum(End, a[i]))}, a, b, &i, 1, color);
808
+ printc(" {s}", .{@tagName(@as(End, @enumFromInt(a[i])))}, a, b, &i, 1, color);
793
809
  },
794
810
  .Immune => {
795
- const id = ID.from(@intCast(u4, a[i]));
811
+ const id = ID.from(@intCast(a[i]));
796
812
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
797
- printc(" {s}", .{@tagName(@intToEnum(Immune, a[i]))}, a, b, &i, 1, color);
813
+ printc(" {s}", .{@tagName(@as(Immune, @enumFromInt(a[i])))}, a, b, &i, 1, color);
798
814
  },
799
815
  .Transform => {
800
- const source = ID.from(@intCast(u4, a[i]));
816
+ const source = ID.from(@intCast(a[i]));
801
817
  printc(" {s}({d})", .{ @tagName(source.player), source.id }, a, b, &i, 1, color);
802
- const target = ID.from(@intCast(u4, a[i]));
818
+ const target = ID.from(@intCast(a[i]));
803
819
  printc(" {s}({d})", .{ @tagName(target.player), target.id }, a, b, &i, 1, color);
804
820
  },
805
821
  else => unreachable,
@@ -838,7 +854,7 @@ pub fn expectLog(
838
854
  actual: []const u8,
839
855
  offset: usize,
840
856
  ) !void {
841
- if (!trace) return;
857
+ if (!enabled) return;
842
858
  const color = color: {
843
859
  if (std.process.hasEnvVarConstant("ZIG_DEBUG_COLOR")) {
844
860
  break :color true;
@@ -881,7 +897,7 @@ fn expectEqualBytes(expected: []const u8, actual: []const u8, offset: usize) !vo
881
897
  const endian = builtin.target.cpu.arch.endian();
882
898
 
883
899
  fn N(e: anytype) u8 {
884
- return @enumToInt(e);
900
+ return @intFromEnum(e);
885
901
  }
886
902
 
887
903
  const p1 = Player.P1;
@@ -905,9 +921,9 @@ fn expectLog1(expected: []const u8, actual: []const u8) !void {
905
921
 
906
922
  fn gen1Formatter(kind: Kind, byte: u8) []const u8 {
907
923
  return switch (kind) {
908
- .Move => @tagName(@intToEnum(M, byte)),
909
- .Species => @tagName(@intToEnum(S, byte)),
910
- .Type => @tagName(@intToEnum(gen1.Type, byte)),
924
+ .Move => @tagName(@as(M, @enumFromInt(byte))),
925
+ .Species => @tagName(@as(S, @enumFromInt(byte))),
926
+ .Type => @tagName(@as(gen1.Type, @enumFromInt(byte))),
911
927
  .Status => gen1.Status.name(byte),
912
928
  };
913
929
  }