From 7bb2d11c9843994fd8dff89002a7abc03bf8e491 Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Sat, 3 Feb 2024 23:53:09 +0200 Subject: [PATCH] Add documentation for localize_npc methods --- common/src/comp/body.rs | 16 ++++++++++++---- common/src/comp/body/biped_large.rs | 19 ++++++++++++++----- common/src/comp/compass.rs | 6 ++++++ rtsim/src/rule/npc_ai.rs | 2 +- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/common/src/comp/body.rs b/common/src/comp/body.rs index 61bbb137a0..37e1b0d121 100644 --- a/common/src/comp/body.rs +++ b/common/src/comp/body.rs @@ -1346,11 +1346,19 @@ impl Body { Vec3::new(0.0, self.dimensions().y * 0.6, self.dimensions().z * 0.7) } - pub fn localize(&self) -> Content { - match self { - Self::BipedLarge(biped_large) => biped_large.localize(), - _ => Content::localized("body-generic"), + /// Should be only used with npc-tell_monster. + /// + /// 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) -> Content { + fn try_localize(body: &Body) -> Option { + match body { + Body::BipedLarge(biped_large) => biped_large.localize_npc(), + _ => None, + } } + + try_localize(self).unwrap_or_else(|| Content::localized("body-generic")) } } diff --git a/common/src/comp/body/biped_large.rs b/common/src/comp/body/biped_large.rs index 4c48b193d6..f2e8521bec 100644 --- a/common/src/comp/body/biped_large.rs +++ b/common/src/comp/body/biped_large.rs @@ -25,9 +25,16 @@ impl Body { Self { species, body_type } } - pub fn localize(&self) -> Content { - Content::localized(match &self.species { - Species::Ogre => "body-biped_large-ogre", + /// Should be only used with npc-tell_monster. + /// + /// 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 { + 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::Wendigo => "body-biped_large-wendigo", Species::Werewolf => "body-biped_large-werewolf", @@ -37,8 +44,10 @@ impl Body { Species::Blueoni => "body-biped_large-blue_oni", Species::Redoni => "body-biped_large-red_oni", Species::Tursus => "body-biped_large-tursus", - _ => "body-generic", - }) + _ => return None, + }; + + Some(Content::localized(key)) } } diff --git a/common/src/comp/compass.rs b/common/src/comp/compass.rs index 0a867c7f4f..cc263abbe6 100644 --- a/common/src/comp/compass.rs +++ b/common/src/comp/compass.rs @@ -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 { Content::localized(match self { 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 { Content::localized(match self { Self::VeryFar => "npc-speech-dist_very_far", diff --git a/rtsim/src/rule/npc_ai.rs b/rtsim/src/rule/npc_ai.rs index eedc7796c3..ea35675c4a 100644 --- a/rtsim/src/rule/npc_ai.rs +++ b/rtsim/src/rule/npc_ai.rs @@ -610,7 +610,7 @@ fn talk_to(tgt: Actor, _subject: Option) -> impl Action + .min_by_key(|other| other.wpos.xy().distance(ctx.npc.wpos.xy()) as i32) { 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()), ("dist", Distance::from_length(monster.wpos.xy().distance(ctx.npc.wpos.xy()) as i32).localize_npc()), ])