diff options
| author | mat <git@matdoes.dev> | 2025-09-26 06:16:33 +0800 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-09-25 19:20:09 -0300 |
| commit | 730297cf561d42fd9132eb201d1aec0d3d7c7e00 (patch) | |
| tree | d26f63b8a4553cc1b07c41a5b1a06aba773e60c4 /azalea-chat/src/click_event.rs | |
| parent | 8927a0fe65f5f89b4459956f19989f27f1e0981c (diff) | |
| download | azalea-drasl-730297cf561d42fd9132eb201d1aec0d3d7c7e00.tar.xz | |
fix compile error with new serde version, and update deps
Diffstat (limited to 'azalea-chat/src/click_event.rs')
| -rw-r--r-- | azalea-chat/src/click_event.rs | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/azalea-chat/src/click_event.rs b/azalea-chat/src/click_event.rs index dddaff74..a61e2561 100644 --- a/azalea-chat/src/click_event.rs +++ b/azalea-chat/src/click_event.rs @@ -1,6 +1,6 @@ use serde::Serialize; #[cfg(feature = "simdnbt")] -use simdnbt::owned::Nbt; +use simdnbt::owned::{Nbt, NbtCompound, NbtTag}; #[derive(Clone, Debug, PartialEq, Serialize)] #[serde(rename_all = "snake_case", tag = "action")] @@ -31,3 +31,48 @@ pub enum ClickEvent { payload: Nbt, }, } + +#[cfg(feature = "simdnbt")] +impl simdnbt::Serialize for ClickEvent { + fn to_compound(self) -> NbtCompound { + let mut compound = NbtCompound::new(); + let mut action = |s: &str| { + compound.insert("action", s); + }; + match self { + ClickEvent::OpenUrl { url } => { + action("open_url"); + compound.insert("url", url); + } + ClickEvent::OpenFile { path } => { + action("open_file"); + compound.insert("path", path); + } + ClickEvent::RunCommand { command } => { + action("run_command"); + compound.insert("command", command); + } + ClickEvent::SuggestCommand { command } => { + action("suggest_command"); + compound.insert("command", command); + } + ClickEvent::ShowDialog => { + action("show_dialog"); + } + ClickEvent::ChangePage { page } => { + action("change_page"); + compound.insert("page", NbtTag::Int(page)); + } + ClickEvent::CopyToClipboard { value } => { + action("copy_to_clipboard"); + compound.insert("value", value); + } + ClickEvent::Custom { id, payload } => { + action("custom"); + compound.insert("id", id); + compound.insert("payload", (**payload).clone()); + } + } + compound + } +} |
