Browse Source

Fix GPS test mode toggle and WASD button state issues

- Restart GPS tracking when disabling test mode
- Add resetWasdState() to clean up movement interval on mode toggle
- Add lostpointercapture handler for when buttons are hidden mid-press
- Add pointerleave handler for edge cases
- Reset WASD state when enabling or disabling test mode

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
master
HikeMap User 4 weeks ago
parent
commit
68f876ec6b
  1. 40
      index.html

40
index.html

@ -6710,7 +6710,8 @@
gpsBackupInterval = null; gpsBackupInterval = null;
} }
// Show WASD controls
// Reset WASD state and show controls
resetWasdState();
const wasdControls = document.getElementById('wasdControls'); const wasdControls = document.getElementById('wasdControls');
if (wasdControls) wasdControls.classList.remove('hidden'); if (wasdControls) wasdControls.classList.remove('hidden');
@ -6722,7 +6723,16 @@
// Hide WASD controls when disabling test mode // Hide WASD controls when disabling test mode
const wasdControls = document.getElementById('wasdControls'); const wasdControls = document.getElementById('wasdControls');
if (wasdControls) wasdControls.classList.add('hidden'); if (wasdControls) wasdControls.classList.add('hidden');
updateStatus('GPS Test Mode disabled', 'info');
// Clean up any active WASD movement state
resetWasdState();
// Restart GPS tracking since user wants to use real GPS
if (gpsWatchId === null) {
toggleGPS();
}
updateStatus('GPS Test Mode disabled - starting GPS', 'info');
} }
} }
@ -6924,6 +6934,23 @@
} }
}); });
// Handle lost pointer capture (e.g., when element is hidden)
btn.addEventListener('lostpointercapture', (e) => {
if (isPressed) {
isPressed = false;
stopMove();
}
});
// Handle pointer leaving button area
btn.addEventListener('pointerleave', (e) => {
// Only stop if we have capture (otherwise normal hover exit)
if (isPressed && !btn.hasPointerCapture(e.pointerId)) {
isPressed = false;
stopMove();
}
});
// Prevent context menu on long press // Prevent context menu on long press
btn.addEventListener('contextmenu', (e) => { btn.addEventListener('contextmenu', (e) => {
e.preventDefault(); e.preventDefault();
@ -6931,6 +6958,15 @@
}); });
} }
// Function to reset WASD state (call when showing/hiding controls)
function resetWasdState() {
if (wasdMoveInterval) {
clearInterval(wasdMoveInterval);
wasdMoveInterval = null;
}
wasdCurrentDir = null;
}
// Initialize WASD controls after DOM is ready // Initialize WASD controls after DOM is ready
if (document.readyState === 'loading') { if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initWasdControls); document.addEventListener('DOMContentLoaded', initWasdControls);

Loading…
Cancel
Save