~starkingdoms/starkingdoms

ref: e49dc2fa16fe95e986b8c6ec8a807d453705bce7 starkingdoms/crates/unified/src/config/part.rs -rw-r--r-- 1.5 KiB
e49dc2faghostly_zsh feat: fuel exists, but does nothing 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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<PartThrusterConfig>,
    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 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<JointOffset> for Transform {
    fn from(value: JointOffset) -> Self {
        Transform {
            translation: value.translation,
            rotation: Quat::from_rotation_z(value.rotation.to_radians()),
            ..Default::default()
        }
    }
}