@pkmn/engine 0.1.0-dev.729b1e87 → 0.1.0-dev.7b099504
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.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 +3 -3
- package/build/pkg/gen1.js +11 -13
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +11 -10
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.js +1 -1
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +396 -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 +24 -34
- package/package.json +41 -30
- package/src/bin/install-pkmn-engine +60 -33
- package/src/bin/pkmn-debug +62 -0
- package/src/lib/binding/node.zig +5 -5
- package/src/lib/binding/wasm.zig +3 -3
- package/src/lib/common/debug.zig +1 -0
- package/src/lib/common/options.zig +3 -3
- package/src/lib/common/protocol.zig +38 -38
- package/src/lib/gen1/README.md +65 -39
- package/src/lib/gen1/data.zig +7 -7
- package/src/lib/gen1/helpers.zig +10 -11
- package/src/lib/gen1/mechanics.zig +416 -301
- package/src/lib/gen2/data.zig +4 -4
- package/src/lib/pkmn.zig +7 -7
- package/src/test/display/pkmn.html.tmpl +368 -0
|
@@ -10,13 +10,15 @@ const path = require('path');
|
|
|
10
10
|
const {pipeline} = require('stream/promises');
|
|
11
11
|
const tty = require('tty');
|
|
12
12
|
|
|
13
|
-
const ZIG_VERSION = {major: 0, minor: 11, patch: 0, dev:
|
|
13
|
+
const ZIG_VERSION = {major: 0, minor: 11, patch: 0, dev: 2750};
|
|
14
14
|
const DEV = ZIG_VERSION.dev ? `-dev.${ZIG_VERSION.dev}` : '';
|
|
15
15
|
const VERSION = `${ZIG_VERSION.major}.${ZIG_VERSION.minor}.${ZIG_VERSION.patch}${DEV}`;
|
|
16
16
|
const INDEX = 'https://ziglang.org/download/index.json';
|
|
17
17
|
const ROOT = path.resolve(__dirname, '..', '..');
|
|
18
|
+
let SILENT = false;
|
|
18
19
|
|
|
19
20
|
const sh = (cmd, args) => execFileSync(cmd, args, {encoding: 'utf8', cwd: ROOT});
|
|
21
|
+
const log = (...args) => { if (!SILENT) console.log(...args); };
|
|
20
22
|
|
|
21
23
|
// This is hardly the browser fetch API, but it works for our primitive needs
|
|
22
24
|
const fetch = url => new Promise((resolve, reject) => {
|
|
@@ -61,7 +63,7 @@ const unpack7 = (input, output) => new Promise((resolve, reject) => {
|
|
|
61
63
|
require.resolve('7zip-min');
|
|
62
64
|
} catch (err) {
|
|
63
65
|
if (err.code !== 'MODULE_NOT_FOUND') throw err;
|
|
64
|
-
|
|
66
|
+
log('Installing 7zip-min package locally to unpack the archive...');
|
|
65
67
|
sh('npm', ['install', '7zip-min', '--no-audit', '--no-save']);
|
|
66
68
|
}
|
|
67
69
|
|
|
@@ -83,7 +85,7 @@ const unpack = async (input, output) => {
|
|
|
83
85
|
sh('tar', ['xf', input, '-C', output]);
|
|
84
86
|
return;
|
|
85
87
|
} catch {
|
|
86
|
-
|
|
88
|
+
log('tar command not found, falling back to 7z');
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
// Try to use a 7z binary if we can, and only install 7zip-min as a last resort
|
|
@@ -120,10 +122,10 @@ const find = zig => {
|
|
|
120
122
|
(!ZIG_VERSION.dev || (dev && dev >= ZIG_VERSION.dev)));
|
|
121
123
|
|
|
122
124
|
if (compatible) {
|
|
123
|
-
|
|
125
|
+
log('Found existing compatible Zig executable:', zig_exe);
|
|
124
126
|
return zig_exe;
|
|
125
127
|
} else {
|
|
126
|
-
|
|
128
|
+
log(`Existing Zig executable is not compatible (${version} < ${VERSION}):`, zig_exe);
|
|
127
129
|
}
|
|
128
130
|
} catch (err) {
|
|
129
131
|
if (err.code !== 'ENOENT') throw err;
|
|
@@ -168,11 +170,11 @@ const install = async () => {
|
|
|
168
170
|
let base = path.basename(url);
|
|
169
171
|
const archive = path.join(dir, path.basename(url));
|
|
170
172
|
|
|
171
|
-
|
|
173
|
+
log(`Downloading Zig tarball from ${url} to ${archive}`);
|
|
172
174
|
try {
|
|
173
175
|
await download(url, archive, release.shasum);
|
|
174
176
|
|
|
175
|
-
|
|
177
|
+
log(`Extracting tarball and installing to ${dir}`);
|
|
176
178
|
await unpack(archive, dir);
|
|
177
179
|
if (archive.endsWith('.zip')) {
|
|
178
180
|
base = base.slice(0, -4);
|
|
@@ -187,17 +189,17 @@ const install = async () => {
|
|
|
187
189
|
} catch (err) {
|
|
188
190
|
if (err.code !== 'ENOENT') throw err;
|
|
189
191
|
}
|
|
190
|
-
|
|
192
|
+
log(`Zig${version === 'master' ? '' : ` v${version}`} executable:`, zig,
|
|
191
193
|
'(this version of Zig will be retained to speed up future updates)');
|
|
192
194
|
const [pre, post] = tty.isatty(1) ? ['\x1b[1m\x1b[35m', '\x1b[0m'] : ['', ''];
|
|
193
|
-
|
|
195
|
+
log(
|
|
194
196
|
`${pre}Consider moving the ${path.dirname(zig)} directory and adding it to your PATH`,
|
|
195
197
|
`to use Zig on other projects, or delete this if you wish to save space.${post}`
|
|
196
198
|
);
|
|
197
199
|
|
|
198
200
|
return zig;
|
|
199
201
|
} finally {
|
|
200
|
-
|
|
202
|
+
log(`Cleaning up ${archive}`);
|
|
201
203
|
try { fs.rmSync(archive); } catch {}
|
|
202
204
|
}
|
|
203
205
|
};
|
|
@@ -206,17 +208,17 @@ const install = async () => {
|
|
|
206
208
|
const downloadHeaders = async () => {
|
|
207
209
|
const include = path.resolve(process.execPath, '..', '..', 'include', 'node');
|
|
208
210
|
if (fs.existsSync(path.join(include, 'node.h'))) {
|
|
209
|
-
|
|
211
|
+
log('Node headers:', include);
|
|
210
212
|
return include;
|
|
211
213
|
}
|
|
212
214
|
|
|
213
215
|
const dir = path.join(ROOT, 'build', 'include');
|
|
214
|
-
const dest = path.join(dir,
|
|
216
|
+
const dest = path.join(dir, 'node');
|
|
215
217
|
if (fs.existsSync(path.join(dest, 'node.h'))) {
|
|
216
|
-
|
|
218
|
+
log('Node headers:', dest);
|
|
217
219
|
return dest;
|
|
218
220
|
} else {
|
|
219
|
-
|
|
221
|
+
log(`Could not find Node headers at ${include}, downloading...`);
|
|
220
222
|
}
|
|
221
223
|
|
|
222
224
|
try {
|
|
@@ -227,20 +229,28 @@ const downloadHeaders = async () => {
|
|
|
227
229
|
|
|
228
230
|
const url = process.release.headersUrl;
|
|
229
231
|
const targz = path.join(dir, path.basename(url));
|
|
232
|
+
const unpacked = path.join(dir, `node-${process.version}`, 'include');
|
|
230
233
|
|
|
231
|
-
|
|
232
|
-
await download(url, targz);
|
|
233
|
-
await unpack(targz, dir);
|
|
234
|
+
log(`Downloading Node headers from ${url} to ${targz}`);
|
|
234
235
|
|
|
235
|
-
|
|
236
|
+
try {
|
|
237
|
+
await download(url, targz);
|
|
238
|
+
await unpack(targz, dir);
|
|
239
|
+
fs.renameSync(path.join(unpacked, 'node'), dest);
|
|
236
240
|
|
|
237
|
-
|
|
241
|
+
log('Node headers:', dest);
|
|
242
|
+
|
|
243
|
+
return dest;
|
|
244
|
+
} finally {
|
|
245
|
+
try { fs.rmSync(targz); } catch {}
|
|
246
|
+
try { fs.rmSync(unpacked, {recursive: true}); } catch {}
|
|
247
|
+
}
|
|
238
248
|
};
|
|
239
249
|
|
|
240
250
|
const downloadImportLib = async () => {
|
|
241
251
|
const library = path.resolve(process.execPath, '..', 'node.lib');
|
|
242
252
|
if (fs.existsSync(path.join(library, 'node.h'))) {
|
|
243
|
-
|
|
253
|
+
log('Node import library:', library);
|
|
244
254
|
return library;
|
|
245
255
|
}
|
|
246
256
|
|
|
@@ -248,10 +258,10 @@ const downloadImportLib = async () => {
|
|
|
248
258
|
const url = new URL('./win-x64/node.lib', process.release.headersUrl).href;
|
|
249
259
|
const dest = path.join(dir, path.basename(url));
|
|
250
260
|
if (fs.existsSync(path.join(dest))) {
|
|
251
|
-
|
|
261
|
+
log('Node import library:', dest);
|
|
252
262
|
return dest;
|
|
253
263
|
} else {
|
|
254
|
-
|
|
264
|
+
log(`Could not find Node import library at ${library}, downloading...`);
|
|
255
265
|
}
|
|
256
266
|
|
|
257
267
|
try {
|
|
@@ -260,24 +270,41 @@ const downloadImportLib = async () => {
|
|
|
260
270
|
if (err.code !== 'EEXIST') throw err;
|
|
261
271
|
}
|
|
262
272
|
|
|
263
|
-
|
|
273
|
+
log(`Downloading Node import library from ${url} to ${dest}`);
|
|
264
274
|
await download(url, dest);
|
|
265
|
-
|
|
275
|
+
log('Node import library:', dest);
|
|
266
276
|
|
|
267
277
|
return dest;
|
|
268
278
|
};
|
|
269
279
|
|
|
270
280
|
(async () => {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
281
|
+
let only = false;
|
|
282
|
+
let options = undefined;
|
|
283
|
+
let error = false;
|
|
284
|
+
for (let i = 2; i < process.argv.length; i++) {
|
|
285
|
+
switch (process.argv[i]) {
|
|
286
|
+
case "--silent": {
|
|
287
|
+
SILENT = true;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
case "--zig": {
|
|
291
|
+
if (options || only) error = true;
|
|
292
|
+
only = true;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
default: {
|
|
296
|
+
if (options || only || !process.argv[i].startsWith('--options=')) error = true;
|
|
297
|
+
options = process.argv[i].slice(10).split(' ');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (error) {
|
|
275
302
|
console.error('Invalid arguments');
|
|
276
303
|
process.exit(1);
|
|
277
304
|
}
|
|
278
305
|
|
|
279
306
|
const zig = await install();
|
|
280
|
-
if (
|
|
307
|
+
if (only) process.exit(0);
|
|
281
308
|
|
|
282
309
|
let tmp;
|
|
283
310
|
try {
|
|
@@ -310,13 +337,13 @@ const downloadImportLib = async () => {
|
|
|
310
337
|
if (!options) {
|
|
311
338
|
const addon = require(copy);
|
|
312
339
|
if (addon.options.showdown) opts.push('-Dshowdown');
|
|
313
|
-
if (addon.options.
|
|
340
|
+
if (addon.options.log) opts.push('-Dlog');
|
|
314
341
|
}
|
|
315
342
|
} else if (!options) {
|
|
316
343
|
const addon = await WebAssembly.instantiate(fs.readFileSync(copy));
|
|
317
344
|
const values = new Uint8Array(addon.instance.exports.memory.buffer);
|
|
318
345
|
if (values[addon.instance.exports.SHOWDOWN.value]) opts.push('-Dshowdown');
|
|
319
|
-
if (values[addon.instance.exports.
|
|
346
|
+
if (values[addon.instance.exports.LOG.value]) opts.push('-Dlog');
|
|
320
347
|
}
|
|
321
348
|
const key = `${type} ${opts.sort().join(' ')}`;
|
|
322
349
|
if (!configs.has(key)) configs.set(key, {type, options: opts});
|
|
@@ -347,7 +374,7 @@ const downloadImportLib = async () => {
|
|
|
347
374
|
opts.includes('-Dshowdown') || opts.includes('-Dshowdown=true') ? '-showdown' : '';
|
|
348
375
|
const flags = opts.length ? ` (${opts.join(' ')})` : '';
|
|
349
376
|
const artifact = path.join('build', 'lib', `pkmn${suffix}.${config.type}`);
|
|
350
|
-
|
|
377
|
+
log(`Building ${artifact}${flags}`);
|
|
351
378
|
sh(zig, args);
|
|
352
379
|
// TODO: ziglang/zig#14647 broke emit_to so we get to rename the file ourselves...
|
|
353
380
|
if (config.type === 'node') {
|
|
@@ -355,7 +382,7 @@ const downloadImportLib = async () => {
|
|
|
355
382
|
const ext = process.platform === 'darwin'
|
|
356
383
|
? 'dylib' : process.platform === 'win32' ? 'dll' : 'so';
|
|
357
384
|
const actual = path.join('build', 'lib', `${prefix}pkmn${suffix}.node.${ext}`);
|
|
358
|
-
fs.renameSync(actual, artifact);
|
|
385
|
+
fs.renameSync(path.join(ROOT, actual), path.join(ROOT, artifact));
|
|
359
386
|
}
|
|
360
387
|
}
|
|
361
388
|
})().catch(e => {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
try {
|
|
5
|
+
require('source-map-support').install();
|
|
6
|
+
} catch (err) {
|
|
7
|
+
if (err.code !== 'MODULE_NOT_FOUND') throw err;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const {execFileSync} = require('child_process');
|
|
11
|
+
const {readFileSync} = require('fs');
|
|
12
|
+
const {join, resolve} = require('path');
|
|
13
|
+
|
|
14
|
+
const ROOT = resolve(__dirname, '..', '..');
|
|
15
|
+
const packageJSON = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
|
|
16
|
+
|
|
17
|
+
const missing = [];
|
|
18
|
+
for (const dep of ['@pkmn/img', 'html-minifier', 'mustache']) {
|
|
19
|
+
try {
|
|
20
|
+
require.resolve(dep);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
if (e.code !== 'MODULE_NOT_FOUND') throw e;
|
|
23
|
+
missing.push(`${dep}@${packageJSON.devDependencies[dep]}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let Dex = undefined;
|
|
28
|
+
try {
|
|
29
|
+
Dex = require('@pkmn/sim').Dex;
|
|
30
|
+
} catch (err) {
|
|
31
|
+
if (err.code !== 'MODULE_NOT_FOUND') throw err;
|
|
32
|
+
try {
|
|
33
|
+
Dex = require('@pkmn/dex').Dex;
|
|
34
|
+
} catch (e) {
|
|
35
|
+
if (e.code !== 'MODULE_NOT_FOUND') throw e;
|
|
36
|
+
missing.push(`@pkmn/dex@${packageJSON.dependencies['@pkmn/data']}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (missing.length) {
|
|
41
|
+
if (+/^v(\d+)/.exec(process.version)[1] < 16) {
|
|
42
|
+
console.error('pkmn-debug requires Node v16+');
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
execFileSync('npm', ['install', ...missing, '--global'], {encoding: 'utf8'});
|
|
47
|
+
|
|
48
|
+
const node_modules = execFileSync('npm', ['root', '--global'], {encoding: 'utf8'}).trim();
|
|
49
|
+
if (!process.env.NODE_PATH || !process.env.NODE_PATH.includes(node_modules)) {
|
|
50
|
+
console.error(`NODE_PATH must include npm's global node_modules directory: '${node_modules}'`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const {Generations} = require('@pkmn/data');
|
|
56
|
+
|
|
57
|
+
const {run} = require('../../build/tools/debug');
|
|
58
|
+
|
|
59
|
+
run(new Generations(Dex)).catch(err => {
|
|
60
|
+
console.error(err.message);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
});
|
package/src/lib/binding/node.zig
CHANGED
|
@@ -21,7 +21,7 @@ fn options(env: c.napi_env) c.napi_value {
|
|
|
21
21
|
var object = Object.init(env);
|
|
22
22
|
const properties = [_]c.napi_property_descriptor{
|
|
23
23
|
Property.init("showdown", .{ .value = Boolean.init(env, pkmn.options.showdown) }),
|
|
24
|
-
Property.init("
|
|
24
|
+
Property.init("log", .{ .value = Boolean.init(env, pkmn.options.log) }),
|
|
25
25
|
};
|
|
26
26
|
assert(c.napi_define_properties(env, object, properties.len, &properties) == c.napi_ok);
|
|
27
27
|
return object;
|
|
@@ -34,11 +34,11 @@ fn bindings(env: c.napi_env) c.napi_value {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
fn bind(env: c.napi_env, gen: anytype) c.napi_value {
|
|
37
|
-
const
|
|
37
|
+
const choices_size = @intCast(u32, gen.CHOICES_SIZE);
|
|
38
38
|
const logs_size = @intCast(u32, gen.LOGS_SIZE);
|
|
39
39
|
var object = Object.init(env);
|
|
40
40
|
const properties = [_]c.napi_property_descriptor{
|
|
41
|
-
Property.init("
|
|
41
|
+
Property.init("CHOICES_SIZE", .{ .value = Number.init(env, choices_size) }),
|
|
42
42
|
Property.init("LOGS_SIZE", .{ .value = Number.init(env, logs_size) }),
|
|
43
43
|
Property.init("update", .{ .method = update(gen) }),
|
|
44
44
|
Property.init("choices", .{ .method = choices(gen) }),
|
|
@@ -108,10 +108,10 @@ fn choices(gen: anytype) c.napi_callback {
|
|
|
108
108
|
const request = @intToEnum(pkmn.Choice.Type, Number.get(env, argv[2], u8));
|
|
109
109
|
|
|
110
110
|
assert(c.napi_get_arraybuffer_info(env, argv[3], &data, &len) == c.napi_ok);
|
|
111
|
-
assert(len == gen.
|
|
111
|
+
assert(len == gen.CHOICES_SIZE);
|
|
112
112
|
assert(data != null);
|
|
113
113
|
|
|
114
|
-
var out = @ptrCast([*]pkmn.Choice, data.?)[0..gen.
|
|
114
|
+
var out = @ptrCast([*]pkmn.Choice, data.?)[0..gen.CHOICES_SIZE];
|
|
115
115
|
const n = battle.choices(player, request, out);
|
|
116
116
|
return Number.init(env, @bitCast(u8, n));
|
|
117
117
|
}
|
package/src/lib/binding/wasm.zig
CHANGED
|
@@ -2,9 +2,9 @@ const std = @import("std");
|
|
|
2
2
|
const pkmn = @import("../pkmn.zig");
|
|
3
3
|
|
|
4
4
|
export const SHOWDOWN = pkmn.options.showdown;
|
|
5
|
-
export const
|
|
5
|
+
export const LOG = pkmn.options.log;
|
|
6
6
|
|
|
7
|
-
export const
|
|
8
|
-
std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.
|
|
7
|
+
export const GEN1_CHOICES_SIZE =
|
|
8
|
+
std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.CHOICES_SIZE)) catch unreachable;
|
|
9
9
|
export const GEN1_LOGS_SIZE =
|
|
10
10
|
std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.LOGS_SIZE)) catch unreachable;
|
package/src/lib/common/debug.zig
CHANGED
|
@@ -3,7 +3,7 @@ const root = @import("root");
|
|
|
3
3
|
|
|
4
4
|
pub const Options = struct {
|
|
5
5
|
showdown: ?bool = null,
|
|
6
|
-
|
|
6
|
+
log: ?bool = null,
|
|
7
7
|
advance: ?bool = null,
|
|
8
8
|
ebc: ?bool = null,
|
|
9
9
|
internal: ?bool = null,
|
|
@@ -11,8 +11,8 @@ pub const Options = struct {
|
|
|
11
11
|
|
|
12
12
|
/// Whether or not Pokémon Showdown compatibility mode is enabled.
|
|
13
13
|
pub const showdown = get("showdown", false);
|
|
14
|
-
/// Whether or not protocol
|
|
15
|
-
pub const
|
|
14
|
+
/// Whether or not protocol message logging is enabled.
|
|
15
|
+
pub const log = get("log", false);
|
|
16
16
|
|
|
17
17
|
pub const advance = get("advance", true);
|
|
18
18
|
pub const ebc = get("ebc", true);
|
|
@@ -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,7 +230,7 @@ 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
|
@enumToInt(ArgType.Move),
|
|
@@ -253,7 +253,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
pub fn switched(self: Self, ident: ID, pokemon: anytype) Error!void {
|
|
256
|
-
if (!
|
|
256
|
+
if (!enabled) return;
|
|
257
257
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Switch), @bitCast(u8, ident) });
|
|
258
258
|
try self.writer.writeAll(&.{ @enumToInt(pokemon.species), pokemon.level });
|
|
259
259
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
@@ -262,7 +262,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
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
|
@enumToInt(ArgType.Cant),
|
|
@@ -272,7 +272,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
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
|
@enumToInt(ArgType.Cant),
|
|
278
278
|
@bitCast(u8, ident),
|
|
@@ -282,20 +282,20 @@ pub fn Log(comptime Writer: type) type {
|
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
pub fn faint(self: Self, ident: ID, done: bool) Error!void {
|
|
285
|
-
if (!
|
|
285
|
+
if (!enabled) return;
|
|
286
286
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Faint), @bitCast(u8, ident) });
|
|
287
287
|
if (done) try self.writer.writeByte(@enumToInt(ArgType.None));
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
pub fn turn(self: Self, num: u16) Error!void {
|
|
291
|
-
if (!
|
|
291
|
+
if (!enabled) return;
|
|
292
292
|
try self.writer.writeByte(@enumToInt(ArgType.Turn));
|
|
293
293
|
try self.writer.writeIntNative(u16, num);
|
|
294
294
|
try self.writer.writeByte(@enumToInt(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
300
|
@enumToInt(ArgType.Win),
|
|
301
301
|
@enumToInt(player),
|
|
@@ -304,12 +304,12 @@ pub fn Log(comptime Writer: type) type {
|
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
pub fn tie(self: Self) Error!void {
|
|
307
|
-
if (!
|
|
307
|
+
if (!enabled) return;
|
|
308
308
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Tie), @enumToInt(ArgType.None) });
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
pub fn damage(self: Self, ident: ID, pokemon: anytype, reason: Damage) Error!void {
|
|
312
|
-
if (!
|
|
312
|
+
if (!enabled) return;
|
|
313
313
|
assert(@enumToInt(reason) <= @enumToInt(Damage.LeechSeed));
|
|
314
314
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Damage), @bitCast(u8, ident) });
|
|
315
315
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
@@ -324,7 +324,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
324
324
|
reason: Damage,
|
|
325
325
|
source: ID,
|
|
326
326
|
) Error!void {
|
|
327
|
-
if (!
|
|
327
|
+
if (!enabled) return;
|
|
328
328
|
assert(@enumToInt(reason) == @enumToInt(Damage.RecoilOf));
|
|
329
329
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Damage), @bitCast(u8, ident) });
|
|
330
330
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
@@ -337,7 +337,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
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
342
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Heal), @bitCast(u8, ident) });
|
|
343
343
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
@@ -346,7 +346,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
pub fn drain(self: Self, source: ID, pokemon: anytype, target: ID) Error!void {
|
|
349
|
-
if (!
|
|
349
|
+
if (!enabled) return;
|
|
350
350
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Heal), @bitCast(u8, source) });
|
|
351
351
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
352
352
|
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
@@ -358,7 +358,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
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
|
@enumToInt(ArgType.Status),
|
|
@@ -369,7 +369,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
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
|
@enumToInt(ArgType.Status),
|
|
375
375
|
@bitCast(u8, ident),
|
|
@@ -380,7 +380,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
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
|
@enumToInt(ArgType.CureStatus),
|
|
386
386
|
@bitCast(u8, ident),
|
|
@@ -390,7 +390,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
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
|
@enumToInt(ArgType.Boost),
|
|
@@ -401,12 +401,12 @@ pub fn Log(comptime Writer: type) type {
|
|
|
401
401
|
}
|
|
402
402
|
|
|
403
403
|
pub fn clearallboost(self: Self) Error!void {
|
|
404
|
-
if (!
|
|
404
|
+
if (!enabled) return;
|
|
405
405
|
try self.writer.writeAll(&.{@enumToInt(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
|
@enumToInt(ArgType.Fail),
|
|
412
412
|
@bitCast(u8, ident),
|
|
@@ -415,17 +415,17 @@ pub fn Log(comptime Writer: type) type {
|
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
pub fn miss(self: Self, source: ID) Error!void {
|
|
418
|
-
if (!
|
|
418
|
+
if (!enabled) return;
|
|
419
419
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Miss), @bitCast(u8, source) });
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
pub fn hitcount(self: Self, ident: ID, num: u8) Error!void {
|
|
423
|
-
if (!
|
|
423
|
+
if (!enabled) return;
|
|
424
424
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.HitCount), @bitCast(u8, ident), num });
|
|
425
425
|
}
|
|
426
426
|
|
|
427
427
|
pub fn prepare(self: Self, source: ID, m: anytype) Error!void {
|
|
428
|
-
if (!
|
|
428
|
+
if (!enabled) return;
|
|
429
429
|
try self.writer.writeAll(&.{
|
|
430
430
|
@enumToInt(ArgType.Prepare),
|
|
431
431
|
@bitCast(u8, source),
|
|
@@ -434,12 +434,12 @@ pub fn Log(comptime Writer: type) type {
|
|
|
434
434
|
}
|
|
435
435
|
|
|
436
436
|
pub fn mustrecharge(self: Self, ident: ID) Error!void {
|
|
437
|
-
if (!
|
|
437
|
+
if (!enabled) return;
|
|
438
438
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.MustRecharge), @bitCast(u8, ident) });
|
|
439
439
|
}
|
|
440
440
|
|
|
441
441
|
pub fn activate(self: Self, ident: ID, reason: Activate) Error!void {
|
|
442
|
-
if (!
|
|
442
|
+
if (!enabled) return;
|
|
443
443
|
try self.writer.writeAll(&.{
|
|
444
444
|
@enumToInt(ArgType.Activate),
|
|
445
445
|
@bitCast(u8, ident),
|
|
@@ -448,12 +448,12 @@ pub fn Log(comptime Writer: type) type {
|
|
|
448
448
|
}
|
|
449
449
|
|
|
450
450
|
pub fn fieldactivate(self: Self) Error!void {
|
|
451
|
-
if (!
|
|
451
|
+
if (!enabled) return;
|
|
452
452
|
try self.writer.writeAll(&.{@enumToInt(ArgType.FieldActivate)});
|
|
453
453
|
}
|
|
454
454
|
|
|
455
455
|
pub fn start(self: Self, ident: ID, reason: Start) Error!void {
|
|
456
|
-
if (!
|
|
456
|
+
if (!enabled) return;
|
|
457
457
|
assert(@enumToInt(reason) < @enumToInt(Start.TypeChange));
|
|
458
458
|
try self.writer.writeAll(&.{
|
|
459
459
|
@enumToInt(ArgType.Start),
|
|
@@ -463,7 +463,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
463
463
|
}
|
|
464
464
|
|
|
465
465
|
pub fn typechange(self: Self, source: ID, types: anytype, target: ID) Error!void {
|
|
466
|
-
if (!
|
|
466
|
+
if (!enabled) return;
|
|
467
467
|
try self.writer.writeAll(&.{
|
|
468
468
|
@enumToInt(ArgType.Start),
|
|
469
469
|
@bitCast(u8, source),
|
|
@@ -474,7 +474,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
474
474
|
}
|
|
475
475
|
|
|
476
476
|
pub fn startEffect(self: Self, ident: ID, reason: Start, m: anytype) Error!void {
|
|
477
|
-
if (!
|
|
477
|
+
if (!enabled) return;
|
|
478
478
|
assert(@enumToInt(reason) > @enumToInt(Start.TypeChange));
|
|
479
479
|
try self.writer.writeAll(&.{
|
|
480
480
|
@enumToInt(ArgType.Start),
|
|
@@ -485,7 +485,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
485
485
|
}
|
|
486
486
|
|
|
487
487
|
pub fn end(self: Self, ident: ID, reason: End) Error!void {
|
|
488
|
-
if (!
|
|
488
|
+
if (!enabled) return;
|
|
489
489
|
try self.writer.writeAll(&.{
|
|
490
490
|
@enumToInt(ArgType.End),
|
|
491
491
|
@bitCast(u8, ident),
|
|
@@ -494,27 +494,27 @@ pub fn Log(comptime Writer: type) type {
|
|
|
494
494
|
}
|
|
495
495
|
|
|
496
496
|
pub fn ohko(self: Self) Error!void {
|
|
497
|
-
if (!
|
|
497
|
+
if (!enabled) return;
|
|
498
498
|
try self.writer.writeAll(&.{@enumToInt(ArgType.OHKO)});
|
|
499
499
|
}
|
|
500
500
|
|
|
501
501
|
pub fn crit(self: Self, ident: ID) Error!void {
|
|
502
|
-
if (!
|
|
502
|
+
if (!enabled) return;
|
|
503
503
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Crit), @bitCast(u8, ident) });
|
|
504
504
|
}
|
|
505
505
|
|
|
506
506
|
pub fn supereffective(self: Self, ident: ID) Error!void {
|
|
507
|
-
if (!
|
|
507
|
+
if (!enabled) return;
|
|
508
508
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.SuperEffective), @bitCast(u8, ident) });
|
|
509
509
|
}
|
|
510
510
|
|
|
511
511
|
pub fn resisted(self: Self, ident: ID) Error!void {
|
|
512
|
-
if (!
|
|
512
|
+
if (!enabled) return;
|
|
513
513
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Resisted), @bitCast(u8, ident) });
|
|
514
514
|
}
|
|
515
515
|
|
|
516
516
|
pub fn immune(self: Self, ident: ID, reason: Immune) Error!void {
|
|
517
|
-
if (!
|
|
517
|
+
if (!enabled) return;
|
|
518
518
|
try self.writer.writeAll(&.{
|
|
519
519
|
@enumToInt(ArgType.Immune),
|
|
520
520
|
@bitCast(u8, ident),
|
|
@@ -523,7 +523,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
523
523
|
}
|
|
524
524
|
|
|
525
525
|
pub fn transform(self: Self, source: ID, target: ID) Error!void {
|
|
526
|
-
if (!
|
|
526
|
+
if (!enabled) return;
|
|
527
527
|
try self.writer.writeAll(&.{
|
|
528
528
|
@enumToInt(ArgType.Transform),
|
|
529
529
|
@bitCast(u8, source),
|
|
@@ -532,12 +532,12 @@ pub fn Log(comptime Writer: type) type {
|
|
|
532
532
|
}
|
|
533
533
|
|
|
534
534
|
pub fn laststill(self: Self) Error!void {
|
|
535
|
-
if (!
|
|
535
|
+
if (!enabled) return;
|
|
536
536
|
try self.writer.writeAll(&.{@enumToInt(ArgType.LastStill)});
|
|
537
537
|
}
|
|
538
538
|
|
|
539
539
|
pub fn lastmiss(self: Self) Error!void {
|
|
540
|
-
if (!
|
|
540
|
+
if (!enabled) return;
|
|
541
541
|
try self.writer.writeAll(&.{@enumToInt(ArgType.LastMiss)});
|
|
542
542
|
}
|
|
543
543
|
};
|
|
@@ -838,7 +838,7 @@ pub fn expectLog(
|
|
|
838
838
|
actual: []const u8,
|
|
839
839
|
offset: usize,
|
|
840
840
|
) !void {
|
|
841
|
-
if (!
|
|
841
|
+
if (!enabled) return;
|
|
842
842
|
const color = color: {
|
|
843
843
|
if (std.process.hasEnvVarConstant("ZIG_DEBUG_COLOR")) {
|
|
844
844
|
break :color true;
|