@pkmn/engine 0.1.0-dev.d56bdadd → 0.1.0-dev.d952b7c9

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 (67) hide show
  1. package/LICENSE +1 -3
  2. package/README.md +46 -19
  3. package/build/pkg/addon/browser.d.ts +3 -0
  4. package/build/pkg/addon/browser.js +43 -0
  5. package/build/pkg/addon/browser.js.map +1 -0
  6. package/build/pkg/addon/node.d.ts +3 -0
  7. package/build/pkg/addon/node.js +96 -0
  8. package/build/pkg/addon/node.js.map +1 -0
  9. package/build/pkg/addon.d.ts +2 -0
  10. package/build/pkg/addon.js +35 -58
  11. package/build/pkg/addon.js.map +1 -1
  12. package/build/pkg/data.d.ts +27 -5
  13. package/build/pkg/data.js.map +1 -1
  14. package/build/pkg/gen1.js +1 -1
  15. package/build/pkg/gen1.js.map +1 -1
  16. package/build/pkg/index.d.ts +24 -10
  17. package/build/pkg/index.js +15 -10
  18. package/build/pkg/index.js.map +1 -1
  19. package/build/pkg/protocol.d.ts +20 -1
  20. package/build/pkg/protocol.js +109 -107
  21. package/build/pkg/protocol.js.map +1 -1
  22. package/build/tools/debug.js +36 -68
  23. package/build/tools/debug.js.map +1 -1
  24. package/build/tools/display/debug.jsx +128 -0
  25. package/build/tools/display/debug.jsx.map +1 -0
  26. package/build/tools/display/index.js +132 -0
  27. package/build/tools/display/index.js.map +1 -0
  28. package/build/tools/display/ui.jsx +349 -0
  29. package/build/tools/display/ui.jsx.map +1 -0
  30. package/build/tools/display/util.js +18 -0
  31. package/build/tools/display/util.js.map +1 -0
  32. package/build.zig +206 -81
  33. package/package.json +51 -30
  34. package/src/bin/install-pkmn-engine +29 -19
  35. package/src/bin/pkmn-debug +1 -1
  36. package/src/lib/common/array.zig +77 -0
  37. package/src/lib/common/data.zig +4 -4
  38. package/src/lib/common/debug.zig +11 -6
  39. package/src/lib/common/js.zig +4 -2
  40. package/src/lib/common/optional.zig +14 -10
  41. package/src/lib/common/options.zig +4 -0
  42. package/src/lib/common/protocol.zig +389 -407
  43. package/src/lib/common/rational.zig +121 -27
  44. package/src/lib/common/rng.zig +7 -7
  45. package/src/lib/common/util.zig +50 -1
  46. package/src/lib/gen1/calc.zig +657 -133
  47. package/src/lib/gen1/chance.zig +376 -267
  48. package/src/lib/gen1/data/species.zig +1 -1
  49. package/src/lib/gen1/data.zig +17 -16
  50. package/src/lib/gen1/helpers.zig +95 -538
  51. package/src/lib/gen1/mechanics.zig +492 -389
  52. package/src/lib/gen2/calc.zig +34 -16
  53. package/src/lib/gen2/chance.zig +84 -496
  54. package/src/lib/gen2/data.zig +8 -7
  55. package/src/lib/gen2/generated.zig +4 -6
  56. package/src/lib/gen2/helpers.zig +41 -13
  57. package/src/lib/gen2/mechanics.zig +448 -377
  58. package/src/lib/{binding/node.zig → node.zig} +9 -12
  59. package/src/lib/pkmn.zig +32 -15
  60. package/src/lib/{binding/wasm.zig → wasm.zig} +2 -1
  61. package/src/tools/display/dom.ts +96 -0
  62. package/src/tools/display/ui.css +351 -0
  63. package/build/test/display.js +0 -400
  64. package/build/test/display.js.map +0 -1
  65. package/src/lib/gen1/README.md +0 -894
  66. package/src/lib/gen2/README.md +0 -329
  67. package/src/test/display/pkmn.html.tmpl +0 -368
