feat(pet): single-click petting, simplify multi-click handling

- Single click emits pet:clicked.
- Double click opens prompt window.
- Remove triple-click handling and shorten click timeout.
This commit is contained in:
VectorShell 2026-06-13 02:16:27 +00:00
parent 8761da5995
commit 46028c7065

View file

@ -94,7 +94,7 @@ ipcRenderer.on("openpets:pet-content-state", (_event, state) => {
const getInteractiveTarget = (event) => {
const target = document.elementFromPoint(event.clientX, event.clientY);
return target && target.closest(".pet-hitbox, .pet-shell, .bubble, .scale-handle");
return target && target.closest(".pet-hitbox, .pet-shell, .bubble");
};
const reportInteractiveHit = (interactive, source, force = false) => {
@ -140,7 +140,7 @@ ipcRenderer.on("openpets:pet-probe-hit-test", (_event, point) => {
const clientX = point.clientX;
const clientY = point.clientY;
const target = document.elementFromPoint(clientX, clientY);
reportInteractiveHit(Boolean(target && target.closest(".pet-hitbox, .pet-shell, .bubble, .scale-handle")) || dragging || scaling, typeof point.reason === "string" ? point.reason.slice(0, 80) : "probe", true);
reportInteractiveHit(Boolean(target && target.closest(".pet-hitbox, .pet-shell, .bubble")) || dragging || scaling, typeof point.reason === "string" ? point.reason.slice(0, 80) : "probe", true);
});
// --- Plugin bubble interactions (actions, inline inputs) -------------------
@ -187,18 +187,43 @@ const sendPetEvent = (name, payload) => {
};
const installPetSenses = () => {
let clickCount = 0;
let clickTimer = null;
let firstClickEvent = null;
const resetClickTimer = () => {
if (clickTimer) {
clearTimeout(clickTimer);
clickTimer = null;
}
};
const flushClicks = () => {
resetClickTimer();
if (clickCount === 1) {
sendPetEvent("pet:clicked", {});
} else if (clickCount === 2 && firstClickEvent) {
sendPetEvent("pet:doubleClicked", {});
requestPromptWindow(firstClickEvent);
}
clickCount = 0;
firstClickEvent = null;
};
document.addEventListener("click", (event) => {
if (event.button !== 0) return;
const target = event.target;
if (!(target instanceof Element)) return;
if (!target.closest(".pet-hitbox, .pet-shell")) return;
if (Date.now() < suppressClickUntil) return;
sendPetEvent("pet:clicked", {});
});
document.addEventListener("dblclick", (event) => {
const target = event.target;
if (!(target instanceof Element) || !target.closest(".pet-hitbox, .pet-shell")) return;
sendPetEvent("pet:doubleClicked", {});
clickCount += 1;
if (clickCount === 1) {
firstClickEvent = event;
}
resetClickTimer();
clickTimer = setTimeout(flushClicks, 200);
});
document.addEventListener("mouseover", (event) => {
const target = event.target;
@ -387,7 +412,6 @@ const installMouseInterop = () => {
if (handleBubbleInteraction(event)) return;
dismissBubble(event);
});
document.addEventListener("dblclick", requestPromptWindow);
installPetSenses();
let dragStartPoint = null;