remove some Option<T> from SR1PartDataAttr

This commit is contained in:
shenjack 2023-04-09 14:18:34 +08:00
parent 655a6776c8
commit e269c7dfdc
4 changed files with 79 additions and 73 deletions

View File

@ -8,7 +8,7 @@ fonts_folder = "libs/fonts"
[window] [window]
style = "None" style = "None"
width = 1406 width = 1406
height = 893 height = 900
visible = true visible = true
gui_scale = 1 gui_scale = 1
caption = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}" caption = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}"

View File

@ -33,9 +33,14 @@
- 正在实现 `SR1PartDataTrait` - 正在实现 `SR1PartDataTrait`
- 用于转换 `RawPartData``SR1PartData` - 用于转换 `RawPartData``SR1PartData`
- 写的真折磨人 - 写的真折磨人
- 移除了 字段 `attr``Option<T>`
- Implementing `SR1PartDataTrait` - Implementing `SR1PartDataTrait`
- Used to convert `RawPartData` and `SR1PartData` - Used to convert `RawPartData` and `SR1PartData`
- It's really torture to write - It's really torture to write
- Removed the `Option<T>` of the field `attr`
- `types::sr1::SR1PartDataAttr`
- 添加 `None` 选项
- Add `None` option
- `SR1PartDataTrait` - `SR1PartDataTrait`
- `to_sr_part_data` - `to_sr_part_data`
- `to_raw_part_data` - `to_raw_part_data`

View File

@ -533,15 +533,32 @@ pub mod ship {
impl SR1PartDataTrait for Part { impl SR1PartDataTrait for Part {
fn to_sr_part_data(&self) -> SR1PartData { fn to_sr_part_data(&self) -> SR1PartData {
// let attr = match self.part_type { let attr = match self.part_type {
// SR1PartTypeEnum::tank => SR1PartDataAttr::Tank {
// }; fuel: if let Some(tank) = &self.tank { tank.fuel } else { 0_f64 },
},
SR1PartTypeEnum::engine => SR1PartDataAttr::Engine {
fuel: if let Some(engine) = &self.engine { engine.fuel } else { 0_f64 },
},
SR1PartTypeEnum::solar => SR1PartDataAttr::Solar {
extension: self.extension.unwrap_or(0_f64),
},
SR1PartTypeEnum::parachute => SR1PartDataAttr::Parachute {
chute_x: self.chute_x.unwrap_or(0_f64),
chute_y: self.chute_y.unwrap_or(0_f64),
chute_angle: self.chute_angle.unwrap_or(0_f64),
chute_height: self.chute_height.unwrap_or(0_f64),
inflate: i8_to_bool(self.inflate.unwrap_or(0_i8)),
inflation: i8_to_bool(self.inflation.unwrap_or(0_i8)),
deployed: i8_to_bool(self.deployed.unwrap_or(0_i8)),
rope: i8_to_bool(self.rope.unwrap_or(0_i8)),
},
_ => SR1PartDataAttr::None,
};
todo!() todo!()
} }
fn to_raw_part_data(&self) -> Part { fn to_raw_part_data(&self) -> Part { self.clone() }
self.clone()
}
} }
impl SR1ShipTrait for RawShip { impl SR1ShipTrait for RawShip {
@ -557,10 +574,8 @@ pub mod ship {
let mut disconnect_parts = Vec::new(); let mut disconnect_parts = Vec::new();
for disconnected_part in &disconnect.parts { for disconnected_part in &disconnect.parts {
let mut parts_vec = Vec::new(); let mut parts_vec = Vec::new();
for part in &disconnected_part.parts.parts { for part in &disconnected_part.parts.parts {
parts_vec.push(part.to_sr_part_data()); parts_vec.push(part.to_sr_part_data());
} }
disconnect_parts.push((parts_vec, disconnected_part.connects.connects.clone())); disconnect_parts.push((parts_vec, disconnected_part.connects.connects.clone()));

View File

@ -380,21 +380,14 @@ pub mod sr1 {
#[inline] #[inline]
fn to_raw_part_data(&self) -> RawPartData { fn to_raw_part_data(&self) -> RawPartData {
let tank = match &self.attr { let tank = match &self.attr {
Some(attr) => match attr {
SR1PartDataAttr::Tank { fuel } => Some(RawTank { fuel: *fuel }), SR1PartDataAttr::Tank { fuel } => Some(RawTank { fuel: *fuel }),
_ => None, _ => None,
},
_ => None,
}; };
let engine = match &self.attr { let engine = match &self.attr {
Some(attr) => match attr {
SR1PartDataAttr::Engine { fuel } => Some(RawEngine { fuel: *fuel }), SR1PartDataAttr::Engine { fuel } => Some(RawEngine { fuel: *fuel }),
_ => None, _ => None,
},
_ => None,
}; };
let pod = match &self.attr { let pod = match &self.attr {
Some(attr) => match attr {
SR1PartDataAttr::Pod { SR1PartDataAttr::Pod {
name, name,
throttle, throttle,
@ -423,11 +416,8 @@ pub mod sr1 {
} }
}), }),
_ => None, _ => None,
},
_ => None,
}; };
let (chute_x, chute_y, chute_angle, chute_height, inflate, inflation, deployed, rope) = match &self.attr { let (chute_x, chute_y, chute_angle, chute_height, inflate, inflation, deployed, rope) = match &self.attr {
Some(attr) => match attr {
SR1PartDataAttr::Parachute { SR1PartDataAttr::Parachute {
chute_x, chute_x,
chute_y, chute_y,
@ -448,15 +438,10 @@ pub mod sr1 {
Some(bool_to_i8(*rope)), Some(bool_to_i8(*rope)),
), ),
_ => (None, None, None, None, None, None, None, None), _ => (None, None, None, None, None, None, None, None),
},
_ => (None, None, None, None, None, None, None, None),
}; };
let extension = match &self.attr { let extension = match &self.attr {
Some(attr) => match attr {
SR1PartDataAttr::Solar { extension } => Some(*extension), SR1PartDataAttr::Solar { extension } => Some(*extension),
_ => None, _ => None,
},
_ => None,
}; };
RawPartData { RawPartData {
tank, tank,
@ -488,7 +473,7 @@ pub mod sr1 {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct SR1PartData { pub struct SR1PartData {
// 单独的属性 // 单独的属性
pub attr: Option<SR1PartDataAttr>, pub attr: SR1PartDataAttr,
// 基本状态属性 // 基本状态属性
pub x: f64, pub x: f64,
pub y: f64, pub y: f64,
@ -532,6 +517,7 @@ pub mod sr1 {
deployed: bool, deployed: bool,
rope: bool, rope: bool,
}, },
None,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]