@caperjs/core 0.3.0 → 0.4.1
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/build/assetpack.mjs +90 -0
- package/build/index.d.mts +29 -0
- package/build/plugins/pruneFallbacks.mjs +25 -2
- package/lib/{CaptionsPlugin-BLbLl3WB.js → CaptionsPlugin-cSJj-R9M.js} +4 -4
- package/lib/{CaptionsPlugin-BLbLl3WB.js.map → CaptionsPlugin-cSJj-R9M.js.map} +1 -1
- package/lib/{DataAdapter-aHSNM_26.js → DataAdapter-D2tc6hx9.js} +5 -5
- package/lib/{DataAdapter-aHSNM_26.js.map → DataAdapter-D2tc6hx9.js.map} +1 -1
- package/lib/{DebugRenderer-8LjHtBzA.js → DebugRenderer-CGUKy6Fy.js} +2 -2
- package/lib/{DebugRenderer-8LjHtBzA.js.map → DebugRenderer-CGUKy6Fy.js.map} +1 -1
- package/lib/{DevToolsPlugin-Vrk6aOtS.js → DevToolsPlugin-B8GX3H9b.js} +2 -2
- package/lib/{DevToolsPlugin-Vrk6aOtS.js.map → DevToolsPlugin-B8GX3H9b.js.map} +1 -1
- package/lib/{GSAPPlugin-Hm3F4zdg.js → GSAPPlugin-Br9AjuTD.js} +5 -5
- package/lib/{GSAPPlugin-Hm3F4zdg.js.map → GSAPPlugin-Br9AjuTD.js.map} +1 -1
- package/lib/{LayoutPlugin-Dpgeawfw.js → LayoutPlugin-BX3OP7pw.js} +4 -4
- package/lib/{LayoutPlugin-Dpgeawfw.js.map → LayoutPlugin-BX3OP7pw.js.map} +1 -1
- package/lib/{SpinePlugin-B08yAw1S.js → SpinePlugin-C-JDdXpf.js} +2 -2
- package/lib/{SpinePlugin-B08yAw1S.js.map → SpinePlugin-C-JDdXpf.js.map} +1 -1
- package/lib/{StatsPlugin-D2Xa5j97.js → StatsPlugin-yJlJtoQ2.js} +7 -10
- package/lib/{StatsPlugin-D2Xa5j97.js.map → StatsPlugin-yJlJtoQ2.js.map} +1 -1
- package/lib/{VoiceOverPlugin-qtFlqpRn.js → VoiceOverPlugin-DjSZp4Ko.js} +4 -4
- package/lib/{VoiceOverPlugin-qtFlqpRn.js.map → VoiceOverPlugin-DjSZp4Ko.js.map} +1 -1
- package/lib/caper.mjs +156 -1927
- package/lib/caper.mjs.map +1 -1
- package/lib/const-C3sxeYhl.js +1746 -0
- package/lib/const-C3sxeYhl.js.map +1 -0
- package/lib/core/create.d.ts.map +1 -1
- package/lib/padding-1kHDpGlQ.js +41 -0
- package/lib/padding-1kHDpGlQ.js.map +1 -0
- package/lib/plugins/FullScreenPlugin.d.ts +0 -5
- package/lib/plugins/FullScreenPlugin.d.ts.map +1 -1
- package/lib/plugins/KeyboardPlugin.d.ts +0 -1
- package/lib/plugins/KeyboardPlugin.d.ts.map +1 -1
- package/lib/plugins/Plugin.d.ts +101 -2
- package/lib/plugins/Plugin.d.ts.map +1 -1
- package/lib/plugins/SceneManagerPlugin.d.ts +0 -1
- package/lib/plugins/SceneManagerPlugin.d.ts.map +1 -1
- package/lib/plugins/StatsPlugin.d.ts +0 -1
- package/lib/plugins/StatsPlugin.d.ts.map +1 -1
- package/lib/plugins/TimerPlugin.d.ts.map +1 -1
- package/lib/plugins/WebEventsPlugin.d.ts +0 -1
- package/lib/plugins/WebEventsPlugin.d.ts.map +1 -1
- package/lib/plugins/breakpoints/BreakpointPlugin.d.ts.map +1 -1
- package/lib/plugins/gesture/GesturePlugin.d.ts.map +1 -1
- package/lib/plugins/input/AbstractControls.d.ts +46 -7
- package/lib/plugins/input/AbstractControls.d.ts.map +1 -1
- package/lib/plugins/input/InputPlugin.d.ts.map +1 -1
- package/lib/plugins/input/controlsCore.d.ts +58 -0
- package/lib/plugins/input/controlsCore.d.ts.map +1 -0
- package/lib/plugins/input/controlsCore.test.d.ts +2 -0
- package/lib/plugins/input/controlsCore.test.d.ts.map +1 -0
- package/lib/plugins/input/keyboard/KeyboardControls.d.ts +15 -0
- package/lib/plugins/input/keyboard/KeyboardControls.d.ts.map +1 -0
- package/lib/plugins/input/keyboard/index.d.ts +1 -1
- package/lib/plugins/input/keyboard/index.d.ts.map +1 -1
- package/lib/plugins/input/touch/VirtualControls.d.ts +7 -19
- package/lib/plugins/input/touch/VirtualControls.d.ts.map +1 -1
- package/lib/{registries-m2vKTIih.js → registries-BfV-VF7a.js} +565 -552
- package/lib/registries-BfV-VF7a.js.map +1 -0
- package/package.json +2 -1
- package/src/core/create.ts +11 -0
- package/src/plugins/FullScreenPlugin.ts +5 -18
- package/src/plugins/KeyboardPlugin.ts +3 -10
- package/src/plugins/Plugin.test.ts +130 -2
- package/src/plugins/Plugin.ts +159 -3
- package/src/plugins/SceneManagerPlugin.ts +3 -8
- package/src/plugins/StatsPlugin.ts +3 -10
- package/src/plugins/TimerPlugin.ts +1 -2
- package/src/plugins/WebEventsPlugin.ts +9 -18
- package/src/plugins/breakpoints/BreakpointPlugin.ts +1 -2
- package/src/plugins/captions/CaptionsPlugin.ts +1 -1
- package/src/plugins/gesture/GesturePlugin.ts +4 -8
- package/src/plugins/input/AbstractControls.ts +103 -8
- package/src/plugins/input/Controls.test.ts +56 -0
- package/src/plugins/input/InputPlugin.ts +6 -14
- package/src/plugins/input/controlsCore.test.ts +151 -0
- package/src/plugins/input/controlsCore.ts +162 -0
- package/src/plugins/input/keyboard/KeyboardControls.ts +84 -0
- package/src/plugins/input/keyboard/index.ts +1 -1
- package/src/plugins/input/touch/VirtualControls.ts +41 -142
- package/src/version.ts +1 -1
- package/lib/plugins/input/keyboard/KeyboardContols.d.ts +0 -33
- package/lib/plugins/input/keyboard/KeyboardContols.d.ts.map +0 -1
- package/lib/registries-m2vKTIih.js.map +0 -1
- package/src/plugins/input/keyboard/KeyboardContols.ts +0 -206
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { Application } from '../../../core/Application';
|
|
2
|
-
import { WithSignals } from '../../../mixins/signals';
|
|
3
|
-
import { bindAllMethods, Logger } from '../../../utils';
|
|
4
|
-
import type { Action } from '../../actions';
|
|
5
|
-
import { normalizeKey, type KeyboardEventDetail } from '../../KeyboardPlugin';
|
|
6
|
-
import { AbstractControls } from '../AbstractControls';
|
|
7
|
-
import type { ControlsActionMap, KeyboardControlsMap, KeyboardControlsScheme } from '../types';
|
|
8
|
-
|
|
9
|
-
export class KeyboardControls extends WithSignals(AbstractControls) {
|
|
10
|
-
protected scheme: Partial<KeyboardControlsMap>;
|
|
11
|
-
private _keyDownMap: Partial<KeyboardControlsScheme>;
|
|
12
|
-
private _keyUpMap: Partial<KeyboardControlsScheme>;
|
|
13
|
-
private _keyCombinations: string[][] = [];
|
|
14
|
-
private _singleDownKeys: Set<string> = new Set();
|
|
15
|
-
private _keyCombinationsMap: Map<string[], Action> = new Map();
|
|
16
|
-
private _activeDownKeys: Map<string, Action> = new Map();
|
|
17
|
-
private _activeUpKeys: Map<string, Action> = new Map();
|
|
18
|
-
private _warnedMissingActions: Set<string> = new Set();
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
super();
|
|
22
|
-
bindAllMethods(this);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get app() {
|
|
26
|
-
return Application.getInstance();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
isActionActive(action: Action): boolean {
|
|
30
|
-
const controlsAction = this.scheme['down']?.[action] ?? null;
|
|
31
|
-
if (!controlsAction) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
if (Array.isArray(controlsAction)) {
|
|
35
|
-
return controlsAction.some((key) => this._isInputActive(key));
|
|
36
|
-
} else {
|
|
37
|
-
return this._isInputActive(controlsAction);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public initialize(scheme: Partial<KeyboardControlsMap>): void {
|
|
42
|
-
super.initialize(scheme as Partial<ControlsActionMap>);
|
|
43
|
-
this._keyDownMap = scheme.down || {};
|
|
44
|
-
this._keyUpMap = scheme.up || {};
|
|
45
|
-
this._sortActions();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public connect() {
|
|
49
|
-
this.addSignalConnection(
|
|
50
|
-
this.app.signal.onActionContextChanged.connect(this._handleContextChanged),
|
|
51
|
-
this.app.keyboard.onKeyDown().connect(this._handleKeyDown),
|
|
52
|
-
this.app.keyboard.onKeyUp().connect(this._handleKeyUp),
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
this._handleContextChanged();
|
|
56
|
-
this.app.ticker.add(this._update);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public destroy(): void {
|
|
60
|
-
this.app.ticker.remove(this._update);
|
|
61
|
-
super.destroy();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** A single key, or a `+` separated combination requiring every key to be down. */
|
|
65
|
-
private _isInputActive(input: string): boolean {
|
|
66
|
-
if (input.includes('+')) {
|
|
67
|
-
return input.split('+').every((key) => this._singleDownKeys.has(key));
|
|
68
|
-
}
|
|
69
|
-
return this._singleDownKeys.has(input);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private _warnMissingAction(key: string) {
|
|
73
|
-
if (this._warnedMissingActions.has(key)) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
this._warnedMissingActions.add(key);
|
|
77
|
-
Logger.warn(`KeyboardControls: scheme references unknown action "${key}"`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private _sortActions() {
|
|
81
|
-
const actions = this.app.actionsPlugin.getActions();
|
|
82
|
-
this._keyCombinations = [];
|
|
83
|
-
this._keyCombinationsMap.clear();
|
|
84
|
-
this._activeDownKeys.clear();
|
|
85
|
-
this._activeUpKeys.clear();
|
|
86
|
-
let keys = Object.keys(this._keyDownMap);
|
|
87
|
-
|
|
88
|
-
keys.forEach((key) => {
|
|
89
|
-
const item = this._keyDownMap[key];
|
|
90
|
-
const action = actions[key];
|
|
91
|
-
if (!action) {
|
|
92
|
-
this._warnMissingAction(key);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
if (
|
|
96
|
-
action.context !== '*' &&
|
|
97
|
-
action.context !== this.app.actionContext &&
|
|
98
|
-
!action.context.includes(this.app.actionContext)
|
|
99
|
-
) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
let input = item;
|
|
103
|
-
if (input) {
|
|
104
|
-
if (!Array.isArray(input)) {
|
|
105
|
-
input = [input];
|
|
106
|
-
}
|
|
107
|
-
input.forEach((inputString: string) => {
|
|
108
|
-
if (inputString.includes('+')) {
|
|
109
|
-
const combo = inputString.split('+');
|
|
110
|
-
this._keyCombinations.push(combo);
|
|
111
|
-
this._keyCombinationsMap.set(combo, key as Action);
|
|
112
|
-
} else {
|
|
113
|
-
this._activeDownKeys.set(inputString, key as Action);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// sort them from the largest to smallest
|
|
120
|
-
this._keyCombinations.sort((a, b) => b.length - a.length);
|
|
121
|
-
|
|
122
|
-
keys = Object.keys(this._keyUpMap);
|
|
123
|
-
keys.forEach((key) => {
|
|
124
|
-
const item = this._keyUpMap[key];
|
|
125
|
-
let input = item;
|
|
126
|
-
if (input) {
|
|
127
|
-
if (!Array.isArray(input)) {
|
|
128
|
-
input = [input];
|
|
129
|
-
}
|
|
130
|
-
input.forEach((inputString: string) => {
|
|
131
|
-
this._activeUpKeys.set(inputString, key as Action);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
//Logger.log('keyDownMap', this._keyDownMap, 'activeDownKeys', this._activeDownKeys);
|
|
137
|
-
//Logger.log('keyUpMap', this._keyUpMap, 'activeUpKeys', this._activeUpKeys);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private _handleContextChanged() {
|
|
141
|
-
this._getPossibleActions();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
private _getPossibleActions() {
|
|
145
|
-
this._sortActions();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
private _handleKeyDown(detail: KeyboardEventDetail): void {
|
|
149
|
-
const key = normalizeKey(detail.event.key);
|
|
150
|
-
this._singleDownKeys.add(key);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
private _handleKeyUp(detail: KeyboardEventDetail): void {
|
|
154
|
-
const key = normalizeKey(detail.event.key);
|
|
155
|
-
this._singleDownKeys.delete(key);
|
|
156
|
-
|
|
157
|
-
const action = this._activeUpKeys.get(key);
|
|
158
|
-
if (action) {
|
|
159
|
-
this.app.action(action, { combination: false, inputState: 'up', key });
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
private _update() {
|
|
164
|
-
if (!this.app.keyboard) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
const keysDown = this.app.keyboard.keysDown;
|
|
168
|
-
if (keysDown.size === 0) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
const eliminated = new Set<string>();
|
|
172
|
-
// this._keyCombinations is already sorted from largest to smallest
|
|
173
|
-
for (let i = 0; i < this._keyCombinations.length; i++) {
|
|
174
|
-
const combination = this._keyCombinations[i];
|
|
175
|
-
// check if all of the keys in the combination are down
|
|
176
|
-
if (combination.some((key) => eliminated.has(key))) {
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
if (combination.every((key) => keysDown.has(key))) {
|
|
180
|
-
combination.forEach((key) => eliminated.add(key));
|
|
181
|
-
// send the action
|
|
182
|
-
const action = this._keyCombinationsMap.get(combination);
|
|
183
|
-
if (action) {
|
|
184
|
-
this.app.action(action, {
|
|
185
|
-
key: combination,
|
|
186
|
-
combination: true,
|
|
187
|
-
inputState: 'down',
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// order doesn't matter here
|
|
194
|
-
this._singleDownKeys.forEach((key) => {
|
|
195
|
-
if (eliminated.has(key)) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (keysDown.has(key)) {
|
|
199
|
-
const action = this._activeDownKeys.get(key);
|
|
200
|
-
if (action) {
|
|
201
|
-
this.app.action(action, { key, combination: false, inputState: 'down' });
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
}
|