@pkmn/engine 0.1.0-dev.ce4c0b2a → 0.1.0-dev.d127cb34
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/LICENSE +1 -1
- package/README.md +23 -15
- package/build/pkg/addon/browser.d.ts +1 -1
- package/build/pkg/addon/browser.js +6 -2
- package/build/pkg/addon/browser.js.map +1 -1
- package/build/pkg/addon/node.js +22 -8
- package/build/pkg/addon/node.js.map +1 -1
- package/build/pkg/addon/wasm.d.ts +2 -0
- package/build/pkg/addon/wasm.js +53 -0
- package/build/pkg/addon/wasm.js.map +1 -0
- package/build/pkg/addon.d.ts +25 -5
- package/build/pkg/addon.js +8 -17
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data/layout.json +15 -2
- package/build/pkg/data/protocol.json +23 -9
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.d.ts +15 -18
- package/build/pkg/gen1.js +28 -19
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +37 -100
- package/build/pkg/index.js +23 -75
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +11 -2
- package/build/pkg/protocol.js.map +1 -1
- package/build/tools/debug.js +56 -13
- package/build/tools/debug.js.map +1 -1
- package/build/tools/display/debug.jsx +19 -81
- package/build/tools/display/debug.jsx.map +1 -1
- package/build/tools/display/index.js +35 -15
- package/build/tools/display/index.js.map +1 -1
- package/build/tools/display/ui.jsx +27 -16
- package/build/tools/display/ui.jsx.map +1 -1
- package/build/tools/display/util.js +141 -2
- package/build/tools/display/util.js.map +1 -1
- package/build.zig +330 -245
- package/package.json +36 -128
- package/src/bin/install-pkmn-engine +25 -9
- package/src/lib/bindings/c.zig +201 -0
- package/src/lib/bindings/node.zig +117 -0
- package/src/lib/bindings/wasm.zig +51 -0
- package/src/lib/common/array.zig +5 -12
- package/src/lib/common/debug.zig +45 -34
- package/src/lib/common/js.zig +3 -9
- package/src/lib/common/optional.zig +26 -26
- package/src/lib/common/options.zig +2 -0
- package/src/lib/common/protocol.zig +228 -197
- package/src/lib/common/rational.zig +278 -285
- package/src/lib/common/rng.zig +1 -3
- package/src/lib/common/util.zig +34 -31
- package/src/lib/gen1/calc.zig +220 -195
- package/src/lib/gen1/chance.zig +184 -108
- package/src/lib/gen1/data/moves.zig +2 -4
- package/src/lib/gen1/data/species.zig +1 -3
- package/src/lib/gen1/data/types.zig +3 -4
- package/src/lib/gen1/data.zig +12 -16
- package/src/lib/gen1/helpers.zig +35 -40
- package/src/lib/gen1/mechanics.zig +147 -127
- package/src/lib/gen2/calc.zig +12 -23
- package/src/lib/gen2/chance.zig +38 -26
- package/src/lib/gen2/data/items.zig +1 -3
- package/src/lib/gen2/data/moves.zig +2 -4
- package/src/lib/gen2/data/species.zig +1 -3
- package/src/lib/gen2/data/types.zig +7 -5
- package/src/lib/gen2/data.zig +19 -22
- package/src/lib/gen2/generated.zig +18 -23
- package/src/lib/gen2/helpers.zig +32 -31
- package/src/lib/gen2/mechanics.zig +58 -55
- package/src/lib/napi.h +2 -0
- package/src/lib/node.zig +4 -121
- package/src/lib/pkmn.zig +98 -19
- package/src/lib/wasm.zig +9 -9
- package/src/tools/display/dom.ts +43 -31
- package/src/tools/display/ui.css +12 -9
package/src/tools/display/dom.ts
CHANGED
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
/** @license MIT modified from Vadim Demedes's https://github.com/vadimdemedes/dom-chef */
|
|
2
|
-
type Attributes = JSX.IntrinsicElements['div'];
|
|
3
|
-
type DocumentFragmentConstructor = typeof DocumentFragment;
|
|
4
|
-
type ElementFunction = (props?: any) => HTMLElement;
|
|
5
2
|
|
|
6
3
|
declare global {
|
|
7
4
|
namespace JSX {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
className: HTMLElement['className'];
|
|
5
|
+
type Element = HTMLElement | DocumentFragment;
|
|
6
|
+
interface IntrinsicElements {
|
|
7
|
+
[elemName: string]: Record<string, unknown>;
|
|
12
8
|
}
|
|
13
9
|
}
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
12
|
+
type Child = Node | string | number | boolean | null | undefined | Child[];
|
|
13
|
+
|
|
14
|
+
type DocumentFragmentFunction = (props?: any) => DocumentFragment;
|
|
15
|
+
type ElementFunction = (props?: any) => HTMLElement;
|
|
21
16
|
|
|
22
17
|
// https://github.com/preactjs/preact/blob/1bbd687c/src/constants.js#L3
|
|
23
18
|
const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
|
|
24
19
|
|
|
25
|
-
const isFragment = (type: DocumentFragmentConstructor | ElementFunction):
|
|
26
|
-
type is DocumentFragmentConstructor => type === DocumentFragment;
|
|
27
|
-
|
|
28
20
|
const setCSSProps = (element: HTMLElement, style: CSSStyleDeclaration) => {
|
|
29
21
|
for (const [name, value] of Object.entries(style)) {
|
|
30
22
|
if (name.startsWith('-')) {
|
|
@@ -41,14 +33,14 @@ const setAttribute = (element: HTMLElement, name: string, value: string) => {
|
|
|
41
33
|
if (value !== undefined && value !== null) element.setAttribute(name, value);
|
|
42
34
|
};
|
|
43
35
|
|
|
44
|
-
const addChildren = (parent:
|
|
36
|
+
const addChildren = (parent: Node, children: Child[]) => {
|
|
45
37
|
for (const child of children) {
|
|
46
38
|
if (child instanceof Node) {
|
|
47
39
|
parent.appendChild(child);
|
|
48
40
|
} else if (Array.isArray(child)) {
|
|
49
41
|
addChildren(parent, child);
|
|
50
42
|
} else if (typeof child !== 'boolean' && typeof child !== 'undefined' && child !== null) {
|
|
51
|
-
parent.appendChild(document.createTextNode(child));
|
|
43
|
+
parent.appendChild(document.createTextNode(String(child)));
|
|
52
44
|
}
|
|
53
45
|
}
|
|
54
46
|
};
|
|
@@ -56,13 +48,33 @@ const addChildren = (parent: Element | DocumentFragment, children: Node[]) => {
|
|
|
56
48
|
// https://github.com/facebook/react/blob/3f899089/packages/react-dom/src/shared/DOMProperty.js#L288-L322
|
|
57
49
|
const FALSIFIABLE_ATTRIBUTES = ['contentEditable', 'draggable', 'spellCheck', 'value'];
|
|
58
50
|
|
|
59
|
-
export
|
|
60
|
-
type:
|
|
61
|
-
attributes?:
|
|
62
|
-
...children:
|
|
63
|
-
)
|
|
51
|
+
export function h<K extends keyof HTMLElementTagNameMap>(
|
|
52
|
+
type: K,
|
|
53
|
+
attributes?: any,
|
|
54
|
+
...children: Child[]
|
|
55
|
+
): HTMLElementTagNameMap[K];
|
|
56
|
+
export function h(
|
|
57
|
+
type: DocumentFragmentFunction,
|
|
58
|
+
attributes?: any,
|
|
59
|
+
...children: Child[]
|
|
60
|
+
): DocumentFragment;
|
|
61
|
+
export function h<T extends HTMLElement>(
|
|
62
|
+
type: (props: any) => T,
|
|
63
|
+
attributes?: any,
|
|
64
|
+
...children: Child[]
|
|
65
|
+
): T;
|
|
66
|
+
export function h(
|
|
67
|
+
type: string,
|
|
68
|
+
attributes?: any,
|
|
69
|
+
...children: Child[]
|
|
70
|
+
): HTMLElement;
|
|
71
|
+
export function h(
|
|
72
|
+
type: DocumentFragmentFunction | ElementFunction | string,
|
|
73
|
+
attributes?: any,
|
|
74
|
+
...children: Child[]
|
|
75
|
+
): JSX.Element {
|
|
64
76
|
if (typeof type !== 'string') {
|
|
65
|
-
const element =
|
|
77
|
+
const element = type(attributes);
|
|
66
78
|
addChildren(element, children);
|
|
67
79
|
return element;
|
|
68
80
|
}
|
|
@@ -78,19 +90,19 @@ export const h = (
|
|
|
78
90
|
const existingClassname = element.getAttribute('class') ?? '';
|
|
79
91
|
setAttribute(element, 'class', (existingClassname + ' ' + String(value)).trim());
|
|
80
92
|
} else if (name === 'style') {
|
|
81
|
-
setCSSProps(element, value);
|
|
93
|
+
setCSSProps(element, value as CSSStyleDeclaration);
|
|
82
94
|
} else if (name.startsWith('on')) {
|
|
83
95
|
const eventName = name.slice(2).toLowerCase().replace(/^-/, '');
|
|
84
|
-
element.addEventListener(eventName, value);
|
|
85
|
-
} else if (name === 'dangerouslySetInnerHTML' &&
|
|
86
|
-
element.innerHTML = value.__html;
|
|
96
|
+
element.addEventListener(eventName, value as EventListenerOrEventListenerObject);
|
|
97
|
+
} else if (name === 'dangerouslySetInnerHTML' && value && (value as any).__html) {
|
|
98
|
+
element.innerHTML = (value as any).__html;
|
|
87
99
|
} else if (name !== 'key' && (FALSIFIABLE_ATTRIBUTES.includes(name) || value !== false)) {
|
|
88
|
-
setAttribute(element, name, value === true ? '' : value);
|
|
100
|
+
setAttribute(element, name, value === true ? '' : String(value));
|
|
89
101
|
}
|
|
90
102
|
}
|
|
91
103
|
|
|
92
104
|
return element;
|
|
93
|
-
}
|
|
105
|
+
}
|
|
94
106
|
|
|
95
|
-
|
|
96
|
-
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
108
|
+
export const Fragment = (unused?: any) => document.createDocumentFragment();
|
package/src/tools/display/ui.css
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
body {
|
|
2
|
+
background: white;
|
|
3
|
+
color: black;
|
|
4
|
+
}
|
|
5
|
+
code {
|
|
6
|
+
background: white;
|
|
7
|
+
color: black;
|
|
8
|
+
}
|
|
1
9
|
#content {
|
|
2
10
|
font-family: "Roboto", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
|
|
3
11
|
margin: 4em auto;
|
|
@@ -233,17 +241,15 @@ th, td {
|
|
|
233
241
|
text-align: center;
|
|
234
242
|
width: 100%;
|
|
235
243
|
}
|
|
244
|
+
.boosts {
|
|
245
|
+
margin: 0 5px;
|
|
246
|
+
}
|
|
236
247
|
.types {
|
|
237
248
|
display: inherit;
|
|
238
249
|
}
|
|
239
250
|
.disabled {
|
|
240
251
|
color: #AAAAAA;
|
|
241
252
|
}
|
|
242
|
-
.log {
|
|
243
|
-
display: flex;
|
|
244
|
-
justify-content: center;
|
|
245
|
-
padding-bottom: 2em;
|
|
246
|
-
}
|
|
247
253
|
.position {
|
|
248
254
|
position: absolute;
|
|
249
255
|
right: 10px;
|
|
@@ -278,9 +284,6 @@ th, td {
|
|
|
278
284
|
justify-content: center;
|
|
279
285
|
padding: 0;
|
|
280
286
|
}
|
|
281
|
-
.boosts {
|
|
282
|
-
margin-left: 5px;
|
|
283
|
-
}
|
|
284
287
|
.moves ul {
|
|
285
288
|
grid-template-columns: repeat(2, auto);
|
|
286
289
|
}
|
|
@@ -320,7 +323,7 @@ th, td {
|
|
|
320
323
|
.boosts {
|
|
321
324
|
display: flex;
|
|
322
325
|
justify-content: space-between;
|
|
323
|
-
margin
|
|
326
|
+
margin: 0.5em 0 0 0;
|
|
324
327
|
}
|
|
325
328
|
}
|
|
326
329
|
@media(max-width: 550px) {
|