wip: add hold-to-click on WRITE CODE button for continuous clicking

This commit is contained in:
Alexander Whitestone
2026-04-11 16:34:27 -04:00
parent abe96a5abd
commit 4078b32d0e

21
game.js
View File

@@ -3072,6 +3072,27 @@ window.addEventListener('keydown', function (e) {
}
});
// Hold-to-click on WRITE CODE button
let _holdInterval = null;
function _startHold() {
if (_holdInterval) return;
writeCode(); // immediate first click
_holdInterval = setInterval(writeCode, 80); // 12.5 clicks/sec while held
}
function _stopHold() {
if (_holdInterval) { clearInterval(_holdInterval); _holdInterval = null; }
}
window.addEventListener('DOMContentLoaded', function () {
const btn = document.querySelector('.main-btn');
if (!btn) return;
btn.addEventListener('mousedown', function (e) { e.preventDefault(); _startHold(); });
btn.addEventListener('mouseup', _stopHold);
btn.addEventListener('mouseleave', _stopHold);
btn.addEventListener('touchstart', function (e) { e.preventDefault(); _startHold(); }, { passive: false });
btn.addEventListener('touchend', _stopHold);
btn.addEventListener('touchcancel', _stopHold);
});
// Ctrl+S to save (must be on keydown to preventDefault)
window.addEventListener('keydown', function (e) {
if ((e.ctrlKey || e.metaKey) && e.code === 'KeyS') {