Skip to main content

clairlune_scene/
placeholder.rs

1//! Milestone M1 placeholder pixel maps, taken from the Python prototype
2//! (PLAN.md section 13). Milestone M2 replaces them with project-drawn sprite
3//! sheets behind a `Character` trait in a `sprites` crate.
4//!
5//! `CLAWD_PLACEHOLDER` depicts Clawd, Anthropic's character. It is fan art and is
6//! NOT covered by this crate's MIT/Apache-2.0 licence; see the NOTICE file. To
7//! remove it (docs/takedown.md), delete the constant and render with Buddy off.
8
9use crate::palette::Rgb;
10
11/// A tiny pixel-art image: one string per row, `.` is transparent.
12#[derive(Clone, Copy, Debug)]
13pub struct PixelMap {
14    pub width: u32,
15    pub height: u32,
16    pub rows: &'static [&'static str],
17    pub colors: &'static [(char, Rgb)],
18}
19
20impl PixelMap {
21    /// Colour of pixel `(x, y)`, or `None` when transparent.
22    pub fn pixel(&self, x: u32, y: u32) -> Option<Rgb> {
23        let ch = self.rows[y as usize].as_bytes()[x as usize] as char;
24        if ch == '.' {
25            return None;
26        }
27        self.colors
28            .iter()
29            .find(|(c, _)| *c == ch)
30            .map(|(_, rgb)| *rgb)
31    }
32
33    /// Every distinct colour the map uses, in table order.
34    pub fn palette(&self) -> impl Iterator<Item = Rgb> + '_ {
35        self.colors.iter().map(|(_, rgb)| *rgb)
36    }
37}
38
39const CLAWD_BODY: Rgb = Rgb::hex(0xD9785C);
40const CLAWD_EYES: Rgb = Rgb::hex(0x261A16);
41
42/// The prototype's 15x9 Clawd (`X` body, `E` eyes). Fan art: see the module docs.
43pub const CLAWD_PLACEHOLDER: PixelMap = PixelMap {
44    width: 15,
45    height: 9,
46    rows: &[
47        "..XXXXXXXXXXX..",
48        "..XXXXXXXXXXX..",
49        "..XXEXXXXXEXX..",
50        "XXXXEXXXXXEXXXX",
51        "XXXXXXXXXXXXXXX",
52        "..XXXXXXXXXXX..",
53        "..XXXXXXXXXXX..",
54        "..X.X.....X.X..",
55        "..X.X.....X.X..",
56    ],
57    colors: &[('X', CLAWD_BODY), ('E', CLAWD_EYES)],
58};
59
60const FIRE_ORANGE: Rgb = Rgb::hex(0xE86028);
61const FIRE_YELLOW: Rgb = Rgb::hex(0xFFAA3C);
62const FIRE_WHITE: Rgb = Rgb::hex(0xFFECAA);
63const LOG: Rgb = Rgb::hex(0x784E30);
64const LOG_DARK: Rgb = Rgb::hex(0x462E1E);
65
66/// The prototype's 9x11 campfire.
67pub const CAMPFIRE: PixelMap = PixelMap {
68    width: 9,
69    height: 11,
70    rows: &[
71        "....Y....",
72        "...OY....",
73        "..OOYO...",
74        "..OYYO...",
75        ".OOYYYO..",
76        ".OYYWYYO.",
77        "OOYYWWYOO",
78        "OYYWWWYYO",
79        ".OYYYYYO.",
80        "BBBBBBBBB",
81        "KKKKKKKKK",
82    ],
83    colors: &[
84        ('O', FIRE_ORANGE),
85        ('Y', FIRE_YELLOW),
86        ('W', FIRE_WHITE),
87        ('B', LOG),
88        ('K', LOG_DARK),
89    ],
90};
91
92/// A log seat by the fire: the unattended variant used when Buddy is off, so the
93/// composition keeps an object where Clawd would stand.
94pub const LOG_SEAT: PixelMap = PixelMap {
95    width: 13,
96    height: 4,
97    rows: &[
98        ".BBBBBBBBBBB.",
99        "KBBBBBBBBBBBB",
100        "BBBBBBBBBBBKB",
101        ".KKKKKKKKKKK.",
102    ],
103    colors: &[('B', LOG), ('K', LOG_DARK)],
104};
105
106const SLATE: Rgb = Rgb::hex(0x5E6B7A);
107const SLATE_DARK: Rgb = Rgb::hex(0x3B4450);
108const BRASS: Rgb = Rgb::hex(0xC9A45C);
109const METAL: Rgb = Rgb::hex(0x3A3330);
110
111/// A small telescope on a tripod (project art, CC BY 4.0).
112pub const TELESCOPE: PixelMap = PixelMap {
113    width: 12,
114    height: 10,
115    rows: &[
116        ".........NN.",
117        ".......TTNN.",
118        ".....TTTT...",
119        "...TTTT.....",
120        "..TTT.......",
121        "....H.......",
122        "...L.L......",
123        "..L...L.....",
124        ".L.....L....",
125        "L.......L...",
126    ],
127    colors: &[('T', SLATE), ('N', SLATE_DARK), ('H', BRASS), ('L', LOG)],
128};
129
130/// A hand lantern (project art, CC BY 4.0).
131pub const LANTERN: PixelMap = PixelMap {
132    width: 5,
133    height: 7,
134    rows: &[
135        "..M..", ".M.M.", "MMMMM", "MYWYM", "MYWYM", "MYYYM", "MMMMM",
136    ],
137    colors: &[('M', METAL), ('Y', FIRE_YELLOW), ('W', FIRE_WHITE)],
138};
139
140#[cfg(test)]
141mod tests {
142    use super::*;
143
144    #[test]
145    fn maps_are_rectangular_and_fully_coloured() {
146        for map in [CLAWD_PLACEHOLDER, CAMPFIRE, LOG_SEAT, TELESCOPE, LANTERN] {
147            assert_eq!(map.rows.len() as u32, map.height);
148            for row in map.rows {
149                assert_eq!(row.len() as u32, map.width);
150                for ch in row.chars() {
151                    assert!(
152                        ch == '.' || map.colors.iter().any(|(c, _)| *c == ch),
153                        "{ch}"
154                    );
155                }
156            }
157        }
158    }
159}