@yagejs/input 0.3.0 → 0.5.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/dist/index.d.ts CHANGED
@@ -1,166 +1,6 @@
1
- import { Vec2, ServiceKey, RendererAdapter, Plugin, EngineContext, SystemScheduler } from '@yagejs/core';
2
-
3
- /** Central input state manager. Resolved via DI with InputManagerKey. */
4
- declare class InputManager {
5
- private pressedKeys;
6
- private justPressedKeys;
7
- private justReleasedKeys;
8
- private holdStart;
9
- private actionMap;
10
- private defaultBindings;
11
- private groups;
12
- private actionGroups;
13
- private disabledGroups;
14
- private pointerScreenPos;
15
- private pointerDownState;
16
- private camera;
17
- private elapsedMs;
18
- private listenResolve;
19
- /** Whether any key mapped to this action is currently held. */
20
- isPressed(action: string): boolean;
21
- /** Whether any key mapped to this action was pressed this frame. */
22
- isJustPressed(action: string): boolean;
23
- /** Whether any key mapped to this action was released this frame. */
24
- isJustReleased(action: string): boolean;
25
- /** Returns true if any key bound to the action exists in the given set. */
26
- private anyKeyInSet;
27
- /** Milliseconds the action has been held. Returns 0 if not held. */
28
- getHoldDuration(action: string): number;
29
- /** Whether the action has been held for at least `minTime` ms. */
30
- isHeldFor(action: string, minTime: number): boolean;
31
- /** Returns -1, 0, or 1 based on negative/positive action states. */
32
- getAxis(negative: string, positive: string): number;
33
- /** Returns a Vec2 from four directional actions. Not normalized. */
34
- getVector(left: string, right: string, up: string, down: string): Vec2;
35
- /** Pointer position in world coordinates (via Camera), or screen coords if no camera. */
36
- getPointerPosition(): Vec2;
37
- /** Raw pointer position in screen coordinates. */
38
- getPointerScreenPosition(): Vec2;
39
- /** Whether any pointer button is currently held. */
40
- isPointerDown(): boolean;
41
- /** Replace the entire action map and store it as the default for {@link resetBindings}. */
42
- setActionMap(actions: ActionMapDefinition): void;
43
- /** Add a key binding to an action. Creates the action if it doesn't exist. */
44
- bindKey(action: string, key: string): void;
45
- /** Remove a key binding from an action. */
46
- unbindKey(action: string, key: string): void;
47
- /** Returns the current key bindings for an action, or an empty array if unmapped. */
48
- getBindings(action: string): readonly string[];
49
- /** Returns all action names that have the given key bound. */
50
- getActionsForKey(key: string): string[];
51
- /**
52
- * Rebind a key to an action with optional conflict detection.
53
- * Conflicts are only detected between actions sharing at least one group.
54
- */
55
- rebind(action: string, key: string, opts?: RebindOptions): RebindResult;
56
- /**
57
- * Finds the first action that uses the given key AND shares at least one
58
- * group with the target action. Ungrouped actions never conflict.
59
- */
60
- private findConflictInGroups;
61
- /** Reset bindings to defaults. If an action name is provided, only reset that action. */
62
- resetBindings(action?: string): void;
63
- /** Export the current bindings as a plain object for serialization. */
64
- exportBindings(): ActionMapDefinition;
65
- /** Load bindings from a plain object. Resets to defaults first, then overlays the provided map. */
66
- loadBindings(map: ActionMapDefinition): void;
67
- /** Configure input groups. Group name -> array of action names. */
68
- setGroups(groups: Record<string, string[]>): void;
69
- /** Enable a group by name. */
70
- enableGroup(name: string): void;
71
- /** Disable a group by name. Actions only in disabled groups become inactive. */
72
- disableGroup(name: string): void;
73
- /** Set exactly these groups as active; all others are disabled. */
74
- setActiveGroups(names: string[]): void;
75
- /** Whether a group is currently enabled. Returns true for unknown group names. */
76
- isGroupEnabled(name: string): boolean;
77
- /** Get all configured group names. */
78
- getGroups(): string[];
79
- /** Get the action names belonging to a group. Returns empty array for unknown groups. */
80
- getGroupActions(name: string): readonly string[];
81
- /** Returns true if the action is ungrouped or any of its groups is enabled. */
82
- private isActionEnabled;
83
- /** Returns a promise that resolves with the next key code pressed. Intercepts the key. */
84
- listenForNextKey(): Promise<string | null>;
85
- /** Cancel an active {@link listenForNextKey}. Resolves the pending promise with `null`. */
86
- cancelListen(): void;
87
- /** @internal */
88
- _onKeyDown(code: string): void;
89
- /** @internal */
90
- _onKeyUp(code: string): void;
91
- /** @internal */
92
- _onPointerMove(screenX: number, screenY: number): void;
93
- /** @internal */
94
- _onPointerDown(): void;
95
- /** @internal */
96
- _onPointerUp(): void;
97
- /** @internal Clear per-frame justPressed/justReleased flags. */
98
- _clearFrameState(): void;
99
- /** Set camera for pointer world-coord conversion. */
100
- setCamera(camera: CameraLike): void;
101
- /** Clear the camera reference (e.g. on scene exit). */
102
- clearCamera(): void;
103
- /** Get all configured action names. */
104
- getActionNames(): string[];
105
- /** @internal Advance the elapsed game-time clock. Called by InputPollSystem. */
106
- _advanceTime(dtMs: number): void;
107
- }
108
-
109
- /** Service key for the InputManager. */
110
- declare const InputManagerKey: ServiceKey<InputManager>;
111
- /** Minimal camera surface needed by InputManager for pointer world-coord conversion. */
112
- interface CameraLike {
113
- screenToWorld(screenX: number, screenY: number): {
114
- x: number;
115
- y: number;
116
- };
117
- }
118
- /**
119
- * Minimal renderer surface needed by InputPlugin for canvas access and
120
- * coordinate mapping. Alias of the cross-package `RendererAdapter` contract.
121
- */
122
- type RendererLike = RendererAdapter;
123
- /** Configuration for the InputPlugin. */
124
- interface InputConfig {
125
- /** Target element for pointer events (default: canvas from renderer, or document). */
126
- target?: HTMLElement;
127
- /** Action map: action name -> array of physical key codes. */
128
- actions?: ActionMapDefinition;
129
- /** Input groups: group name -> array of action names belonging to it. */
130
- groups?: Record<string, string[]>;
131
- /** Key codes to call preventDefault() on (default: none). */
132
- preventDefaultKeys?: string[];
133
- /**
134
- * Optional override for the renderer service key. When omitted, InputPlugin
135
- * auto-resolves `RendererAdapterKey` — the canonical `@yagejs/renderer`
136
- * plugin registers itself under that key, so pointer events target its
137
- * canvas and coordinates route through `canvasToVirtual` out of the box.
138
- * Set this only if you ship a custom renderer registered under a different
139
- * key.
140
- */
141
- rendererKey?: ServiceKey<RendererAdapter>;
142
- }
143
- /** Maps action names to arrays of physical key codes. */
144
- type ActionMapDefinition = Record<string, string[]>;
145
- /** How to handle a conflict when rebinding a key already used by another action in the same group. */
146
- type InputConflictPolicy = "replace" | "keep-both" | "reject";
147
- /** Options for {@link InputManager.rebind}. */
148
- interface RebindOptions {
149
- /** Index of the binding slot to replace. Appends if the slot does not exist. */
150
- slot?: number;
151
- /** How to resolve conflicts with other actions in the same group(s). Default: `"reject"`. */
152
- conflict?: InputConflictPolicy;
153
- }
154
- /** Result of a {@link InputManager.rebind} call. */
155
- interface RebindResult {
156
- /** Whether the rebind succeeded. */
157
- ok: boolean;
158
- /** Present when `ok` is false due to a conflict with `conflict: "reject"`. */
159
- conflict?: {
160
- action: string;
161
- key: string;
162
- };
163
- }
1
+ import { Plugin, EngineContext, SystemScheduler } from '@yagejs/core';
2
+ import { I as InputConfig } from './api-BaItBbSe.js';
3
+ export { A as ActionMapDefinition, C as CameraLike, G as GamepadAxisKey, a as GamepadInfo, b as InputConflictPolicy, c as InputManager, d as InputManagerKey, P as PointerInfo, e as PointerType, R as RebindOptions, f as RebindResult, g as RendererLike } from './api-BaItBbSe.js';
164
4
 
165
5
  /** Input plugin — wires keyboard and pointer listeners, registers InputManager. */
166
6
  declare class InputPlugin implements Plugin {
@@ -180,4 +20,4 @@ declare class InputPlugin implements Plugin {
180
20
  /** Returns a human-readable display name for a `KeyboardEvent.code` or mouse key string. */
181
21
  declare function getKeyDisplayName(code: string): string;
182
22
 
183
- export { type ActionMapDefinition, type CameraLike, type InputConfig, type InputConflictPolicy, InputManager, InputManagerKey, InputPlugin, type RebindOptions, type RebindResult, type RendererLike, getKeyDisplayName };
23
+ export { InputConfig, InputPlugin, getKeyDisplayName };