use std::ops::Deref;
use bevy::asset::processor::ErasedProcessor;
use bevy::ecs::entity::MapEntities;
use bevy::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Component, Serialize, Deserialize)]
/// The primary component for a ship structure
pub struct Ship;
#[derive(Component, Serialize, Deserialize)]
#[relationship_target(relationship = PartInShip, linked_spawn)]
pub struct Parts(#[entities] Vec<Entity>);
#[derive(Component, Serialize, Deserialize)]
#[relationship(relationship_target = Parts)]
pub struct PartInShip(#[entities] Entity);
#[derive(Component, Serialize, Deserialize)]
pub struct Joint {
pub id: JointId,
pub transform: Transform
}
#[derive(Component, Serialize, Deserialize)]
pub struct Peer(#[entities] Entity);
#[derive(Component, Serialize, Deserialize)]
#[relationship(relationship_target = Joints)]
pub struct JointOf(#[entities] pub Entity);
#[derive(Component, Serialize, Deserialize)]
#[relationship_target(relationship = JointOf)]
pub struct Joints(#[entities] Vec<Entity>);
#[derive(Component, Serialize, Deserialize)]
#[relationship(relationship_target = JointSnaps)]
pub struct JointSnapOf(#[entities] pub Entity);
#[derive(Component, Serialize, Deserialize)]
#[relationship_target(relationship = JointSnapOf)]
pub struct JointSnaps(#[entities] Vec<Entity>);
#[derive(Serialize, Deserialize)]
pub struct JointId(pub String);
impl JointId {
pub fn from_part_and_joint_id(part: String, joint: String) -> Self {
Self(format!("{part}:{joint}"))
}
}
#[derive(Serialize, Deserialize, Component)]
pub struct JointSnapFor(#[entities] pub Entity);