use std::ops::Deref;
use bevy::ecs::entity::MapEntities;
use bevy::math::Vec2;
use bevy::prelude::Bundle;
use serde::{Deserialize, Serialize};
use crate::prelude::{ChildOf, Component, Entity, Transform};
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct ThrusterId(pub String);
impl ThrusterId {
#[must_use]
pub fn from_part_and_thruster_id(part: impl AsRef<str>, thruster: impl AsRef<str>) -> Self {
Self(format!("{}:{}", part.as_ref(), thruster.as_ref()))
}
}
#[derive(Component, Serialize, Deserialize, MapEntities)]
#[relationship_target(relationship = ThrusterOfPart, linked_spawn)]
pub struct PartThrusters(#[entities] Vec<Entity>);
impl Deref for PartThrusters {
type Target = Vec<Entity>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Component, Serialize, Deserialize, MapEntities)]
#[relationship(relationship_target = PartThrusters)]
pub struct ThrusterOfPart(#[entities] pub Entity);
#[derive(Component, Serialize, Deserialize)]
pub struct Thruster {
pub id: ThrusterId,
pub thrust_vector: Vec2
}
#[derive(Bundle)]
pub struct ThrusterBundle {
pub thruster: Thruster,
pub transform: Transform,
pub child_of: ChildOf,
pub thruster_of_part: ThrusterOfPart,
}