use bevy::asset::Asset; use bevy::math::{Quat, Vec3}; use bevy::prelude::{Transform, TypePath}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, TypePath, Serialize, Clone, Debug, PartialEq, Asset)] pub struct PartConfig { pub part: PartPartConfig, pub physics: PartPhysicsConfig, pub thruster: Option, pub joints: Vec, } #[derive(Deserialize, TypePath, Serialize, Clone, Debug, PartialEq)] pub struct PartPartConfig { pub name: String, pub sprite_connected: String, pub sprite_disconnected: String, } #[derive(Deserialize, TypePath, Serialize, Clone, Debug, PartialEq)] pub struct PartPhysicsConfig { pub width: f32, pub height: f32, pub mass: f32, } #[derive(Deserialize, TypePath, Serialize, Clone, Debug, PartialEq)] pub struct PartThrusterConfig { pub flow_rate: f32, // kg/s pub exhaust_speed: f32, // m/s } #[derive(Deserialize, TypePath, Serialize, Clone, Debug, PartialEq)] pub struct JointConfig { pub id: String, pub target: JointOffset, pub snap: JointOffset, } #[derive(Deserialize, Serialize, Clone, Debug, TypePath, PartialEq, Copy)] pub struct JointOffset { pub translation: Vec3, pub rotation: f32, } impl From for Transform { fn from(value: JointOffset) -> Self { Transform { translation: value.translation, rotation: Quat::from_rotation_z(value.rotation.to_radians()), ..Default::default() } } }