use sardonyx_assets::PrefabData;
use sardonyx_core::ecs::prelude::{Component, Entity, HashMapStorage, NullStorage, WriteStorage};
use sardonyx_error::Error;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
pub struct FlyControlTag;
impl Component for FlyControlTag {
type Storage = NullStorage<FlyControlTag>;
}
#[derive(Debug, Clone)]
pub struct ArcBallControlTag {
pub target: Entity,
pub distance: f32,
}
impl Component for ArcBallControlTag {
type Storage = HashMapStorage<ArcBallControlTag>;
}
#[derive(Debug, Default, Clone, Deserialize, Serialize)]
pub struct ControlTagPrefab {
pub arc_ball: Option<(usize, f32)>,
}
impl<'a> PrefabData<'a> for ControlTagPrefab {
type SystemData = (
WriteStorage<'a, FlyControlTag>,
WriteStorage<'a, ArcBallControlTag>,
);
type Result = ();
fn add_to_entity(
&self,
entity: Entity,
system_data: &mut Self::SystemData,
entities: &[Entity],
_: &[Entity],
) -> Result<(), Error> {
system_data.0.insert(entity, FlyControlTag)?;
if let Some((index, distance)) = self.arc_ball {
system_data.1.insert(
entity,
ArcBallControlTag {
target: entities[index],
distance,
},
)?;
}
Ok(())
}
}