Something went wrong. Try again.
HEXWORK - A Lantern in the Deep: 3D ASCII terminal roguelike RPG in Rust.
Entirely designed and built by Muse Spark 1.3 to evaluate if I like the model.
Something went wrong. Try again.
1.6 kB · 78 lines
Rust
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879//! hexwork-ui: screen stack + HUD + log (docs/04 §4.6).//! Full keyboard play mandatory; every mouse action has a key twin.
pub mod board;pub mod chapel;pub mod death_ui;pub mod explore;pub mod hud;pub mod identify_ui;pub mod inventory;pub mod logfmt;pub mod look;pub mod screens;pub mod settings;pub mod sheet;pub mod stream;pub mod text;pub mod town;pub mod transfer;pub mod undo;
/// Screens in the stack: Title → Chargen → Play → … → Death/Replay.#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub enum Screen { Title, Chargen, Play, Look, Inventory, Contracts, Map, Chapel, Death, Replay,}
/// Searchable message log. NetHack voice lives here.#[derive(Clone, Debug, Default)]pub struct Log { lines: Vec<String>,}
impl Log { pub fn new() -> Self { Self::default() }
pub fn push(&mut self, line: impl Into<String>) { self.lines.push(line.into()); }
/// Case-insensitive substring search (the `/` key). pub fn search(&self, query: &str) -> Vec<&str> { let q = query.to_lowercase(); self.lines .iter() .filter(|l| l.to_lowercase().contains(&q)) .map(|s| s.as_str()) .collect() }
pub fn lines(&self) -> &[String] { &self.lines }}
#[cfg(test)]mod tests { use super::*;
#[test] fn log_search_is_case_insensitive() { let mut log = Log::new(); log.push("You smell ozone and wet wool."); assert_eq!(log.search("OZONE").len(), 1); assert!(log.search("dragon").is_empty()); }}