Sync analog clock with manual mode

This commit is contained in:
Kiyomichi Kosaka 2025-06-15 10:06:53 +02:00
parent f0ce3b29d6
commit 3a63ced4e6
2 changed files with 32 additions and 5 deletions

View File

@ -71,9 +71,7 @@
lastAngles[id] = angle; lastAngles[id] = angle;
} }
function updateClock() { function renderClock(cob) {
const now = new Date();
const cob = toCobiets(now);
// Use fractional progress within each unit so angles stay small // Use fractional progress within each unit so angles stay small
const xf = (cob % COBIE_UNITS.quantic) / COBIE_UNITS.quantic; const xf = (cob % COBIE_UNITS.quantic) / COBIE_UNITS.quantic;
const qf = (cob % COBIE_UNITS.chronon) / COBIE_UNITS.chronon; const qf = (cob % COBIE_UNITS.chronon) / COBIE_UNITS.chronon;
@ -87,10 +85,26 @@
rotateHand('handMegasequence', mf * 360); 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() { function initClock() {
placeMarkers(); placeMarkers();
updateClock(); startClock();
setInterval(updateClock, 1000);
const clk = document.getElementById('clock'); const clk = document.getElementById('clock');
if (clk) { if (clk) {
clk.addEventListener('click', () => { clk.addEventListener('click', () => {
@ -100,6 +114,10 @@
}); });
} }
window.addEventListener('resize', placeMarkers); window.addEventListener('resize', placeMarkers);
window.CobieClock = {
start: startClock,
showTime
};
} }
if (document.readyState === 'loading') { if (document.readyState === 'loading') {

View File

@ -640,6 +640,9 @@ function updateCalendar() {
clearInterval(updateInterval); clearInterval(updateInterval);
document.querySelector('.current-time').classList.add('manual'); document.querySelector('.current-time').classList.add('manual');
updateCurrentTime(); updateCurrentTime();
if (window.CobieClock) {
window.CobieClock.showTime(manualCobiets);
}
}); });
})(cellCob + currentTime); })(cellCob + currentTime);
} }
@ -737,6 +740,9 @@ function goToNow() {
clearInterval(updateInterval); clearInterval(updateInterval);
updateInterval = setInterval(updateCurrentTime, 1000); updateInterval = setInterval(updateCurrentTime, 1000);
document.querySelector('.current-time').classList.remove('manual'); document.querySelector('.current-time').classList.remove('manual');
if (window.CobieClock) {
window.CobieClock.start();
}
} }
function enterEdit() { function enterEdit() {
@ -794,6 +800,9 @@ function commitInput() {
updateCurrentTime(); updateCurrentTime();
updateCalendar(); updateCalendar();
document.querySelector('.current-time').classList.add('manual'); document.querySelector('.current-time').classList.add('manual');
if (window.CobieClock) {
window.CobieClock.showTime(manualCobiets);
}
} }
// swap elements // swap elements