DR rs 0.3.2

This commit is contained in:
shenjack 2024-05-15 23:54:32 +08:00
parent aeeb5e46c2
commit ea76747998
Signed by: shenjack
GPG Key ID: 7B1134A979775551
3 changed files with 19 additions and 12 deletions

View File

@ -11,7 +11,6 @@ use crate::sr1_parse::{get_max_box, SR1PartData, SR1PartListTrait};
use crate::sr1_parse::{SR1PartList, SR1PartType, SR1Ship}; use crate::sr1_parse::{SR1PartList, SR1PartType, SR1Ship};
use crate::IdType; use crate::IdType;
// use serde_xml_rs::to_string;
use quick_xml::se::to_string; use quick_xml::se::to_string;
#[pyclass] #[pyclass]

View File

@ -6,7 +6,7 @@ use crate::dr_physics::math::{Edge, Shape};
use crate::dr_physics::math::{Point2D, Rotate}; use crate::dr_physics::math::{Point2D, Rotate};
use crate::sr1_parse::part_list::Damage as RawDamage; use crate::sr1_parse::part_list::Damage as RawDamage;
use crate::sr1_parse::part_list::{AttachPoint, AttachPoints, Engine, Lander, Rcs, Shape as RawShape, Solar, Tank}; use crate::sr1_parse::part_list::{AttachPoint, AttachPoints, Engine, Lander, Rcs, Shape as RawShape, Solar, Tank};
use crate::sr1_parse::part_list::{RawPartList, RawPartType, SR1PartTypeEnum}; use crate::sr1_parse::part_list::{RawPartList, RawPartType, SR1PartTypeEnum, FuelType};
use crate::sr1_parse::ship::{ use crate::sr1_parse::ship::{
Activate as RawActivate, Connection, Connections, DisconnectedPart as RawDisconnectedPart, Activate as RawActivate, Connection, Connections, DisconnectedPart as RawDisconnectedPart,
DisconnectedParts as RawDisconnectedParts, Engine as RawEngine, Part as RawPartData, Parts as RawParts, DisconnectedParts as RawDisconnectedParts, Engine as RawEngine, Part as RawPartData, Parts as RawParts,
@ -41,7 +41,7 @@ pub enum SR1PartTypeAttr {
Tank { Tank {
fuel: f64, fuel: f64,
dry_mass: f64, dry_mass: f64,
fuel_type: i32, fuel_type: FuelType,
}, },
Engine { Engine {
power: f64, power: f64,
@ -53,7 +53,7 @@ pub enum SR1PartTypeAttr {
/// 1 -> Rcs /// 1 -> Rcs
/// 2 -> 电量 /// 2 -> 电量
/// 3 -> 固推 /// 3 -> 固推
fuel_type: i32, fuel_type: FuelType,
throttle_exponential: bool, throttle_exponential: bool,
}, },
Rcs { Rcs {
@ -219,11 +219,13 @@ pub trait SR1PartDataTrait {
pub trait SR1PartListTrait { pub trait SR1PartListTrait {
fn to_sr_part_list(&self, name: Option<String>) -> SR1PartList; fn to_sr_part_list(&self, name: Option<String>) -> SR1PartList;
#[allow(unused)]
fn to_raw_part_list(&self) -> RawPartList; fn to_raw_part_list(&self) -> RawPartList;
} }
pub trait SR1ShipTrait { pub trait SR1ShipTrait {
fn to_sr_ship(&self, name: Option<String>) -> SR1Ship; fn to_sr_ship(&self, name: Option<String>) -> SR1Ship;
#[allow(unused)]
fn to_raw_ship(&self) -> RawShip; fn to_raw_ship(&self) -> RawShip;
} }

View File

@ -149,11 +149,17 @@ impl Damage {
} }
// This enumeration can be considered to replace the integer-represented "fuel type". // This enumeration can be considered to replace the integer-represented "fuel type".
#[derive(Debug, Serialize, Deserialize, Copy, Clone, Default)]
pub enum FuelType { pub enum FuelType {
Common, /// 就是液体燃料
Rcs, #[default]
Battery, Common = 0,
Soild, /// RCS 推进剂
Rcs = 1,
/// 电!!!!!
Battery = 2,
/// 固推神教!
Soild = 3,
} }
#[derive(Debug, Serialize, Deserialize, Copy, Clone)] #[derive(Debug, Serialize, Deserialize, Copy, Clone)]
@ -167,7 +173,7 @@ pub struct Tank {
// 2 -> 电量 // 2 -> 电量
// 3 -> 固推 // 3 -> 固推
#[serde(rename = "@fuelType")] #[serde(rename = "@fuelType")]
pub fuel_type: Option<i32>, pub fuel_type: Option<FuelType>,
} }
#[derive(Debug, Serialize, Deserialize, Copy, Clone)] #[derive(Debug, Serialize, Deserialize, Copy, Clone)]
@ -181,7 +187,7 @@ pub struct Engine {
#[serde(rename = "@turn")] #[serde(rename = "@turn")]
pub turn: f64, pub turn: f64,
#[serde(rename = "@fuelType")] #[serde(rename = "@fuelType")]
pub fuel_type: Option<i32>, pub fuel_type: Option<FuelType>,
#[serde(rename = "@throttleExponential")] #[serde(rename = "@throttleExponential")]
pub throttle_exponential: Option<bool>, pub throttle_exponential: Option<bool>,
} }
@ -286,7 +292,7 @@ impl SR1PartTypeData for RawPartType {
Some(SR1PartTypeAttr::Tank { Some(SR1PartTypeAttr::Tank {
fuel: tank.fuel, fuel: tank.fuel,
dry_mass: tank.dry_mass, dry_mass: tank.dry_mass,
fuel_type: tank.fuel_type.unwrap_or(0), fuel_type: tank.fuel_type.unwrap_or_default(),
}) })
} }
SR1PartTypeEnum::engine => { SR1PartTypeEnum::engine => {
@ -296,7 +302,7 @@ impl SR1PartTypeData for RawPartType {
consumption: engine.consumption, consumption: engine.consumption,
size: engine.size, size: engine.size,
turn: engine.turn, turn: engine.turn,
fuel_type: engine.fuel_type.unwrap_or(0), fuel_type: engine.fuel_type.unwrap_or_default(),
throttle_exponential: engine.throttle_exponential.unwrap_or(false), throttle_exponential: engine.throttle_exponential.unwrap_or(false),
}) })
} }