diff options
Diffstat (limited to 'src/names/mod.rs')
| -rw-r--r-- | src/names/mod.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/names/mod.rs b/src/names/mod.rs index 719455f..9b5d9a6 100644 --- a/src/names/mod.rs +++ b/src/names/mod.rs @@ -21,10 +21,12 @@ use std::fmt::Write as _; use rand::RngExt; use rand::seq::IndexedRandom; +use serde::{Deserialize, Serialize}; use crate::seed::Rng; -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] pub enum Culture { Qaari, Cant, @@ -198,7 +200,7 @@ impl Culture { self.expand(pick(self.phonology().places, rng), rng) } - fn expand(self, template: &str, rng: &mut Rng) -> String { + pub(crate) fn expand(self, template: &str, rng: &mut Rng) -> String { let mut out = String::new(); let mut rest = template; while let Some(open) = rest.find('{') { @@ -217,6 +219,13 @@ impl Culture { } } +/// The phrase with "a" or "an" in front, by its first letter: "an ice +/// world", "a desert world". +pub fn a(phrase: &str) -> String { + let article = if phrase.starts_with(['a', 'e', 'i', 'o', 'u']) { "an" } else { "a" }; + format!("{article} {phrase}") +} + pub(crate) fn pick(list: &'static [&'static str], rng: &mut Rng) -> &'static str { list.choose(rng).expect("name lists are never empty") } |