mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-22 19:49:31 -07:00
hazard scroll working, needs styling #92
This commit is contained in:
@@ -2,6 +2,7 @@ import { locationCleanup } from './utils/string.mjs';
|
|||||||
import { elemForEach } from './utils/elem.mjs';
|
import { elemForEach } from './utils/elem.mjs';
|
||||||
import getCurrentWeather from './currentweather.mjs';
|
import getCurrentWeather from './currentweather.mjs';
|
||||||
import { currentDisplay } from './navigation.mjs';
|
import { currentDisplay } from './navigation.mjs';
|
||||||
|
import getHazards from './hazards.mjs';
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
const degree = String.fromCharCode(176);
|
const degree = String.fromCharCode(176);
|
||||||
@@ -13,6 +14,7 @@ let interval;
|
|||||||
let screenIndex = 0;
|
let screenIndex = 0;
|
||||||
let sinceLastUpdate = 0;
|
let sinceLastUpdate = 0;
|
||||||
let nextUpdate = DEFAULT_UPDATE;
|
let nextUpdate = DEFAULT_UPDATE;
|
||||||
|
let hazardData;
|
||||||
|
|
||||||
// start drawing conditions
|
// start drawing conditions
|
||||||
// reset starts from the first item in the text scroll list
|
// reset starts from the first item in the text scroll list
|
||||||
@@ -51,6 +53,8 @@ const incrementInterval = (force) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
screenIndex = (screenIndex + 1) % (lastScreen);
|
screenIndex = (screenIndex + 1) % (lastScreen);
|
||||||
|
// only show hazards when present
|
||||||
|
if (hazardData?.length > 0) screenIndex = 0;
|
||||||
// draw new text
|
// draw new text
|
||||||
drawScreen();
|
drawScreen();
|
||||||
};
|
};
|
||||||
@@ -58,11 +62,23 @@ const incrementInterval = (force) => {
|
|||||||
const drawScreen = async () => {
|
const drawScreen = async () => {
|
||||||
// get the conditions
|
// get the conditions
|
||||||
const data = await getCurrentWeather();
|
const data = await getCurrentWeather();
|
||||||
|
const hazards = await getHazards(() => this.stillWaiting());
|
||||||
|
|
||||||
|
// combine data
|
||||||
|
data.hazards = hazards;
|
||||||
|
hazardData = hazards;
|
||||||
|
|
||||||
// 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 = screens[screenIndex](data);
|
||||||
|
|
||||||
|
// update classes on the scroll area
|
||||||
|
elemForEach('.weather-display .scroll .fixed', (elem) => {
|
||||||
|
elem.classList.forEach((cls) => { if (cls !== 'fixed') elem.classList.remove(cls); });
|
||||||
|
thisScreen?.classes?.forEach((cls) => elem.classList.add(cls));
|
||||||
|
});
|
||||||
|
|
||||||
if (typeof thisScreen === 'string') {
|
if (typeof thisScreen === 'string') {
|
||||||
// only a string
|
// only a string
|
||||||
drawCondition(thisScreen);
|
drawCondition(thisScreen);
|
||||||
@@ -80,8 +96,23 @@ const drawScreen = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hazards = (data) => {
|
||||||
|
// test for data
|
||||||
|
if (!data.hazards || data.hazards.length === 0) return false;
|
||||||
|
|
||||||
|
const hazard = `${data.hazards[0].properties.event} ${data.hazards[0].properties.description}`;
|
||||||
|
|
||||||
|
return {
|
||||||
|
text: hazard,
|
||||||
|
type: 'scroll',
|
||||||
|
classes: ['hazard'],
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// 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 screens = [
|
||||||
|
// hazards
|
||||||
|
hazards,
|
||||||
// station name
|
// station name
|
||||||
(data) => `Conditions at ${locationCleanup(data.station.properties.name).substr(0, 20)}`,
|
(data) => `Conditions at ${locationCleanup(data.station.properties.name).substr(0, 20)}`,
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class Hazards extends WeatherDisplay {
|
|||||||
// special height and width for scrolling
|
// special height and width for scrolling
|
||||||
super(navId, elemId, 'Hazards', defaultActive);
|
super(navId, elemId, 'Hazards', defaultActive);
|
||||||
this.showOnProgress = false;
|
this.showOnProgress = false;
|
||||||
|
this.okToDrawCurrentConditions = false;
|
||||||
|
|
||||||
// 0 screens skips this during "play"
|
// 0 screens skips this during "play"
|
||||||
this.timing.totalScreens = 0;
|
this.timing.totalScreens = 0;
|
||||||
@@ -155,6 +156,17 @@ class Hazards extends WeatherDisplay {
|
|||||||
// return the value as expected
|
// return the value as expected
|
||||||
return superValue;
|
return superValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make data available outside this class
|
||||||
|
// promise allows for data to be requested before it is available
|
||||||
|
async getHazards(stillWaiting) {
|
||||||
|
if (stillWaiting) this.stillWaitingCallbacks.push(stillWaiting);
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (this.data) resolve(this.data);
|
||||||
|
// data not available, put it into the data callback queue
|
||||||
|
this.getDataCallbacks.push(() => resolve(this.data));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const calcSeverity = (severity, event) => {
|
const calcSeverity = (severity, event) => {
|
||||||
@@ -165,4 +177,7 @@ const calcSeverity = (severity, event) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// register display
|
// register display
|
||||||
registerDisplay(new Hazards(0, 'hazards', true));
|
const display = new Hazards(0, 'hazards', true);
|
||||||
|
registerDisplay(display);
|
||||||
|
|
||||||
|
export default display.getHazards.bind(display);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -4,6 +4,7 @@
|
|||||||
.weather-display .main.hazards {
|
.weather-display .main.hazards {
|
||||||
&.main {
|
&.main {
|
||||||
overflow-y: hidden;
|
overflow-y: hidden;
|
||||||
|
height: 480px;
|
||||||
|
|
||||||
.hazard-lines {
|
.hazard-lines {
|
||||||
min-height: 400px;
|
min-height: 400px;
|
||||||
@@ -18,9 +19,10 @@
|
|||||||
@include u.text-shadow(0px);
|
@include u.text-shadow(0px);
|
||||||
position: relative;
|
position: relative;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
margin-top: 110px;
|
margin-top: 10px;
|
||||||
margin-left: 80px;
|
margin-left: 80px;
|
||||||
margin-right: 80px;
|
margin-right: 80px;
|
||||||
|
padding-bottom: 10px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,15 +113,20 @@
|
|||||||
|
|
||||||
.scroll {
|
.scroll {
|
||||||
@include u.text-shadow(3px, 1.5px);
|
@include u.text-shadow(3px, 1.5px);
|
||||||
width: calc(640px - 2 * 30px);
|
width: 640px;
|
||||||
height: 70px;
|
height: 70px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
|
|
||||||
|
&.hazard {
|
||||||
|
background-color: rgb(112, 35, 35);
|
||||||
|
}
|
||||||
|
|
||||||
.fixed {
|
.fixed {
|
||||||
font-family: 'Star4000';
|
font-family: 'Star4000';
|
||||||
font-size: 24pt;
|
font-size: 24pt;
|
||||||
margin-left: 55px;
|
margin-left: 55px;
|
||||||
|
margin-right: 55px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
.scroll-area {
|
.scroll-area {
|
||||||
@@ -132,5 +137,6 @@
|
|||||||
// left: calc((elem width) - 640px);
|
// left: calc((elem width) - 640px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
<div class="main has-scroll hazards no-header">
|
<div class="main hazards no-header">
|
||||||
<div class="hazard-lines">
|
<div class="hazard-lines">
|
||||||
<div class="hazard template">
|
<div class="hazard template">
|
||||||
<div class="hazard-text"></div>
|
<div class="hazard-text"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<%- include('scroll.ejs') %>
|
|
||||||
Reference in New Issue
Block a user