@@ -1 +1 @@
1
- {"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/tools/debug.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AAEzB,qCAAmD;AAEnD,gCAAmE;AACnE,oDAAsC;AACtC,sCAAiD;AACjD,kDAAoC;AACpC,6CAA8C;AAE9C,MAAM,YAAY;IAChB,GAAG,CAAa;IAChB,MAAM,CAAS;IAEf,YAAY,GAAe,EAAE,MAAc;QACzC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,IAAI,EAAE;QACJ,MAAM,CAAC,EAAE,CAAC,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,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACzD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const engine = __importStar(require("../../pkg"));
27
+ const data_1 = require("../../pkg/data");
28
+ const gen1 = __importStar(require("../../pkg/gen1"));
29
+ const ui_1 = require("./ui");
30
+ const util = __importStar(require("./util"));
31
+ class SpeciesNames {
32
+ gen;
33
+ battle;
34
+ constructor(gen, battle) {
35
+ this.gen = gen;
36
+ this.battle = battle;
37
+ }
38
+ get p1() {
39
+ const [p1] = Array.from(this.battle.sides);
40
+ const team = Array.from(p1.pokemon)
41
+ .sort((a, b) => a.position - b.position)
42
+ .map(p => ({ species: p.stored.species }));
43
+ return new engine.SideInfo(this.gen, { name: 'Player 1', team });
44
+ }
45
+ get p2() {
46
+ const [, p2] = Array.from(this.battle.sides);
47
+ const team = Array.from(p2.pokemon)
48
+ .sort((a, b) => a.position - b.position)
49
+ .map(p => ({ species: p.stored.species }));
50
+ return new engine.SideInfo(this.gen, { name: 'Player 2', team });
51
+ }
52
+ }
53
+ const App = ({ gen, data, error, seed }) => {
54
+ let offset = 0;
55
+ const showdown = !!data.getUint8(offset);
56
+ offset += 2;
57
+ const N = data.getUint16(offset, data_1.LE);
58
+ offset += 2;
59
+ const lookup = engine.Lookup.get(gen);
60
+ const size = data_1.LAYOUT[gen.num - 1].sizes.Battle;
61
+ const deserialize = (d) => {
62
+ switch (gen.num) {
63
+ case 1: return new gen1.Battle(lookup, d, { inert: true, showdown });
64
+ default: throw new Error(`Unsupported gen: ${gen.num}`);
65
+ }
66
+ };
67
+ const battle = deserialize(windowed(data, offset, offset += size));
68
+ const names = new SpeciesNames(gen, battle);
69
+ const log = new engine.Log(gen, lookup, names);
70
+ let partial = undefined;
71
+ let last = undefined;
72
+ const frames = [];
73
+ while (offset < data.byteLength) {
74
+ partial = { parsed: [] };
75
+ const it = log.parse(windowed(data, offset))[Symbol.iterator]();
76
+ let r = it.next();
77
+ while (!r.done) {
78
+ partial.parsed.push(r.value);
79
+ r = it.next();
80
+ }
81
+ offset += N || r.value;
82
+ if (offset >= data.byteLength)
83
+ break;
84
+ partial.battle = deserialize(windowed(data, offset, offset += size));
85
+ if (offset >= data.byteLength)
86
+ break;
87
+ partial.result = engine.Result.decode(data.getUint8(offset++));
88
+ if (offset >= data.byteLength)
89
+ break;
90
+ partial.c1 = engine.Choice.decode(data.getUint8(offset++));
91
+ if (offset >= data.byteLength)
92
+ break;
93
+ partial.c2 = engine.Choice.decode(data.getUint8(offset++));
94
+ frames.push(<Frame frame={partial} gen={gen} showdown={showdown} last={last}/>);
95
+ last = partial.battle;
96
+ partial = undefined;
97
+ }
98
+ frames.push(<Frame frame={partial || {}} gen={gen} showdown={showdown} last={last}/>);
99
+ return <>
100
+ {!!seed && <h1>0x{seed.toString(16).toUpperCase()}</h1>}
101
+ {frames}
102
+ {error && <pre className='error'><code>{error}</code></pre>}
103
+ </>;
104
+ };
105
+ const Frame = ({ frame, gen, showdown, last }) => <div className='frame'>
106
+ {frame.parsed && <div className='log'>
107
+ <pre><code>{util.toText(frame.parsed)}</code></pre>
108
+ </div>}
109
+ {frame.battle && <ui_1.Battle battle={frame.battle} gen={gen} showdown={showdown} last={last}/>}
110
+ {frame.result && <div className='sides' style={{ textAlign: 'center' }}>
111
+ <pre className='side'><code>{frame.result.p1} -&gt; {util.pretty(frame.c1)}</code></pre>
112
+ <pre className='side'><code>{frame.result.p2} -&gt; {util.pretty(frame.c2)}</code></pre>
113
+ </div>}
114
+ </div>;
115
+ function windowed(data, byteOffset, byteLength) {
116
+ const length = byteLength ? byteLength - byteOffset : undefined;
117
+ return new DataView(data.buffer, data.byteOffset + byteOffset, length);
118
+ }
119
+ // Data is inlined in the same script tag to save bytes - it would be more proper embed the data in
120
+ // a <script type="application/json" id="data">...</script>, however this would force us all of the
121
+ // keys to be quoted which wastes space (not to mention parsing the object would then add latency)
122
+ const json = window.DATA;
123
+ const GEN = (0, ui_1.adapt)(new ui_1.Gen(json.gen));
124
+ // NB: "The Unicode Problem" is not relevant here - we know this isn't Unicode text
125
+ // https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
126
+ const buf = Uint8Array.from(atob(json.buf), c => c.charCodeAt(0));
127
+ document.getElementById('content').appendChild(<App gen={GEN} data={new DataView(buf.buffer, buf.byteOffset, buf.byteLength)} error={json.error} seed={json.seed && BigInt(json.seed)}/>);
128
+ //# sourceMappingURL=debug.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.jsx","sourceRoot":"","sources":["../../../src/tools/display/debug.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA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,CAAC;IAChE,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,GAAG,UAAU,EAAE,MAAM,CAAC,CAAC;AACzE,CAAC;AAED,mGAAmG;AACnG,mGAAmG;AACnG,kGAAkG;AAClG,MAAM,IAAI,GAAI,MAAc,CAAC,IAAI,CAAC;AAClC,MAAM,GAAG,GAAG,IAAA,UAAK,EAAC,IAAI,QAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACrC,mFAAmF;AACnF,+EAA+E;AAC/E,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAE,CAAC,WAAW,CAAC,CAAC,GAAG,CAClD,GAAG,CAAC,CAAC,GAAG,CAAC,CACT,IAAI,CAAC,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAC/D,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAClB,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EACrC,CAAC,CAAC"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.render = render;
30
+ exports.prune = prune;
31
+ const fs = __importStar(require("fs"));
32
+ const path = __importStar(require("path"));
33
+ const esbuild = __importStar(require("esbuild"));
34
+ const html_minifier_1 = require("html-minifier");
35
+ __exportStar(require("./util"), exports);
36
+ const ROOT = path.resolve(__dirname, '..', '..', '..');
37
+ function render(entryPoint, json) {
38
+ const result = esbuild.buildSync({
39
+ jsx: 'transform',
40
+ jsxFactory: 'h',
41
+ jsxFragment: 'Fragment',
42
+ // NB: trying to include the .js built version of this doesn't work, it must be the .ts version
43
+ inject: [path.join(ROOT, 'src', 'tools', 'display', 'dom.ts')],
44
+ entryPoints: [entryPoint],
45
+ // esbuild is insanely annoying and refuses to look in NODE_MODULES to find globally installed
46
+ // packages unless we explicitly tell it to do so. require.resolve.paths will return the full
47
+ // lookup path Node uses... which is what a sane person would expect esbuild to do to begin with
48
+ nodePaths: require.resolve.paths('') ?? [],
49
+ bundle: true,
50
+ write: false,
51
+ });
52
+ return (0, html_minifier_1.minify)(`<!DOCTYPE html>
53
+ <html lang="en">
54
+ <head>
55
+ <meta charset="utf-8">
56
+ <meta name="viewport" content="width=device-width, initial-scale=1">
57
+ <link rel="icon" href="https://pkmn.cc/favicon.ico">
58
+ <title>@pkmn/engine</title>
59
+ <style>${fs.readFileSync(path.join(ROOT, 'src', 'tools', 'display', 'ui.css'), 'utf8')}</style>
60
+ </head>
61
+ <body>
62
+ <noscript>You need to enable JavaScript to run this app.</noscript>
63
+ <div id="content"></div>
64
+ <script>
65
+ window.DATA = ${JSON.stringify(json)};
66
+
67
+ ${result.outputFiles[0].text}
68
+
69
+ for (const details of document.getElementsByTagName('details')) {
70
+ details.addEventListener('toggle', e => {
71
+ for (const d of details.parentElement.parentElement.getElementsByTagName('details')) {
72
+ if (d.open !== details.open) d.open = details.open;
73
+ }
74
+ });
75
+ }
76
+ </script>
77
+ </body>
78
+ </html>`, { minifyCSS: true, minifyJS: true });
79
+ }
80
+ function prune(gen, battle) {
81
+ // In order to avoid requiring the full @pkmn/data Generation (more importantly, the @pkmn/dex Dex
82
+ // data backing it), we need to figure out the minimum amount of data actually required to render
83
+ // the battle. We only need data for the game objects that occur in the battle, though without
84
+ // reading through all of the frames here we can't know for sure what is required. We error on the
85
+ // side of overincluding information to save having to parse the entire buffer twice
86
+ const pruned = { num: gen.num, species: {}, moves: {} };
87
+ let metronome = false;
88
+ for (const side of battle.sides) {
89
+ for (const pokemon of side.pokemon) {
90
+ const s = gen.species.get(pokemon.species);
91
+ // Certain Pokémon can change formes in battle (eg. Shaymin-Sky -> Shaymin) so
92
+ // we just greedily include all formes of a species just to be safe
93
+ for (const forme of [s.id, ...(s.formes ?? [])]) {
94
+ const species = gen.species.get(forme);
95
+ pruned.species[species.id] = {
96
+ name: species.name,
97
+ num: species.num,
98
+ genderRatio: species.genderRatio,
99
+ gender: species.gender,
100
+ };
101
+ }
102
+ // Similarly - Metronome can proc pretty much any other move. If any Pokémon
103
+ // has Metronome we just give up and include the whole set of moves
104
+ if (!metronome) {
105
+ for (const ms of pokemon.moves) {
106
+ if (ms.id === 'metronome') {
107
+ metronome = true;
108
+ break;
109
+ }
110
+ const move = gen.moves.get(ms.id);
111
+ pruned.moves[move.id] = pruneMove(gen, move);
112
+ }
113
+ }
114
+ }
115
+ }
116
+ if (metronome) {
117
+ for (const move of gen.moves) {
118
+ pruned.moves[move.id] = pruneMove(gen, move);
119
+ }
120
+ }
121
+ return pruned;
122
+ }
123
+ function pruneMove(gen, move) {
124
+ return {
125
+ name: move.name,
126
+ num: move.num,
127
+ maxpp: Math.min(move.pp / 5 * 8, gen.num === 1 ? 61 : 64),
128
+ basePower: move.basePower,
129
+ type: move.type,
130
+ };
131
+ }
132
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/display/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,wBA2CC;AAED,sBAgDC;AA5GD,uCAAyB;AACzB,2CAA6B;AAG7B,iDAAmC;AACnC,iDAAqC;AAMrC,yCAAuB;AAEvB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAEvD,SAAgB,MAAM,CAAC,UAAkB,EAAE,IAAS;IAClD,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;QAC/B,GAAG,EAAE,WAAW;QAChB,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,UAAU;QACvB,+FAA+F;QAC/F,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC9D,WAAW,EAAE,CAAC,UAAU,CAAC;QACzB,8FAA8F;QAC9F,6FAA6F;QAC7F,gGAAgG;QAChG,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE;QAC1C,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;IAEH,OAAO,IAAA,sBAAM,EAAC;;;;;;;aAOH,EAAE,CAAC,YAAY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inding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.TypeIcon = exports.TypeIcons = exports.PokemonSprite = exports.PokemonIcon = exports.Boost = exports.Stat = exports.Status = exports.PokemonNameStatus = exports.Pokemon = exports.Side = exports.Battle = exports.Gen = void 0;
27
+ exports.getHP = getHP;
28
+ exports.adapt = adapt;
29
+ const pkmn = __importStar(require("@pkmn/data"));
30
+ const adaptable = __importStar(require("@pkmn/img/adaptable"));
31
+ const POSITIONS = ['a', 'b', 'c', 'd', 'e', 'f'];
32
+ const STATS = ['hp', 'atk', 'def', 'spa', 'spd', 'spe'];
33
+ const DISPLAY = { hp: 'HP', atk: 'Atk', def: 'Def', spa: 'SpA', spd: 'SpD', spe: 'Spe', spc: 'Spc' };
34
+ const VOLATILES = {
35
+ bide: ['Bide', 'good'],
36
+ thrashing: ['Thrashing', 'neutral'],
37
+ flinch: ['Flinch', 'bad'],
38
+ charging: ['Charging', 'good'],
39
+ binding: ['Binding', 'bad'],
40
+ invulnerable: ['Invulnerable', 'good'],
41
+ confusion: ['Confusion', 'bad'],
42
+ mist: ['Mist', 'good'],
43
+ focusenergy: ['Focus Energy', 'good'],
44
+ substitute: ['Substitute', 'good'],
45
+ recharging: ['Recharging', 'bad'],
46
+ rage: ['Rage', 'neutral'],
47
+ leechseed: ['Leech Seed', 'bad'],
48
+ lightscreen: ['Light Screen', 'good'],
49
+ reflect: ['Reflect', 'good'],
50
+ transform: ['Transformed', 'neutral'],
51
+ };
52
+ class Gen {
53
+ num;
54
+ species;
55
+ moves;
56
+ constructor(json) {
57
+ this.num = json.num;
58
+ this.species = new API(json.species);
59
+ this.moves = new API(json.moves);
60
+ }
61
+ }
62
+ exports.Gen = Gen;
63
+ class API {
64
+ raw;
65
+ constructor(raw) {
66
+ this.raw = raw;
67
+ }
68
+ get(id) {
69
+ return { id, ...this.raw[id] };
70
+ }
71
+ *[Symbol.iterator]() {
72
+ for (const id in this.raw) {
73
+ yield this.get(id);
74
+ }
75
+ }
76
+ }
77
+ const Battle = (props) => {
78
+ const { battle, last, hide } = props;
79
+ const [p1, p2] = Array.from(battle.sides);
80
+ const [o1, o2] = last ? Array.from(last.sides) : [undefined, undefined];
81
+ return <div className='battle'>
82
+ {!hide && battle.turn && <div className='details'>
83
+ <h2>Turn {battle.turn}</h2>
84
+ <div className="inner">
85
+ <div><strong>Last Damage:</strong> {battle.lastDamage}</div>
86
+ <div><strong>Seed:</strong> {battle.prng.join(', ')}</div>
87
+ </div>
88
+ </div>}
89
+ <div className='sides'>
90
+ <exports.Side {...props} side={p1} player={'p1'} last={o1}/>
91
+ <exports.Side {...props} side={p2} player={'p2'} last={o2}/>
92
+ </div>
93
+ </div>;
94
+ };
95
+ exports.Battle = Battle;
96
+ const Side = ({ side, battle, player, gen, showdown, last, hide }) => {
97
+ let header = undefined;
98
+ if (battle.turn) {
99
+ const used = side.lastUsedMove ? gen.moves.get(side.lastUsedMove).name : <em>None</em>;
100
+ const selected = side.lastSelectedMove ? gen.moves.get(side.lastSelectedMove) : undefined;
101
+ const move = selected?.name ?? <em>None</em>;
102
+ const counterable = !!selected && selected.basePower > 0 && selected.id !== 'counter' &&
103
+ (selected.type === 'Normal' || selected.type === 'Fighting');
104
+ const mismatch = counterable !== side.lastMoveCounterable ? '*' : '';
105
+ const index = side.lastMoveIndex ? ` (${side.lastMoveIndex})` : '';
106
+ header = <div className='details'>
107
+ <div><strong>Last Used</strong><br />{used}</div>
108
+ <div><strong>Last Selected</strong><br />{move}{mismatch}{index}</div>
109
+ </div>;
110
+ }
111
+ let active = undefined;
112
+ if (side.active) {
113
+ let prev = undefined;
114
+ if (last) {
115
+ for (const pokemon of last.pokemon) {
116
+ if (pokemon.position === side.active.position) {
117
+ prev = pokemon;
118
+ break;
119
+ }
120
+ }
121
+ }
122
+ active = <div className='active'>
123
+ <exports.Pokemon pokemon={side.active} battle={battle} active={true} gen={gen} showdown={showdown} last={prev}/></div>;
124
+ }
125
+ let i = 0;
126
+ let icons = [];
127
+ const teamicons = [];
128
+ for (const pokemon of side.pokemon) {
129
+ if (i === 3) {
130
+ teamicons.push(<div className='teamicons'>{icons}</div>);
131
+ icons = [];
132
+ }
133
+ icons.push(<exports.PokemonIcon pokemon={pokemon} side={player}/>);
134
+ i++;
135
+ }
136
+ if (icons.length)
137
+ teamicons.push(<div className='teamicons'>{icons}</div>);
138
+ const party = [];
139
+ for (const pokemon of side.pokemon) {
140
+ party.push(<exports.Pokemon pokemon={pokemon} battle={battle} active={false} gen={gen} showdown={showdown}/>);
141
+ }
142
+ return <div className={`side ${player}`}>
143
+ {!hide && header}
144
+ {active}
145
+ {!hide && <details className='team'><summary>{teamicons}</summary>{party}</details>}
146
+ </div>;
147
+ };
148
+ exports.Side = Side;
149
+ const Pokemon = ({ pokemon, battle, active, gen, showdown, last }) => {
150
+ const ths = [];
151
+ const tds = [];
152
+ const stats = active ? pokemon.stats : pokemon.stored.stats;
153
+ for (const stat of STATS) {
154
+ if (gen.num === 1 && stat === 'spd')
155
+ continue;
156
+ ths.push(<th>{DISPLAY[gen.num === 1 && stat === 'spa' ? 'spc' : stat]}</th>);
157
+ const boost = active ? pokemon.boosts[stat] : 0;
158
+ tds.push(<td><exports.Stat value={stats[stat]} boost={boost}/></td>);
159
+ }
160
+ const boosts = active ? <div className='boosts'>
161
+ {!!pokemon.boosts.accuracy &&
162
+ <div><strong>Accuracy:</strong><exports.Boost value={pokemon.boosts.accuracy}/></div>}
163
+ {!!pokemon.boosts.evasion &&
164
+ <div><strong>Evasion:</strong><exports.Boost value={pokemon.boosts.evasion}/></div>}
165
+ </div> : '';
166
+ const lis = [];
167
+ const moves = active ? pokemon.moves : pokemon.stored.moves;
168
+ for (const move of moves) {
169
+ const { name, maxpp } = gen.moves.get(move.id);
170
+ const disabled = !move.pp || move.disabled ? 'disabled' : '';
171
+ const title = move.disabled ? `Disabled: ${move.disabled}` : '';
172
+ lis.push(<li className={disabled} title={title}>{name} <small>({move.pp}/{maxpp})</small></li>);
173
+ }
174
+ const volatiles = [];
175
+ for (const v in pokemon.volatiles) {
176
+ const volatile = v;
177
+ const [name, type] = VOLATILES[volatile];
178
+ let text = '';
179
+ if (['binding', 'confusion', 'substitute'].includes(volatile)) {
180
+ const narrowed = volatile;
181
+ text = (Object.values(pokemon.volatiles[narrowed])[0]).toString();
182
+ }
183
+ else if (volatile === 'bide') {
184
+ const val = pokemon.volatiles[volatile];
185
+ text = `${val.duration} (${val.damage})`;
186
+ }
187
+ else if (volatile === 'rage') {
188
+ const val = pokemon.volatiles[volatile];
189
+ text = val.accuracy ? val.accuracy.toString() : '';
190
+ }
191
+ else if (volatile === 'thrashing') {
192
+ const val = pokemon.volatiles[volatile];
193
+ text = `${val.duration}${val.accuracy ? ` (${val.accuracy})` : ''}`;
194
+ }
195
+ else if (volatile === 'transform') {
196
+ const { player, slot } = pokemon.volatiles[volatile];
197
+ const p = +player.charAt(1) - 1;
198
+ let i = 0;
199
+ for (const side of battle.sides) {
200
+ if (i++ === p) {
201
+ i = 1;
202
+ for (const poke of side.pokemon) {
203
+ if (i++ === slot) {
204
+ text = `${player}${POSITIONS[poke.position - 1]}`;
205
+ break;
206
+ }
207
+ }
208
+ break;
209
+ }
210
+ }
211
+ }
212
+ text = (text ? `${name}: ${text}` : name).replace(' ', '\u00A0');
213
+ volatiles.push(<span className={`volatile ${type}`}>{text}</span>);
214
+ }
215
+ const position = active ? '' : <div className='position'>{POSITIONS[pokemon.position - 1]}</div>;
216
+ return <div className='pokemon'>
217
+ <div className='left' title={`${pokemon.hp}/${pokemon.stats.hp}`}>
218
+ {position}
219
+ <div className='statbar rstatbar' style={{ display: 'block', opacity: 1 }}>
220
+ <exports.PokemonNameStatus pokemon={pokemon} active={active} gen={gen}/>
221
+ <HPBar pokemon={pokemon} last={last}/>
222
+ </div>
223
+ <exports.PokemonSprite pokemon={pokemon} active={active} showdown={showdown}/>
224
+ <exports.TypeIcons pokemon={pokemon} active={active}/>
225
+ </div>
226
+ <div className='right'>
227
+ {position}
228
+ <div className='stats'><table><tr>{ths}</tr><tr>{tds}</tr></table>
229
+ {boosts}
230
+ </div>
231
+ <div className='moves'><ul>{lis}</ul> </div>
232
+ {active && <div className='volatiles'>{volatiles}</div>}
233
+ </div>
234
+ </div>;
235
+ };
236
+ exports.Pokemon = Pokemon;
237
+ const PokemonNameStatus = ({ pokemon, active, gen }) => {
238
+ const species = active ? pokemon.species : pokemon.stored.species;
239
+ const n = gen.species.get(species).name;
240
+ const name = <strong>{n}&nbsp;<small>L{pokemon.level}</small></strong>;
241
+ return <span className='name'>
242
+ <exports.Status pokemon={pokemon}/>
243
+ {(active && pokemon.species !== pokemon.stored.species) ? <em>{name}</em> : name}
244
+ </span>;
245
+ };
246
+ exports.PokemonNameStatus = PokemonNameStatus;
247
+ const HPBar = ({ pokemon, last }) => {
248
+ const { percent, color, style } = getHP(pokemon);
249
+ let bar = <div className={`hp ${color}`} style={style}></div>;
250
+ if (last && last.position === pokemon.position && pokemon.hp < last.hp) {
251
+ const prev = getHP(last);
252
+ bar = <div className={`prevhp ${prev.color ? 'prev' + prev.color : ''}`} style={prev.style}>
253
+ {bar}
254
+ </div>;
255
+ }
256
+ return <div className='hpbar'>{bar}<div className='hptext'>{percent}%</div></div>;
257
+ };
258
+ const Status = ({ pokemon }) => {
259
+ if (!pokemon.status)
260
+ return '';
261
+ const classes = `status ${pokemon.status === 'tox' ? 'psn' : pokemon.status}`;
262
+ let title = '';
263
+ if (pokemon.statusData.sleep)
264
+ title += `Sleep: ${pokemon.statusData.sleep}`;
265
+ if (pokemon.status === 'tox' || pokemon.statusData.toxic) {
266
+ title += `${title ? ' ' : ''}Toxic: ${pokemon.statusData.toxic}`;
267
+ }
268
+ return <span className={classes} title={title}>
269
+ {pokemon.statusData.self ? 'slf' : pokemon.status}
270
+ </span>;
271
+ };
272
+ exports.Status = Status;
273
+ const Stat = ({ value, boost }) => {
274
+ if (!boost)
275
+ return value.toString();
276
+ if (boost > 0)
277
+ return <span className='good'>{value} (+{boost})</span>;
278
+ return <span className='bad'>{value} ({boost})</span>;
279
+ };
280
+ exports.Stat = Stat;
281
+ const Boost = ({ value }) => {
282
+ if (value > 0)
283
+ return <span className='good'>+{value}</span>;
284
+ return <span className='bad'>{value}</span>;
285
+ };
286
+ exports.Boost = Boost;
287
+ const PokemonIcon = ({ pokemon, side }) => {
288
+ const fainted = pokemon.hp === 0;
289
+ const i = Icons.getPokemon(pokemon.stored.species, { side, fainted, domain: 'pkmn.cc' });
290
+ return <span style={i.css}></span>;
291
+ };
292
+ exports.PokemonIcon = PokemonIcon;
293
+ const PokemonSprite = ({ pokemon, active, showdown }) => {
294
+ const species = active ? pokemon.species : pokemon.stored.species;
295
+ const s = Sprites.getPokemon(species, { gen: showdown ? 'gen1' : 'gen1rb' });
296
+ const fainted = pokemon.hp === 0;
297
+ return <img className='sprite' src={s.url} width={s.w} height={s.h} style={{
298
+ imageRendering: s.pixelated ? 'pixelated' : undefined,
299
+ opacity: fainted ? 0.3 : undefined,
300
+ filter: fainted ? 'grayscale(100%) brightness(.5)' : undefined,
301
+ }}/>;
302
+ };
303
+ exports.PokemonSprite = PokemonSprite;
304
+ const TypeIcons = ({ pokemon, active }) => {
305
+ const types = active ? pokemon.types : pokemon.stored.types;
306
+ const type1 = <exports.TypeIcon type={types[0]}/>;
307
+ const type2 = types[0] !== types[1] ? <exports.TypeIcon type={types[1]}/> : '';
308
+ return <div className='types'>{type1}{type2}</div>;
309
+ };
310
+ exports.TypeIcons = TypeIcons;
311
+ const TypeIcon = ({ type }) => {
312
+ const i = Icons.getType(type);
313
+ const style = { imageRendering: 'pixelated' };
314
+ return <img className='icon' src={i.url} width={i.w} height={i.h} style={style}/>;
315
+ };
316
+ exports.TypeIcon = TypeIcon;
317
+ function getHP(pokemon) {
318
+ const ratio = pokemon.hp / pokemon.stats.hp;
319
+ let percent = Math.ceil(ratio * 100);
320
+ if ((percent === 100) && (ratio < 1.0)) {
321
+ percent = 99;
322
+ }
323
+ const width = (pokemon.hp === 1 && pokemon.stats.hp > 45)
324
+ ? '1px' : ratio === 1.0
325
+ ? 'var(--hp-bar)' : `calc(${ratio} * var(--hp-bar))`;
326
+ const color = ratio > 0.5 ? '' : ratio > 0.2 ? 'hp-yellow' : 'hp-red';
327
+ const style = { width: width, borderRightWidth: `${percent === 100 ? 1 : 0}px;` };
328
+ return { percent, color, style };
329
+ }
330
+ // @pkmn/img/adaptable means we can use our pruned data to provide sprite
331
+ // info for just the SpriteGen's that we're going to use
332
+ function adapt(gen) {
333
+ const Data = new class {
334
+ getPokemon(name) {
335
+ const s = gen.species.get(pkmn.toID(name));
336
+ return { spriteid: s.id, gen: gen.num, ...s };
337
+ }
338
+ getItem() {
339
+ return undefined;
340
+ }
341
+ getAvatar() {
342
+ return undefined;
343
+ }
344
+ };
345
+ globalThis.Sprites = new adaptable.Sprites(Data);
346
+ globalThis.Icons = new adaptable.Icons(Data);
347
+ return gen;
348
+ }
349
+ //# sourceMappingURL=ui.jsx.map