@caperjs/core 0.3.0 → 0.4.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/build/assetpack.mjs +90 -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 +1 -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,28 +1,20 @@
|
|
|
1
|
-
import { bindAllMethods
|
|
2
|
-
import type { ControlsActionMap, JoystickControlsScheme, TouchControlsMap
|
|
1
|
+
import { bindAllMethods } from '../../../utils';
|
|
2
|
+
import type { ControlsActionMap, JoystickControlsScheme, TouchControlsMap } from '../types';
|
|
3
3
|
|
|
4
4
|
import { JoystickDirection } from '..';
|
|
5
|
-
import { Application } from '../../../core/Application';
|
|
6
|
-
import { WithSignals } from '../../../mixins/signals';
|
|
7
5
|
import type { SignalConnection } from '../../../signals';
|
|
8
6
|
import type { IButton, IJoystick } from '../../../ui';
|
|
9
7
|
import type { Action } from '../../actions';
|
|
10
8
|
import { AbstractControls } from '../AbstractControls';
|
|
9
|
+
import { evaluateCombinations } from '../controlsCore';
|
|
11
10
|
|
|
12
|
-
export class VirtualControls extends
|
|
11
|
+
export class VirtualControls extends AbstractControls {
|
|
13
12
|
protected scheme: Partial<TouchControlsMap>;
|
|
13
|
+
protected readonly logLabel = 'VirtualControls';
|
|
14
14
|
private _buttons: Set<IButton> = new Set();
|
|
15
|
-
private _joystickMap: Partial<JoystickControlsScheme>;
|
|
16
|
-
private _buttonDownMap: Partial<TouchControlsScheme>;
|
|
17
|
-
private _buttonUpMap: Partial<TouchControlsScheme>;
|
|
18
|
-
private _combinations: string[][] = [];
|
|
19
15
|
private _singleDownButtons: Set<string> = new Set();
|
|
20
16
|
private _activeJoystickDirections: Map<JoystickDirection, Action> = new Map();
|
|
21
|
-
private _activeButtonDownIds: Map<string, Action> = new Map();
|
|
22
|
-
private _activeButtonUpIds: Map<string, Action> = new Map();
|
|
23
|
-
private _combinationsMap: Map<string[], Action> = new Map();
|
|
24
17
|
private _buttonConnections: Map<IButton, SignalConnection[]> = new Map();
|
|
25
|
-
private _warnedMissingActions: Set<string> = new Set();
|
|
26
18
|
|
|
27
19
|
constructor() {
|
|
28
20
|
super();
|
|
@@ -39,10 +31,6 @@ export class VirtualControls extends WithSignals(AbstractControls) {
|
|
|
39
31
|
this._joystick = value;
|
|
40
32
|
}
|
|
41
33
|
|
|
42
|
-
get app() {
|
|
43
|
-
return Application.getInstance();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
34
|
addButton(button: IButton) {
|
|
47
35
|
if (!button || this._buttons.has(button)) {
|
|
48
36
|
return;
|
|
@@ -71,124 +59,40 @@ export class VirtualControls extends WithSignals(AbstractControls) {
|
|
|
71
59
|
|
|
72
60
|
public initialize(scheme: Partial<TouchControlsMap>): void {
|
|
73
61
|
super.initialize(scheme as Partial<ControlsActionMap>);
|
|
74
|
-
this._buttonDownMap = scheme.down || {};
|
|
75
|
-
this._buttonUpMap = scheme.up || {};
|
|
76
|
-
this._joystickMap = scheme.joystick || {};
|
|
77
|
-
this.addSignalConnection(this.app.signal.onActionContextChanged.connect(this._sortActions));
|
|
78
|
-
this._sortActions();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public connect() {
|
|
82
|
-
this.app.ticker.add(this._update);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public destroy(): void {
|
|
86
|
-
this.app.ticker.remove(this._update);
|
|
87
|
-
super.destroy();
|
|
88
62
|
}
|
|
89
63
|
|
|
90
64
|
isActionActive(action: Action): boolean {
|
|
91
65
|
const buttonAction = this.scheme['down']?.[action] ?? null;
|
|
92
66
|
if (buttonAction) {
|
|
93
|
-
|
|
94
|
-
|
|
67
|
+
return super.isActionActive(action);
|
|
68
|
+
}
|
|
69
|
+
const joystickAction = this.scheme['joystick']?.[action] ?? null;
|
|
70
|
+
if (this._joystick && joystickAction) {
|
|
71
|
+
if (Array.isArray(joystickAction)) {
|
|
72
|
+
return joystickAction.includes(this._joystick.direction);
|
|
95
73
|
} else {
|
|
96
|
-
return this.
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
const joystickAction = this.scheme['joystick']?.[action] ?? null;
|
|
100
|
-
if (this._joystick && joystickAction) {
|
|
101
|
-
if (Array.isArray(joystickAction)) {
|
|
102
|
-
return joystickAction.includes(this._joystick.direction);
|
|
103
|
-
} else {
|
|
104
|
-
return joystickAction === this._joystick?.direction;
|
|
105
|
-
}
|
|
74
|
+
return joystickAction === this._joystick?.direction;
|
|
106
75
|
}
|
|
107
76
|
}
|
|
108
77
|
return false;
|
|
109
78
|
}
|
|
110
79
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (input.includes('+')) {
|
|
114
|
-
return input.split('+').every((id) => this._singleDownButtons.has(id) || this._joystick?.direction === id);
|
|
115
|
-
}
|
|
116
|
-
return this._singleDownButtons.has(input);
|
|
80
|
+
protected isInputDown(id: string): boolean {
|
|
81
|
+
return this._singleDownButtons.has(id);
|
|
117
82
|
}
|
|
118
83
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
this._warnedMissingActions.add(key);
|
|
124
|
-
Logger.warn(`VirtualControls: scheme references unknown action "${key}"`);
|
|
84
|
+
/** A joystick direction can take part in a combination, but never stands alone. */
|
|
85
|
+
protected isComboPartDown(id: string): boolean {
|
|
86
|
+
return this._singleDownButtons.has(id) || this._joystick?.direction === id;
|
|
125
87
|
}
|
|
126
88
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this._combinations = [];
|
|
130
|
-
this._combinationsMap.clear();
|
|
131
|
-
this._activeJoystickDirections.clear();
|
|
132
|
-
this._activeButtonDownIds.clear();
|
|
133
|
-
this._activeButtonUpIds.clear();
|
|
134
|
-
|
|
135
|
-
let buttons = Object.keys(this._buttonDownMap);
|
|
136
|
-
buttons.forEach((key) => {
|
|
137
|
-
const item = this._buttonDownMap[key];
|
|
138
|
-
const action = actions[key];
|
|
139
|
-
if (!action) {
|
|
140
|
-
this._warnMissingAction(key);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (
|
|
144
|
-
action.context !== '*' &&
|
|
145
|
-
action.context !== this.app.actionContext &&
|
|
146
|
-
!action.context.includes(this.app.actionContext)
|
|
147
|
-
) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
let input = item;
|
|
151
|
-
if (input) {
|
|
152
|
-
if (!Array.isArray(input)) {
|
|
153
|
-
input = [input];
|
|
154
|
-
}
|
|
155
|
-
input.forEach((inputString) => {
|
|
156
|
-
if (inputString.includes('+')) {
|
|
157
|
-
const combo = inputString.split('+');
|
|
158
|
-
this._combinations.push(combo);
|
|
159
|
-
this._combinationsMap.set(combo, key as Action);
|
|
160
|
-
} else {
|
|
161
|
-
this._activeButtonDownIds.set(inputString, key as Action);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// sort them from the largest to smallest
|
|
168
|
-
this._combinations.sort((a, b) => b.length - a.length);
|
|
169
|
-
|
|
170
|
-
buttons = Object.keys(this._buttonUpMap);
|
|
171
|
-
buttons.forEach((key) => {
|
|
172
|
-
const item = this._buttonUpMap[key];
|
|
173
|
-
const action = actions[key];
|
|
174
|
-
if (!action) {
|
|
175
|
-
this._warnMissingAction(key);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
if (
|
|
179
|
-
action.context !== '*' &&
|
|
180
|
-
action.context !== this.app.actionContext &&
|
|
181
|
-
!action.context.includes(this.app.actionContext)
|
|
182
|
-
) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
this._activeButtonUpIds.set(item as string, key as Action);
|
|
186
|
-
});
|
|
89
|
+
protected _sortActions(): void {
|
|
90
|
+
super._sortActions();
|
|
187
91
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
let input =
|
|
92
|
+
this._activeJoystickDirections.clear();
|
|
93
|
+
const joystickMap: Partial<JoystickControlsScheme> = this.scheme.joystick || {};
|
|
94
|
+
Object.keys(joystickMap).forEach((key) => {
|
|
95
|
+
let input = joystickMap[key];
|
|
192
96
|
if (input) {
|
|
193
97
|
if (!Array.isArray(input)) {
|
|
194
98
|
input = [input];
|
|
@@ -206,7 +110,7 @@ export class VirtualControls extends WithSignals(AbstractControls) {
|
|
|
206
110
|
|
|
207
111
|
private _handleButtonUp(button: IButton): void {
|
|
208
112
|
this._singleDownButtons.delete(button.id!);
|
|
209
|
-
const action = this.
|
|
113
|
+
const action = this.activeUpInputs.get(button.id!);
|
|
210
114
|
if (action) {
|
|
211
115
|
this.app.action(action, {
|
|
212
116
|
combination: false,
|
|
@@ -216,30 +120,25 @@ export class VirtualControls extends WithSignals(AbstractControls) {
|
|
|
216
120
|
}
|
|
217
121
|
}
|
|
218
122
|
|
|
219
|
-
|
|
123
|
+
protected _update() {
|
|
220
124
|
const joystickDirection = this._joystick?.direction ?? null;
|
|
221
125
|
const buttonsDown = this._singleDownButtons;
|
|
222
|
-
|
|
223
|
-
// this.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
button: combination,
|
|
237
|
-
combination: true,
|
|
238
|
-
inputState: 'down',
|
|
239
|
-
});
|
|
240
|
-
}
|
|
126
|
+
|
|
127
|
+
// this.combinations is already sorted from largest to smallest
|
|
128
|
+
const { fired, eliminated } = evaluateCombinations(
|
|
129
|
+
this.combinations,
|
|
130
|
+
(key) => buttonsDown.has(key) || joystickDirection === key,
|
|
131
|
+
);
|
|
132
|
+
fired.forEach((combination) => {
|
|
133
|
+
const action = this.combinationsMap.get(combination);
|
|
134
|
+
if (action) {
|
|
135
|
+
this.app.action(action, {
|
|
136
|
+
button: combination,
|
|
137
|
+
combination: true,
|
|
138
|
+
inputState: 'down',
|
|
139
|
+
});
|
|
241
140
|
}
|
|
242
|
-
}
|
|
141
|
+
});
|
|
243
142
|
|
|
244
143
|
// order doesn't matter here
|
|
245
144
|
this._singleDownButtons.forEach((id) => {
|
|
@@ -247,7 +146,7 @@ export class VirtualControls extends WithSignals(AbstractControls) {
|
|
|
247
146
|
return;
|
|
248
147
|
}
|
|
249
148
|
if (buttonsDown.has(id)) {
|
|
250
|
-
const action = this.
|
|
149
|
+
const action = this.activeDownInputs.get(id);
|
|
251
150
|
if (action) {
|
|
252
151
|
this.app.action(action, {
|
|
253
152
|
button: id,
|
package/src/version.ts
CHANGED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Application } from '../../../core/Application';
|
|
2
|
-
import { Action } from '../../actions';
|
|
3
|
-
import { AbstractControls } from '../AbstractControls';
|
|
4
|
-
import { KeyboardControlsMap } from '../types';
|
|
5
|
-
declare const KeyboardControls_base: typeof AbstractControls & import('../../..').Constructor<import('../../..').ISignalContainer>;
|
|
6
|
-
export declare class KeyboardControls extends KeyboardControls_base {
|
|
7
|
-
protected scheme: Partial<KeyboardControlsMap>;
|
|
8
|
-
private _keyDownMap;
|
|
9
|
-
private _keyUpMap;
|
|
10
|
-
private _keyCombinations;
|
|
11
|
-
private _singleDownKeys;
|
|
12
|
-
private _keyCombinationsMap;
|
|
13
|
-
private _activeDownKeys;
|
|
14
|
-
private _activeUpKeys;
|
|
15
|
-
private _warnedMissingActions;
|
|
16
|
-
constructor();
|
|
17
|
-
get app(): Application;
|
|
18
|
-
isActionActive(action: Action): boolean;
|
|
19
|
-
initialize(scheme: Partial<KeyboardControlsMap>): void;
|
|
20
|
-
connect(): void;
|
|
21
|
-
destroy(): void;
|
|
22
|
-
/** A single key, or a `+` separated combination requiring every key to be down. */
|
|
23
|
-
private _isInputActive;
|
|
24
|
-
private _warnMissingAction;
|
|
25
|
-
private _sortActions;
|
|
26
|
-
private _handleContextChanged;
|
|
27
|
-
private _getPossibleActions;
|
|
28
|
-
private _handleKeyDown;
|
|
29
|
-
private _handleKeyUp;
|
|
30
|
-
private _update;
|
|
31
|
-
}
|
|
32
|
-
export {};
|
|
33
|
-
//# sourceMappingURL=KeyboardContols.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeyboardContols.d.ts","sourceRoot":"","sources":["../../../../src/plugins/input/keyboard/KeyboardContols.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAqB,mBAAmB,EAA0B,MAAM,UAAU,CAAC;;AAE/F,qBAAa,gBAAiB,SAAQ,qBAA6B;IACjE,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC/C,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,SAAS,CAAkC;IACnD,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,eAAe,CAA0B;IACjD,OAAO,CAAC,mBAAmB,CAAoC;IAC/D,OAAO,CAAC,eAAe,CAAkC;IACzD,OAAO,CAAC,aAAa,CAAkC;IACvD,OAAO,CAAC,qBAAqB,CAA0B;;IAOvD,IAAI,GAAG,gBAEN;IAED,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAYhC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,IAAI;IAOtD,OAAO;IAWP,OAAO,IAAI,IAAI;IAKtB,mFAAmF;IACnF,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,YAAY;IA4DpB,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,OAAO;CA2ChB"}
|