From 3a63ced4e6db986698dbdc8ad792189aa892331d Mon Sep 17 00:00:00 2001 From: Kiyomichi Kosaka Date: Sun, 15 Jun 2025 10:06:53 +0200 Subject: [PATCH] Sync analog clock with manual mode --- clock.js | 28 +++++++++++++++++++++++----- script.js | 9 +++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/clock.js b/clock.js index 575fe69..99bac7b 100644 --- a/clock.js +++ b/clock.js @@ -71,9 +71,7 @@ lastAngles[id] = angle; } - function updateClock() { - const now = new Date(); - const cob = toCobiets(now); + function renderClock(cob) { // Use fractional progress within each unit so angles stay small const xf = (cob % COBIE_UNITS.quantic) / COBIE_UNITS.quantic; const qf = (cob % COBIE_UNITS.chronon) / COBIE_UNITS.chronon; @@ -87,10 +85,26 @@ rotateHand('handMegasequence', mf * 360); } + function updateClock() { + renderClock(toCobiets(new Date())); + } + + let intervalId = null; + + function startClock() { + clearInterval(intervalId); + updateClock(); + intervalId = setInterval(updateClock, 1000); + } + + function showTime(cob) { + clearInterval(intervalId); + renderClock(cob); + } + function initClock() { placeMarkers(); - updateClock(); - setInterval(updateClock, 1000); + startClock(); const clk = document.getElementById('clock'); if (clk) { clk.addEventListener('click', () => { @@ -100,6 +114,10 @@ }); } window.addEventListener('resize', placeMarkers); + window.CobieClock = { + start: startClock, + showTime + }; } if (document.readyState === 'loading') { diff --git a/script.js b/script.js index 4202ffd..9c5fdde 100644 --- a/script.js +++ b/script.js @@ -640,6 +640,9 @@ function updateCalendar() { clearInterval(updateInterval); document.querySelector('.current-time').classList.add('manual'); updateCurrentTime(); + if (window.CobieClock) { + window.CobieClock.showTime(manualCobiets); + } }); })(cellCob + currentTime); } @@ -737,6 +740,9 @@ function goToNow() { clearInterval(updateInterval); updateInterval = setInterval(updateCurrentTime, 1000); document.querySelector('.current-time').classList.remove('manual'); + if (window.CobieClock) { + window.CobieClock.start(); + } } function enterEdit() { @@ -794,6 +800,9 @@ function commitInput() { updateCurrentTime(); updateCalendar(); document.querySelector('.current-time').classList.add('manual'); + if (window.CobieClock) { + window.CobieClock.showTime(manualCobiets); + } } // swap elements