aboutsummaryrefslogtreecommitdiff
path: root/azalea-chat/src/hover_event.rs
blob: 825c253b2e8df3701b4603c607d5815b12dedca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use serde::Serialize;
#[cfg(feature = "simdnbt")]
use simdnbt::owned::NbtCompound;

use crate::FormattedText;

#[derive(Clone, Debug, PartialEq, Serialize)]
#[serde(rename_all = "snake_case", tag = "action")]
pub enum HoverEvent {
    ShowText {
        value: Box<FormattedText>,
    },
    // TODO
    ShowItem {
        // item: ItemStack,
    },
    ShowEntity {
        id: i32,
        // uuid: Uuid,
        name: Box<FormattedText>,
    },
}

#[cfg(feature = "simdnbt")]
impl simdnbt::Serialize for HoverEvent {
    fn to_compound(self) -> NbtCompound {
        let mut compound = NbtCompound::new();
        let mut action = |s: &str| {
            compound.insert("action", s);
        };
        match self {
            HoverEvent::ShowText { value } => {
                action("show_text");
                compound.insert("value", value.to_compound());
            }
            HoverEvent::ShowItem { .. } => {
                action("show_item");
            }
            HoverEvent::ShowEntity { id, name } => {
                action("show_entity");
                compound.insert("id", id);
                // compound.insert("uuid", uuid.to_string());
                compound.insert("name", name.to_compound());
            }
        }
        compound
    }
}