like2d 2.7.4 → 2.9.0
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 +34 -35
- package/dist/core/audio.d.ts +12 -9
- package/dist/core/audio.d.ts.map +1 -1
- package/dist/core/audio.js +7 -4
- package/dist/core/canvas.d.ts +58 -0
- package/dist/core/canvas.d.ts.map +1 -0
- package/dist/core/canvas.js +209 -0
- package/dist/core/events.d.ts +92 -7
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/events.js +20 -0
- package/dist/core/gamepad-mapping.d.ts +57 -18
- package/dist/core/gamepad-mapping.d.ts.map +1 -1
- package/dist/core/gamepad-mapping.js +23 -223
- package/dist/core/gamepad.d.ts +34 -58
- package/dist/core/gamepad.d.ts.map +1 -1
- package/dist/core/gamepad.js +79 -213
- package/dist/core/graphics.d.ts +175 -64
- package/dist/core/graphics.d.ts.map +1 -1
- package/dist/core/graphics.js +294 -198
- package/dist/core/input-state.d.ts +2 -2
- package/dist/core/input-state.d.ts.map +1 -1
- package/dist/core/input.d.ts +22 -15
- package/dist/core/input.d.ts.map +1 -1
- package/dist/core/input.js +25 -37
- package/dist/core/keyboard.d.ts +7 -7
- package/dist/core/keyboard.d.ts.map +1 -1
- package/dist/core/keyboard.js +24 -31
- package/dist/core/like.d.ts +98 -44
- package/dist/core/like.d.ts.map +1 -1
- package/dist/core/like.js +8 -0
- package/dist/core/mouse.d.ts +45 -22
- package/dist/core/mouse.d.ts.map +1 -1
- package/dist/core/mouse.js +90 -78
- package/dist/core/timer.d.ts +2 -5
- package/dist/core/timer.d.ts.map +1 -1
- package/dist/core/timer.js +2 -14
- package/dist/engine.d.ts +61 -11
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +119 -102
- package/dist/index.d.ts +42 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -14
- package/dist/math/index.d.ts +2 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/index.js +1 -0
- package/dist/math/rect.d.ts +71 -0
- package/dist/math/rect.d.ts.map +1 -0
- package/dist/{core → math}/rect.js +8 -0
- package/dist/math/vector2.d.ts +78 -0
- package/dist/math/vector2.d.ts.map +1 -0
- package/dist/{core → math}/vector2.js +24 -0
- package/dist/prefab-scenes/index.d.ts +7 -0
- package/dist/prefab-scenes/index.d.ts.map +1 -0
- package/dist/prefab-scenes/index.js +6 -0
- package/dist/prefab-scenes/startScreen.d.ts +59 -0
- package/dist/prefab-scenes/startScreen.d.ts.map +1 -0
- package/dist/{scenes/startup.js → prefab-scenes/startScreen.js} +47 -7
- package/dist/scene.d.ts +103 -5
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +28 -1
- package/package.json +18 -2
- package/dist/core/canvas-config.d.ts +0 -22
- package/dist/core/canvas-config.d.ts.map +0 -1
- package/dist/core/canvas-config.js +0 -14
- package/dist/core/canvas-manager.d.ts +0 -25
- package/dist/core/canvas-manager.d.ts.map +0 -1
- package/dist/core/canvas-manager.js +0 -178
- package/dist/core/gamepad-buttons.d.ts +0 -23
- package/dist/core/gamepad-buttons.d.ts.map +0 -1
- package/dist/core/gamepad-buttons.js +0 -36
- package/dist/core/rect.d.ts +0 -26
- package/dist/core/rect.d.ts.map +0 -1
- package/dist/core/vector2.d.ts +0 -26
- package/dist/core/vector2.d.ts.map +0 -1
- package/dist/gamecontrollerdb.txt +0 -2221
- package/dist/scenes/startup.d.ts +0 -18
- package/dist/scenes/startup.d.ts.map +0 -1
package/dist/core/input.js
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
+
import { GamepadInternal } from './gamepad';
|
|
1
2
|
import { InputStateTracker } from './input-state';
|
|
2
|
-
|
|
3
|
-
const buttonMap = {
|
|
4
|
-
'Left': 1,
|
|
5
|
-
'Right': 3,
|
|
6
|
-
'Middle': 2,
|
|
7
|
-
'1': 1,
|
|
8
|
-
'2': 2,
|
|
9
|
-
'3': 3,
|
|
10
|
-
'4': 4,
|
|
11
|
-
'5': 5,
|
|
12
|
-
};
|
|
13
|
-
export class Input {
|
|
3
|
+
export class InputInternal {
|
|
14
4
|
constructor(deps) {
|
|
15
5
|
Object.defineProperty(this, "actionMap", {
|
|
16
6
|
enumerable: true,
|
|
@@ -46,13 +36,16 @@ export class Input {
|
|
|
46
36
|
this.mouse = deps.mouse;
|
|
47
37
|
this.gamepad = deps.gamepad;
|
|
48
38
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
39
|
+
setAction(action, inputs = []) {
|
|
40
|
+
if (inputs.length) {
|
|
41
|
+
const bindings = inputs.map(input => this.parseInput(input));
|
|
42
|
+
this.actionMap.set(action, bindings);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.actionMap.delete(action);
|
|
46
|
+
this.actionStateTracker.currState.delete(action);
|
|
47
|
+
this.actionStateTracker.prevState.delete(action);
|
|
48
|
+
}
|
|
56
49
|
}
|
|
57
50
|
isDown(action) {
|
|
58
51
|
const bindings = this.actionMap.get(action);
|
|
@@ -66,8 +59,8 @@ export class Input {
|
|
|
66
59
|
justReleased(action) {
|
|
67
60
|
return this.actionStateTracker.justReleased(action);
|
|
68
61
|
}
|
|
69
|
-
|
|
70
|
-
this.gamepad.
|
|
62
|
+
_update() {
|
|
63
|
+
this.gamepad._update();
|
|
71
64
|
const activeActions = new Set();
|
|
72
65
|
for (const [action] of this.actionMap) {
|
|
73
66
|
if (this.isDown(action)) {
|
|
@@ -81,30 +74,25 @@ export class Input {
|
|
|
81
74
|
const normalized = input.trim();
|
|
82
75
|
if (normalized.startsWith('Mouse')) {
|
|
83
76
|
const buttonCode = normalized.replace('Mouse', '');
|
|
84
|
-
return { type: 'mouse',
|
|
77
|
+
return { type: 'mouse', button: buttonCode };
|
|
85
78
|
}
|
|
86
79
|
if (normalized.startsWith('Button') || normalized.startsWith('DP')) {
|
|
87
|
-
return {
|
|
80
|
+
return {
|
|
81
|
+
type: "gamepad",
|
|
82
|
+
gamepad: 0,
|
|
83
|
+
button: GamepadInternal.getButtonNumber(normalized),
|
|
84
|
+
};
|
|
88
85
|
}
|
|
89
|
-
return { type: 'keyboard',
|
|
86
|
+
return { type: 'keyboard', scancode: normalized };
|
|
90
87
|
}
|
|
91
88
|
isBindingActive(binding) {
|
|
92
89
|
switch (binding.type) {
|
|
93
90
|
case 'keyboard':
|
|
94
|
-
return this.keyboard.isDown(binding.
|
|
95
|
-
case 'mouse':
|
|
96
|
-
|
|
97
|
-
if (button !== undefined) {
|
|
98
|
-
return this.mouse.isDown(button);
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
91
|
+
return this.keyboard.isDown(binding.scancode);
|
|
92
|
+
case 'mouse':
|
|
93
|
+
return this.mouse.isDown(binding.button);
|
|
102
94
|
case 'gamepad': {
|
|
103
|
-
|
|
104
|
-
if (buttonIndex !== undefined) {
|
|
105
|
-
return this.gamepad.isButtonDownOnAny(buttonIndex);
|
|
106
|
-
}
|
|
107
|
-
return false;
|
|
95
|
+
return !!this.gamepad.isButtonDown(binding.gamepad, binding.button);
|
|
108
96
|
}
|
|
109
97
|
default:
|
|
110
98
|
return false;
|
package/dist/core/keyboard.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { EngineDispatch } from "../engine";
|
|
2
|
+
export declare class KeyboardInternal {
|
|
3
|
+
private dispatch;
|
|
2
4
|
private pressedScancodes;
|
|
3
|
-
|
|
4
|
-
private
|
|
5
|
-
|
|
6
|
-
private blurHandler;
|
|
7
|
-
constructor();
|
|
5
|
+
private canvas;
|
|
6
|
+
private abort;
|
|
7
|
+
constructor(canvas: HTMLCanvasElement | null, dispatch: EngineDispatch);
|
|
8
8
|
private handleKeyDown;
|
|
9
9
|
private handleKeyUp;
|
|
10
10
|
private handleBlur;
|
|
11
|
-
|
|
11
|
+
_dispose(): void;
|
|
12
12
|
isDown(scancode: string): boolean;
|
|
13
13
|
isAnyDown(...scancodes: string[]): boolean;
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/core/keyboard.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/core/keyboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,qBAAa,gBAAgB;IAKmB,OAAO,CAAC,QAAQ;IAJ9D,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,KAAK,CAAyB;gBAE1B,MAAM,EAAE,iBAAiB,GAAG,IAAI,EAAU,QAAQ,EAAE,cAAc;IAU9E,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,UAAU;IAIlB,QAAQ,IAAI,IAAI;IAKhB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIjC,SAAS,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO;CAG3C"}
|
package/dist/core/keyboard.js
CHANGED
|
@@ -1,64 +1,57 @@
|
|
|
1
|
-
export class
|
|
2
|
-
constructor() {
|
|
3
|
-
Object.defineProperty(this, "
|
|
4
|
-
enumerable: true,
|
|
5
|
-
configurable: true,
|
|
6
|
-
writable: true,
|
|
7
|
-
value: new Set()
|
|
8
|
-
});
|
|
9
|
-
Object.defineProperty(this, "onKeyEvent", {
|
|
1
|
+
export class KeyboardInternal {
|
|
2
|
+
constructor(canvas, dispatch) {
|
|
3
|
+
Object.defineProperty(this, "dispatch", {
|
|
10
4
|
enumerable: true,
|
|
11
5
|
configurable: true,
|
|
12
6
|
writable: true,
|
|
13
|
-
value:
|
|
7
|
+
value: dispatch
|
|
14
8
|
});
|
|
15
|
-
|
|
16
|
-
Object.defineProperty(this, "keydownHandler", {
|
|
9
|
+
Object.defineProperty(this, "pressedScancodes", {
|
|
17
10
|
enumerable: true,
|
|
18
11
|
configurable: true,
|
|
19
12
|
writable: true,
|
|
20
|
-
value:
|
|
13
|
+
value: new Set()
|
|
21
14
|
});
|
|
22
|
-
Object.defineProperty(this, "
|
|
15
|
+
Object.defineProperty(this, "canvas", {
|
|
23
16
|
enumerable: true,
|
|
24
17
|
configurable: true,
|
|
25
18
|
writable: true,
|
|
26
|
-
value:
|
|
19
|
+
value: null
|
|
27
20
|
});
|
|
28
|
-
Object.defineProperty(this, "
|
|
21
|
+
Object.defineProperty(this, "abort", {
|
|
29
22
|
enumerable: true,
|
|
30
23
|
configurable: true,
|
|
31
24
|
writable: true,
|
|
32
|
-
value:
|
|
25
|
+
value: new AbortController()
|
|
33
26
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
window.addEventListener('keyup', this.keyupHandler);
|
|
41
|
-
window.addEventListener('blur', this.blurHandler);
|
|
27
|
+
this.canvas = canvas;
|
|
28
|
+
if (this.canvas) {
|
|
29
|
+
this.canvas.addEventListener('keydown', this.handleKeyDown.bind(this), { signal: this.abort.signal });
|
|
30
|
+
this.canvas.addEventListener('keyup', this.handleKeyUp.bind(this), { signal: this.abort.signal });
|
|
31
|
+
this.canvas.addEventListener('blur', this.handleBlur.bind(this), { signal: this.abort.signal });
|
|
32
|
+
}
|
|
42
33
|
}
|
|
43
34
|
handleKeyDown(e) {
|
|
35
|
+
const scrollKeys = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Space', 'PageUp', 'PageDown', 'Home', 'End'];
|
|
36
|
+
if (scrollKeys.includes(e.code)) {
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
}
|
|
44
39
|
if (e.code) {
|
|
45
40
|
this.pressedScancodes.add(e.code);
|
|
46
41
|
}
|
|
47
|
-
this.
|
|
42
|
+
this.dispatch('keypressed', [e.code, e.key]);
|
|
48
43
|
}
|
|
49
44
|
handleKeyUp(e) {
|
|
50
45
|
if (e.code) {
|
|
51
46
|
this.pressedScancodes.delete(e.code);
|
|
52
47
|
}
|
|
53
|
-
this.
|
|
48
|
+
this.dispatch('keyreleased', [e.code, e.key]);
|
|
54
49
|
}
|
|
55
50
|
handleBlur() {
|
|
56
51
|
this.pressedScancodes.clear();
|
|
57
52
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
window.removeEventListener('keyup', this.keyupHandler);
|
|
61
|
-
window.removeEventListener('blur', this.blurHandler);
|
|
53
|
+
_dispose() {
|
|
54
|
+
this.abort.abort();
|
|
62
55
|
this.pressedScancodes.clear();
|
|
63
56
|
}
|
|
64
57
|
isDown(scancode) {
|
package/dist/core/like.d.ts
CHANGED
|
@@ -1,23 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module like
|
|
3
|
+
* @description A catalogue of subsystems
|
|
4
|
+
*
|
|
5
|
+
* This is how we know what's part of like.
|
|
6
|
+
* `like.gfx`, `like.canvas`, and such.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
import type { AudioInternal } from './audio';
|
|
10
|
+
import type { TimerInternal } from './timer';
|
|
11
|
+
import type { InputInternal } from './input';
|
|
12
|
+
import type { KeyboardInternal } from './keyboard';
|
|
13
|
+
import type { MouseInternal } from './mouse';
|
|
14
|
+
import type { GamepadInternal } from './gamepad';
|
|
15
|
+
import type { CanvasInternal } from './canvas';
|
|
9
16
|
import type { BoundGraphics } from './graphics';
|
|
10
|
-
import
|
|
17
|
+
import { EventMap, EventType, LikeEvent } from './events';
|
|
18
|
+
import { TopLevelEventHandler } from '..';
|
|
19
|
+
import { Scene } from '../scene';
|
|
20
|
+
type Callback<K extends EventType> = (...args: EventMap[K]) => void;
|
|
21
|
+
type Callbacks = {
|
|
22
|
+
[K in EventType]?: Callback<K>;
|
|
23
|
+
};
|
|
24
|
+
export type LikeInternal = Callbacks & {
|
|
25
|
+
readonly audio: AudioInternal;
|
|
26
|
+
readonly timer: TimerInternal;
|
|
27
|
+
readonly input: InputInternal;
|
|
28
|
+
readonly keyboard: KeyboardInternal;
|
|
29
|
+
readonly mouse: MouseInternal;
|
|
30
|
+
readonly gamepad: GamepadInternal;
|
|
31
|
+
canvas: CanvasInternal;
|
|
32
|
+
/** Graphics context for rendering operations */
|
|
33
|
+
gfx: BoundGraphics;
|
|
34
|
+
/**
|
|
35
|
+
* Start the game loop. Call this only once.
|
|
36
|
+
* @returns Promise that resolves when the engine is ready
|
|
37
|
+
*/
|
|
38
|
+
start(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Clears out event listeners to avoid memory leaks.
|
|
41
|
+
*/
|
|
42
|
+
dispose(): void;
|
|
43
|
+
/**
|
|
44
|
+
* A simple way to set the current scene, which acts like a pluggable
|
|
45
|
+
* set of callbacks.
|
|
46
|
+
*
|
|
47
|
+
* Translates into `like.handleEvent = (event) => sceneDispatch(scene, like, event)`
|
|
48
|
+
* followed by dispatching a `load` event.
|
|
49
|
+
*
|
|
50
|
+
* {@link Scene} for detailed usage.
|
|
51
|
+
* @param scene Scene to load, leave out to use callbacks.
|
|
52
|
+
*/
|
|
53
|
+
setScene(scene?: Scene): void;
|
|
54
|
+
/**
|
|
55
|
+
* LIKE's runtime is built around calling handleEvent.
|
|
56
|
+
*
|
|
57
|
+
* For more advanced LIKE users, overriding this function allows you
|
|
58
|
+
* to create your own fundamental systems by writing an {@link TopLevelEventHandler}
|
|
59
|
+
*
|
|
60
|
+
* The built-in event handler amounts to calling `like[ev.type](...ev.args)`, as
|
|
61
|
+
* does the scene one which is a bit more like `yourScene[ev.type](like, ...ev.args)`.
|
|
62
|
+
*
|
|
63
|
+
* The code for them is very short and simple. Take a look if you're interested
|
|
64
|
+
* in building your own.
|
|
65
|
+
*/
|
|
66
|
+
handleEvent?: TopLevelEventHandler;
|
|
67
|
+
callOwnHandlers(event: LikeEvent): void;
|
|
68
|
+
};
|
|
11
69
|
/**
|
|
12
|
-
*
|
|
13
|
-
|
|
70
|
+
* A little helper that hides methods with underscores.
|
|
71
|
+
*/
|
|
72
|
+
type Public<T> = {
|
|
73
|
+
[K in keyof T as K extends `_${string}` ? never : K]: T[K];
|
|
74
|
+
};
|
|
75
|
+
type Canvas = Public<CanvasInternal>;
|
|
76
|
+
type Keyboard = Public<KeyboardInternal>;
|
|
77
|
+
type Mouse = Public<MouseInternal>;
|
|
78
|
+
type Audio = Public<AudioInternal>;
|
|
79
|
+
type Timer = Public<TimerInternal>;
|
|
80
|
+
type Input = Public<InputInternal>;
|
|
81
|
+
type Gamepad = Public<GamepadInternal>;
|
|
82
|
+
/**
|
|
83
|
+
* The main Like instance.
|
|
84
|
+
* Use this object much how you would the `love` object in Love2D.
|
|
85
|
+
* This is the interface returned by {@link createLike}.
|
|
86
|
+
*
|
|
87
|
+
* Assigns callbacks to handle events. See {@link EventMap} for all available events.
|
|
14
88
|
*
|
|
15
|
-
*
|
|
89
|
+
* Don't forget to call `await start()` when you're ready,
|
|
90
|
+
* and `dispose()` if you're done with it.
|
|
16
91
|
*/
|
|
17
|
-
export
|
|
18
|
-
/**
|
|
92
|
+
export type Like = LikeInternal & {
|
|
93
|
+
/** Canvas settings, including even Pixel Art mode. */
|
|
94
|
+
readonly canvas: Canvas;
|
|
95
|
+
/** Synchronous audio handles with global control. */
|
|
19
96
|
readonly audio: Audio;
|
|
20
|
-
/** Timer system for tracking time, delta, and
|
|
97
|
+
/** Timer system for tracking time, delta, FPS, and freezing the whole game. */
|
|
21
98
|
readonly timer: Timer;
|
|
22
99
|
/** Input system for action-based input handling */
|
|
23
100
|
readonly input: Input;
|
|
@@ -27,33 +104,10 @@ export interface Like {
|
|
|
27
104
|
readonly mouse: Mouse;
|
|
28
105
|
/** Gamepad input handling */
|
|
29
106
|
readonly gamepad: Gamepad;
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
setMode(mode: PartialCanvasMode): void;
|
|
37
|
-
/**
|
|
38
|
-
* Get the current canvas mode configuration.
|
|
39
|
-
* @returns The current canvas mode or undefined if not available
|
|
40
|
-
*/
|
|
41
|
-
getMode(): CanvasMode | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Get the current canvas size in pixels.
|
|
44
|
-
* @returns The canvas size as a Vector2 [width, height]
|
|
45
|
-
*/
|
|
46
|
-
getCanvasSize(): Vector2;
|
|
47
|
-
/**
|
|
48
|
-
* Set the active scene. Pass null to revert to global callbacks.
|
|
49
|
-
*/
|
|
50
|
-
setScene(scene: Scene | null): void;
|
|
51
|
-
}
|
|
52
|
-
export type { Audio, Source, SourceOptions } from './audio';
|
|
53
|
-
export type { Timer } from './timer';
|
|
54
|
-
export type { Input, InputBinding, InputType } from './input';
|
|
55
|
-
export type { Keyboard } from './keyboard';
|
|
56
|
-
export type { Mouse, MousePositionTransform } from './mouse';
|
|
57
|
-
export type { Gamepad, StickPosition, ButtonCallback } from './gamepad';
|
|
58
|
-
export type { CanvasMode, PartialCanvasMode } from './canvas-config';
|
|
107
|
+
/** Look at {@link handleEvent} -- it serves the same purpose. */
|
|
108
|
+
run?: never;
|
|
109
|
+
/** I think you meant to type like.canvas instead. */
|
|
110
|
+
window?: never;
|
|
111
|
+
};
|
|
112
|
+
export {};
|
|
59
113
|
//# sourceMappingURL=like.d.ts.map
|
package/dist/core/like.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"like.d.ts","sourceRoot":"","sources":["../../src/core/like.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"like.d.ts","sourceRoot":"","sources":["../../src/core/like.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS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,KAAK,CAAC;IAEtB,6BAA6B;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,iEAAiE;IACjE,GAAG,CAAC,EAAE,KAAK,CAAC;IAEZ,sDAAsD;IACtD,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB,CAAA"}
|
package/dist/core/like.js
CHANGED
package/dist/core/mouse.d.ts
CHANGED
|
@@ -1,29 +1,52 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { EngineDispatch } from '../engine';
|
|
2
|
+
import { type Vector2 } from '../math/vector2';
|
|
3
|
+
import { type MouseButton } from './events';
|
|
4
|
+
/**
|
|
5
|
+
* Mouse input handling. Bound to canvas. Emits relative movement when pointer locked.
|
|
6
|
+
* Buttons: 1 = left, 2 = middle, 3 = right.
|
|
7
|
+
*/
|
|
8
|
+
export declare class MouseInternal {
|
|
9
|
+
private canvas;
|
|
10
|
+
private dispatch;
|
|
11
|
+
private pos;
|
|
12
|
+
private lastPos;
|
|
6
13
|
private buttons;
|
|
7
|
-
|
|
8
|
-
private
|
|
9
|
-
|
|
10
|
-
private mousedownHandler;
|
|
11
|
-
private mouseupHandler;
|
|
12
|
-
private blurHandler;
|
|
13
|
-
constructor(transformFn?: MousePositionTransform);
|
|
14
|
-
setTransform(transformFn: MousePositionTransform | undefined): void;
|
|
14
|
+
private cursorVisible;
|
|
15
|
+
private abort;
|
|
16
|
+
constructor(canvas: HTMLCanvasElement, dispatch: EngineDispatch);
|
|
15
17
|
private handleMouseMove;
|
|
16
18
|
private handleMouseDown;
|
|
17
19
|
private handleMouseUp;
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
+
private handleWheel;
|
|
21
|
+
_dispose(): void;
|
|
22
|
+
/** Mouse position, transformed to canvas pixels. */
|
|
20
23
|
getPosition(): Vector2;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
getPressedButtons(): Set<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
/** Check if button is held. Button 1 = left, 2 = middle, 3 = right. */
|
|
25
|
+
isDown(button: MouseButton): boolean;
|
|
26
|
+
/** All currently held buttons. */
|
|
27
|
+
getPressedButtons(): Set<MouseButton>;
|
|
28
|
+
/** True when pointer is locked to canvas.
|
|
29
|
+
* {@link lockPointer}
|
|
30
|
+
*/
|
|
31
|
+
isPointerLocked(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether to lock (capture) the pointer.
|
|
34
|
+
*
|
|
35
|
+
* In locked mode, the cursor cannot escape the canvas.
|
|
36
|
+
* It also becomes invisible.
|
|
37
|
+
*
|
|
38
|
+
* Note that event {@link mousemoved} passes both
|
|
39
|
+
* `pos` and `delta`.
|
|
40
|
+
*
|
|
41
|
+
* Though the emulated cursor in locked mode
|
|
42
|
+
* (locked mode doesn't natively track absolute position)
|
|
43
|
+
* may be stuck on canvas edges, the `delta` field always
|
|
44
|
+
* represents mouse movement.
|
|
45
|
+
*/
|
|
46
|
+
lockPointer(locked: boolean): void;
|
|
47
|
+
/** Show or hide cursor. Unlike pointer lock, cursor can still leave canvas. */
|
|
48
|
+
showCursor(visible: boolean): void;
|
|
49
|
+
/** Current cursor visibility state. */
|
|
50
|
+
isCursorVisible(): boolean;
|
|
28
51
|
}
|
|
29
52
|
//# sourceMappingURL=mouse.d.ts.map
|
package/dist/core/mouse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mouse.d.ts","sourceRoot":"","sources":["../../src/core/mouse.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"mouse.d.ts","sourceRoot":"","sources":["../../src/core/mouse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAQ,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAM5C;;;GAGG;AACH,qBAAa,aAAa;IAOZ,OAAO,CAAC,MAAM;IAAqB,OAAO,CAAC,QAAQ;IAN/D,OAAO,CAAC,GAAG,CAAmB;IAC9B,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,KAAK,CAAyB;gBAElB,MAAM,EAAE,iBAAiB,EAAU,QAAQ,EAAE,cAAc;IAQ/E,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,WAAW;IAInB,QAAQ,IAAI,IAAI;IAIhB,oDAAoD;IACpD,WAAW,IAAI,OAAO;IAItB,uEAAuE;IACvE,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO;IAIpC,kCAAkC;IAClC,iBAAiB,IAAI,GAAG,CAAC,WAAW,CAAC;IAIrC;;OAEG;IACH,eAAe,IAAI,OAAO;IAI1B;;;;;;;;;;;;;MAaE;IACF,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;IAUlC,+EAA+E;IAC/E,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAOlC,uCAAuC;IACvC,eAAe,IAAI,OAAO;CAG3B"}
|