From 0fde88cd8f4ea8697feef37f60b366a8530eca6f Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Fri, 27 Jun 2025 22:51:22 -0500 Subject: [PATCH] restructure current weather scroll to allow add/remove of rss feed #57 --- .../scripts/modules/currentweatherscroll.mjs | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/server/scripts/modules/currentweatherscroll.mjs b/server/scripts/modules/currentweatherscroll.mjs index 6064310..6bfb1e3 100644 --- a/server/scripts/modules/currentweatherscroll.mjs +++ b/server/scripts/modules/currentweatherscroll.mjs @@ -60,7 +60,7 @@ const incrementInterval = (force) => { stop(display?.elemId === 'progress'); return; } - screenIndex = (screenIndex + 1) % (lastScreen); + screenIndex = (screenIndex + 1) % (workingScreens.length); // draw new text drawScreen(); @@ -78,7 +78,7 @@ const drawScreen = async () => { // nothing to do if there's no data yet if (!data) return; - const thisScreen = screens[screenIndex](data); + const thisScreen = workingScreens[screenIndex](data); // update classes on the scroll area 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 -const screens = [ +const baseScreens = [ // hazards hazards, // 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 const drawCondition = (text) => { // update all html scroll elements @@ -183,19 +188,16 @@ const setHeader = (text) => { }); }; -// store the original number of screens -const originalScreens = screens.length; -let lastScreen = originalScreens; - -// reset the number of screens +// reset the screens back to the original set const reset = () => { - lastScreen = originalScreens; + workingScreens = [...baseScreens]; + additionalScreens = []; }; -// add screen -const addScreen = (screen) => { - screens.push(screen); - lastScreen += 1; +// add screen, keepBase keeps the regular weather crawl +const addScreen = (screen, keepBase = true) => { + additionalScreens.push(screen); + workingScreens = [...(keepBase ? baseScreens : []), ...additionalScreens]; }; const drawScrollCondition = (screen) => {