remove some Option<T> from SR1PartDataAttr
This commit is contained in:
parent
655a6776c8
commit
e269c7dfdc
@ -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}"
|
||||||
|
@ -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`
|
||||||
|
@ -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()));
|
||||||
|
@ -380,82 +380,67 @@ 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,
|
current_stage,
|
||||||
current_stage,
|
steps,
|
||||||
steps,
|
} => Some({
|
||||||
} => Some({
|
let mut actives = Vec::new();
|
||||||
let mut actives = Vec::new();
|
for step in steps {
|
||||||
for step in steps {
|
let mut steps_ = Vec::new();
|
||||||
let mut steps_ = Vec::new();
|
for active in step {
|
||||||
for active in step {
|
steps_.push(RawActivate {
|
||||||
steps_.push(RawActivate {
|
id: active.0,
|
||||||
id: active.0,
|
moved: bool_to_i8(active.1),
|
||||||
moved: bool_to_i8(active.1),
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
actives.push(RawStep { activates: steps_ });
|
|
||||||
}
|
}
|
||||||
let stages = RawStaging {
|
actives.push(RawStep { activates: steps_ });
|
||||||
current_stage: *current_stage,
|
}
|
||||||
steps: actives,
|
let stages = RawStaging {
|
||||||
};
|
current_stage: *current_stage,
|
||||||
RawPod {
|
steps: actives,
|
||||||
name: name.clone(),
|
};
|
||||||
throttle: *throttle,
|
RawPod {
|
||||||
stages,
|
name: name.clone(),
|
||||||
}
|
throttle: *throttle,
|
||||||
}),
|
stages,
|
||||||
_ => 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,
|
chute_angle,
|
||||||
chute_angle,
|
chute_height,
|
||||||
chute_height,
|
inflate,
|
||||||
inflate,
|
inflation,
|
||||||
inflation,
|
deployed,
|
||||||
deployed,
|
rope,
|
||||||
rope,
|
} => (
|
||||||
} => (
|
Some(*chute_x),
|
||||||
Some(*chute_x),
|
Some(*chute_y),
|
||||||
Some(*chute_y),
|
Some(*chute_angle),
|
||||||
Some(*chute_angle),
|
Some(*chute_height),
|
||||||
Some(*chute_height),
|
Some(bool_to_i8(*inflate)),
|
||||||
Some(bool_to_i8(*inflate)),
|
Some(bool_to_i8(*inflation)),
|
||||||
Some(bool_to_i8(*inflation)),
|
Some(bool_to_i8(*deployed)),
|
||||||
Some(bool_to_i8(*deployed)),
|
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 {
|
||||||
@ -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)]
|
||||||
|
Loading…
Reference in New Issue
Block a user