2019-11-24 20:12:03 +00:00
|
|
|
use crate::{comp, state, sync};
|
2019-04-29 20:37:19 +00:00
|
|
|
use serde_derive::{Deserialize, Serialize};
|
|
|
|
use std::marker::PhantomData;
|
2019-11-24 20:12:03 +00:00
|
|
|
use sum_type::sum_type;
|
2019-04-10 17:23:27 +00:00
|
|
|
|
2019-11-30 05:33:17 +00:00
|
|
|
// TODO: remove me
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub enum MustHaveMoreThanOneVariant {}
|
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// Automatically derive From<T> for EcsResPacket
|
|
|
|
// for each variant EcsResPacket::T(T).
|
2019-11-04 00:57:36 +00:00
|
|
|
sum_type! {
|
2019-04-10 17:23:27 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
2019-05-16 23:05:46 +00:00
|
|
|
pub enum EcsResPacket {
|
2019-11-30 05:33:17 +00:00
|
|
|
MustHaveMoreThanOneVariant(MustHaveMoreThanOneVariant),
|
2019-05-16 23:05:46 +00:00
|
|
|
TimeOfDay(state::TimeOfDay),
|
|
|
|
}
|
|
|
|
}
|
2019-11-24 20:12:03 +00:00
|
|
|
impl sync::ResPacket for EcsResPacket {
|
2019-11-04 00:57:36 +00:00
|
|
|
fn apply(self, world: &specs::World) {
|
|
|
|
match self {
|
2019-11-30 05:33:17 +00:00
|
|
|
EcsResPacket::MustHaveMoreThanOneVariant(_) => unimplemented!(),
|
2019-11-24 20:12:03 +00:00
|
|
|
EcsResPacket::TimeOfDay(time_of_day) => sync::handle_res_update(time_of_day, world),
|
2019-11-04 00:57:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-17 09:22:32 +00:00
|
|
|
// Automatically derive From<T> for EcsCompPacket
|
|
|
|
// for each variant EcsCompPacket::T(T.)
|
2019-11-04 00:57:36 +00:00
|
|
|
sum_type! {
|
2019-05-16 23:05:46 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub enum EcsCompPacket {
|
2019-06-30 11:48:28 +00:00
|
|
|
Body(comp::Body),
|
2019-04-10 17:23:27 +00:00
|
|
|
Player(comp::Player),
|
2019-07-02 18:52:44 +00:00
|
|
|
CanBuild(comp::CanBuild),
|
2019-05-13 13:58:01 +00:00
|
|
|
Stats(comp::Stats),
|
2019-07-21 16:50:13 +00:00
|
|
|
LightEmitter(comp::LightEmitter),
|
2019-07-26 21:01:41 +00:00
|
|
|
Item(comp::Item),
|
2019-08-02 18:56:37 +00:00
|
|
|
Scale(comp::Scale),
|
2019-09-09 19:11:40 +00:00
|
|
|
MountState(comp::MountState),
|
|
|
|
Mounting(comp::Mounting),
|
2019-09-25 20:22:39 +00:00
|
|
|
Mass(comp::Mass),
|
2019-10-17 20:59:36 +00:00
|
|
|
Gravity(comp::Gravity),
|
2019-10-02 19:28:35 +00:00
|
|
|
Sticky(comp::Sticky),
|
2019-04-10 17:23:27 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-17 09:22:32 +00:00
|
|
|
// Automatically derive From<T> for EcsCompPhantom
|
|
|
|
// for each variant EcsCompPhantom::T(PhantomData<T>).
|
2019-11-04 00:57:36 +00:00
|
|
|
sum_type! {
|
2019-04-10 17:23:27 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
2019-05-16 23:05:46 +00:00
|
|
|
pub enum EcsCompPhantom {
|
2019-06-30 11:48:28 +00:00
|
|
|
Body(PhantomData<comp::Body>),
|
2019-04-10 17:23:27 +00:00
|
|
|
Player(PhantomData<comp::Player>),
|
2019-07-02 18:52:44 +00:00
|
|
|
CanBuild(PhantomData<comp::CanBuild>),
|
2019-05-13 13:58:01 +00:00
|
|
|
Stats(PhantomData<comp::Stats>),
|
2019-07-21 16:50:13 +00:00
|
|
|
LightEmitter(PhantomData<comp::LightEmitter>),
|
2019-07-26 21:01:41 +00:00
|
|
|
Item(PhantomData<comp::Item>),
|
2019-08-02 18:56:37 +00:00
|
|
|
Scale(PhantomData<comp::Scale>),
|
2019-09-09 19:11:40 +00:00
|
|
|
MountState(PhantomData<comp::MountState>),
|
|
|
|
Mounting(PhantomData<comp::Mounting>),
|
2019-09-25 20:22:39 +00:00
|
|
|
Mass(PhantomData<comp::Mass>),
|
2019-10-17 20:59:36 +00:00
|
|
|
Gravity(PhantomData<comp::Gravity>),
|
2019-10-02 19:28:35 +00:00
|
|
|
Sticky(PhantomData<comp::Sticky>),
|
2019-04-10 17:23:27 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-24 20:12:03 +00:00
|
|
|
impl sync::CompPacket for EcsCompPacket {
|
2019-05-16 23:05:46 +00:00
|
|
|
type Phantom = EcsCompPhantom;
|
2019-11-04 00:57:36 +00:00
|
|
|
fn apply_insert(self, entity: specs::Entity, world: &specs::World) {
|
|
|
|
match self {
|
2019-11-24 20:12:03 +00:00
|
|
|
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),
|
2019-11-04 00:57:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fn apply_modify(self, entity: specs::Entity, world: &specs::World) {
|
|
|
|
match self {
|
2019-11-24 20:12:03 +00:00
|
|
|
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),
|
2019-11-04 00:57:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fn apply_remove(phantom: Self::Phantom, entity: specs::Entity, world: &specs::World) {
|
|
|
|
match phantom {
|
2019-11-24 20:12:03 +00:00
|
|
|
EcsCompPhantom::Body(_) => sync::handle_remove::<comp::Body>(entity, world),
|
|
|
|
EcsCompPhantom::Player(_) => sync::handle_remove::<comp::Player>(entity, world),
|
|
|
|
EcsCompPhantom::CanBuild(_) => sync::handle_remove::<comp::CanBuild>(entity, world),
|
|
|
|
EcsCompPhantom::Stats(_) => sync::handle_remove::<comp::Stats>(entity, world),
|
2019-11-04 00:57:36 +00:00
|
|
|
EcsCompPhantom::LightEmitter(_) => {
|
2019-11-24 20:12:03 +00:00
|
|
|
sync::handle_remove::<comp::LightEmitter>(entity, world)
|
2019-11-04 00:57:36 +00:00
|
|
|
}
|
2019-11-24 20:12:03 +00:00
|
|
|
EcsCompPhantom::Item(_) => sync::handle_remove::<comp::Item>(entity, world),
|
|
|
|
EcsCompPhantom::Scale(_) => sync::handle_remove::<comp::Scale>(entity, world),
|
|
|
|
EcsCompPhantom::MountState(_) => sync::handle_remove::<comp::MountState>(entity, world),
|
|
|
|
EcsCompPhantom::Mounting(_) => sync::handle_remove::<comp::Mounting>(entity, world),
|
|
|
|
EcsCompPhantom::Mass(_) => sync::handle_remove::<comp::Mass>(entity, world),
|
|
|
|
EcsCompPhantom::Gravity(_) => sync::handle_remove::<comp::Gravity>(entity, world),
|
|
|
|
EcsCompPhantom::Sticky(_) => sync::handle_remove::<comp::Sticky>(entity, world),
|
2019-11-04 00:57:36 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-10 17:23:27 +00:00
|
|
|
}
|