Add documentation for localize_npc methods

This commit is contained in:
juliancoffee 2024-02-03 23:53:09 +02:00
parent 3ebf17370c
commit 7bb2d11c98
4 changed files with 33 additions and 10 deletions

View File

@ -1346,11 +1346,19 @@ impl Body {
Vec3::new(0.0, self.dimensions().y * 0.6, self.dimensions().z * 0.7) Vec3::new(0.0, self.dimensions().y * 0.6, self.dimensions().z * 0.7)
} }
pub fn localize(&self) -> Content { /// Should be only used with npc-tell_monster.
match self { ///
Self::BipedLarge(biped_large) => biped_large.localize(), /// If you want to use for displaying names in HUD, add new strings.
_ => Content::localized("body-generic"), /// If you want to use for anything else, add new strings.
pub fn localize_npc(&self) -> Content {
fn try_localize(body: &Body) -> Option<Content> {
match body {
Body::BipedLarge(biped_large) => biped_large.localize_npc(),
_ => None,
}
} }
try_localize(self).unwrap_or_else(|| Content::localized("body-generic"))
} }
} }

View File

@ -25,9 +25,16 @@ impl Body {
Self { species, body_type } Self { species, body_type }
} }
pub fn localize(&self) -> Content { /// Should be only used with npc-tell_monster.
Content::localized(match &self.species { ///
Species::Ogre => "body-biped_large-ogre", /// If you want to use for displaying names in HUD, add new strings.
/// If you want to use for anything else, add new strings.
pub fn localize_npc(&self) -> Option<Content> {
let key = match &self.species {
Species::Ogre => match self.body_type {
BodyType::Male => "body-biped_large-ogre-male",
BodyType::Female => "body-biped_large-ogre-female",
},
Species::Cyclops => "body-biped_large-cyclops", Species::Cyclops => "body-biped_large-cyclops",
Species::Wendigo => "body-biped_large-wendigo", Species::Wendigo => "body-biped_large-wendigo",
Species::Werewolf => "body-biped_large-werewolf", Species::Werewolf => "body-biped_large-werewolf",
@ -37,8 +44,10 @@ impl Body {
Species::Blueoni => "body-biped_large-blue_oni", Species::Blueoni => "body-biped_large-blue_oni",
Species::Redoni => "body-biped_large-red_oni", Species::Redoni => "body-biped_large-red_oni",
Species::Tursus => "body-biped_large-tursus", Species::Tursus => "body-biped_large-tursus",
_ => "body-generic", _ => return None,
}) };
Some(Content::localized(key))
} }
} }

View File

@ -54,6 +54,9 @@ impl Direction {
} }
} }
/// Should be only used with care with npc-tell_monster and npc-tell_site
///
/// If you add new usages for it, please consult i18n team.
pub fn localize_npc(&self) -> Content { pub fn localize_npc(&self) -> Content {
Content::localized(match self { Content::localized(match self {
Direction::North => "npc-speech-dir_north", Direction::North => "npc-speech-dir_north",
@ -103,6 +106,9 @@ impl Distance {
} }
} }
/// Should be only used with care with npc-tell_monster and npc-tell_site
///
/// If you add new usages for it, please consult i18n team.
pub fn localize_npc(&self) -> Content { pub fn localize_npc(&self) -> Content {
Content::localized(match self { Content::localized(match self {
Self::VeryFar => "npc-speech-dist_very_far", Self::VeryFar => "npc-speech-dist_very_far",

View File

@ -610,7 +610,7 @@ fn talk_to<S: State>(tgt: Actor, _subject: Option<Subject>) -> impl Action<S> +
.min_by_key(|other| other.wpos.xy().distance(ctx.npc.wpos.xy()) as i32) .min_by_key(|other| other.wpos.xy().distance(ctx.npc.wpos.xy()) as i32)
{ {
Content::localized_with_args("npc-speech-tell_monster", [ Content::localized_with_args("npc-speech-tell_monster", [
("body", monster.body.localize()), ("body", monster.body.localize_npc()),
("dir", Direction::from_dir(monster.wpos.xy() - ctx.npc.wpos.xy()).localize_npc()), ("dir", Direction::from_dir(monster.wpos.xy() - ctx.npc.wpos.xy()).localize_npc()),
("dist", Distance::from_length(monster.wpos.xy().distance(ctx.npc.wpos.xy()) as i32).localize_npc()), ("dist", Distance::from_length(monster.wpos.xy().distance(ctx.npc.wpos.xy()) as i32).localize_npc()),
]) ])