Skip to content

Commit ca78384

Browse files
unhappychoiceclaude
andcommitted
feat(weather): emit PixelArt sprites for current conditions
Extends the `weather` fetcher (Open-Meteo now) with a `PixelArt` shape variant. Each WMO weather code maps to one of eight bundled 16x16 sprites: clear / mostly_clear / partly_cloudy / overcast / fog / rain / snow / thunderstorm. Unknown codes fall back to overcast so the renderer always has something to draw. Sprites are authored as ASCII grids with a per-sprite palette in `weather/sprites.rs`, decoded once via `OnceLock`. Keeps the binary text diff reviewable (no PNG assets to track) and bypasses any runtime PNG decode. Refs #259, #68 (weather extension). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent b275bde commit ca78384

3 files changed

Lines changed: 431 additions & 1 deletion

File tree

‎src/fetcher/weather/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::sync::Arc;
77
pub(crate) mod common;
88
mod forecast;
99
mod now;
10+
mod sprites;
1011

1112
use super::Fetcher;
1213

‎src/fetcher/weather/now.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use super::super::{FetchContext, FetchError, Fetcher, Safety};
2121
use super::common::{
2222
API_BASE, Units, http, parse_options, payload, weather_badge, weather_description,
2323
};
24+
use super::sprites::sprite_for_code;
2425

2526
const HOURLY_HOURS: usize = 24;
2627

@@ -69,7 +70,7 @@ impl Fetcher for WeatherFetcher {
6970
Safety::Safe
7071
}
7172
fn description(&self) -> &'static str {
72-
"Forecast for a fixed (latitude, longitude) via Open-Meteo. `Entries` / `Text` summarise current conditions; `PointSeries` carries the next 24h of hourly temperature (signed °C / °F); `NumberSeries` / `Bars` carry hourly precipitation in tenths of mm/inch; `Badge` flags severe weather codes (thunderstorm = error, freezing / snow / heavy rain = warn). Metric or imperial units, no API key required."
73+
"Forecast for a fixed (latitude, longitude) via Open-Meteo. `Entries` / `Text` summarise current conditions; `PointSeries` carries the next 24h of hourly temperature (signed °C / °F); `NumberSeries` / `Bars` carry hourly precipitation in tenths of mm/inch; `Badge` flags severe weather codes (thunderstorm = error, freezing / snow / heavy rain = warn); `PixelArt` paints a 16×16 truecolor sprite of the current sky. Metric or imperial units, no API key required."
7374
}
7475
fn refresh_interval(&self) -> u64 {
7576
60 * 30
@@ -82,6 +83,7 @@ impl Fetcher for WeatherFetcher {
8283
Shape::NumberSeries,
8384
Shape::Bars,
8485
Shape::Badge,
86+
Shape::PixelArt,
8587
]
8688
}
8789
fn option_schemas(&self) -> &[OptionSchema] {
@@ -106,6 +108,7 @@ impl Fetcher for WeatherFetcher {
106108
Shape::NumberSeries => number_series(&sample.hourly),
107109
Shape::Bars => precipitation_bars(&sample.hourly),
108110
Shape::Badge => Body::Badge(weather_badge(sample.code)),
111+
Shape::PixelArt => Body::PixelArt(sprite_for_code(sample.code)),
109112
_ => return None,
110113
})
111114
}
@@ -122,6 +125,7 @@ impl Fetcher for WeatherFetcher {
122125
Shape::NumberSeries => number_series(&report.hourly),
123126
Shape::Bars => precipitation_bars(&report.hourly),
124127
Shape::Badge => Body::Badge(weather_badge(report.code)),
128+
Shape::PixelArt => Body::PixelArt(sprite_for_code(report.code)),
125129
_ => entries(&report),
126130
};
127131
Ok(payload(body))
@@ -531,6 +535,7 @@ mod tests {
531535
Shape::NumberSeries,
532536
Shape::Bars,
533537
Shape::Badge,
538+
Shape::PixelArt,
534539
]
535540
.as_slice()
536541
);
@@ -545,6 +550,7 @@ mod tests {
545550
| (Shape::NumberSeries, Body::NumberSeries(_))
546551
| (Shape::Bars, Body::Bars(_))
547552
| (Shape::Badge, Body::Badge(_))
553+
| (Shape::PixelArt, Body::PixelArt(_))
548554
));
549555
}
550556
let text = fetcher

0 commit comments

Comments
 (0)