restructure current weather scroll to allow add/remove of rss feed #57

This commit is contained in:
Matt Walsh
2025-06-27 22:51:22 -05:00
parent c6af9a2913
commit 0fde88cd8f

View File

@@ -60,7 +60,7 @@ const incrementInterval = (force) => {
stop(display?.elemId === 'progress'); stop(display?.elemId === 'progress');
return; return;
} }
screenIndex = (screenIndex + 1) % (lastScreen); screenIndex = (screenIndex + 1) % (workingScreens.length);
// draw new text // draw new text
drawScreen(); drawScreen();
@@ -78,7 +78,7 @@ const drawScreen = async () => {
// nothing to do if there's no data yet // nothing to do if there's no data yet
if (!data) return; if (!data) return;
const thisScreen = screens[screenIndex](data); const thisScreen = workingScreens[screenIndex](data);
// update classes on the scroll area // update classes on the scroll area
elemForEach('.weather-display .scroll', (elem) => { elemForEach('.weather-display .scroll', (elem) => {
@@ -125,8 +125,10 @@ const hazards = (data) => {
}; };
}; };
// additional screens are stored in a separate for simple clearing/resettings
let additionalScreens = [];
// the "screens" are stored in an array for easy addition and removal // the "screens" are stored in an array for easy addition and removal
const screens = [ const baseScreens = [
// hazards // hazards
hazards, hazards,
// station name // station name
@@ -168,6 +170,9 @@ const screens = [
}, },
]; ];
// working screens are the combination of base screens (when active) and additional screens
let workingScreens = [...baseScreens, ...additionalScreens];
// internal draw function with preset parameters // internal draw function with preset parameters
const drawCondition = (text) => { const drawCondition = (text) => {
// update all html scroll elements // update all html scroll elements
@@ -183,19 +188,16 @@ const setHeader = (text) => {
}); });
}; };
// store the original number of screens // reset the screens back to the original set
const originalScreens = screens.length;
let lastScreen = originalScreens;
// reset the number of screens
const reset = () => { const reset = () => {
lastScreen = originalScreens; workingScreens = [...baseScreens];
additionalScreens = [];
}; };
// add screen // add screen, keepBase keeps the regular weather crawl
const addScreen = (screen) => { const addScreen = (screen, keepBase = true) => {
screens.push(screen); additionalScreens.push(screen);
lastScreen += 1; workingScreens = [...(keepBase ? baseScreens : []), ...additionalScreens];
}; };
const drawScrollCondition = (screen) => { const drawScrollCondition = (screen) => {