@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.
- package/README.md +52 -24
- package/build/pkg/addon.d.ts +7 -0
- package/build/pkg/addon.js +111 -0
- package/build/pkg/addon.js.map +1 -0
- package/build/pkg/data/layout.json +1 -1
- package/build/pkg/data.d.ts +1 -2
- package/build/pkg/data.js +3 -5
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.d.ts +5 -4
- package/build/pkg/gen1.js +43 -24
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +15 -12
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +4 -2
- package/build/pkg/protocol.js +4 -2
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +400 -0
- package/build/test/display.js.map +1 -0
- package/build/tools/debug.js +133 -0
- package/build/tools/debug.js.map +1 -0
- package/build.zig +30 -39
- package/package.json +45 -34
- package/src/bin/install-pkmn-engine +47 -28
- package/src/bin/pkmn-debug +62 -0
- package/src/lib/binding/node.zig +7 -7
- package/src/lib/binding/wasm.zig +3 -3
- package/src/lib/common/data.zig +1 -1
- package/src/lib/common/debug.zig +1 -0
- package/src/lib/common/options.zig +3 -3
- package/src/lib/common/protocol.zig +140 -133
- package/src/lib/gen1/README.md +106 -70
- package/src/lib/gen1/data/moves.zig +10 -10
- package/src/lib/gen1/data/species.zig +2 -2
- package/src/lib/gen1/data/types.zig +2 -2
- package/src/lib/gen1/data.zig +32 -28
- package/src/lib/gen1/helpers.zig +6 -17
- package/src/lib/gen1/mechanics.zig +418 -325
- package/src/lib/gen2/data/items.zig +3 -3
- package/src/lib/gen2/data/moves.zig +1 -1
- package/src/lib/gen2/data/species.zig +1 -1
- package/src/lib/gen2/data/types.zig +3 -3
- package/src/lib/gen2/data.zig +12 -12
- package/src/lib/gen2/helpers.zig +3 -3
- package/src/lib/pkmn.zig +7 -7
- 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
|
|
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 (!
|
|
233
|
+
if (!enabled) return;
|
|
234
234
|
assert(m != .None);
|
|
235
235
|
try self.writer.writeAll(&.{
|
|
236
|
-
@
|
|
236
|
+
@intFromEnum(ArgType.Move),
|
|
237
237
|
@bitCast(u8, source),
|
|
238
|
-
@
|
|
238
|
+
@intFromEnum(m),
|
|
239
239
|
@bitCast(u8, target),
|
|
240
240
|
});
|
|
241
|
-
const none = &[_]u8{@
|
|
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(@
|
|
246
|
-
break :blk &[_]u8{ @
|
|
245
|
+
assert(@intFromEnum(f) != 0);
|
|
246
|
+
break :blk &[_]u8{ @intFromEnum(Move.From), @intFromEnum(f) };
|
|
247
247
|
} else none,
|
|
248
248
|
else => blk: {
|
|
249
|
-
assert(@
|
|
250
|
-
break :blk &[_]u8{ @
|
|
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 (!
|
|
257
|
-
try self.writer.writeAll(&.{ @
|
|
258
|
-
try self.writer.writeAll(&.{ @
|
|
256
|
+
if (!enabled) return;
|
|
257
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Switch), @bitCast(u8, 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 (!
|
|
265
|
+
if (!enabled) return;
|
|
266
266
|
assert(reason != .Disable);
|
|
267
267
|
try self.writer.writeAll(&.{
|
|
268
|
-
@
|
|
268
|
+
@intFromEnum(ArgType.Cant),
|
|
269
269
|
@bitCast(u8, ident),
|
|
270
|
-
@
|
|
270
|
+
@intFromEnum(reason),
|
|
271
271
|
});
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
pub fn disabled(self: Self, ident: ID, m: anytype) Error!void {
|
|
275
|
-
if (!
|
|
275
|
+
if (!enabled) return;
|
|
276
276
|
try self.writer.writeAll(&.{
|
|
277
|
-
@
|
|
277
|
+
@intFromEnum(ArgType.Cant),
|
|
278
278
|
@bitCast(u8, ident),
|
|
279
|
-
@
|
|
280
|
-
@
|
|
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 (!
|
|
286
|
-
try self.writer.writeAll(&.{ @
|
|
287
|
-
if (done) try self.writer.writeByte(@
|
|
285
|
+
if (!enabled) return;
|
|
286
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Faint), @bitCast(u8, 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 (!
|
|
292
|
-
try self.writer.writeByte(@
|
|
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(@
|
|
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 (!
|
|
298
|
+
if (!enabled) return;
|
|
299
299
|
try self.writer.writeAll(&.{
|
|
300
|
-
@
|
|
301
|
-
@
|
|
302
|
-
@
|
|
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 (!
|
|
308
|
-
try self.writer.writeAll(&.{ @
|
|
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 (!
|
|
313
|
-
assert(@
|
|
314
|
-
try self.writer.writeAll(&.{ @
|
|
312
|
+
if (!enabled) return;
|
|
313
|
+
assert(@intFromEnum(reason) <= @intFromEnum(Damage.LeechSeed));
|
|
314
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Damage), @bitCast(u8, 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, @
|
|
317
|
+
try self.writer.writeAll(&.{ pokemon.status, @intFromEnum(reason) });
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
pub fn damageOf(
|
|
@@ -324,221 +324,228 @@ pub fn Log(comptime Writer: type) type {
|
|
|
324
324
|
reason: Damage,
|
|
325
325
|
source: ID,
|
|
326
326
|
) Error!void {
|
|
327
|
-
if (!
|
|
328
|
-
assert(@
|
|
329
|
-
try self.writer.writeAll(&.{ @
|
|
327
|
+
if (!enabled) return;
|
|
328
|
+
assert(@intFromEnum(reason) == @intFromEnum(Damage.RecoilOf));
|
|
329
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Damage), @bitCast(u8, 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
|
-
@
|
|
334
|
+
@intFromEnum(reason),
|
|
335
335
|
@bitCast(u8, source),
|
|
336
336
|
});
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
pub fn heal(self: Self, ident: ID, pokemon: anytype, reason: Heal) Error!void {
|
|
340
|
-
if (!
|
|
340
|
+
if (!enabled) return;
|
|
341
341
|
assert(reason != .Drain);
|
|
342
|
-
try self.writer.writeAll(&.{ @
|
|
342
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Heal), @bitCast(u8, 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, @
|
|
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 (!
|
|
350
|
-
try self.writer.writeAll(&.{ @
|
|
349
|
+
if (!enabled) return;
|
|
350
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Heal), @bitCast(u8, 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
|
-
@
|
|
355
|
+
@intFromEnum(Heal.Drain),
|
|
356
356
|
@bitCast(u8, target),
|
|
357
357
|
});
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
pub fn status(self: Self, ident: ID, value: u8, reason: Status) Error!void {
|
|
361
|
-
if (!
|
|
361
|
+
if (!enabled) return;
|
|
362
362
|
assert(reason != .From);
|
|
363
363
|
try self.writer.writeAll(&.{
|
|
364
|
-
@
|
|
364
|
+
@intFromEnum(ArgType.Status),
|
|
365
365
|
@bitCast(u8, ident),
|
|
366
366
|
value,
|
|
367
|
-
@
|
|
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 (!
|
|
372
|
+
if (!enabled) return;
|
|
373
373
|
try self.writer.writeAll(&.{
|
|
374
|
-
@
|
|
374
|
+
@intFromEnum(ArgType.Status),
|
|
375
375
|
@bitCast(u8, ident),
|
|
376
376
|
value,
|
|
377
|
-
@
|
|
378
|
-
@
|
|
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 (!
|
|
383
|
+
if (!enabled) return;
|
|
384
384
|
try self.writer.writeAll(&.{
|
|
385
|
-
@
|
|
385
|
+
@intFromEnum(ArgType.CureStatus),
|
|
386
386
|
@bitCast(u8, ident),
|
|
387
387
|
value,
|
|
388
|
-
@
|
|
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 (!
|
|
393
|
+
if (!enabled) return;
|
|
394
394
|
assert(num != 0 and (reason != .Rage or num > 0));
|
|
395
395
|
try self.writer.writeAll(&.{
|
|
396
|
-
@
|
|
396
|
+
@intFromEnum(ArgType.Boost),
|
|
397
397
|
@bitCast(u8, ident),
|
|
398
|
-
@
|
|
398
|
+
@intFromEnum(reason),
|
|
399
399
|
@intCast(u8, num + 6),
|
|
400
400
|
});
|
|
401
401
|
}
|
|
402
402
|
|
|
403
403
|
pub fn clearallboost(self: Self) Error!void {
|
|
404
|
-
if (!
|
|
405
|
-
try self.writer.writeAll(&.{@
|
|
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 (!
|
|
409
|
+
if (!enabled) return;
|
|
410
410
|
try self.writer.writeAll(&.{
|
|
411
|
-
@
|
|
411
|
+
@intFromEnum(ArgType.Fail),
|
|
412
412
|
@bitCast(u8, ident),
|
|
413
|
-
@
|
|
413
|
+
@intFromEnum(reason),
|
|
414
414
|
});
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
pub fn miss(self: Self, source: ID) Error!void {
|
|
418
|
-
if (!
|
|
419
|
-
try self.writer.writeAll(&.{ @
|
|
418
|
+
if (!enabled) return;
|
|
419
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Miss), @bitCast(u8, source) });
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
pub fn hitcount(self: Self, ident: ID, num: u8) Error!void {
|
|
423
|
-
if (!
|
|
424
|
-
try self.writer.writeAll(&.{
|
|
423
|
+
if (!enabled) return;
|
|
424
|
+
try self.writer.writeAll(&.{
|
|
425
|
+
@intFromEnum(ArgType.HitCount),
|
|
426
|
+
@bitCast(u8, ident),
|
|
427
|
+
num,
|
|
428
|
+
});
|
|
425
429
|
}
|
|
426
430
|
|
|
427
431
|
pub fn prepare(self: Self, source: ID, m: anytype) Error!void {
|
|
428
|
-
if (!
|
|
432
|
+
if (!enabled) return;
|
|
429
433
|
try self.writer.writeAll(&.{
|
|
430
|
-
@
|
|
434
|
+
@intFromEnum(ArgType.Prepare),
|
|
431
435
|
@bitCast(u8, source),
|
|
432
|
-
@
|
|
436
|
+
@intFromEnum(m),
|
|
433
437
|
});
|
|
434
438
|
}
|
|
435
439
|
|
|
436
440
|
pub fn mustrecharge(self: Self, ident: ID) Error!void {
|
|
437
|
-
if (!
|
|
438
|
-
try self.writer.writeAll(&.{ @
|
|
441
|
+
if (!enabled) return;
|
|
442
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.MustRecharge), @bitCast(u8, ident) });
|
|
439
443
|
}
|
|
440
444
|
|
|
441
445
|
pub fn activate(self: Self, ident: ID, reason: Activate) Error!void {
|
|
442
|
-
if (!
|
|
446
|
+
if (!enabled) return;
|
|
443
447
|
try self.writer.writeAll(&.{
|
|
444
|
-
@
|
|
448
|
+
@intFromEnum(ArgType.Activate),
|
|
445
449
|
@bitCast(u8, ident),
|
|
446
|
-
@
|
|
450
|
+
@intFromEnum(reason),
|
|
447
451
|
});
|
|
448
452
|
}
|
|
449
453
|
|
|
450
454
|
pub fn fieldactivate(self: Self) Error!void {
|
|
451
|
-
if (!
|
|
452
|
-
try self.writer.writeAll(&.{@
|
|
455
|
+
if (!enabled) return;
|
|
456
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.FieldActivate)});
|
|
453
457
|
}
|
|
454
458
|
|
|
455
459
|
pub fn start(self: Self, ident: ID, reason: Start) Error!void {
|
|
456
|
-
if (!
|
|
457
|
-
assert(@
|
|
460
|
+
if (!enabled) return;
|
|
461
|
+
assert(@intFromEnum(reason) < @intFromEnum(Start.TypeChange));
|
|
458
462
|
try self.writer.writeAll(&.{
|
|
459
|
-
@
|
|
463
|
+
@intFromEnum(ArgType.Start),
|
|
460
464
|
@bitCast(u8, ident),
|
|
461
|
-
@
|
|
465
|
+
@intFromEnum(reason),
|
|
462
466
|
});
|
|
463
467
|
}
|
|
464
468
|
|
|
465
469
|
pub fn typechange(self: Self, source: ID, types: anytype, target: ID) Error!void {
|
|
466
|
-
if (!
|
|
470
|
+
if (!enabled) return;
|
|
467
471
|
try self.writer.writeAll(&.{
|
|
468
|
-
@
|
|
472
|
+
@intFromEnum(ArgType.Start),
|
|
469
473
|
@bitCast(u8, source),
|
|
470
|
-
@
|
|
474
|
+
@intFromEnum(Start.TypeChange),
|
|
471
475
|
@bitCast(u8, types),
|
|
472
476
|
@bitCast(u8, target),
|
|
473
477
|
});
|
|
474
478
|
}
|
|
475
479
|
|
|
476
480
|
pub fn startEffect(self: Self, ident: ID, reason: Start, m: anytype) Error!void {
|
|
477
|
-
if (!
|
|
478
|
-
assert(@
|
|
481
|
+
if (!enabled) return;
|
|
482
|
+
assert(@intFromEnum(reason) > @intFromEnum(Start.TypeChange));
|
|
479
483
|
try self.writer.writeAll(&.{
|
|
480
|
-
@
|
|
484
|
+
@intFromEnum(ArgType.Start),
|
|
481
485
|
@bitCast(u8, ident),
|
|
482
|
-
@
|
|
483
|
-
@
|
|
486
|
+
@intFromEnum(reason),
|
|
487
|
+
@intFromEnum(m),
|
|
484
488
|
});
|
|
485
489
|
}
|
|
486
490
|
|
|
487
491
|
pub fn end(self: Self, ident: ID, reason: End) Error!void {
|
|
488
|
-
if (!
|
|
492
|
+
if (!enabled) return;
|
|
489
493
|
try self.writer.writeAll(&.{
|
|
490
|
-
@
|
|
494
|
+
@intFromEnum(ArgType.End),
|
|
491
495
|
@bitCast(u8, ident),
|
|
492
|
-
@
|
|
496
|
+
@intFromEnum(reason),
|
|
493
497
|
});
|
|
494
498
|
}
|
|
495
499
|
|
|
496
500
|
pub fn ohko(self: Self) Error!void {
|
|
497
|
-
if (!
|
|
498
|
-
try self.writer.writeAll(&.{@
|
|
501
|
+
if (!enabled) return;
|
|
502
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.OHKO)});
|
|
499
503
|
}
|
|
500
504
|
|
|
501
505
|
pub fn crit(self: Self, ident: ID) Error!void {
|
|
502
|
-
if (!
|
|
503
|
-
try self.writer.writeAll(&.{ @
|
|
506
|
+
if (!enabled) return;
|
|
507
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Crit), @bitCast(u8, ident) });
|
|
504
508
|
}
|
|
505
509
|
|
|
506
510
|
pub fn supereffective(self: Self, ident: ID) Error!void {
|
|
507
|
-
if (!
|
|
508
|
-
try self.writer.writeAll(&.{
|
|
511
|
+
if (!enabled) return;
|
|
512
|
+
try self.writer.writeAll(&.{
|
|
513
|
+
@intFromEnum(ArgType.SuperEffective),
|
|
514
|
+
@bitCast(u8, ident),
|
|
515
|
+
});
|
|
509
516
|
}
|
|
510
517
|
|
|
511
518
|
pub fn resisted(self: Self, ident: ID) Error!void {
|
|
512
|
-
if (!
|
|
513
|
-
try self.writer.writeAll(&.{ @
|
|
519
|
+
if (!enabled) return;
|
|
520
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Resisted), @bitCast(u8, ident) });
|
|
514
521
|
}
|
|
515
522
|
|
|
516
523
|
pub fn immune(self: Self, ident: ID, reason: Immune) Error!void {
|
|
517
|
-
if (!
|
|
524
|
+
if (!enabled) return;
|
|
518
525
|
try self.writer.writeAll(&.{
|
|
519
|
-
@
|
|
526
|
+
@intFromEnum(ArgType.Immune),
|
|
520
527
|
@bitCast(u8, ident),
|
|
521
|
-
@
|
|
528
|
+
@intFromEnum(reason),
|
|
522
529
|
});
|
|
523
530
|
}
|
|
524
531
|
|
|
525
532
|
pub fn transform(self: Self, source: ID, target: ID) Error!void {
|
|
526
|
-
if (!
|
|
533
|
+
if (!enabled) return;
|
|
527
534
|
try self.writer.writeAll(&.{
|
|
528
|
-
@
|
|
535
|
+
@intFromEnum(ArgType.Transform),
|
|
529
536
|
@bitCast(u8, source),
|
|
530
537
|
@bitCast(u8, target),
|
|
531
538
|
});
|
|
532
539
|
}
|
|
533
540
|
|
|
534
541
|
pub fn laststill(self: Self) Error!void {
|
|
535
|
-
if (!
|
|
536
|
-
try self.writer.writeAll(&.{@
|
|
542
|
+
if (!enabled) return;
|
|
543
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.LastStill)});
|
|
537
544
|
}
|
|
538
545
|
|
|
539
546
|
pub fn lastmiss(self: Self) Error!void {
|
|
540
|
-
if (!
|
|
541
|
-
try self.writer.writeAll(&.{@
|
|
547
|
+
if (!enabled) return;
|
|
548
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.LastMiss)});
|
|
542
549
|
}
|
|
543
550
|
};
|
|
544
551
|
}
|
|
@@ -593,7 +600,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
593
600
|
|
|
594
601
|
var i: usize = 0;
|
|
595
602
|
while (i < a.len) {
|
|
596
|
-
const arg = @
|
|
603
|
+
const arg = @enumFromInt(ArgType, a[i]);
|
|
597
604
|
const name = switch (arg) {
|
|
598
605
|
.None => if (color) "\x1b[2m-\x1b[0m" else "-",
|
|
599
606
|
.LastStill => "|[still]",
|
|
@@ -644,7 +651,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
644
651
|
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
645
652
|
const target = ID.from(@intCast(u4, a[i]));
|
|
646
653
|
printc(" {s}({d})", .{ @tagName(target.player), target.id }, a, b, &i, 1, color);
|
|
647
|
-
const reason = @
|
|
654
|
+
const reason = @enumFromInt(Move, a[i]);
|
|
648
655
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
649
656
|
if (reason == .From) printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
650
657
|
},
|
|
@@ -672,7 +679,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
672
679
|
.Cant => {
|
|
673
680
|
const id = ID.from(@intCast(u4, a[i]));
|
|
674
681
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
675
|
-
const reason = @
|
|
682
|
+
const reason = @enumFromInt(Cant, a[i]);
|
|
676
683
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
677
684
|
if (reason == .Disable) {
|
|
678
685
|
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
@@ -695,7 +702,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
695
702
|
};
|
|
696
703
|
printc(" {d}", .{turn}, a, b, &i, 2, color);
|
|
697
704
|
},
|
|
698
|
-
.Win => printc(" {s}", .{@tagName(@
|
|
705
|
+
.Win => printc(" {s}", .{@tagName(@enumFromInt(Player, a[i]))}, a, b, &i, 1, color),
|
|
699
706
|
.Damage, .Heal => {
|
|
700
707
|
var id = ID.from(@intCast(u4, a[i]));
|
|
701
708
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
@@ -716,13 +723,13 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
716
723
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
717
724
|
if (arg == .Damage) {
|
|
718
725
|
const reason = a[i];
|
|
719
|
-
printc(" {s}", .{@tagName(@
|
|
720
|
-
if (reason == @
|
|
726
|
+
printc(" {s}", .{@tagName(@enumFromInt(Damage, reason))}, a, b, &i, 1, color);
|
|
727
|
+
if (reason == @intFromEnum(Damage.RecoilOf)) {
|
|
721
728
|
id = ID.from(@intCast(u4, a[i]));
|
|
722
729
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
723
730
|
}
|
|
724
731
|
} else {
|
|
725
|
-
const reason = @
|
|
732
|
+
const reason = @enumFromInt(Heal, a[i]);
|
|
726
733
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
727
734
|
if (reason == .Drain) {
|
|
728
735
|
id = ID.from(@intCast(u4, a[i]));
|
|
@@ -734,7 +741,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
734
741
|
const id = ID.from(@intCast(u4, a[i]));
|
|
735
742
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
736
743
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
737
|
-
const reason = @
|
|
744
|
+
const reason = @enumFromInt(Status, a[i]);
|
|
738
745
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
739
746
|
if (reason == .From) printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
740
747
|
},
|
|
@@ -742,18 +749,18 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
742
749
|
const id = ID.from(@intCast(u4, a[i]));
|
|
743
750
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
744
751
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
745
|
-
printc(" {s}", .{@tagName(@
|
|
752
|
+
printc(" {s}", .{@tagName(@enumFromInt(CureStatus, a[i]))}, a, b, &i, 1, color);
|
|
746
753
|
},
|
|
747
754
|
.Boost => {
|
|
748
755
|
const id = ID.from(@intCast(u4, a[i]));
|
|
749
756
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
750
|
-
printc(" {s}", .{@tagName(@
|
|
757
|
+
printc(" {s}", .{@tagName(@enumFromInt(Boost, a[i]))}, a, b, &i, 1, color);
|
|
751
758
|
printc(" {d}", .{a[i]}, a, b, &i, 1, color);
|
|
752
759
|
},
|
|
753
760
|
.Fail => {
|
|
754
761
|
const id = ID.from(@intCast(u4, a[i]));
|
|
755
762
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
756
|
-
printc(" {s}", .{@tagName(@
|
|
763
|
+
printc(" {s}", .{@tagName(@enumFromInt(Fail, a[i]))}, a, b, &i, 1, color);
|
|
757
764
|
},
|
|
758
765
|
.HitCount => {
|
|
759
766
|
const id = ID.from(@intCast(u4, a[i]));
|
|
@@ -768,33 +775,33 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
768
775
|
.Activate => {
|
|
769
776
|
const id = ID.from(@intCast(u4, a[i]));
|
|
770
777
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
771
|
-
printc(" {s}", .{@tagName(@
|
|
778
|
+
printc(" {s}", .{@tagName(@enumFromInt(Activate, a[i]))}, a, b, &i, 1, color);
|
|
772
779
|
},
|
|
773
780
|
.Start => {
|
|
774
781
|
const id = ID.from(@intCast(u4, a[i]));
|
|
775
782
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
776
783
|
const reason = a[i];
|
|
777
|
-
printc(" {s}", .{@tagName(@
|
|
778
|
-
if (@
|
|
784
|
+
printc(" {s}", .{@tagName(@enumFromInt(Start, reason))}, a, b, &i, 1, color);
|
|
785
|
+
if (@enumFromInt(Start, reason) == .TypeChange) {
|
|
779
786
|
const types = @bitCast(gen1.Types, a[i]);
|
|
780
787
|
const args = .{
|
|
781
|
-
formatter(.Type, @
|
|
782
|
-
formatter(.Type, @
|
|
788
|
+
formatter(.Type, @intFromEnum(types.type1)),
|
|
789
|
+
formatter(.Type, @intFromEnum(types.type2)),
|
|
783
790
|
};
|
|
784
791
|
printc(" {s}/{s}", args, a, b, &i, 1, color);
|
|
785
|
-
} else if (reason >= @
|
|
792
|
+
} else if (reason >= @intFromEnum(Start.Disable)) {
|
|
786
793
|
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
787
794
|
}
|
|
788
795
|
},
|
|
789
796
|
.End => {
|
|
790
797
|
const id = ID.from(@intCast(u4, a[i]));
|
|
791
798
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
792
|
-
printc(" {s}", .{@tagName(@
|
|
799
|
+
printc(" {s}", .{@tagName(@enumFromInt(End, a[i]))}, a, b, &i, 1, color);
|
|
793
800
|
},
|
|
794
801
|
.Immune => {
|
|
795
802
|
const id = ID.from(@intCast(u4, a[i]));
|
|
796
803
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
797
|
-
printc(" {s}", .{@tagName(@
|
|
804
|
+
printc(" {s}", .{@tagName(@enumFromInt(Immune, a[i]))}, a, b, &i, 1, color);
|
|
798
805
|
},
|
|
799
806
|
.Transform => {
|
|
800
807
|
const source = ID.from(@intCast(u4, a[i]));
|
|
@@ -838,7 +845,7 @@ pub fn expectLog(
|
|
|
838
845
|
actual: []const u8,
|
|
839
846
|
offset: usize,
|
|
840
847
|
) !void {
|
|
841
|
-
if (!
|
|
848
|
+
if (!enabled) return;
|
|
842
849
|
const color = color: {
|
|
843
850
|
if (std.process.hasEnvVarConstant("ZIG_DEBUG_COLOR")) {
|
|
844
851
|
break :color true;
|
|
@@ -881,7 +888,7 @@ fn expectEqualBytes(expected: []const u8, actual: []const u8, offset: usize) !vo
|
|
|
881
888
|
const endian = builtin.target.cpu.arch.endian();
|
|
882
889
|
|
|
883
890
|
fn N(e: anytype) u8 {
|
|
884
|
-
return @
|
|
891
|
+
return @intFromEnum(e);
|
|
885
892
|
}
|
|
886
893
|
|
|
887
894
|
const p1 = Player.P1;
|
|
@@ -905,9 +912,9 @@ fn expectLog1(expected: []const u8, actual: []const u8) !void {
|
|
|
905
912
|
|
|
906
913
|
fn gen1Formatter(kind: Kind, byte: u8) []const u8 {
|
|
907
914
|
return switch (kind) {
|
|
908
|
-
.Move => @tagName(@
|
|
909
|
-
.Species => @tagName(@
|
|
910
|
-
.Type => @tagName(@
|
|
915
|
+
.Move => @tagName(@enumFromInt(M, byte)),
|
|
916
|
+
.Species => @tagName(@enumFromInt(S, byte)),
|
|
917
|
+
.Type => @tagName(@enumFromInt(gen1.Type, byte)),
|
|
911
918
|
.Status => gen1.Status.name(byte),
|
|
912
919
|
};
|
|
913
920
|
}
|