diff --git a/crates/benilla-app/src/lanes/chat_clock_live_tests.rs b/crates/benilla-app/src/lanes/chat_clock_live_tests.rs index 55e42977c..5c3f79097 100644 --- a/crates/benilla-app/src/lanes/chat_clock_live_tests.rs +++ b/crates/benilla-app/src/lanes/chat_clock_live_tests.rs @@ -318,3 +318,29 @@ fn the_channel_lookups_read_the_slots_at_the_call() { "the copy holds none" ); } + +/// A line's language reaches Lua as its `Languages.dbc` name in the client's locale, the name +/// `GetDefaultLanguage()` also answers, so a localized client's stock header test sees its own +/// tongue and draws no `[Language]` tag. +#[test] +fn a_line_names_its_language_in_the_locale() { + let mut c = client(); + c.app + .world_mut() + .insert_resource(crate::ui_unit::LanguagesRes( + benilla_formats::Languages::from_rows(&[(7, "通用语")]), + )); + c.eval::<()>( + false, + r#"Lang = nil + local g = CreateFrame("Frame") + g:RegisterEvent("CHAT_MSG_MONSTER_SAY") + g:SetScript("OnEvent", function() Lang = arg3 end)"#, + ); + let mut line = boar_says("hi"); + if let SessionEvent::Chat(m) = &mut line { + m.language = 7; + } + c.frame(vec![vec![line]]); + assert_eq!(c.eval::(false, "return Lang"), "通用语"); +} diff --git a/crates/benilla-app/src/ui_chat/event.rs b/crates/benilla-app/src/ui_chat/event.rs index cf2250f0b..0ad3c3a70 100644 --- a/crates/benilla-app/src/ui_chat/event.rs +++ b/crates/benilla-app/src/ui_chat/event.rs @@ -674,25 +674,3 @@ pub(crate) fn flag_of_tag(chat_tag: u8) -> &'static str { _ => "", } } - -/// The 1.12 language names by wire id (vmangos `SharedDefines.h`, `LANG_*`), for the `[Language]` -/// header. Language 0 has no `Languages.dbc` row, so the stock `arg3 ~= "Universal"` test never -/// fires: an empty arg3 is what suppresses the header (`ChatFrame.lua:1442`). -pub(crate) fn language_name(id: u32) -> &'static str { - match id { - 1 => "Orcish", - 2 => "Darnassian", - 3 => "Taurahe", - 6 => "Dwarvish", - 7 => "Common", - 8 => "Demonic", - 9 => "Titan", - 10 => "Thalassian", - 11 => "Draconic", - 12 => "Kalimag", - 13 => "Gnomish", - 14 => "Troll", - 33 => "Gutterspeak", - _ => "", // 0, Universal, and unknown ids: no header - } -} diff --git a/crates/benilla-app/src/ui_chat/feed.rs b/crates/benilla-app/src/ui_chat/feed.rs index ff611b603..c554bbff1 100644 --- a/crates/benilla-app/src/ui_chat/feed.rs +++ b/crates/benilla-app/src/ui_chat/feed.rs @@ -14,7 +14,7 @@ use crate::names::NameCache; use crate::net::{GuidIndex, NetCommands, ObjectStore, SelfGuid}; use super::edit::ChannelState; -use super::event::{flag_of_tag, kind_of_wire, language_name, ChatEvent, ChatEventKind}; +use super::event::{flag_of_tag, kind_of_wire, ChatEvent, ChatEventKind}; use super::frames::{route, ChatWindows}; use crate::query_cache::Ask; @@ -1927,7 +1927,7 @@ fn fire_one( }), // The effective language, not the wire's: narration types and GM mode force // 0, which also drops the `[Language]` header. - language: language_name(language).to_string(), + language: langs.language_name(language), channel: channel_base, flag: flag_of_tag(msg.chat_tag).to_string(), ..Default::default() diff --git a/crates/benilla-app/src/ui_chat/language.rs b/crates/benilla-app/src/ui_chat/language.rs index 4a656711f..5237723ec 100644 --- a/crates/benilla-app/src/ui_chat/language.rs +++ b/crates/benilla-app/src/ui_chat/language.rs @@ -47,6 +47,8 @@ impl ChatLanguages { /// skill per language, the GM bit and whether a local player is held at all. pub(crate) struct Gate<'a> { words: Option<&'a LanguageWords>, + /// `Languages.dbc` at the client's locale, which names a line's language to Lua. + names: Option<&'a benilla_formats::Languages>, /// language id → this character's skill in it. Absent = 0 = never understood. skill: HashMap, /// `PLAYER_FLAGS & 0x8`: a GM reads every line plain, with no `[Language]` header. @@ -56,6 +58,17 @@ pub(crate) struct Gate<'a> { } impl Gate<'_> { + /// The line's language as Lua reads it, `arg3`: its `Languages.dbc` name in the client's + /// locale, which is also what `GetDefaultLanguage()` answers, so the stock header test + /// (`arg3 ~= this.defaultLanguage`, `ChatFrame.lua:1442`) compares like with like. Language 0 + /// has no row, so it is empty and draws no header. + pub(crate) fn language_name(&self, language: u32) -> String { + self.names + .and_then(|n| n.name(language)) + .unwrap_or_default() + .to_string() + } + /// This character's skill in `language`, the second argument of `0x49b560`. pub(crate) fn skill(&self, language: u32) -> u32 { self.skill.get(&language).copied().unwrap_or(0) @@ -136,6 +149,8 @@ pub(crate) struct LanguageReads<'w, 's> { actions: Option>, spells: Option>, skill_lines: Option>, + /// The language names; absent without an install, where a line's language is unnamed. + names: Option>, me: Query<'w, 's, &'static ObjectStore, With>, } @@ -146,10 +161,12 @@ impl LanguageReads<'_, '_> { /// `PLAYER_SKILL_INFO` value. pub(crate) fn gate(&self) -> Gate<'_> { let words = self.langs.as_deref().and_then(|l| l.words.as_ref()); + let names = self.names.as_deref().map(|n| &n.0); let Ok(store) = self.me.single() else { // No body: every line renders plain. return Gate { words, + names, skill: HashMap::new(), gm: false, have_player: false, @@ -176,6 +193,7 @@ impl LanguageReads<'_, '_> { } Gate { words, + names, skill, gm: store.0.player_flags() & PLAYER_FLAGS_GM != 0, have_player: true, @@ -272,6 +290,7 @@ mod tests { fn langs(skill: &[(u32, u32)], gm: bool) -> Gate<'static> { Gate { words: None, + names: None, skill: skill.iter().copied().collect(), gm, have_player: true, diff --git a/crates/benilla-formats/src/languages.rs b/crates/benilla-formats/src/languages.rs index c165640d6..9c86846e1 100644 --- a/crates/benilla-formats/src/languages.rs +++ b/crates/benilla-formats/src/languages.rs @@ -85,6 +85,14 @@ impl Languages { .filter_map(|(id, name)| Some((*id, name.as_deref()?))) } + /// The name of the row whose id is `id`, in the locale's column; `None` with no such row. + pub fn name(&self, id: u32) -> Option<&str> { + self.0 + .iter() + .find(|(row, _)| *row == id) + .and_then(|(_, name)| name.as_deref()) + } + pub fn len(&self) -> usize { self.0.len() }