~starkingdoms/starkingdoms

ref: f5b36bb07dfc827a4435fd116c1438f7776c1fa0 starkingdoms/crates/unified/src/config/part.rs -rw-r--r-- 1.6 KiB
f5b36bb0ghostly_zsh fix: orbit predictor is scaled and positioned constantly on hte screen 18 days 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
50
51
52
53
54
55
use bevy::asset::Asset;
use bevy::math::{Quat, Vec3};
use crate::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, TypePath, Serialize, Clone, Debug, PartialEq, Asset)]
pub struct PartConfig {
    pub part: PartPartConfig,
    pub physics: PartPhysicsConfig,
    #[serde(rename = "thruster")]
    #[serde(default)]
    pub thrusters: Vec<ThrusterConfig>,
    #[serde(default)]
    #[serde(rename = "joint")]
    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, TypePath, Serialize, Clone, Debug, PartialEq)]
pub struct ThrusterConfig {
    pub id: String,
    #[serde(default)]
    pub apply_force_at_local: Vec2,
    pub thrust_vector: Vec2,
}
#[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()
        }
    }
}