Skip to content

Commit

Permalink
Merge pull request #333 from azylko/TheaterNameGen332
Browse files Browse the repository at this point in the history
Theater Name Generator
  • Loading branch information
MikkelPaulson authored Aug 20, 2024
2 parents 1618e3e + 9a7e763 commit 5911277
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/world/place/building/business/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod inn;
mod theater;

use super::BuildingType;
use crate::world::place::{Place, PlaceType};
Expand Down Expand Up @@ -112,6 +113,7 @@ pub fn generate(place: &mut Place, rng: &mut impl Rng, demographics: &Demographi
#[allow(clippy::single_match)]
match subtype {
BusinessType::Inn => inn::generate(place, rng, demographics),
BusinessType::Theater => theater::generate(place, rng, demographics),
_ => {}
}
}
Expand Down
77 changes: 77 additions & 0 deletions core/src/world/place/building/business/theater.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use crate::world::{word, Demographics, Place};
use rand::prelude::*;

pub fn generate(place: &mut Place, rng: &mut impl Rng, _demographics: &Demographics) {
place.name.replace_with(|_| name(rng));
}

fn name(rng: &mut impl Rng) -> String {
match rng.gen_range(0..7) {
0..=2 => format!("The {}", thing(rng)),
3..=5 => format!("{} {}", thing(rng), theater_synonym(rng)),
6 => format!(
"{} {} {}",
word::adjective(rng),
thing(rng),
theater_synonym(rng)
),
_ => unreachable!(),
}
}

fn thing(rng: &mut impl Rng) -> &'static str {
match rng.gen_range(0..6) {
0 => word::animal(rng),
1..=2 => word::symbol(rng),
3..=4 => word::gem(rng),
5 => word::person(rng),
_ => unreachable!(),
}
}

fn theater_synonym(rng: &mut impl Rng) -> &'static str {
#[rustfmt::skip]
const THEATER_SYNONYMS: &[&str] = &[
"Theater", "Opera House", "Ampitheater", "Hall", "Playhouse",
];
THEATER_SYNONYMS[rng.gen_range(0..THEATER_SYNONYMS.len())]
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn name_test() {
let mut rng = SmallRng::seed_from_u64(0);

assert_eq!(
[
"Lance Playhouse",
"Lucky Helmet Playhouse",
"The Mermaid",
"The Opal",
"Sun Playhouse",
"Bronze Steeple Theater",
"The Sibling",
"Anchor Hall",
"Book Ampitheater",
"Foil Ampitheater",
"Deer Ampitheater",
"Amber Theater",
"The Otter",
"Ancestor Hall",
"Diamond Opera House",
"Green Sapphire Playhouse",
"The Rook",
"Purple Opal Theater",
"Feather Playhouse",
"Phalactary Ampitheater"
]
.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>(),
(0..20).map(|_| name(&mut rng)).collect::<Vec<String>>(),
);
}
}
1 change: 1 addition & 0 deletions data/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* **Enhancement:** Name generator now works for `theater`. @azylko
* **Bug:** Fixed a positioning issue with the autocomplete popup. @MikkelPaulson
* **Enhancement:** Name generator now works for `canyon`. @chrisrenfrow
* **Bug:** Fixed an edge case where unsaved journal entries might not be
Expand Down

0 comments on commit 5911277

Please sign in to comment.