From da150409ea6b63f8a70450d5d7a62ac00a8c2ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaic=20Salom=C3=A3o?= Date: Sun, 25 Oct 2026 02:49:22 -0300 Subject: [PATCH] Complete and color mod commands in the chat on the server thread --- crates/horizon-client/src/game/chat.rs | 2 +- crates/horizon-client/src/game/mods.rs | 25 ++++++++++++++++++++++++ crates/horizon-client/src/game/remote.rs | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/src/game/chat.rs b/crates/horizon-client/src/game/chat.rs index 1bc30513b..e879698c7 100644 --- a/crates/horizon-client/src/game/chat.rs +++ b/crates/horizon-client/src/game/chat.rs @@ -18,7 +18,7 @@ fn chat_tree<'a>( mods: &'a super::mods::ModsState, ) -> &'a horizon_client::command::Dispatcher { match remote.as_ref().and_then(|r| r.commands.as_ref()) { - Some(tree) => tree, + Some(tree) => mods.remote_dispatcher().unwrap_or(tree), None => mods.dispatcher(), } } diff --git a/crates/horizon-client/src/game/mods.rs b/crates/horizon-client/src/game/mods.rs index 572f9fe2b..982c7f097 100644 --- a/crates/horizon-client/src/game/mods.rs +++ b/crates/horizon-client/src/game/mods.rs @@ -39,6 +39,9 @@ pub(super) struct ModsState { /// The chat's command tree while a running mod owns commands. #[cfg(feature = "mods")] tree: Option, + /// The server's command tree with the running mods' commands added. + #[cfg(feature = "mods")] + remote_tree: Option, } impl ModsState { /// The chat's command tree: vanilla's, plus the running mods' commands. @@ -49,6 +52,14 @@ impl ModsState { } vanilla::game_dispatcher() } + /// The server's tree plus the mods' commands, when a mod owns any. + pub(super) fn remote_dispatcher(&self) -> Option<&Dispatcher> { + #[cfg(feature = "mods")] + if let Some(tree) = &self.remote_tree { + return Some(tree); + } + None + } /// Whether a mod runs: the chat keeps its lines for them. pub(super) fn running(&self) -> bool { #[cfg(feature = "mods")] @@ -158,6 +169,7 @@ impl Game<'_> { ); } } + pub(super) fn merge_remote_tree(&mut self) {} pub(super) fn sync_mods(&mut self) {} pub(super) fn tick_mods(&mut self) {} pub(super) fn mods_frame(&mut self, _elapsed: Duration) {} @@ -238,7 +250,20 @@ impl Game<'_> { .peek() .is_some() .then(|| vanilla::game_dispatcher().with_mod_commands(names)); + self.merge_remote_tree(); } + + /// The server's command tree with the mods' commands, for the chat. + pub(super) fn merge_remote_tree(&mut self) { + let names: Vec = self.mods.mods.commands().map(str::to_owned).collect(); + self.mods.remote_tree = self + .remote + .as_ref() + .and_then(|r| r.commands.as_ref()) + .filter(|_| !names.is_empty()) + .map(|t| t.with_mod_commands(names.iter().map(String::as_str))); + } + /// After the options changed: restart the mods if the list of the ones /// turned on did. pub(super) fn sync_mods(&mut self) { diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 23c6677c2..9da81e551 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -2423,6 +2423,7 @@ impl Game<'_> { if let Some(r) = self.remote.as_mut() { r.commands = Some(tree); } + self.merge_remote_tree(); } C::SystemChat(p) => { // The component as sent, translated in the client's own