use crate::{comp, sync}; use serde_derive::{Deserialize, Serialize}; use std::marker::PhantomData; use sum_type::sum_type; // Automatically derive From for EcsCompPacket // for each variant EcsCompPacket::T(T.) sum_type! { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EcsCompPacket { Body(comp::Body), Player(comp::Player), CanBuild(comp::CanBuild), Stats(comp::Stats), LightEmitter(comp::LightEmitter), Item(comp::Item), Scale(comp::Scale), MountState(comp::MountState), Mounting(comp::Mounting), Mass(comp::Mass), Gravity(comp::Gravity), Sticky(comp::Sticky), } } // Automatically derive From for EcsCompPhantom // for each variant EcsCompPhantom::T(PhantomData). sum_type! { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EcsCompPhantom { Body(PhantomData), Player(PhantomData), CanBuild(PhantomData), Stats(PhantomData), LightEmitter(PhantomData), Item(PhantomData), Scale(PhantomData), MountState(PhantomData), Mounting(PhantomData), Mass(PhantomData), Gravity(PhantomData), Sticky(PhantomData), } } impl sync::CompPacket for EcsCompPacket { type Phantom = EcsCompPhantom; fn apply_insert(self, entity: specs::Entity, world: &specs::World) { match self { EcsCompPacket::Body(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Player(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::CanBuild(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Stats(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::LightEmitter(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Item(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Scale(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::MountState(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Mounting(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Mass(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Gravity(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Sticky(comp) => sync::handle_insert(comp, entity, world), } } fn apply_modify(self, entity: specs::Entity, world: &specs::World) { match self { EcsCompPacket::Body(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Player(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::CanBuild(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Stats(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::LightEmitter(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Item(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Scale(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::MountState(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Mounting(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Mass(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Gravity(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Sticky(comp) => sync::handle_modify(comp, entity, world), } } fn apply_remove(phantom: Self::Phantom, entity: specs::Entity, world: &specs::World) { match phantom { EcsCompPhantom::Body(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Player(_) => sync::handle_remove::(entity, world), EcsCompPhantom::CanBuild(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Stats(_) => sync::handle_remove::(entity, world), EcsCompPhantom::LightEmitter(_) => { sync::handle_remove::(entity, world) } EcsCompPhantom::Item(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Scale(_) => sync::handle_remove::(entity, world), EcsCompPhantom::MountState(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Mounting(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Mass(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Gravity(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Sticky(_) => sync::handle_remove::(entity, world), } } }