use std::borrow::Cow;
use bevy_ecs::prelude::{Bundle, Component};
use derive_more::{Deref, DerefMut};
use valence_entity::EntityLayerId;
use valence_server::protocol::packets::play::boss_bar_s2c::{
BossBarAction, BossBarColor, BossBarDivision, BossBarFlags,
};
use valence_server::{Text, UniqueId};
#[derive(Bundle, Default)]
pub struct BossBarBundle {
pub id: UniqueId,
pub title: BossBarTitle,
pub health: BossBarHealth,
pub style: BossBarStyle,
pub flags: BossBarFlags,
pub layer: EntityLayerId,
}
#[derive(Component, Clone, Default, Deref, DerefMut)]
pub struct BossBarTitle(pub Text);
impl ToPacketAction for BossBarTitle {
fn to_packet_action(&self) -> BossBarAction {
BossBarAction::UpdateTitle(Cow::Borrowed(&self.0))
}
}
#[derive(Component, Default, Deref, DerefMut)]
pub struct BossBarHealth(pub f32);
impl ToPacketAction for BossBarHealth {
fn to_packet_action(&self) -> BossBarAction {
BossBarAction::UpdateHealth(self.0)
}
}
#[derive(Component, Default)]
pub struct BossBarStyle {
pub color: BossBarColor,
pub division: BossBarDivision,
}
impl ToPacketAction for BossBarStyle {
fn to_packet_action(&self) -> BossBarAction {
BossBarAction::UpdateStyle(self.color, self.division)
}
}
impl ToPacketAction for BossBarFlags {
fn to_packet_action(&self) -> BossBarAction {
BossBarAction::UpdateFlags(*self)
}
}
pub(crate) trait ToPacketAction {
fn to_packet_action(&self) -> BossBarAction;
}