Untitled
unknown
plain_text
10 months ago
3.6 kB
16
Indexable
// =========================
// Changeover settings
// =========================
let changeover = {
spruesToMales: 4*60*1000, // default 4 min
malesToSprues: 2*60*1000 // default 2 min
};
// Add inputs in the settings modal if needed
// spruesToMalesMin, spruesToMalesSec, malesToSpruesMin, malesToSpruesSec
// =========================
// App state
// =========================
let currentPhase = 'sprues'; // 'sprues' | 'males' | 'changeover'
let nextShiftAfterChangeover = null;
// =========================
// switchShift updated
// =========================
function switchShift() {
let from = currentPhase === 'sprues' ? 'sprues' : (currentPhase === 'males' ? 'males' : nextShiftAfterChangeover);
let to = from === 'sprues' ? 'males' : 'sprues';
// determine changeover duration
const coDuration = from === 'sprues' ? changeover.spruesToMales : changeover.malesToSprues;
// enter changeover first
currentPhase = 'changeover';
remaining = coDuration;
nextShiftAfterChangeover = to;
endTime = running ? performance.now() + remaining : null;
// update UI to show "Changeover"
updateUI(true);
visualEndOfShift();
announce(`Changeover: ${msToMMSS(remaining)} until ${labelFor(to)}.`);
// after countdown, enter next shift automatically
// handled by rafTick
}
// =========================
// updateUI updated
// =========================
function updateUI(forceAnnounce){
countdownText.textContent = msToMMSS(remaining);
if(currentPhase === 'changeover'){
nowLabel.textContent = 'Changeover';
durationDisplay.textContent = `Changeover ${msToMMSS(remaining)}`;
nextInfo.textContent = `Next: ${labelFor(nextShiftAfterChangeover)} (in ${msToMMSS(remaining)})`;
progressRing.setAttribute('stroke', 'rgba(255,255,255,0.08)');
} else {
nowLabel.textContent = labelFor(currentPhase);
durationDisplay.textContent = `${labelFor(currentPhase)} ${msToMMSS(durationMs[currentPhase])}`;
const next = nextShift();
nextInfo.textContent = `Next: ${labelFor(next)} (in ${msToMMSS(remaining)})`;
const gradId = currentPhase === 'sprues' ? 'url(#gSprues)' : 'url(#gMales)';
progressRing.setAttribute('stroke', gradId);
}
// existing theme logic
applyThemeForCurrentShift();
if(forceAnnounce){
if(currentPhase === 'changeover'){
ariaLive.textContent = `Changeover: ${msToMMSS(remaining)} remaining until ${labelFor(nextShiftAfterChangeover)}.`;
} else {
ariaLive.textContent = `Now ${labelFor(currentPhase)}. ${msToMMSS(remaining)} remaining. Next ${labelFor(nextShift())}.`;
}
}
}
// =========================
// rafTick updated
// =========================
function rafTick(now){
rafId = requestAnimationFrame(rafTick);
if(!running) return;
const current = performance.now();
remaining = Math.max(0, endTime - current);
if(remaining <= 0.001){
remaining = 0;
if(currentPhase === 'changeover'){
// enter the next main shift
currentPhase = nextShiftAfterChangeover;
remaining = durationMs[currentPhase];
endTime = running ? performance.now() + remaining : null;
applyThemeForCurrentShift();
updateUI(true);
announce(`Now ${labelFor(currentPhase)}. Next: ${labelFor(nextShift())}.`);
} else {
// regular shift ends → switchShift enters changeover
switchShift();
}
return;
}
updateUI(false);
}
// =========================
// labelFor helper
// =========================
function labelFor(phase){
if(phase === 'sprues') return 'Sprues';
if(phase === 'males') return 'Males';
if(phase === 'changeover') return 'Changeover';
return '';
}Editor is loading...
Leave a Comment