palette changes

This commit is contained in:
2026-06-16 00:14:59 -05:00
parent 50d56aa428
commit 7608fc959f
3 changed files with 25 additions and 70 deletions
+12 -2
View File
@@ -43,6 +43,9 @@ pub(crate) struct Layer {
/// layer of identical floor).
/// - `sparse` — a list of `{ x, y, ch }` cells over an otherwise all-spaces grid
/// (handy for a layer holding just a few objects).
///
/// A space (`' '`) is always a transparent empty cell and is never a palette key
/// (any `" "` entry in `palette` is ignored).
#[derive(Deserialize, Serialize)]
pub(crate) struct LayerData {
/// Multi-line grid string; one char per cell, looked up in `palette`.
@@ -341,12 +344,14 @@ pub(crate) fn build_layer(
errors: &mut Vec<LogLine>,
) -> Result<(Layer, Vec<Placement>), String> {
// Resolve each palette entry once (per-cell work like generators happens below).
// Space is always a transparent empty cell, so it is never a palette key — any
// `" "` entry is ignored.
let resolved: HashMap<char, Resolved> = data
.palette
.iter()
.map(|(key, entry)| {
.filter_map(|(key, entry)| {
let ch = key.chars().next().unwrap_or(' ');
(ch, resolve_entry(ch, entry, errors))
(ch != ' ').then(|| (ch, resolve_entry(ch, entry, errors)))
})
.collect();
@@ -358,6 +363,11 @@ pub(crate) fn build_layer(
let mut placements: Vec<Placement> = Vec::new();
for (y, row) in grid.iter().enumerate() {
for (x, &ch) in row.iter().enumerate() {
// A space is always a transparent empty cell, palette or not.
if ch == ' ' {
cells.push((Glyph::transparent(), Archetype::Empty));
continue;
}
match resolved.get(&ch) {
Some(Resolved::Cell(g, a)) => cells.push((*g, *a)),
Some(Resolved::FloorGen(g)) => cells.push((g.generate(rng), Archetype::Empty)),