palette changes
This commit is contained in:
+12
-2
@@ -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)),
|
||||
|
||||
Reference in New Issue
Block a user