@oidoid/void 0.1.0-4 → 0.1.0-6
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/dist/meta.json +1 -0
- package/dist/package.json +66 -0
- package/dist/public/favicon/favicon16.png +0 -0
- package/dist/public/favicon/favicon192.png +0 -0
- package/dist/public/favicon/favicon32.png +0 -0
- package/dist/public/favicon/favicon48.png +0 -0
- package/dist/public/favicon/favicon512.png +0 -0
- package/dist/public/favicon/favicon64.png +0 -0
- package/dist/public/index.html +23 -0
- package/dist/public/index.js +3844 -0
- package/dist/public/index.js.map +7 -0
- package/dist/public/manifest.json +1 -0
- package/dist/public/preload-atlas.png +0 -0
- package/dist/public/void-v0.1.0-4.html +111 -0
- package/dist/public/void-v0.1.0-5.html +111 -0
- package/dist/public/void-v0.1.0-6.html +111 -0
- package/dist/schema/config-file.d.ts +32 -0
- package/dist/schema/config-file.js +41 -0
- package/dist/schema/config-file.js.map +1 -0
- package/dist/schema/config-file.v0.json +68 -0
- package/dist/src/audio.d.ts +7 -0
- package/dist/src/audio.js +25 -0
- package/dist/src/audio.js.map +1 -0
- package/dist/src/demo/assets/manifest.json +46 -0
- package/dist/src/demo/assets/preload-atlas.json +193 -0
- package/dist/src/demo/ents/clock-ent.d.ts +10 -0
- package/dist/src/demo/ents/clock-ent.js +26 -0
- package/dist/src/demo/ents/clock-ent.js.map +1 -0
- package/dist/src/demo/ents/render-toggle-ent.d.ts +10 -0
- package/dist/src/demo/ents/render-toggle-ent.js +38 -0
- package/dist/src/demo/ents/render-toggle-ent.js.map +1 -0
- package/dist/src/demo/ents/work-counter-ent.d.ts +10 -0
- package/dist/src/demo/ents/work-counter-ent.js +24 -0
- package/dist/src/demo/ents/work-counter-ent.js.map +1 -0
- package/dist/src/demo/game.d.ts +13 -0
- package/dist/src/demo/game.js +155 -0
- package/dist/src/demo/game.js.map +1 -0
- package/dist/src/demo/index.d.ts +1 -0
- package/dist/src/demo/index.js +8 -0
- package/dist/src/demo/index.js.map +1 -0
- package/dist/src/demo/tsconfig.json +15 -0
- package/dist/src/demo/types/tag.d.ts +2 -0
- package/dist/src/demo/types/tag.js +2 -0
- package/dist/src/demo/types/tag.js.map +1 -0
- package/dist/src/demo/void.json +11 -0
- package/dist/src/ents/button-ent.d.ts +38 -0
- package/dist/src/ents/button-ent.js +124 -0
- package/dist/src/ents/button-ent.js.map +1 -0
- package/dist/src/ents/cursor-ent.d.ts +18 -0
- package/dist/src/ents/cursor-ent.js +58 -0
- package/dist/src/ents/cursor-ent.js.map +1 -0
- package/dist/src/ents/ent.d.ts +7 -0
- package/dist/src/ents/ent.js +2 -0
- package/dist/src/ents/ent.js.map +1 -0
- package/dist/src/ents/follow-cam-ent.d.ts +25 -0
- package/dist/src/ents/follow-cam-ent.js +87 -0
- package/dist/src/ents/follow-cam-ent.js.map +1 -0
- package/dist/src/ents/nine-patch-ent.d.ts +43 -0
- package/dist/src/ents/nine-patch-ent.js +143 -0
- package/dist/src/ents/nine-patch-ent.js.map +1 -0
- package/dist/src/ents/text-ent.d.ts +23 -0
- package/dist/src/ents/text-ent.js +109 -0
- package/dist/src/ents/text-ent.js.map +1 -0
- package/dist/src/ents/zoo.d.ts +16 -0
- package/dist/src/ents/zoo.js +38 -0
- package/dist/src/ents/zoo.js.map +1 -0
- package/dist/src/graphics/atlas-parser.d.ts +4 -0
- package/dist/src/graphics/atlas-parser.js +27 -0
- package/dist/src/graphics/atlas-parser.js.map +1 -0
- package/dist/src/graphics/atlas.d.ts +49 -0
- package/dist/src/graphics/atlas.js +7 -0
- package/dist/src/graphics/atlas.js.map +1 -0
- package/dist/src/graphics/cam.d.ts +89 -0
- package/dist/src/graphics/cam.js +211 -0
- package/dist/src/graphics/cam.js.map +1 -0
- package/dist/src/graphics/gl.d.ts +24 -0
- package/dist/src/graphics/gl.js +70 -0
- package/dist/src/graphics/gl.js.map +1 -0
- package/dist/src/graphics/layer.d.ts +21 -0
- package/dist/src/graphics/layer.js +23 -0
- package/dist/src/graphics/layer.js.map +1 -0
- package/dist/src/graphics/renderer.d.ts +22 -0
- package/dist/src/graphics/renderer.js +168 -0
- package/dist/src/graphics/renderer.js.map +1 -0
- package/dist/src/graphics/sprite-frag.glsl.d.ts +1 -0
- package/dist/src/graphics/sprite-frag.glsl.js +35 -0
- package/dist/src/graphics/sprite-frag.glsl.js.map +1 -0
- package/dist/src/graphics/sprite-vert.glsl.d.ts +1 -0
- package/dist/src/graphics/sprite-vert.glsl.js +68 -0
- package/dist/src/graphics/sprite-vert.glsl.js.map +1 -0
- package/dist/src/graphics/sprite.d.ts +108 -0
- package/dist/src/graphics/sprite.js +301 -0
- package/dist/src/graphics/sprite.js.map +1 -0
- package/dist/src/index.d.ts +30 -0
- package/dist/src/index.js +33 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/input/context-menu.d.ts +8 -0
- package/dist/src/input/context-menu.js +25 -0
- package/dist/src/input/context-menu.js.map +1 -0
- package/dist/src/input/gamepad.d.ts +18 -0
- package/dist/src/input/gamepad.js +49 -0
- package/dist/src/input/gamepad.js.map +1 -0
- package/dist/src/input/input.d.ts +148 -0
- package/dist/src/input/input.js +383 -0
- package/dist/src/input/input.js.map +1 -0
- package/dist/src/input/keyboard.d.ts +17 -0
- package/dist/src/input/keyboard.js +46 -0
- package/dist/src/input/keyboard.js.map +1 -0
- package/dist/src/input/pointer.d.ts +53 -0
- package/dist/src/input/pointer.js +162 -0
- package/dist/src/input/pointer.js.map +1 -0
- package/dist/src/input/wheel.d.ts +12 -0
- package/dist/src/input/wheel.js +30 -0
- package/dist/src/input/wheel.js.map +1 -0
- package/dist/src/looper.d.ts +15 -0
- package/dist/src/looper.js +48 -0
- package/dist/src/looper.js.map +1 -0
- package/dist/src/mem/pool.d.ts +31 -0
- package/dist/src/mem/pool.js +98 -0
- package/dist/src/mem/pool.js.map +1 -0
- package/dist/src/pixel-ratio-observer.d.ts +10 -0
- package/dist/src/pixel-ratio-observer.js +26 -0
- package/dist/src/pixel-ratio-observer.js.map +1 -0
- package/dist/src/random/random.d.ts +8 -0
- package/dist/src/random/random.js +23 -0
- package/dist/src/random/random.js.map +1 -0
- package/dist/src/storage/local-storage.d.ts +3 -0
- package/dist/src/storage/local-storage.js +11 -0
- package/dist/src/storage/local-storage.js.map +1 -0
- package/dist/src/text/font.d.ts +6 -0
- package/dist/src/text/font.js +20 -0
- package/dist/src/text/font.js.map +1 -0
- package/dist/src/text/mem-prop-5x6.json +573 -0
- package/dist/src/text/text-layout.d.ts +19 -0
- package/dist/src/text/text-layout.js +85 -0
- package/dist/src/text/text-layout.js.map +1 -0
- package/dist/src/tsconfig.json +15 -0
- package/dist/src/types/geo.d.ts +38 -0
- package/dist/src/types/geo.js +61 -0
- package/dist/src/types/geo.js.map +1 -0
- package/dist/src/types/json.d.ts +31 -0
- package/dist/src/types/json.js +2 -0
- package/dist/src/types/json.js.map +1 -0
- package/dist/src/types/time.d.ts +19 -0
- package/dist/src/types/time.js +10 -0
- package/dist/src/types/time.js.map +1 -0
- package/dist/src/types/void-version.d.ts +9 -0
- package/dist/src/types/void-version.js +2 -0
- package/dist/src/types/void-version.js.map +1 -0
- package/dist/src/utils/async-util.d.ts +11 -0
- package/dist/src/utils/async-util.js +36 -0
- package/dist/src/utils/async-util.js.map +1 -0
- package/dist/src/utils/canvas-util.d.ts +7 -0
- package/dist/src/utils/canvas-util.js +128 -0
- package/dist/src/utils/canvas-util.js.map +1 -0
- package/dist/src/utils/color-util.d.ts +1 -0
- package/dist/src/utils/color-util.js +4 -0
- package/dist/src/utils/color-util.js.map +1 -0
- package/dist/src/utils/debug.d.ts +17 -0
- package/dist/src/utils/debug.js +34 -0
- package/dist/src/utils/debug.js.map +1 -0
- package/dist/src/utils/dom-util.d.ts +3 -0
- package/dist/src/utils/dom-util.js +29 -0
- package/dist/src/utils/dom-util.js.map +1 -0
- package/dist/src/utils/fetch-util.d.ts +3 -0
- package/dist/src/utils/fetch-util.js +24 -0
- package/dist/src/utils/fetch-util.js.map +1 -0
- package/dist/src/utils/math.d.ts +6 -0
- package/dist/src/utils/math.js +18 -0
- package/dist/src/utils/math.js.map +1 -0
- package/dist/src/utils/vibrate.d.ts +1 -0
- package/dist/src/utils/vibrate.js +4 -0
- package/dist/src/utils/vibrate.js.map +1 -0
- package/dist/src/void.d.ts +43 -0
- package/dist/src/void.js +95 -0
- package/dist/src/void.js.map +1 -0
- package/dist/tools/atlas-pack/aseprite.d.ts +58 -0
- package/dist/tools/atlas-pack/aseprite.js +16 -0
- package/dist/tools/atlas-pack/aseprite.js.map +1 -0
- package/dist/tools/atlas-pack/atlas-json-parser.d.ts +21 -0
- package/dist/tools/atlas-pack/atlas-json-parser.js +116 -0
- package/dist/tools/atlas-pack/atlas-json-parser.js.map +1 -0
- package/dist/tools/atlas-pack/atlas-pack.d.ts +2 -0
- package/dist/tools/atlas-pack/atlas-pack.js +17 -0
- package/dist/tools/atlas-pack/atlas-pack.js.map +1 -0
- package/dist/tools/bundle/bundle.d.ts +3 -0
- package/dist/tools/bundle/bundle.js +48 -0
- package/dist/tools/bundle/bundle.js.map +1 -0
- package/dist/tools/bundle/html-plugin.d.ts +3 -0
- package/dist/tools/bundle/html-plugin.js +88 -0
- package/dist/tools/bundle/html-plugin.js.map +1 -0
- package/dist/tools/tsconfig-base.json +45 -0
- package/dist/tools/tsconfig.json +21 -0
- package/dist/tools/types/config.d.ts +20 -0
- package/dist/tools/types/config.js +22 -0
- package/dist/tools/types/config.js.map +1 -0
- package/dist/tools/utils/argv.d.ts +12 -0
- package/dist/tools/utils/argv.js +19 -0
- package/dist/tools/utils/argv.js.map +1 -0
- package/dist/tools/utils/exec.d.ts +3 -0
- package/dist/tools/utils/exec.js +15 -0
- package/dist/tools/utils/exec.js.map +1 -0
- package/dist/tools/utils/file-util.d.ts +1 -0
- package/dist/tools/utils/file-util.js +13 -0
- package/dist/tools/utils/file-util.js.map +1 -0
- package/dist/tools/utils/html-parser.d.ts +1 -0
- package/dist/tools/utils/html-parser.js +10 -0
- package/dist/tools/utils/html-parser.js.map +1 -0
- package/dist/tools/void.d.ts +17 -0
- package/dist/tools/void.js +30 -0
- package/dist/tools/void.js.map +1 -0
- package/package.json +31 -41
- package/readme.md +1 -1
- package/schema/config-file.test.ts +55 -0
- package/schema/config-file.ts +69 -0
- package/schema/config-file.v0.json +68 -0
- package/tools/atlas-pack/aseprite.ts +60 -0
- package/tools/atlas-pack/atlas-json-parser.test.ts +780 -0
- package/tools/atlas-pack/atlas-json-parser.ts +159 -0
- package/tools/atlas-pack/atlas-pack.ts +38 -0
- package/tools/bundle/bundle.ts +65 -0
- package/tools/bundle/html-plugin.ts +135 -0
- package/tools/types/config.ts +43 -0
- package/tools/utils/argv.test.ts +41 -0
- package/tools/utils/argv.ts +29 -0
- package/tools/utils/exec.ts +22 -0
- package/tools/utils/file-util.ts +11 -0
- package/tools/utils/html-parser.ts +9 -0
- package/tools/void.ts +54 -0
- package/dist/atlas/anim.d.ts +0 -30
- package/dist/atlas/anim.js +0 -16
- package/dist/atlas/anim.js.map +0 -1
- package/dist/atlas/aseprite.d.ts +0 -37
- package/dist/atlas/aseprite.js +0 -2
- package/dist/atlas/aseprite.js.map +0 -1
- package/dist/atlas/atlas-parser.d.ts +0 -52
- package/dist/atlas/atlas-parser.js +0 -109
- package/dist/atlas/atlas-parser.js.map +0 -1
- package/dist/atlas/atlas.d.ts +0 -4
- package/dist/atlas/atlas.js +0 -2
- package/dist/atlas/atlas.js.map +0 -1
- package/dist/audio/synth.d.ts +0 -4
- package/dist/audio/synth.js +0 -21
- package/dist/audio/synth.js.map +0 -1
- package/dist/graphics/bitmap.d.ts +0 -14
- package/dist/graphics/bitmap.js +0 -14
- package/dist/graphics/bitmap.js.map +0 -1
- package/dist/graphics/cam.d.ts +0 -16
- package/dist/graphics/cam.js +0 -42
- package/dist/graphics/cam.js.map +0 -1
- package/dist/graphics/frag.glsl.d.ts +0 -1
- package/dist/graphics/frag.glsl.js +0 -15
- package/dist/graphics/frag.glsl.js.map +0 -1
- package/dist/graphics/frame-listener.d.ts +0 -16
- package/dist/graphics/frame-listener.js +0 -83
- package/dist/graphics/frame-listener.js.map +0 -1
- package/dist/graphics/renderer.d.ts +0 -12
- package/dist/graphics/renderer.js +0 -184
- package/dist/graphics/renderer.js.map +0 -1
- package/dist/graphics/vert.glsl.d.ts +0 -1
- package/dist/graphics/vert.glsl.js +0 -46
- package/dist/graphics/vert.glsl.js.map +0 -1
- package/dist/index.d.ts +0 -31
- package/dist/index.js +0 -79
- package/dist/index.js.map +0 -1
- package/dist/input/gamepad-poller.d.ts +0 -8
- package/dist/input/gamepad-poller.js +0 -38
- package/dist/input/gamepad-poller.js.map +0 -1
- package/dist/input/input.d.ts +0 -44
- package/dist/input/input.js +0 -175
- package/dist/input/input.js.map +0 -1
- package/dist/input/keyboard-poller.d.ts +0 -7
- package/dist/input/keyboard-poller.js +0 -30
- package/dist/input/keyboard-poller.js.map +0 -1
- package/dist/input/pointer-poller.d.ts +0 -12
- package/dist/input/pointer-poller.js +0 -67
- package/dist/input/pointer-poller.js.map +0 -1
- package/dist/sprite/sprite.d.ts +0 -51
- package/dist/sprite/sprite.js +0 -161
- package/dist/sprite/sprite.js.map +0 -1
- package/dist/storage/json-storage.d.ts +0 -4
- package/dist/storage/json-storage.js +0 -13
- package/dist/storage/json-storage.js.map +0 -1
- package/dist/test/tsconfig.json +0 -14
- package/dist/text/font.d.ts +0 -6
- package/dist/text/font.js +0 -18
- package/dist/text/font.js.map +0 -1
- package/dist/text/text-layout.d.ts +0 -11
- package/dist/text/text-layout.js +0 -73
- package/dist/text/text-layout.js.map +0 -1
- package/dist/tsconfig.json +0 -13
- package/dist/types/2d.d.ts +0 -9
- package/dist/types/2d.js +0 -2
- package/dist/types/2d.js.map +0 -1
- package/dist/void.js +0 -60
- package/dist/void.js.map +0 -7
- package/dist/void.meta.json +0 -289
- package/src/atlas/anim.js +0 -17
- package/tools/atlas-parser.js +0 -120
- package/tools/void.js +0 -143
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { animCels, celMillis } from "../graphics/atlas.js";
|
|
2
|
+
import { boxHits } from "../types/geo.js";
|
|
3
|
+
import { mod } from "../utils/math.js";
|
|
4
|
+
export const drawableBytes = 12;
|
|
5
|
+
/** granularity (0.015625) of `Drawable` coords. */
|
|
6
|
+
export const drawableEpsilon = 1 / 64;
|
|
7
|
+
export const drawableMaxWH = { w: 4095, h: 4095 };
|
|
8
|
+
/**
|
|
9
|
+
* everything not requiring an atlas. the box is the drawn region. assume little
|
|
10
|
+
* endian.
|
|
11
|
+
*
|
|
12
|
+
* 0 xxxx xxxx x [-131072, 131071.984375] (1/64th fixed-point). 1b sign, 17b
|
|
13
|
+
* 1 xxxx xxxx int, 6b fraction.
|
|
14
|
+
* 2 xxxx xxxx
|
|
15
|
+
* 3 yyyy yyyy y.
|
|
16
|
+
* 4 yyyy yyyy
|
|
17
|
+
* 5 yyyy yyyy
|
|
18
|
+
* 6 sxyz llll stretch, flip x, flip y, zend, z layer (4b).
|
|
19
|
+
* 7 wwww wwww width [0, 4095]. zero means discard.
|
|
20
|
+
* 8 hhhh wwww height. zero means discard.
|
|
21
|
+
* 9 hhhh hhhh
|
|
22
|
+
* a iiic cccc animation ID [0, 2047], animation cel [0, 31].
|
|
23
|
+
* b iiii iiii
|
|
24
|
+
*
|
|
25
|
+
* animations default to looping without CPU interaction.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export class Drawable {
|
|
29
|
+
i;
|
|
30
|
+
#pool;
|
|
31
|
+
constructor(pool, i) {
|
|
32
|
+
this.#pool = pool;
|
|
33
|
+
this.i = i;
|
|
34
|
+
}
|
|
35
|
+
above(draw) {
|
|
36
|
+
const compare = this.z === draw.z
|
|
37
|
+
? (draw.zend ? draw.y + draw.h : draw.y) -
|
|
38
|
+
(this.zend ? this.y + this.h : this.y)
|
|
39
|
+
: this.z - draw.z;
|
|
40
|
+
return compare < 0;
|
|
41
|
+
}
|
|
42
|
+
get cel() {
|
|
43
|
+
const iiic_cccc = this.#pool.view.getUint8(this.i + 10);
|
|
44
|
+
return iiic_cccc & 0x1f;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* [0, 31]. rendered cel offset. call reset() to play animation from start.
|
|
48
|
+
*/
|
|
49
|
+
set cel(cel) {
|
|
50
|
+
const iiic_cccc = this.#pool.view.getUint8(this.i + 10);
|
|
51
|
+
this.#pool.view.setUint8(this.i + 10, (iiic_cccc & ~0x1f) | (cel & 0x1f));
|
|
52
|
+
}
|
|
53
|
+
/** test if render area overlaps box or sprite render area. */
|
|
54
|
+
clips(box) {
|
|
55
|
+
return boxHits(this, box);
|
|
56
|
+
}
|
|
57
|
+
get flipX() {
|
|
58
|
+
const sxyz_llll = this.#pool.view.getUint8(this.i + 6);
|
|
59
|
+
return !!(sxyz_llll & 0x40);
|
|
60
|
+
}
|
|
61
|
+
set flipX(flip) {
|
|
62
|
+
const sxyz_llll = this.#pool.view.getUint8(this.i + 6);
|
|
63
|
+
this.#pool.view.setUint8(this.i + 6, (sxyz_llll & ~0x40) | (-flip & 0x40));
|
|
64
|
+
}
|
|
65
|
+
get flipY() {
|
|
66
|
+
const sxyz_llll = this.#pool.view.getUint8(this.i + 6);
|
|
67
|
+
return !!(sxyz_llll & 0x20);
|
|
68
|
+
}
|
|
69
|
+
set flipY(flip) {
|
|
70
|
+
const sxyz_llll = this.#pool.view.getUint8(this.i + 6);
|
|
71
|
+
this.#pool.view.setUint8(this.i + 6, (sxyz_llll & ~0x20) | (-flip & 0x20));
|
|
72
|
+
}
|
|
73
|
+
get h() {
|
|
74
|
+
const h12_wwww = this.#pool.view.getUint16(this.i + 8, true);
|
|
75
|
+
return h12_wwww >>> 4;
|
|
76
|
+
}
|
|
77
|
+
/** [0, 4095]. */
|
|
78
|
+
set h(h) {
|
|
79
|
+
const h12_wwww = this.#pool.view.getUint16(this.i + 8, true);
|
|
80
|
+
this.#pool.view.setUint16(this.i + 8, (h12_wwww & ~(0xfff << 4)) | ((h & 0xfff) << 4), true);
|
|
81
|
+
}
|
|
82
|
+
get id() {
|
|
83
|
+
const i11_c5 = this.#pool.view.getUint16(this.i + 10, true);
|
|
84
|
+
return (i11_c5 >>> 5) & 0x7ff;
|
|
85
|
+
}
|
|
86
|
+
/** [0, 2047]. */
|
|
87
|
+
set id(id) {
|
|
88
|
+
const i11_c5 = this.#pool.view.getUint16(this.i + 10, true);
|
|
89
|
+
this.#pool.view.setUint16(this.i + 10, (i11_c5 & ~(0x7ff << 5)) | ((id & 0x7ff) << 5), true);
|
|
90
|
+
}
|
|
91
|
+
get stretch() {
|
|
92
|
+
const sxyz_llll = this.#pool.view.getUint8(this.i + 6);
|
|
93
|
+
return !!(sxyz_llll & 0x80);
|
|
94
|
+
}
|
|
95
|
+
/** wrap texture (default) or stretch to width and height. */
|
|
96
|
+
set stretch(stretch) {
|
|
97
|
+
const sxyz_llll = this.#pool.view.getUint8(this.i + 6);
|
|
98
|
+
this.#pool.view.setUint8(this.i + 6, (sxyz_llll & ~0x80) | (-stretch & 0x80));
|
|
99
|
+
}
|
|
100
|
+
get w() {
|
|
101
|
+
const hhhh_w12 = this.#pool.view.getUint16(this.i + 7, true);
|
|
102
|
+
return hhhh_w12 & 0xfff;
|
|
103
|
+
}
|
|
104
|
+
/** [0, 4095]. */
|
|
105
|
+
set w(w) {
|
|
106
|
+
const hhhh_w12 = this.#pool.view.getUint16(this.i + 7, true);
|
|
107
|
+
this.#pool.view.setUint16(this.i + 7, (hhhh_w12 & ~0xfff) | (w & 0xfff), true);
|
|
108
|
+
}
|
|
109
|
+
get x() {
|
|
110
|
+
const y8_x24 = this.#pool.view.getUint32(this.i + 0, true);
|
|
111
|
+
return ((y8_x24 << 8) >> 8) / 64; // signed shift.
|
|
112
|
+
}
|
|
113
|
+
/** [-131072, 131071.984375] with 1/64th (0.015625) granularity. */
|
|
114
|
+
set x(x) {
|
|
115
|
+
const y8_x24 = this.#pool.view.getUint32(this.i + 0, true);
|
|
116
|
+
this.#pool.view.setUint32(this.i + 0, (y8_x24 & ~0xff_ffff) | ((x * 64) & 0xff_ffff), true);
|
|
117
|
+
}
|
|
118
|
+
get xy() {
|
|
119
|
+
return { x: this.x, y: this.y };
|
|
120
|
+
}
|
|
121
|
+
set xy(xy) {
|
|
122
|
+
this.x = xy.x;
|
|
123
|
+
this.y = xy.y;
|
|
124
|
+
}
|
|
125
|
+
get y() {
|
|
126
|
+
const sxyz_llll_y24 = this.#pool.view.getUint32(this.i + 3, true);
|
|
127
|
+
return ((sxyz_llll_y24 << 8) >> 8) / 64; // signed shift.
|
|
128
|
+
}
|
|
129
|
+
/** [-131072, 131071.984375] with 1/64th (0.015625) granularity. */
|
|
130
|
+
set y(y) {
|
|
131
|
+
const sxyz_llll_y24 = this.#pool.view.getUint32(this.i + 3, true);
|
|
132
|
+
this.#pool.view.setUint32(this.i + 3, (sxyz_llll_y24 & ~0xff_ffff) | ((y * 64) & 0xff_ffff), true);
|
|
133
|
+
}
|
|
134
|
+
get z() {
|
|
135
|
+
const sxyz_llll = this.#pool.view.getUint8(this.i + 6);
|
|
136
|
+
return (sxyz_llll & 0xf);
|
|
137
|
+
}
|
|
138
|
+
/** layer [0 (closest), 14 (furthest)]; 15 is hidden. */
|
|
139
|
+
set z(z) {
|
|
140
|
+
const sxyz_llll = this.#pool.view.getUint8(this.i + 6);
|
|
141
|
+
this.#pool.view.setUint8(this.i + 6, (sxyz_llll & ~0xf) | (z & 0xf));
|
|
142
|
+
}
|
|
143
|
+
get zend() {
|
|
144
|
+
const sxyz_llll = this.#pool.view.getUint8(this.i + 6);
|
|
145
|
+
return !!(sxyz_llll & 0x10);
|
|
146
|
+
}
|
|
147
|
+
/** z-order by top (default) or bottom of box. */
|
|
148
|
+
set zend(end) {
|
|
149
|
+
const sxyz_llll = this.#pool.view.getUint8(this.i + 6);
|
|
150
|
+
this.#pool.view.setUint8(this.i + 6, (sxyz_llll & ~0x10) | (-end & 0x10));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// to-do: can I declaration merge or namespace merge away from the tag type?
|
|
154
|
+
export class Sprite extends Drawable {
|
|
155
|
+
#atlas;
|
|
156
|
+
#framer;
|
|
157
|
+
#hitbox;
|
|
158
|
+
#hurtbox;
|
|
159
|
+
constructor(pool, i, atlas, framer) {
|
|
160
|
+
super(pool, i);
|
|
161
|
+
this.#atlas = atlas;
|
|
162
|
+
this.#framer = framer;
|
|
163
|
+
}
|
|
164
|
+
get anim() {
|
|
165
|
+
return this.#atlas.anim[this.tag];
|
|
166
|
+
}
|
|
167
|
+
get flipX() {
|
|
168
|
+
return super.flipX;
|
|
169
|
+
}
|
|
170
|
+
set flipX(flip) {
|
|
171
|
+
if (this.flipX === flip)
|
|
172
|
+
return;
|
|
173
|
+
super.flipX = flip;
|
|
174
|
+
this.#hitbox = undefined;
|
|
175
|
+
this.#hurtbox = undefined;
|
|
176
|
+
}
|
|
177
|
+
get flipY() {
|
|
178
|
+
return super.flipY;
|
|
179
|
+
}
|
|
180
|
+
set flipY(flip) {
|
|
181
|
+
if (this.flipY === flip)
|
|
182
|
+
return;
|
|
183
|
+
super.flipY = flip;
|
|
184
|
+
this.#hitbox = undefined;
|
|
185
|
+
this.#hurtbox = undefined;
|
|
186
|
+
}
|
|
187
|
+
get h() {
|
|
188
|
+
return super.h;
|
|
189
|
+
}
|
|
190
|
+
set h(h) {
|
|
191
|
+
if (this.h === h)
|
|
192
|
+
return;
|
|
193
|
+
super.h = h;
|
|
194
|
+
this.#hitbox = undefined;
|
|
195
|
+
this.#hurtbox = undefined;
|
|
196
|
+
}
|
|
197
|
+
get hitbox() {
|
|
198
|
+
if (this.#hitbox)
|
|
199
|
+
return this.#hitbox;
|
|
200
|
+
const { hitbox } = this.anim;
|
|
201
|
+
if (!hitbox)
|
|
202
|
+
return;
|
|
203
|
+
return (this.#hitbox ??= {
|
|
204
|
+
x: this.x + (this.flipX ? this.w - hitbox.w - hitbox.x : hitbox.x),
|
|
205
|
+
y: this.y + (this.flipY ? this.h - hitbox.h - hitbox.y : hitbox.y),
|
|
206
|
+
w: hitbox.w,
|
|
207
|
+
h: hitbox.h
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
hits(box) {
|
|
211
|
+
const hitbox = this.hitbox;
|
|
212
|
+
if (!hitbox)
|
|
213
|
+
return false;
|
|
214
|
+
const hurtbox = box instanceof Sprite ? box.hurtbox : box;
|
|
215
|
+
return !!hurtbox && boxHits(hitbox, hurtbox);
|
|
216
|
+
}
|
|
217
|
+
get hurtbox() {
|
|
218
|
+
if (this.#hurtbox)
|
|
219
|
+
return this.#hurtbox;
|
|
220
|
+
const { hurtbox } = this.anim;
|
|
221
|
+
if (!hurtbox)
|
|
222
|
+
return;
|
|
223
|
+
return (this.#hurtbox ??= {
|
|
224
|
+
x: this.x + (this.flipX ? this.w - hurtbox.w - hurtbox.x : hurtbox.x),
|
|
225
|
+
y: this.y + (this.flipY ? this.h - hurtbox.h - hurtbox.y : hurtbox.y),
|
|
226
|
+
w: hurtbox.w,
|
|
227
|
+
h: hurtbox.h
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
get id() {
|
|
231
|
+
return super.id;
|
|
232
|
+
}
|
|
233
|
+
set id(id) {
|
|
234
|
+
if (this.id === id)
|
|
235
|
+
return;
|
|
236
|
+
super.id = id;
|
|
237
|
+
this.#hitbox = undefined;
|
|
238
|
+
this.#hurtbox = undefined;
|
|
239
|
+
}
|
|
240
|
+
/** true if animation has played once. */
|
|
241
|
+
get looped() {
|
|
242
|
+
// this comparison resets after the second loop since cel can only count to
|
|
243
|
+
// 2 * anim.cels.
|
|
244
|
+
return mod(this.#currentCel - this.cel, animCels * 2) >= this.anim.cels;
|
|
245
|
+
}
|
|
246
|
+
/** sets cel to animation start. */
|
|
247
|
+
reset() {
|
|
248
|
+
this.cel = this.#currentCel; // setter truncates.
|
|
249
|
+
}
|
|
250
|
+
// to-do: unit test and catch up on unit tests elsewhere.
|
|
251
|
+
get tag() {
|
|
252
|
+
return this.#atlas.tags[this.id];
|
|
253
|
+
}
|
|
254
|
+
/** sets animation, resets cel, dimensions, hitbox, and hurtbox. */
|
|
255
|
+
set tag(tag) {
|
|
256
|
+
const anim = this.#atlas.anim[tag];
|
|
257
|
+
this.w = anim.w;
|
|
258
|
+
this.h = anim.h;
|
|
259
|
+
this.id = anim.id;
|
|
260
|
+
this.reset();
|
|
261
|
+
}
|
|
262
|
+
toString() {
|
|
263
|
+
return `Sprite{${this.tag} (${this.x} ${this.y} ${this.z}) ${this.w}×${this.h}}`;
|
|
264
|
+
}
|
|
265
|
+
get w() {
|
|
266
|
+
return super.w;
|
|
267
|
+
}
|
|
268
|
+
set w(w) {
|
|
269
|
+
if (this.w === w)
|
|
270
|
+
return;
|
|
271
|
+
super.w = w;
|
|
272
|
+
this.#hitbox = undefined;
|
|
273
|
+
this.#hurtbox = undefined;
|
|
274
|
+
}
|
|
275
|
+
get x() {
|
|
276
|
+
return super.x;
|
|
277
|
+
}
|
|
278
|
+
set x(x) {
|
|
279
|
+
if (this.x === x)
|
|
280
|
+
return;
|
|
281
|
+
super.x = x;
|
|
282
|
+
this.#hitbox = undefined;
|
|
283
|
+
this.#hurtbox = undefined;
|
|
284
|
+
}
|
|
285
|
+
get y() {
|
|
286
|
+
return super.y;
|
|
287
|
+
}
|
|
288
|
+
set y(y) {
|
|
289
|
+
if (this.y === y)
|
|
290
|
+
return;
|
|
291
|
+
super.y = y;
|
|
292
|
+
this.#hitbox = undefined;
|
|
293
|
+
this.#hurtbox = undefined;
|
|
294
|
+
}
|
|
295
|
+
/** current fractional cel in [0, 2 * anim.cels). */
|
|
296
|
+
get #currentCel() {
|
|
297
|
+
const cel = this.#framer.age / celMillis;
|
|
298
|
+
return cel % (this.anim.cels * 2);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=sprite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sprite.js","sourceRoot":"","sources":["../../../src/graphics/sprite.ts"],"names":[],"mappings":"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AC,CAAA;QACX,IAAI,CAAC,OAAO,GAAG,SAAS,CAAA;QACxB,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAA;IAC3B,CAAC;IAED,IAAa,CAAC;QACZ,OAAO,KAAK,CAAC,CAAC,CAAA;IAChB,CAAC;IAED,IAAa,CAAC,CAAC,CAAS;QACtB,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC;YAAE,OAAM;QACxB,KAAK,CAAC,CAAC,GAAG,CAAC,CAAA;QACX,IAAI,CAAC,OAAO,GAAG,SAAS,CAAA;QACxB,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAA;IAC3B,CAAC;IAED,IAAa,CAAC;QACZ,OAAO,KAAK,CAAC,CAAC,CAAA;IAChB,CAAC;IAED,IAAa,CAAC,CAAC,CAAS;QACtB,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC;YAAE,OAAM;QACxB,KAAK,CAAC,CAAC,GAAG,CAAC,CAAA;QACX,IAAI,CAAC,OAAO,GAAG,SAAS,CAAA;QACxB,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAA;IAC3B,CAAC;IAED,oDAAoD;IACpD,IAAI,WAAW;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,SAAS,CAAA;QACxC,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAA;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export { type Font, memProp5x6 } from 'mem-font';
|
|
2
|
+
export * from './ents/button-ent.ts';
|
|
3
|
+
export * from './ents/cursor-ent.ts';
|
|
4
|
+
export * from './ents/ent.ts';
|
|
5
|
+
export * from './ents/follow-cam-ent.ts';
|
|
6
|
+
export * from './ents/nine-patch-ent.ts';
|
|
7
|
+
export * from './ents/text-ent.ts';
|
|
8
|
+
export * from './ents/zoo.ts';
|
|
9
|
+
export * from './graphics/atlas.ts';
|
|
10
|
+
export * from './graphics/atlas-parser.ts';
|
|
11
|
+
export * from './graphics/cam.ts';
|
|
12
|
+
export * from './graphics/layer.ts';
|
|
13
|
+
export * from './graphics/sprite.ts';
|
|
14
|
+
export * from './input/input.ts';
|
|
15
|
+
export type { PointEvent } from './input/pointer.ts';
|
|
16
|
+
export * from './mem/pool.ts';
|
|
17
|
+
export * from './random/random.ts';
|
|
18
|
+
export * from './storage/local-storage.ts';
|
|
19
|
+
export * from './text/font.ts';
|
|
20
|
+
export * from './text/text-layout.ts';
|
|
21
|
+
export * from './types/geo.ts';
|
|
22
|
+
export * from './types/json.ts';
|
|
23
|
+
export * from './types/time.ts';
|
|
24
|
+
export * from './utils/async-util.ts';
|
|
25
|
+
export * from './utils/canvas-util.ts';
|
|
26
|
+
export * from './utils/debug.ts';
|
|
27
|
+
export * from './utils/dom-util.ts';
|
|
28
|
+
export * from './utils/fetch-util.ts';
|
|
29
|
+
export * from './void.ts';
|
|
30
|
+
export declare const version: string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { voidVersion } from "./types/void-version.js";
|
|
2
|
+
export { memProp5x6 } from 'mem-font';
|
|
3
|
+
export * from "./ents/button-ent.js";
|
|
4
|
+
export * from "./ents/cursor-ent.js";
|
|
5
|
+
export * from "./ents/ent.js";
|
|
6
|
+
export * from "./ents/follow-cam-ent.js";
|
|
7
|
+
export * from "./ents/nine-patch-ent.js";
|
|
8
|
+
export * from "./ents/text-ent.js";
|
|
9
|
+
export * from "./ents/zoo.js";
|
|
10
|
+
export * from "./graphics/atlas.js";
|
|
11
|
+
export * from "./graphics/atlas-parser.js";
|
|
12
|
+
export * from "./graphics/cam.js";
|
|
13
|
+
export * from "./graphics/layer.js";
|
|
14
|
+
export * from "./graphics/sprite.js";
|
|
15
|
+
export * from "./input/input.js";
|
|
16
|
+
export * from "./mem/pool.js";
|
|
17
|
+
export * from "./random/random.js";
|
|
18
|
+
export * from "./storage/local-storage.js";
|
|
19
|
+
export * from "./text/font.js";
|
|
20
|
+
export * from "./text/text-layout.js";
|
|
21
|
+
export * from "./types/geo.js";
|
|
22
|
+
export * from "./types/json.js";
|
|
23
|
+
export * from "./types/time.js";
|
|
24
|
+
export * from "./utils/async-util.js";
|
|
25
|
+
export * from "./utils/canvas-util.js";
|
|
26
|
+
export * from "./utils/debug.js";
|
|
27
|
+
export * from "./utils/dom-util.js";
|
|
28
|
+
export * from "./utils/fetch-util.js";
|
|
29
|
+
export * from "./void.js";
|
|
30
|
+
export const version = voidVersion
|
|
31
|
+
? `${voidVersion.version}+${voidVersion.published}.${voidVersion.hash}`
|
|
32
|
+
: '?';
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAA;AAEnD,OAAO,EAAY,UAAU,EAAC,MAAM,UAAU,CAAA;AAC9C,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,eAAe,CAAA;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAEhC,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,gBAAgB,CAAA;AAC9B,cAAc,uBAAuB,CAAA;AACrC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,WAAW,CAAA;AAEzB,MAAM,CAAC,MAAM,OAAO,GAAW,WAAW;IACxC,CAAC,CAAC,GAAG,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,SAAS,IAAI,WAAW,CAAC,IAAI,EAAE;IACvE,CAAC,CAAC,GAAG,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export class ContextMenu {
|
|
3
|
+
enable = false;
|
|
4
|
+
#target;
|
|
5
|
+
constructor(target) {
|
|
6
|
+
this.#target = target;
|
|
7
|
+
}
|
|
8
|
+
register(op) {
|
|
9
|
+
const fn = this.#target[`${op}EventListener`].bind(this.#target);
|
|
10
|
+
fn('contextmenu', this.#onContextMenu);
|
|
11
|
+
// disable long press vibration. nonpassive must be explicit.
|
|
12
|
+
fn('touchstart', this.#onContextMenu, { passive: false });
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
[Symbol.dispose]() {
|
|
16
|
+
this.register('remove');
|
|
17
|
+
}
|
|
18
|
+
#onContextMenu = (ev) => {
|
|
19
|
+
if (!ev.isTrusted || ev.metaKey || ev.altKey || ev.ctrlKey)
|
|
20
|
+
return;
|
|
21
|
+
if (!this.enable)
|
|
22
|
+
ev.preventDefault();
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=context-menu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-menu.js","sourceRoot":"","sources":["../../../src/input/context-menu.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,MAAM,OAAO,WAAW;IACtB,MAAM,GAAY,KAAK,CAAA;IACd,OAAO,CAAa;IAE7B,YAAY,MAAmB;QAC7B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACvB,CAAC;IAED,QAAQ,CAAC,EAAoB;QAC3B,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAChE,EAAE,CAAC,aAAa,EAAE,IAAI,CAAC,cAA+B,CAAC,CAAA;QACvD,6DAA6D;QAC7D,EAAE,CAAC,YAAY,EAAE,IAAI,CAAC,cAA+B,EAAE,EAAC,OAAO,EAAE,KAAK,EAAC,CAAC,CAAA;QACxE,OAAO,IAAI,CAAA;IACb,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IACzB,CAAC;IAED,cAAc,GAAG,CAAC,EAA6B,EAAQ,EAAE;QACvD,IAAI,CAAC,EAAE,CAAC,SAAS,IAAI,EAAE,CAAC,OAAO,IAAI,EAAE,CAAC,MAAM,IAAI,EAAE,CAAC,OAAO;YAAE,OAAM;QAClE,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,EAAE,CAAC,cAAc,EAAE,CAAA;IACvC,CAAC,CAAA;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export declare class Gamepad {
|
|
3
|
+
#private;
|
|
4
|
+
bits: number;
|
|
5
|
+
readonly bitByAxis: {
|
|
6
|
+
[axis: number]: [less: number, more: number];
|
|
7
|
+
};
|
|
8
|
+
readonly bitByButton: {
|
|
9
|
+
[btn: number]: number;
|
|
10
|
+
};
|
|
11
|
+
onEvent: () => void;
|
|
12
|
+
constructor(target: EventTarget);
|
|
13
|
+
get connected(): boolean;
|
|
14
|
+
register(op: 'add' | 'remove'): this;
|
|
15
|
+
reset(): void;
|
|
16
|
+
[Symbol.dispose](): void;
|
|
17
|
+
update(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export class Gamepad {
|
|
3
|
+
bits = 0;
|
|
4
|
+
// to-do: support analog button values, expose connected status and vibration,
|
|
5
|
+
// and distinct devices. would be nice if vibration could merge with
|
|
6
|
+
// navigator.vibrate().
|
|
7
|
+
bitByAxis = {};
|
|
8
|
+
bitByButton = {};
|
|
9
|
+
onEvent = () => { };
|
|
10
|
+
#target;
|
|
11
|
+
constructor(target) {
|
|
12
|
+
this.#target = target;
|
|
13
|
+
}
|
|
14
|
+
get connected() {
|
|
15
|
+
return isSecureContext && navigator.getGamepads().filter(Boolean).length > 0;
|
|
16
|
+
}
|
|
17
|
+
register(op) {
|
|
18
|
+
const fn = this.#target[`${op}EventListener`].bind(this.#target);
|
|
19
|
+
fn('gamepadconnected', this.onEvent);
|
|
20
|
+
fn('gamepaddisconnected', this.onEvent);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
reset() {
|
|
24
|
+
this.bits = 0;
|
|
25
|
+
}
|
|
26
|
+
[Symbol.dispose]() {
|
|
27
|
+
this.register('remove');
|
|
28
|
+
}
|
|
29
|
+
update() {
|
|
30
|
+
if (!isSecureContext)
|
|
31
|
+
return;
|
|
32
|
+
for (const pad of navigator.getGamepads()) {
|
|
33
|
+
for (const [index, axis] of pad?.axes.entries() ?? []) {
|
|
34
|
+
const lessMore = this.bitByAxis[index];
|
|
35
|
+
if (!lessMore)
|
|
36
|
+
continue;
|
|
37
|
+
const bit = axis < 0 ? lessMore[0] : axis === 0 ? 0 : lessMore[1];
|
|
38
|
+
this.bits |= Math.abs(axis) >= 0.5 ? bit : 0;
|
|
39
|
+
}
|
|
40
|
+
for (const [index, btn] of pad?.buttons.entries() ?? []) {
|
|
41
|
+
const bit = this.bitByButton[index];
|
|
42
|
+
if (bit == null)
|
|
43
|
+
continue;
|
|
44
|
+
this.bits |= btn.pressed ? bit : 0;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=gamepad.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gamepad.js","sourceRoot":"","sources":["../../../src/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AK,CAAC,CAAA;gBACtC,IAAI,CAAC,QAAQ;oBAAE,SAAQ;gBACvB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;gBACjE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;YAC9C,CAAC;YACD,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,GAAG,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;gBACxD,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;gBACnC,IAAI,GAAG,IAAI,IAAI;oBAAE,SAAQ;gBACzB,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;YACpC,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { Cam, LevelClientLocalXY } from '../graphics/cam.ts';
|
|
2
|
+
import type { XY, XYZ } from '../types/geo.ts';
|
|
3
|
+
import type { Millis } from '../types/time.ts';
|
|
4
|
+
import type { PointType } from './pointer.ts';
|
|
5
|
+
export type Chord<Button> = [Button, ...Button[]];
|
|
6
|
+
export type Combo<Button> = [Chord<Button>, ...Chord<Button>[]];
|
|
7
|
+
export type DefaultButton = 'L' | 'R' | 'U' | 'D' | 'A' | 'B' | 'C' | 'Click' | 'Click2' | 'ClickMiddle' | 'Menu' | 'Back';
|
|
8
|
+
export type Point = LevelClientLocalXY & {
|
|
9
|
+
click: LevelClientLocalXY | undefined;
|
|
10
|
+
type: PointType | undefined;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* doesn't consider handled. local and level positions are reevaluated each
|
|
14
|
+
* frame.
|
|
15
|
+
*/
|
|
16
|
+
type PointerState = Point & {
|
|
17
|
+
center: LevelClientLocalXY;
|
|
18
|
+
/** false when pinched. */
|
|
19
|
+
drag: {
|
|
20
|
+
on: boolean;
|
|
21
|
+
start: boolean;
|
|
22
|
+
end: boolean;
|
|
23
|
+
};
|
|
24
|
+
/** true if changed since last update. */
|
|
25
|
+
invalid: boolean;
|
|
26
|
+
/** may be negative. */
|
|
27
|
+
pinch: {
|
|
28
|
+
client: XY;
|
|
29
|
+
/** level / local. */
|
|
30
|
+
xy: XY;
|
|
31
|
+
} | undefined;
|
|
32
|
+
/** secondary points. */
|
|
33
|
+
secondary: Point[];
|
|
34
|
+
};
|
|
35
|
+
/** triggered. */
|
|
36
|
+
type WheelState = {
|
|
37
|
+
delta: {
|
|
38
|
+
client: Readonly<XYZ>;
|
|
39
|
+
/** level / local. */
|
|
40
|
+
xy: XY;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* input device abstraction. aggregates devices, records history, and provides
|
|
45
|
+
* a convenient API.
|
|
46
|
+
*
|
|
47
|
+
* devices own as much device-specific detail and as little coordination (time
|
|
48
|
+
* and device) as practical. devices avoid caching state which is the
|
|
49
|
+
* responsibility of Input. devices strive to provide the current state and
|
|
50
|
+
* nothing else.
|
|
51
|
+
*
|
|
52
|
+
* if you miss reporting on a event between long updates, you just miss it.
|
|
53
|
+
* that's the nature of polling. there's no queue.
|
|
54
|
+
*
|
|
55
|
+
* to-do: expose analog state of gamepad. offer direction as a number instead of
|
|
56
|
+
* bool.
|
|
57
|
+
* to-do: multiplayer. possible if devices were requested instead of sought.
|
|
58
|
+
* to-do: expose input source device.
|
|
59
|
+
*/
|
|
60
|
+
export declare class Input<Button extends string> {
|
|
61
|
+
#private;
|
|
62
|
+
/** time allowed between combo inputs. */
|
|
63
|
+
comboMaxIntervalMillis: Millis;
|
|
64
|
+
/**
|
|
65
|
+
* true if any button, key, or click was _ever_ on. doesn't consider handled.
|
|
66
|
+
*/
|
|
67
|
+
gestured: boolean;
|
|
68
|
+
/** clear buttonish inputs for rest of frame. */
|
|
69
|
+
handled: boolean;
|
|
70
|
+
/** true if _any_ input has changed since previous update. */
|
|
71
|
+
invalid: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* minimum duration for an input to be considered held. durations are
|
|
74
|
+
* calculated at frame boundaries, not on actual press. devices are treated
|
|
75
|
+
* strictly as polled aggregates.
|
|
76
|
+
*/
|
|
77
|
+
minHeldMillis: Millis;
|
|
78
|
+
constructor(cam: Readonly<Cam>, target: Element);
|
|
79
|
+
get anyOn(): boolean;
|
|
80
|
+
/** for debugging. */
|
|
81
|
+
get combo(): Button[][];
|
|
82
|
+
/**
|
|
83
|
+
* enable when game is paused or in photo mode to allow right clicks and long
|
|
84
|
+
* presses to save canvas.
|
|
85
|
+
*/
|
|
86
|
+
get contextMenu(): {
|
|
87
|
+
enable: boolean;
|
|
88
|
+
};
|
|
89
|
+
/** doesn't consider handled. gamepads must be polled. */
|
|
90
|
+
get gamepad(): Readonly<object | undefined>;
|
|
91
|
+
/** true if bits hasn't changed for a while. */
|
|
92
|
+
get held(): boolean;
|
|
93
|
+
isAnyOn(...btns: Readonly<Chord<Button>>): boolean;
|
|
94
|
+
isAnyOnStart(...btns: Readonly<Chord<Button>>): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* buttons are exact. eg, up won't match up AND down like `isOn('U')` will.
|
|
97
|
+
* combo is exact too. `['A'], ['A']` will match `['A'], ['A']` but not
|
|
98
|
+
* `['A'], ['A'], ['A']`.
|
|
99
|
+
*/
|
|
100
|
+
isCombo(...combo: Readonly<Combo<Button>>): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* `['A'], ['A']` will match `['A'], ['A']` and `['B'], ['A'], ['A']`. eg,
|
|
103
|
+
* double-clicks often don't care about any preceding buttons.
|
|
104
|
+
*/
|
|
105
|
+
isComboEndsWith(...combo: Readonly<Combo<Button>>): boolean;
|
|
106
|
+
/** like isComboEndsWith() but test if the last button is triggered. */
|
|
107
|
+
isComboEndsWithStart(...combo: Readonly<Combo<Button>>): boolean;
|
|
108
|
+
/** like isCombo() but test if the last button is triggered. */
|
|
109
|
+
isComboStart(...combo: Readonly<Combo<Button>>): boolean;
|
|
110
|
+
isOff(...btns: Readonly<Chord<Button>>): boolean;
|
|
111
|
+
isOffStart(...btns: Readonly<Chord<Button>>): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* true if all buttons are on inclusively. eg, `isOn('U')` is true when up is
|
|
114
|
+
* pressed or when up and down are pressed.
|
|
115
|
+
*/
|
|
116
|
+
isOn(...btns: Readonly<Chord<Button>>): boolean;
|
|
117
|
+
isOnStart(...btns: Readonly<Chord<Button>>): boolean;
|
|
118
|
+
get key(): {
|
|
119
|
+
invalid: boolean;
|
|
120
|
+
};
|
|
121
|
+
mapDefault(): Input<Button | DefaultButton>;
|
|
122
|
+
mapGamepadAxis(less: Button, more: Button, ...axes: readonly number[]): void;
|
|
123
|
+
mapGamepadButton(btn: Button, ...indices: readonly number[]): void;
|
|
124
|
+
/** @arg codes union of KeyboardEvent.code. */
|
|
125
|
+
mapKeyboardCode(btn: Button, ...codes: readonly string[]): void;
|
|
126
|
+
mapPointerClick(btn: Button, ...clicks: readonly number[]): void;
|
|
127
|
+
get on(): Button[];
|
|
128
|
+
set onEvent(cb: () => void);
|
|
129
|
+
/** doesn't consider handled. */
|
|
130
|
+
get point(): PointerState | undefined;
|
|
131
|
+
get pointer(): {
|
|
132
|
+
dragMinClient: number;
|
|
133
|
+
};
|
|
134
|
+
register(op: 'add' | 'remove'): this;
|
|
135
|
+
reset: () => void;
|
|
136
|
+
/** true if bits has changed. */
|
|
137
|
+
get started(): boolean;
|
|
138
|
+
/**
|
|
139
|
+
* call on new frame before altering cam. dispatches always occur before an
|
|
140
|
+
* update.
|
|
141
|
+
* @arg millis duration since last update.
|
|
142
|
+
*/
|
|
143
|
+
update(millis: Millis): void;
|
|
144
|
+
[Symbol.dispose](): void;
|
|
145
|
+
/** doesn't consider handled. */
|
|
146
|
+
get wheel(): Readonly<WheelState | undefined>;
|
|
147
|
+
}
|
|
148
|
+
export {};
|