forked from Blendman974/faceclaw
Add touch-down event to simulated and watch inputs
This commit is contained in:
1 parent
45d2ece0d2
commit
2052e268b0
19 files changed
+191
-35
No files matched your search
@@ -17,8 +17,9 @@
|
||||
* fall back to raster (the planner needs a non-negative origin), which is
|
||||
* small and rare.
|
||||
*
|
||||
* Controls (a watch swipe in either direction is the primary flap):
|
||||
* ring-press flaps immediately; watch swipes/clicks also flap. Double-click pauses;
|
||||
* Controls: a touch-down on the ring or watch pad (ring-press) flaps
|
||||
* immediately; a click, a watch swipe in either direction or a crown turn
|
||||
* without one flaps too. Double-click pauses;
|
||||
* tap-then-hold opens the window menu. Ready / paused / game over: click or
|
||||
* a swipe starts or resumes, double-click yields focus. Losing input focus
|
||||
* mid-flight (a shell overlay such as the system menu or a notification,
|
||||
@@ -45,6 +46,7 @@ import {
|
||||
GESTURE_CLICK,
|
||||
GESTURE_DOUBLE_CLICK,
|
||||
type InputEvent,
|
||||
PressTracker,
|
||||
} from "../../ui/gestures";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import {
|
||||
@@ -153,6 +155,8 @@ type FlappyWindow = {
|
||||
lastMinorSfxAtMs: number;
|
||||
soundOn: boolean;
|
||||
lastSubmittedFingerprint: string;
|
||||
/** Which gestures already flapped on their ring-press. */
|
||||
presses: PressTracker;
|
||||
};
|
||||
|
||||
const windows = new Map<string, FlappyWindow>();
|
||||
@@ -210,6 +214,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
||||
lastMinorSfxAtMs: 0,
|
||||
soundOn: loadSoundEnabled("flappy"),
|
||||
lastSubmittedFingerprint: "",
|
||||
presses: new PressTracker(),
|
||||
};
|
||||
resetGame(window);
|
||||
windows.set(message.windowId, window);
|
||||
@@ -374,6 +379,7 @@ function windowMenu(window: FlappyWindow): WindowMenu {
|
||||
// --- Input ------------------------------------------------------------------
|
||||
|
||||
function handleInput(window: FlappyWindow, event: InputEvent, frameId: number): void {
|
||||
const followsPress = window.presses.followsPress(event);
|
||||
// An open window menu owns all input (it closes itself via pop); menus are
|
||||
// list UIs, so watch swipes take their standard fallback meanings there.
|
||||
if (window.menu?.isOpen()) {
|
||||
@@ -398,7 +404,7 @@ function handleInput(window: FlappyWindow, event: InputEvent, frameId: number):
|
||||
switch (window.phase) {
|
||||
case "ready":
|
||||
case "playing":
|
||||
handleFlightInput(window, event, frameId);
|
||||
handleFlightInput(window, event, frameId, followsPress);
|
||||
break;
|
||||
case "dying":
|
||||
// Let the tumble finish; a flap mashed during it must not restart.
|
||||
@@ -410,22 +416,24 @@ function handleInput(window: FlappyWindow, event: InputEvent, frameId: number):
|
||||
}
|
||||
}
|
||||
|
||||
/** Input while ready or flying: the flap gestures, plus pause. */
|
||||
function handleFlightInput(window: FlappyWindow, event: InputEvent, frameId: number): void {
|
||||
/**
|
||||
* Input while ready or flying: the flap gestures, plus pause. `followsPress`
|
||||
* marks a gesture whose touch-down already flapped (see PressTracker).
|
||||
*/
|
||||
function handleFlightInput(window: FlappyWindow, event: InputEvent, frameId: number, followsPress: boolean): void {
|
||||
switch (event.type) {
|
||||
case "ring-press":
|
||||
flap(window);
|
||||
break;
|
||||
// Either swipe direction flaps: on the watch the flap is a reflex, and
|
||||
// which way the thumb went shouldn't matter.
|
||||
case "swipe-up":
|
||||
case "swipe-down":
|
||||
case "ring-press":
|
||||
flap(window);
|
||||
break;
|
||||
case "click":
|
||||
// The ring already flapped on down; its later click must not flap again.
|
||||
if (event.source !== "ring") flap(window);
|
||||
if (!followsPress) flap(window);
|
||||
break;
|
||||
case "scroll-up":
|
||||
if (event.source === "watch") flap(window);
|
||||
if (event.source === "watch" && !followsPress) flap(window);
|
||||
break;
|
||||
case "double-click":
|
||||
if (window.phase === "playing") {
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* keep the BLE payload down to the dirty region around the ball.
|
||||
*
|
||||
* Controls (ball ready): scroll sets launch power, click launches. In play:
|
||||
* ring-press flips both flippers for 300 ms; click launches from the plunger,
|
||||
* a touch-down (ring-press) flips both flippers for 300 ms, as does a click
|
||||
* without one; click launches from the plunger,
|
||||
* double-click pauses. Swipes no longer trigger individual flippers;
|
||||
* up/down raise and lower launch power at the plunger.
|
||||
* Paused/game over: click resumes or starts a new game, double-click yields
|
||||
@@ -42,6 +43,7 @@ import {
|
||||
GESTURE_DOUBLE_CLICK,
|
||||
GESTURE_SCROLL,
|
||||
type InputEvent,
|
||||
PressTracker,
|
||||
} from "../../ui/gestures";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
|
||||
@@ -273,6 +275,8 @@ type PinballWindow = {
|
||||
lastMinorSfxAtMs: number;
|
||||
soundOn: boolean;
|
||||
lastSubmittedFingerprint: string;
|
||||
/** Which gestures already flipped on their ring-press. */
|
||||
presses: PressTracker;
|
||||
};
|
||||
|
||||
const windows = new Map<string, PinballWindow>();
|
||||
@@ -336,6 +340,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
||||
lastMinorSfxAtMs: 0,
|
||||
soundOn: loadSoundEnabled("pinball"),
|
||||
lastSubmittedFingerprint: "",
|
||||
presses: new PressTracker(),
|
||||
};
|
||||
windows.set(message.windowId, window);
|
||||
break;
|
||||
@@ -491,6 +496,7 @@ function windowMenu(window: PinballWindow): WindowMenu {
|
||||
}
|
||||
|
||||
function handleInput(window: PinballWindow, event: InputEvent, frameId: number): void {
|
||||
const followsPress = window.presses.followsPress(event);
|
||||
// An open window menu owns all input (it closes itself via pop); menus are
|
||||
// list UIs, so watch swipes take their standard fallback meanings there.
|
||||
if (window.menu?.isOpen()) {
|
||||
@@ -502,13 +508,14 @@ function handleInput(window: PinballWindow, event: InputEvent, frameId: number):
|
||||
}
|
||||
|
||||
if (window.phase === "playing") {
|
||||
handlePlayingInput(window, event, frameId);
|
||||
handlePlayingInput(window, event, frameId, followsPress);
|
||||
} else {
|
||||
handleIdleInput(window, event, frameId);
|
||||
}
|
||||
}
|
||||
|
||||
function handlePlayingInput(window: PinballWindow, event: InputEvent, frameId: number): void {
|
||||
/** `followsPress` marks a gesture whose touch-down already flipped (see PressTracker). */
|
||||
function handlePlayingInput(window: PinballWindow, event: InputEvent, frameId: number, followsPress: boolean): void {
|
||||
const ready = window.ballState === "ready";
|
||||
switch (event.type) {
|
||||
case "scroll-up":
|
||||
@@ -539,7 +546,7 @@ function handlePlayingInput(window: PinballWindow, event: InputEvent, frameId: n
|
||||
case "click":
|
||||
if (ready) {
|
||||
launchBall(window);
|
||||
} else if (event.source !== "ring") {
|
||||
} else if (!followsPress) {
|
||||
flip(window, window.flippers[0]!);
|
||||
flip(window, window.flippers[1]!);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user