use bevy::asset::Asset;
use bevy::math::{Quat, Vec3};
use bevy::prelude::{Component, Transform, TypePath};
use serde::{Deserialize, Serialize};
#[derive(Deserialize, TypePath, Serialize, Clone, Debug, PartialEq, Asset)]
pub struct PartConfig {
pub part: PartPartConfig,
pub physics: PartPhysicsConfig,
pub joints: Vec<JointConfig>,
}
#[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 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<JointOffset> for Transform {
fn from(value: JointOffset) -> Self {
Transform {
translation: value.translation,
rotation: Quat::from_rotation_z(value.rotation),
..Default::default()
}
}
}