Skip to main content

flatland_client_ui/
map_presentation.rs

1//! Map presentation catalogs (`assets/world/terrain-kinds.yaml`, `map-glyphs.yaml`, item templates).
2
3use crate::color::{parse_color, RgbColor};
4
5use std::collections::HashMap;
6use std::path::PathBuf;
7use std::sync::{OnceLock, RwLock};
8
9use flatland_protocol::{NpcView, ResourceNodeState, ResourceNodeView, TerrainKindView};
10use serde::Deserialize;
11
12#[derive(Debug, Clone, PartialEq, Eq)]
13pub struct MapPresentation {
14    pub glyph: String,
15    pub color: RgbColor,
16}
17
18impl MapPresentation {
19    fn new(glyph: impl Into<String>, color: RgbColor) -> Self {
20        Self {
21            glyph: glyph.into(),
22            color,
23        }
24    }
25}
26
27#[derive(Debug, Default, Deserialize)]
28struct DefaultsYaml {
29    #[serde(default)]
30    resource: Option<GlyphColorYaml>,
31    #[serde(default)]
32    resource_harvesting: Option<GlyphColorYaml>,
33    #[serde(default)]
34    resource_cooldown: Option<GlyphColorYaml>,
35    #[serde(default)]
36    npc_wildlife: Option<GlyphColorYaml>,
37    #[serde(default)]
38    npc_friendly: Option<GlyphColorYaml>,
39    #[serde(default)]
40    player: Option<GlyphColorYaml>,
41    #[serde(default)]
42    corpse: Option<GlyphColorYaml>,
43    #[serde(default)]
44    loot: Option<GlyphColorYaml>,
45    #[serde(default)]
46    chest: Option<GlyphColorYaml>,
47    #[serde(default)]
48    chest_locked: Option<GlyphColorYaml>,
49    #[serde(default)]
50    door_closed: Option<GlyphColorYaml>,
51    #[serde(default)]
52    door_open: Option<GlyphColorYaml>,
53    #[serde(default)]
54    wall: Option<GlyphColorYaml>,
55    #[serde(default)]
56    well_center: Option<GlyphColorYaml>,
57    #[serde(default)]
58    quest_board: Option<GlyphColorYaml>,
59}
60
61#[derive(Debug, Deserialize)]
62struct GlyphColorYaml {
63    glyph: String,
64    color: String,
65}
66
67#[derive(Debug, Deserialize)]
68struct TerrainKindsFile {
69    terrain_kinds: HashMap<String, GlyphColorYaml>,
70}
71
72#[derive(Debug, Deserialize)]
73struct ItemGlyphsFile {
74    items: Vec<ItemGlyphEntry>,
75}
76
77#[derive(Debug, Deserialize)]
78struct ItemGlyphEntry {
79    template_id: String,
80    #[serde(default)]
81    glyph: Option<String>,
82    #[serde(default)]
83    color: Option<String>,
84}
85
86#[derive(Debug, Deserialize)]
87struct MapGlyphsFile {
88    #[serde(default)]
89    defaults: DefaultsYaml,
90    #[serde(default)]
91    npcs: HashMap<String, GlyphColorYaml>,
92    #[serde(default)]
93    entities: HashMap<String, GlyphColorYaml>,
94}
95
96#[derive(Debug)]
97struct Catalog {
98    terrain: HashMap<String, MapPresentation>,
99    defaults: DefaultsBlock,
100    items: HashMap<String, MapPresentation>,
101    npcs: HashMap<String, MapPresentation>,
102    entities: HashMap<String, MapPresentation>,
103}
104
105#[derive(Debug)]
106struct DefaultsBlock {
107    resource: MapPresentation,
108    resource_harvesting: MapPresentation,
109    resource_cooldown: MapPresentation,
110    npc_wildlife: MapPresentation,
111    npc_friendly: MapPresentation,
112    player: MapPresentation,
113    corpse: MapPresentation,
114    loot: MapPresentation,
115    chest: MapPresentation,
116    chest_locked: MapPresentation,
117    door_closed: MapPresentation,
118    door_open: MapPresentation,
119    wall: MapPresentation,
120    well_center: MapPresentation,
121    quest_board: MapPresentation,
122}
123
124fn find_assets_path(relative: &str) -> PathBuf {
125    let manifest = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
126    for ancestor in manifest.ancestors() {
127        let candidate = ancestor.join(relative);
128        if candidate.is_file() {
129            return candidate;
130        }
131    }
132    PathBuf::from(relative)
133}
134
135fn find_assets_dir(relative: &str) -> PathBuf {
136    let manifest = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
137    for ancestor in manifest.ancestors() {
138        let candidate = ancestor.join(relative);
139        if candidate.is_dir() {
140            return candidate;
141        }
142    }
143    PathBuf::from(relative)
144}
145
146fn parse_entry(def: &GlyphColorYaml) -> Option<MapPresentation> {
147    if def.glyph.is_empty() {
148        return None;
149    }
150    let color = parse_color(&def.color)?;
151    Some(MapPresentation::new(def.glyph.clone(), color))
152}
153
154fn parse_map(defs: HashMap<String, GlyphColorYaml>) -> HashMap<String, MapPresentation> {
155    defs.into_iter()
156        .filter_map(|(k, v)| parse_entry(&v).map(|p| (k, p)))
157        .collect()
158}
159
160fn builtin_defaults() -> DefaultsBlock {
161    DefaultsBlock {
162        resource: MapPresentation::new("?", RgbColor::DARK_GRAY),
163        resource_harvesting: MapPresentation::new("%", RgbColor::YELLOW),
164        resource_cooldown: MapPresentation::new("·", RgbColor::DARK_GRAY),
165        npc_wildlife: MapPresentation::new("N", RgbColor::YELLOW),
166        npc_friendly: MapPresentation::new("N", RgbColor::CYAN),
167        player: MapPresentation::new("@", RgbColor::GREEN),
168        corpse: MapPresentation::new("x", RgbColor::DARK_GRAY),
169        loot: MapPresentation::new("*", RgbColor::YELLOW),
170        chest: MapPresentation::new("■", RgbColor::rgb(139, 90, 43)),
171        chest_locked: MapPresentation::new("▣", RgbColor::rgb(160, 82, 45)),
172        door_closed: MapPresentation::new("D", RgbColor::RED),
173        door_open: MapPresentation::new("d", RgbColor::LIGHT_RED),
174        wall: MapPresentation::new("+", RgbColor::MAGENTA),
175        well_center: MapPresentation::new("O", RgbColor::CYAN),
176        quest_board: MapPresentation::new("!", RgbColor::rgb(0xe8, 0xc5, 0x47)),
177    }
178}
179
180fn merge_default(yaml: Option<GlyphColorYaml>, fallback: &MapPresentation) -> MapPresentation {
181    yaml.and_then(|d| parse_entry(&d))
182        .unwrap_or_else(|| fallback.clone())
183}
184
185fn builtin_terrain(kind: TerrainKindView) -> MapPresentation {
186    match kind {
187        TerrainKindView::Grass => MapPresentation::new(".", RgbColor::rgb(0x5a, 0x73, 0x56)),
188        TerrainKindView::Hill => MapPresentation::new("^", RgbColor::rgb(0x9a, 0x92, 0x68)),
189        TerrainKindView::Trail => MapPresentation::new(":", RgbColor::rgb(0xc4, 0xb8, 0x90)),
190        TerrainKindView::Rock => MapPresentation::new("#", RgbColor::rgb(0x5a, 0x50, 0x48)),
191        TerrainKindView::Bog => MapPresentation::new(",", RgbColor::MAGENTA),
192        TerrainKindView::ShallowWater => MapPresentation::new("~", RgbColor::CYAN),
193        TerrainKindView::DeepWater => MapPresentation::new("~", RgbColor::BLUE),
194    }
195}
196
197fn terrain_key(kind: TerrainKindView) -> &'static str {
198    match kind {
199        TerrainKindView::Grass => "grass",
200        TerrainKindView::Hill => "hill",
201        TerrainKindView::Trail => "trail",
202        TerrainKindView::Rock => "rock",
203        TerrainKindView::Bog => "bog",
204        TerrainKindView::ShallowWater => "shallow_water",
205        TerrainKindView::DeepWater => "deep_water",
206    }
207}
208
209/// Ground elevation → hue ladder (low cool green → mid olive → high warm tan → snow).
210fn elevation_palette(elevation: f32) -> RgbColor {
211    let bucket = elevation.round().clamp(-3.0, 8.0) as i32;
212    match bucket {
213        b if b <= -1 => RgbColor::rgb(0x3d, 0x58, 0x6a), // below grade — cool slate
214        0 => RgbColor::rgb(0x4a, 0x6b, 0x42),            // lowland green
215        1 => RgbColor::rgb(0x62, 0x7a, 0x48),            // foothill
216        2 => RgbColor::rgb(0x7a, 0x86, 0x4c),            // slope olive
217        3 => RgbColor::rgb(0x96, 0x8a, 0x58),            // upper slope tan-green
218        4 => RgbColor::rgb(0xae, 0x8c, 0x62),            // ridge / plateau
219        5 => RgbColor::rgb(0xc8, 0xa4, 0x72),            // high scree
220        6 => RgbColor::rgb(0xde, 0xc0, 0x90),            // near summit
221        _ => RgbColor::rgb(0xec, 0xea, 0xf4),            // snow cap
222    }
223}
224
225fn darken_rgb(color: RgbColor, factor: f32) -> RgbColor {
226    RgbColor::rgb(
227        (color.r as f32 * factor) as u8,
228        (color.g as f32 * factor) as u8,
229        (color.b as f32 * factor) as u8,
230    )
231}
232
233fn lighten_rgb(color: RgbColor, factor: f32) -> RgbColor {
234    RgbColor::rgb(
235        ((color.r as f32 * factor).min(255.0)) as u8,
236        ((color.g as f32 * factor).min(255.0)) as u8,
237        ((color.b as f32 * factor).min(255.0)) as u8,
238    )
239}
240
241fn load_item_presentations() -> HashMap<String, MapPresentation> {
242    let path = find_assets_dir("assets/items");
243    let Ok(entries) = std::fs::read_dir(&path) else {
244        return HashMap::new();
245    };
246    let fallback = RgbColor::rgb(0x8a, 0x8a, 0x8a);
247    let mut out = HashMap::new();
248    let mut files: Vec<PathBuf> = entries
249        .filter_map(|e| e.ok())
250        .map(|e| e.path())
251        .filter(|p| {
252            p.is_file()
253                && p.extension()
254                    .is_some_and(|ext| ext == "yaml" || ext == "yml")
255        })
256        .collect();
257    files.sort();
258    for file in files {
259        let Ok(raw) = std::fs::read_to_string(&file) else {
260            continue;
261        };
262        let Ok(root) = serde_yaml::from_str::<ItemGlyphsFile>(&raw) else {
263            continue;
264        };
265        for item in root.items {
266            let Some(glyph) = item.glyph else {
267                continue;
268            };
269            let color = item
270                .color
271                .as_deref()
272                .and_then(parse_color)
273                .unwrap_or(fallback);
274            out.insert(item.template_id, MapPresentation::new(glyph, color));
275        }
276    }
277    out
278}
279
280fn load_catalog() -> Catalog {
281    let mut terrain = HashMap::new();
282    if let Ok(raw) = std::fs::read_to_string(find_assets_path("assets/world/terrain-kinds.yaml")) {
283        if let Ok(file) = serde_yaml::from_str::<TerrainKindsFile>(&raw) {
284            terrain = parse_map(file.terrain_kinds);
285        }
286    }
287
288    let mut defaults = builtin_defaults();
289    let items = load_item_presentations();
290    let mut npcs = HashMap::new();
291    let mut entities = HashMap::new();
292
293    if let Ok(raw) = std::fs::read_to_string(find_assets_path("assets/world/map-glyphs.yaml")) {
294        if let Ok(file) = serde_yaml::from_str::<MapGlyphsFile>(&raw) {
295            let base = builtin_defaults();
296            defaults = DefaultsBlock {
297                resource: merge_default(file.defaults.resource, &base.resource),
298                resource_harvesting: merge_default(
299                    file.defaults.resource_harvesting,
300                    &base.resource_harvesting,
301                ),
302                resource_cooldown: merge_default(
303                    file.defaults.resource_cooldown,
304                    &base.resource_cooldown,
305                ),
306                npc_wildlife: merge_default(file.defaults.npc_wildlife, &base.npc_wildlife),
307                npc_friendly: merge_default(file.defaults.npc_friendly, &base.npc_friendly),
308                player: merge_default(file.defaults.player, &base.player),
309                corpse: merge_default(file.defaults.corpse, &base.corpse),
310                loot: merge_default(file.defaults.loot, &base.loot),
311                chest: merge_default(file.defaults.chest, &base.chest),
312                chest_locked: merge_default(file.defaults.chest_locked, &base.chest_locked),
313                door_closed: merge_default(file.defaults.door_closed, &base.door_closed),
314                door_open: merge_default(file.defaults.door_open, &base.door_open),
315                wall: merge_default(file.defaults.wall, &base.wall),
316                well_center: merge_default(file.defaults.well_center, &base.well_center),
317                quest_board: merge_default(file.defaults.quest_board, &base.quest_board),
318            };
319            npcs = parse_map(file.npcs);
320            entities = parse_map(file.entities);
321        }
322    }
323
324    Catalog {
325        terrain,
326        defaults,
327        items,
328        npcs,
329        entities,
330    }
331}
332
333fn catalog_cell() -> &'static RwLock<Catalog> {
334    static CELL: OnceLock<RwLock<Catalog>> = OnceLock::new();
335    CELL.get_or_init(|| RwLock::new(load_catalog()))
336}
337
338fn catalog() -> std::sync::RwLockReadGuard<'static, Catalog> {
339    catalog_cell()
340        .read()
341        .expect("map presentation catalog lock")
342}
343
344/// Reload `terrain-kinds.yaml`, `map-glyphs.yaml`, and item glyphs from disk.
345pub fn reload_map_presentation_catalog() {
346    *catalog_cell()
347        .write()
348        .expect("map presentation catalog lock") = load_catalog();
349}
350
351/// Reload presentation YAML when the sim reports a newer content revision (after publish).
352pub fn maybe_reload_for_content_rev(content_rev: u64) {
353    static LAST_REV: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
354    let prev = LAST_REV.load(std::sync::atomic::Ordering::Relaxed);
355    if content_rev > 0 && content_rev != prev {
356        LAST_REV.store(content_rev, std::sync::atomic::Ordering::Relaxed);
357        reload_map_presentation_catalog();
358    }
359}
360
361fn npc_glyph_lookup(c: &Catalog, npc: &NpcView) -> Option<MapPresentation> {
362    let id_key = npc.id.to_ascii_lowercase();
363    if let Some(p) = c.npcs.get(&id_key) {
364        return Some(p.clone());
365    }
366    if let Some(prefix) = id_key.split('_').next() {
367        if let Some(p) = c.npcs.get(prefix) {
368            return Some(p.clone());
369        }
370    }
371    let label_key = npc.label.to_ascii_lowercase();
372    c.npcs.get(&label_key).cloned()
373}
374
375pub fn terrain_for(kind: TerrainKindView) -> MapPresentation {
376    catalog()
377        .terrain
378        .get(terrain_key(kind))
379        .cloned()
380        .unwrap_or_else(|| builtin_terrain(kind))
381}
382
383/// Terrain glyph + color from zone kind and ground elevation (topographic read).
384pub fn terrain_for_elevation(kind: TerrainKindView, elevation: f32) -> MapPresentation {
385    match kind {
386        TerrainKindView::ShallowWater | TerrainKindView::DeepWater | TerrainKindView::Bog => {
387            return terrain_for(kind);
388        }
389        TerrainKindView::Trail => {
390            let color = lighten_rgb(elevation_palette(elevation), 1.12);
391            return MapPresentation::new(":", color);
392        }
393        TerrainKindView::Rock => {
394            let color = darken_rgb(elevation_palette(elevation), 0.62);
395            let glyph = if elevation >= 3.5 { "▓" } else { "#" };
396            return MapPresentation::new(glyph, color);
397        }
398        _ => {}
399    }
400
401    let base = terrain_for(kind);
402    let color = elevation_palette(elevation);
403    if elevation.abs() < 0.25 {
404        return MapPresentation::new(base.glyph, color);
405    }
406
407    let bucket = elevation.round().clamp(-9.0, 9.0) as i32;
408    let ch = match bucket {
409        b if b >= 6 => '▲',
410        b if b >= 4 => '▲',
411        b if b >= 2 => '^',
412        b if b >= 1 => '▴',
413        b if b <= -1 => '▾',
414        _ => base.glyph.chars().next().unwrap_or('.'),
415    };
416    MapPresentation::new(ch.to_string(), color)
417}
418
419/// Terrain presentation for a zone cell, applying optional per-zone glyph/color overrides from YAML.
420pub fn terrain_for_zone(
421    kind: TerrainKindView,
422    elevation: f32,
423    glyph_override: Option<&str>,
424    color_override: Option<&str>,
425) -> MapPresentation {
426    let mut pres = terrain_for_elevation(kind, elevation);
427    if let Some(g) = glyph_override.map(str::trim).filter(|s| !s.is_empty()) {
428        let ch = g.chars().next().unwrap_or('.');
429        pres.glyph = ch.to_string();
430    }
431    if let Some(raw) = color_override.map(str::trim).filter(|s| !s.is_empty()) {
432        if let Some(color) = parse_color(raw) {
433            pres.color = color;
434        }
435    }
436    pres
437}
438
439pub fn resource_for(node: &ResourceNodeView) -> MapPresentation {
440    let c = catalog();
441    match node.state {
442        ResourceNodeState::Harvesting => c.defaults.resource_harvesting.clone(),
443        ResourceNodeState::Cooldown => c.defaults.resource_cooldown.clone(),
444        ResourceNodeState::Available => c
445            .items
446            .get(&node.item_template)
447            .cloned()
448            .unwrap_or_else(|| c.defaults.resource.clone()),
449    }
450}
451
452pub fn npc_for(npc: &NpcView) -> MapPresentation {
453    let c = catalog();
454    if let Some(p) = npc_glyph_lookup(&c, npc) {
455        return p;
456    }
457    if npc.entity_id.is_some() {
458        return c.defaults.npc_wildlife.clone();
459    }
460    c.defaults.npc_friendly.clone()
461}
462
463pub fn player_presentation() -> MapPresentation {
464    catalog().defaults.player.clone()
465}
466
467pub fn corpse_presentation() -> MapPresentation {
468    catalog().defaults.corpse.clone()
469}
470
471pub fn loot_presentation() -> MapPresentation {
472    catalog().defaults.loot.clone()
473}
474
475pub fn chest_presentation(locked: bool) -> MapPresentation {
476    let c = catalog();
477    if locked {
478        c.defaults.chest_locked.clone()
479    } else {
480        c.defaults.chest.clone()
481    }
482}
483
484pub fn door_presentation(open: bool) -> MapPresentation {
485    let c = catalog();
486    if open {
487        c.defaults.door_open.clone()
488    } else {
489        c.defaults.door_closed.clone()
490    }
491}
492
493pub fn wall_presentation() -> MapPresentation {
494    catalog().defaults.wall.clone()
495}
496
497pub fn well_center_presentation() -> MapPresentation {
498    catalog().defaults.well_center.clone()
499}
500
501pub fn quest_board_presentation() -> MapPresentation {
502    catalog().defaults.quest_board.clone()
503}
504
505pub fn shallow_water_presentation() -> MapPresentation {
506    terrain_for(TerrainKindView::ShallowWater)
507}
508
509pub fn entity_fallback(label: &str) -> MapPresentation {
510    let c = catalog();
511    let initial = label
512        .chars()
513        .next()
514        .map(|ch| ch.to_ascii_uppercase().to_string())
515        .unwrap_or_else(|| "?".into());
516    if let Some(mut p) = c.entities.get("wildlife_other").cloned() {
517        p.glyph = initial.clone();
518        return p;
519    }
520    MapPresentation::new(initial, RgbColor::YELLOW)
521}
522
523/// One row in the `?` help map legend (glyphs from YAML catalogs).
524#[derive(Debug, Clone)]
525pub struct MapLegendEntry {
526    pub presentation: MapPresentation,
527    pub label: String,
528}
529
530fn legend_push(out: &mut Vec<MapLegendEntry>, pres: &MapPresentation, label: impl Into<String>) {
531    out.push(MapLegendEntry {
532        presentation: pres.clone(),
533        label: label.into(),
534    });
535}
536
537/// Map legend rows for help overlay and `flatland3 keys`.
538pub fn map_legend_entries() -> Vec<MapLegendEntry> {
539    let c = catalog();
540    let mut out = Vec::new();
541
542    legend_push(&mut out, &c.defaults.player, "you");
543    legend_push(&mut out, &c.defaults.loot, "ground loot");
544    legend_push(&mut out, &c.defaults.corpse, "carcass");
545    legend_push(&mut out, &c.defaults.door_closed, "door (closed)");
546    legend_push(&mut out, &c.defaults.door_open, "door (open)");
547    legend_push(&mut out, &c.defaults.wall, "wall");
548    legend_push(&mut out, &c.defaults.well_center, "well");
549    legend_push(&mut out, &c.defaults.resource_harvesting, "harvesting node");
550    legend_push(&mut out, &c.defaults.resource_cooldown, "node cooldown");
551
552    let mut terrain: Vec<_> = c.terrain.iter().collect();
553    terrain.sort_by_key(|(k, _)| *k);
554    if terrain.is_empty() {
555        for kind in [
556            TerrainKindView::Grass,
557            TerrainKindView::Hill,
558            TerrainKindView::Trail,
559            TerrainKindView::Rock,
560            TerrainKindView::Bog,
561            TerrainKindView::ShallowWater,
562            TerrainKindView::DeepWater,
563        ] {
564            let pres = terrain_for(kind);
565            legend_push(&mut out, &pres, terrain_key(kind).replace('_', " "));
566        }
567    } else {
568        for (kind, pres) in terrain {
569            legend_push(&mut out, pres, kind.replace('_', " "));
570        }
571    }
572
573    let mut npcs: Vec<_> = c.npcs.iter().collect();
574    npcs.sort_by_key(|(k, _)| *k);
575    for (id, pres) in npcs {
576        legend_push(&mut out, pres, format!("{id}"));
577    }
578
579    let mut items: Vec<_> = c.items.iter().collect();
580    items.sort_by_key(|(k, _)| *k);
581    for (id, pres) in items {
582        legend_push(&mut out, pres, id.replace('_', " "));
583    }
584
585    out
586}
587
588pub fn format_map_legend_plain() -> String {
589    let mut out = String::from("Map legend\n");
590    for entry in map_legend_entries() {
591        out.push_str(&format!(
592            "  {}  {}\n",
593            entry.presentation.glyph, entry.label
594        ));
595    }
596    out.push_str("  [red cell]  T1 combat target\n");
597    out.push_str("  [blue cell]  T2 combat target\n");
598    out
599}
600
601#[cfg(test)]
602mod tests {
603    use super::*;
604
605    #[test]
606    fn parses_named_and_hex_colors() {
607        assert_eq!(parse_color("cyan"), Some(RgbColor::CYAN));
608        assert_eq!(parse_color("#0af"), Some(RgbColor::rgb(0x00, 0xaa, 0xff)));
609    }
610
611    #[test]
612    fn terrain_and_resource_catalog_load() {
613        let oak = resource_for(&ResourceNodeView {
614            id: "t".into(),
615            label: "Oak".into(),
616            x: 0.0,
617            y: 0.0,
618            z: 0.0,
619            item_template: "oak_log".into(),
620            state: ResourceNodeState::Available,
621            blocking: false,
622            blocking_radius_m: 0.8,
623            tile_id: None,
624            sprite_mode: None,
625            presentation_state: None,
626        });
627        assert_eq!(oak.glyph, "?");
628
629        let rabbit = npc_for(&NpcView {
630            id: "r1".into(),
631            label: "Rabbit".into(),
632            role: "critter".into(),
633            x: 0.0,
634            y: 0.0,
635            building_id: None,
636            entity_id: Some(2),
637            life_state: None,
638            hp_pct: None,
639            can_trade: false,
640            tile_id: None,
641            behavior_state: None,
642            sprite_mode: None,
643            presentation_state: None,
644        });
645        assert_eq!(rabbit.glyph, "N");
646
647        let jack = npc_for(&NpcView {
648            id: "jack_wanderer".into(),
649            label: "Jack".into(),
650            role: "villager".into(),
651            x: 0.0,
652            y: 0.0,
653            building_id: None,
654            entity_id: None,
655            life_state: None,
656            hp_pct: None,
657            can_trade: false,
658            tile_id: None,
659            behavior_state: None,
660            sprite_mode: None,
661            presentation_state: None,
662        });
663        assert_eq!(jack.glyph, "N");
664        assert_eq!(jack.color, parse_color("cyan").expect("cyan"));
665    }
666
667    #[test]
668    fn trail_and_rock_use_distinct_glyphs_with_elevation_tint() {
669        let trail = terrain_for_elevation(TerrainKindView::Trail, 2.0);
670        assert_eq!(trail.glyph, ":");
671        let rock = terrain_for_elevation(TerrainKindView::Rock, 4.0);
672        assert_eq!(rock.glyph, "▓");
673        let low = terrain_for_elevation(TerrainKindView::Grass, 0.0);
674        let high = terrain_for_elevation(TerrainKindView::Grass, 4.0);
675        assert_ne!(low.color, high.color);
676    }
677
678    #[test]
679    fn terrain_for_zone_applies_glyph_and_color_overrides() {
680        let base = terrain_for_elevation(TerrainKindView::Grass, 0.0);
681        let custom = terrain_for_zone(TerrainKindView::Grass, 0.0, Some("%"), Some("blue"));
682        assert_eq!(custom.glyph, "%");
683        assert_eq!(custom.color, parse_color("blue").expect("blue"));
684        assert_ne!(custom.glyph, base.glyph);
685        assert_ne!(custom.color, base.color);
686    }
687}