Call vibration only on user-driven shakes

This commit is contained in:
chris 2025-11-20 11:06:34 -05:00
parent 804c34ef61
commit f8f83f2f37

11
app.js
View File

@ -533,12 +533,12 @@
}
}
function triggerShake(card) {
function triggerShake(card, vibrate = true) {
if (card) {
card.classList.add('apply-shake');
setTimeout(() => card.classList.remove('apply-shake'), 500);
}
if (navigator.vibrate) navigator.vibrate([90, 40, 90]);
if (vibrate && navigator.vibrate) navigator.vibrate([90, 40, 90]);
}
function openStats() {
@ -839,10 +839,7 @@
state.streak = 0;
game.attempts = timedOut ? 3 : game.attempts + 1;
const penalty = game.attempts >= 3 || timedOut ? 10 : (game.attempts === 2 ? 5 : 0);
if (card) {
card.classList.add('apply-shake');
setTimeout(() => card.classList.remove('apply-shake'), 500);
}
triggerShake(card, !timedOut);
if (!timedOut) {
dementor.progress += 0.2; updateDementorVisuals();
game.currentInput = "";
@ -873,7 +870,7 @@
// guard in case question changed
const currentId = `${Math.min(game.currentFact.n1, game.currentFact.n2)}x${Math.max(game.currentFact.n1, game.currentFact.n2)}`;
if (currentId !== factId) return;
triggerShake(card);
triggerShake(card, false); // triggered from timeout; not a direct gesture
feedback.style.color = '#ffb0b0';
feedback.innerText = `Answer is ${game.currentFact.ans}.${penalty ? ` (-${penalty} XP)` : ''} Press CAST to continue.`;
addToTroubleList(game.currentFact.n1, game.currentFact.n2);