mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-17 09:09:30 -07:00
Merge remote-tracking branch 'upstream/main' into modernization-and-refactor
This commit is contained in:
@@ -18,6 +18,7 @@ let screenIndex = 0;
|
||||
let sinceLastUpdate = 0;
|
||||
let nextUpdate = DEFAULT_UPDATE;
|
||||
let resetFlag;
|
||||
let defaultScreensLoaded = true;
|
||||
|
||||
// start drawing conditions
|
||||
// reset starts from the first item in the text scroll list
|
||||
@@ -63,7 +64,7 @@ const incrementInterval = (force) => {
|
||||
stop(display?.elemId === 'progress');
|
||||
return;
|
||||
}
|
||||
screenIndex = (screenIndex + 1) % (lastScreen);
|
||||
screenIndex = (screenIndex + 1) % (workingScreens.length);
|
||||
|
||||
// draw new text
|
||||
drawScreen();
|
||||
@@ -87,7 +88,7 @@ const drawScreen = async () => {
|
||||
// if we have no current weather and no hazards, there's nothing to display
|
||||
if (!data && (!scrollData.hazards || scrollData.hazards.length === 0)) return;
|
||||
|
||||
const thisScreen = screens[screenIndex](scrollData);
|
||||
const thisScreen = workingScreens[screenIndex](scrollData);
|
||||
|
||||
// update classes on the scroll area
|
||||
elemForEach('.weather-display .scroll', (elem) => {
|
||||
@@ -136,8 +137,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
|
||||
@@ -179,6 +182,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
|
||||
@@ -194,19 +200,18 @@ 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 = [];
|
||||
defaultScreensLoaded = true;
|
||||
};
|
||||
|
||||
// add screen
|
||||
const addScreen = (screen) => {
|
||||
screens.push(screen);
|
||||
lastScreen += 1;
|
||||
// add screen, keepBase keeps the regular weather crawl
|
||||
const addScreen = (screen, keepBase = true) => {
|
||||
defaultScreensLoaded = false;
|
||||
additionalScreens.push(screen);
|
||||
workingScreens = [...(keepBase ? baseScreens : []), ...additionalScreens];
|
||||
};
|
||||
|
||||
const drawScrollCondition = (screen) => {
|
||||
@@ -259,6 +264,9 @@ const parseMessage = (event) => {
|
||||
}
|
||||
};
|
||||
|
||||
const screenCount = () => workingScreens.length;
|
||||
const atDefault = () => defaultScreensLoaded;
|
||||
|
||||
// add event listener for start message
|
||||
window.addEventListener('message', parseMessage);
|
||||
|
||||
@@ -266,10 +274,14 @@ window.CurrentWeatherScroll = {
|
||||
addScreen,
|
||||
reset,
|
||||
start,
|
||||
screenCount,
|
||||
atDefault,
|
||||
};
|
||||
|
||||
export {
|
||||
addScreen,
|
||||
reset,
|
||||
start,
|
||||
screenCount,
|
||||
atDefault,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user