From 2577b91741e20458a7ad02b78e3564e0b3912fb8 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sat, 27 May 2023 00:12:24 +0800 Subject: [PATCH] fix #21 also --- configs/main.toml | 2 +- docs/src/change_log/dr_game.md | 11 +++++++- .../Difficult_Rocket_rs/src/src/sr1_data.rs | 26 ++++++++++++++----- .../Difficult_Rocket_rs/src/src/types.rs | 20 +++++++------- mods/dr_game/sr1_ship.py | 1 - 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/configs/main.toml b/configs/main.toml index 400236e..089d5fa 100644 --- a/configs/main.toml +++ b/configs/main.toml @@ -7,7 +7,7 @@ fonts_folder = "libs/fonts" [window] style = "None" -width = 1683 +width = 1311 height = 1474 visible = true gui_scale = 1 diff --git a/docs/src/change_log/dr_game.md b/docs/src/change_log/dr_game.md index f18587a..c3c5287 100644 --- a/docs/src/change_log/dr_game.md +++ b/docs/src/change_log/dr_game.md @@ -18,10 +18,19 @@ - 基于 `PyConsole` - 用于替换 `DR sdk` 的默认控制台方法 -## DR rs 0.2.9.2 +## DR rs 0.2.9.3 ### `sr1_data` +- `inflation` + - `Option` -> `Option` + +### Bug 修复 + +- [#21](https://github.com/shenjackyuanjie/Difficult-Rocket/issues/21) `field: "missing field Activate"` + +## DR rs 0.2.9.2 + ### Bug 修复 - [#20](https://github.com/shenjackyuanjie/Difficult-Rocket/issues/20) `` diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data.rs index 89792c1..d0f70a0 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data.rs @@ -12,10 +12,9 @@ pub mod part_list { use pyo3::prelude::*; use serde::{Deserialize, Serialize}; // use quick_xml::de::from_str; - use serde_xml_rs::from_str; - use crate::types::sr1::{SR1PartList, SR1PartType, SR1PartTypeAttr}; use crate::types::sr1::{SR1PartListTrait, SR1PartTypeData}; + use serde_xml_rs::from_str; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct RawPartList { @@ -377,6 +376,7 @@ pub mod ship { use serde::{Deserialize, Serialize}; // use quick_xml::de::from_str; use serde_xml_rs::from_str; + use serde_xml_rs::Error as XmlError; use super::part_list::SR1PartTypeEnum; @@ -444,7 +444,7 @@ pub mod ship { pub chute_height: Option, pub extension: Option, pub inflate: Option, - pub inflation: Option, + pub inflation: Option, pub exploded: Option, pub rope: Option, // ? @@ -473,7 +473,7 @@ pub mod ship { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Staging { #[serde(rename = "currentStage")] - pub current_stage: u32, + pub current_stage: i32, #[serde(rename = "Step")] pub steps: Vec, } @@ -481,7 +481,7 @@ pub mod ship { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Step { #[serde(rename = "Activate")] - pub activates: Vec, + pub activates: Option>, // Option for https://github.com/shenjackyuanjie/Difficult-Rocket/issues/21 } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -595,8 +595,20 @@ pub mod ship { #[inline] pub fn from_file(path: String) -> Option { let ship_file = fs::read_to_string(path).unwrap(); - let ship: RawShip = from_str(&ship_file).unwrap(); - Some(ship) + let ship = from_str(&ship_file); + match ship { + Ok(ship) => Some(ship), + Err(e) => { + println!("ERROR!\n{:?}\n----------", e); + match e { + XmlError::ParseIntError { source } => { + println!("ParseIntError: {:?}", source.kind()); + None + } + _ => None, + } + } + } } } diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/types.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/types.rs index b1eef10..a99c752 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/types.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/types.rs @@ -434,7 +434,7 @@ pub mod sr1 { moved: bool_to_i8(active.1.to_owned()), }); } - actives.push(RawStep { activates: steps_ }); + actives.push(RawStep { activates: Some(steps_) }); } let stages = RawStaging { current_stage: current_stage.to_owned(), @@ -466,7 +466,7 @@ pub mod sr1 { chute_height: self.attr.chute_height, extension: self.attr.extension, inflate: option_bool_to_option_i8(self.attr.inflate), - inflation: option_bool_to_option_i8(self.attr.inflation), + inflation: self.attr.inflation, exploded: Some(bool_to_i8(self.explode)), rope: option_bool_to_option_i8(self.attr.rope), chute_angle: self.attr.chute_angle, @@ -530,7 +530,7 @@ pub mod sr1 { // Pod pub name: Option, pub throttle: Option, - pub current_stage: Option, + pub current_stage: Option, pub steps: Option>>, // Solar pub extension: Option, @@ -540,7 +540,7 @@ pub mod sr1 { pub chute_height: Option, pub chute_angle: Option, pub inflate: Option, - pub inflation: Option, + pub inflation: Option, pub deployed: Option, pub rope: Option, // part_type @@ -581,7 +581,7 @@ pub mod sr1 { fuel: Option, name: Option, throttle: Option, - current_stage: Option, + current_stage: Option, steps: Option>>, extension: Option, chute_x: Option, @@ -589,7 +589,7 @@ pub mod sr1 { chute_height: Option, chute_angle: Option, inflate: Option, - inflation: Option, + inflation: Option, deployed: Option, rope: Option, part_type: Option, @@ -630,8 +630,10 @@ pub mod sr1 { let mut steps = Vec::new(); for step in &pod.stages.steps { let mut step_vec = Vec::new(); - for act in &step.activates { - step_vec.push((act.id, i8_to_bool(act.moved))); + if let Some(active) = &step.activates { + for act in active { + step_vec.push((act.id, i8_to_bool(act.moved))); + } } steps.push(step_vec); } @@ -653,7 +655,7 @@ pub mod sr1 { chute_height: raw_data.chute_height, chute_angle: raw_data.chute_angle, inflate: option_i8_to_option_bool(raw_data.inflate), - inflation: option_i8_to_option_bool(raw_data.inflation), + inflation: raw_data.inflation, deployed: option_i8_to_option_bool(raw_data.deployed), rope: option_i8_to_option_bool(raw_data.rope), part_type: Cell::new(part_type), diff --git a/mods/dr_game/sr1_ship.py b/mods/dr_game/sr1_ship.py index 172f09c..1c309f8 100644 --- a/mods/dr_game/sr1_ship.py +++ b/mods/dr_game/sr1_ship.py @@ -385,7 +385,6 @@ class SR1ShipRender(BaseScreen): img_center = (abs(img_box[0]), abs(img_box[3])) print(f"img_box: {img_box} img_size: {img_size} img_center: {img_center}") try: - from pyglet.image.codecs.pil import PILImageEncoder from PIL import Image except ImportError: traceback.print_exc()