remove some Option<T> from SR1PartDataAttr
This commit is contained in:
parent
655a6776c8
commit
e269c7dfdc
@ -8,7 +8,7 @@ fonts_folder = "libs/fonts"
|
||||
[window]
|
||||
style = "None"
|
||||
width = 1406
|
||||
height = 893
|
||||
height = 900
|
||||
visible = true
|
||||
gui_scale = 1
|
||||
caption = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}"
|
||||
|
@ -33,9 +33,14 @@
|
||||
- 正在实现 `SR1PartDataTrait`
|
||||
- 用于转换 `RawPartData` 和 `SR1PartData`
|
||||
- 写的真折磨人
|
||||
- 移除了 字段 `attr` 的 `Option<T>`
|
||||
- Implementing `SR1PartDataTrait`
|
||||
- Used to convert `RawPartData` and `SR1PartData`
|
||||
- It's really torture to write
|
||||
- Removed the `Option<T>` of the field `attr`
|
||||
- `types::sr1::SR1PartDataAttr`
|
||||
- 添加 `None` 选项
|
||||
- Add `None` option
|
||||
- `SR1PartDataTrait`
|
||||
- `to_sr_part_data`
|
||||
- `to_raw_part_data`
|
||||
|
@ -533,15 +533,32 @@ pub mod ship {
|
||||
|
||||
impl SR1PartDataTrait for Part {
|
||||
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!()
|
||||
}
|
||||
|
||||
fn to_raw_part_data(&self) -> Part {
|
||||
self.clone()
|
||||
}
|
||||
fn to_raw_part_data(&self) -> Part { self.clone() }
|
||||
}
|
||||
|
||||
impl SR1ShipTrait for RawShip {
|
||||
@ -557,10 +574,8 @@ pub mod ship {
|
||||
|
||||
let mut disconnect_parts = Vec::new();
|
||||
for disconnected_part in &disconnect.parts {
|
||||
|
||||
let mut parts_vec = Vec::new();
|
||||
for part in &disconnected_part.parts.parts {
|
||||
|
||||
parts_vec.push(part.to_sr_part_data());
|
||||
}
|
||||
disconnect_parts.push((parts_vec, disconnected_part.connects.connects.clone()));
|
||||
|
@ -380,82 +380,67 @@ pub mod sr1 {
|
||||
#[inline]
|
||||
fn to_raw_part_data(&self) -> RawPartData {
|
||||
let tank = match &self.attr {
|
||||
Some(attr) => match attr {
|
||||
SR1PartDataAttr::Tank { fuel } => Some(RawTank { fuel: *fuel }),
|
||||
_ => None,
|
||||
},
|
||||
SR1PartDataAttr::Tank { fuel } => Some(RawTank { fuel: *fuel }),
|
||||
_ => None,
|
||||
};
|
||||
let engine = match &self.attr {
|
||||
Some(attr) => match attr {
|
||||
SR1PartDataAttr::Engine { fuel } => Some(RawEngine { fuel: *fuel }),
|
||||
_ => None,
|
||||
},
|
||||
SR1PartDataAttr::Engine { fuel } => Some(RawEngine { fuel: *fuel }),
|
||||
_ => None,
|
||||
};
|
||||
let pod = match &self.attr {
|
||||
Some(attr) => match attr {
|
||||
SR1PartDataAttr::Pod {
|
||||
name,
|
||||
throttle,
|
||||
current_stage,
|
||||
steps,
|
||||
} => Some({
|
||||
let mut actives = Vec::new();
|
||||
for step in steps {
|
||||
let mut steps_ = Vec::new();
|
||||
for active in step {
|
||||
steps_.push(RawActivate {
|
||||
id: active.0,
|
||||
moved: bool_to_i8(active.1),
|
||||
});
|
||||
}
|
||||
actives.push(RawStep { activates: steps_ });
|
||||
SR1PartDataAttr::Pod {
|
||||
name,
|
||||
throttle,
|
||||
current_stage,
|
||||
steps,
|
||||
} => Some({
|
||||
let mut actives = Vec::new();
|
||||
for step in steps {
|
||||
let mut steps_ = Vec::new();
|
||||
for active in step {
|
||||
steps_.push(RawActivate {
|
||||
id: active.0,
|
||||
moved: bool_to_i8(active.1),
|
||||
});
|
||||
}
|
||||
let stages = RawStaging {
|
||||
current_stage: *current_stage,
|
||||
steps: actives,
|
||||
};
|
||||
RawPod {
|
||||
name: name.clone(),
|
||||
throttle: *throttle,
|
||||
stages,
|
||||
}
|
||||
}),
|
||||
_ => None,
|
||||
},
|
||||
actives.push(RawStep { activates: steps_ });
|
||||
}
|
||||
let stages = RawStaging {
|
||||
current_stage: *current_stage,
|
||||
steps: actives,
|
||||
};
|
||||
RawPod {
|
||||
name: name.clone(),
|
||||
throttle: *throttle,
|
||||
stages,
|
||||
}
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
let (chute_x, chute_y, chute_angle, chute_height, inflate, inflation, deployed, rope) = match &self.attr {
|
||||
Some(attr) => match attr {
|
||||
SR1PartDataAttr::Parachute {
|
||||
chute_x,
|
||||
chute_y,
|
||||
chute_angle,
|
||||
chute_height,
|
||||
inflate,
|
||||
inflation,
|
||||
deployed,
|
||||
rope,
|
||||
} => (
|
||||
Some(*chute_x),
|
||||
Some(*chute_y),
|
||||
Some(*chute_angle),
|
||||
Some(*chute_height),
|
||||
Some(bool_to_i8(*inflate)),
|
||||
Some(bool_to_i8(*inflation)),
|
||||
Some(bool_to_i8(*deployed)),
|
||||
Some(bool_to_i8(*rope)),
|
||||
),
|
||||
_ => (None, None, None, None, None, None, None, None),
|
||||
},
|
||||
SR1PartDataAttr::Parachute {
|
||||
chute_x,
|
||||
chute_y,
|
||||
chute_angle,
|
||||
chute_height,
|
||||
inflate,
|
||||
inflation,
|
||||
deployed,
|
||||
rope,
|
||||
} => (
|
||||
Some(*chute_x),
|
||||
Some(*chute_y),
|
||||
Some(*chute_angle),
|
||||
Some(*chute_height),
|
||||
Some(bool_to_i8(*inflate)),
|
||||
Some(bool_to_i8(*inflation)),
|
||||
Some(bool_to_i8(*deployed)),
|
||||
Some(bool_to_i8(*rope)),
|
||||
),
|
||||
_ => (None, None, None, None, None, None, None, None),
|
||||
};
|
||||
let extension = match &self.attr {
|
||||
Some(attr) => match attr {
|
||||
SR1PartDataAttr::Solar { extension } => Some(*extension),
|
||||
_ => None,
|
||||
},
|
||||
SR1PartDataAttr::Solar { extension } => Some(*extension),
|
||||
_ => None,
|
||||
};
|
||||
RawPartData {
|
||||
@ -488,7 +473,7 @@ pub mod sr1 {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SR1PartData {
|
||||
// 单独的属性
|
||||
pub attr: Option<SR1PartDataAttr>,
|
||||
pub attr: SR1PartDataAttr,
|
||||
// 基本状态属性
|
||||
pub x: f64,
|
||||
pub y: f64,
|
||||
@ -532,6 +517,7 @@ pub mod sr1 {
|
||||
deployed: bool,
|
||||
rope: bool,
|
||||
},
|
||||
None,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
Loading…
Reference in New Issue
Block a user