From a48a5ddec4146eef5c4daf517aa017c42b9146f7 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sun, 12 Feb 2023 12:26:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20DR=5Frs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Difficult_Rocket/__init__.py | 2 +- Difficult_Rocket/api/types/SR1/__init__.py | 2 +- Difficult_Rocket/api/types/__init__.py | 3 +- Difficult_Rocket/client/__init__.py | 2 +- Difficult_Rocket/client/render/sr1_ship.py | 8 +- build_rs.ps1 | 23 ++++- configs/main.toml | 4 +- docs/src/update_logs.md | 10 +++ libs/Difficult_Rocket_rs/src/Cargo.lock | 51 ++++++----- libs/Difficult_Rocket_rs/src/Cargo.toml | 2 +- libs/Difficult_Rocket_rs/src/src/lib.rs | 2 +- .../Difficult_Rocket_rs/src/src/sr1_render.rs | 50 ++--------- libs/Difficult_Rocket_rs/src/src/types.rs | 88 ++++++++++++++++++- requirement-build.txt | 4 +- requirement-dev.txt | 6 +- 15 files changed, 167 insertions(+), 90 deletions(-) diff --git a/Difficult_Rocket/__init__.py b/Difficult_Rocket/__init__.py index df56207..05ff274 100644 --- a/Difficult_Rocket/__init__.py +++ b/Difficult_Rocket/__init__.py @@ -24,7 +24,7 @@ from libs.MCDR.version import Version game_version = Version("0.7.0.2") # 游戏版本 build_version = Version("1.1.0.0") # 编译文件版本(与游戏本体无关) -DR_rust_version = Version("0.1.9.0") # DR 的 Rust 编写部分的版本 +DR_rust_version = Version("0.1.10.0") # DR 的 Rust 编写部分的版本 __version__ = game_version long_version: int = 12 diff --git a/Difficult_Rocket/api/types/SR1/__init__.py b/Difficult_Rocket/api/types/SR1/__init__.py index 3f525f5..fa05b12 100644 --- a/Difficult_Rocket/api/types/SR1/__init__.py +++ b/Difficult_Rocket/api/types/SR1/__init__.py @@ -21,7 +21,7 @@ class SR1PartData: x: float y: float id: int - type_: str + p_type: str active: bool angle: float angle_v: float diff --git a/Difficult_Rocket/api/types/__init__.py b/Difficult_Rocket/api/types/__init__.py index 4e281d4..992b94c 100644 --- a/Difficult_Rocket/api/types/__init__.py +++ b/Difficult_Rocket/api/types/__init__.py @@ -80,8 +80,7 @@ class Options: """ 如果子类定义了这个函数,则会在 __init__ 之后调用这个函数 """ def load_file(self) -> bool: - """ - 如果子类定义了这个函数,则会在 __init__ 和 init 之后再调用这个函数 + """如果子类定义了这个函数,则会在 __init__ 和 init 之后再调用这个函数 请注意,这个函数请尽量使用 try 包裹住可能出现错误的部分 否则会在控制台输出你的报错""" diff --git a/Difficult_Rocket/client/__init__.py b/Difficult_Rocket/client/__init__.py index 98721a3..1ec6147 100644 --- a/Difficult_Rocket/client/__init__.py +++ b/Difficult_Rocket/client/__init__.py @@ -198,7 +198,7 @@ class ClientWindow(Window): self.screen_list: List[BaseScreen] self.screen_list.append(DRDEBUGScreen(self)) self.screen_list.append(DRScreen(self)) - self.screen_list.append(SR1ShipRender(self, DR_option.gui_scale)) + self.screen_list.append(SR1ShipRender(self)) def load_fonts(self) -> None: fonts_folder_path = self.main_config['runtime']['fonts_folder'] diff --git a/Difficult_Rocket/client/render/sr1_ship.py b/Difficult_Rocket/client/render/sr1_ship.py index d474857..2a0ead1 100644 --- a/Difficult_Rocket/client/render/sr1_ship.py +++ b/Difficult_Rocket/client/render/sr1_ship.py @@ -56,7 +56,7 @@ def get_sr1_part(part_xml: Element) -> Optional[SR1PartData]: # f'angle: {part_angle} angle_v: {part_angle_v} editor_angle: {part_editor_angle} ' # f'flip_x: {part_flip_x} flip_y: {part_flip_y} explode: {part_explode} ' # f'textures: {SR1PartTexture.get_textures_from_type(part_type)}') - return SR1PartData(x=part_x, y=part_y, id=part_id, type_=part_type, + return SR1PartData(x=part_x, y=part_y, id=part_id, p_type=part_type, active=part_activate, angle=part_angle, angle_v=part_angle_v, editor_angle=part_editor_angle, flip_x=part_flip_x, flip_y=part_flip_y, explode=part_explode, textures=part_textures) @@ -76,11 +76,9 @@ class SR1ShipRender(BaseScreen): """用于渲染 sr1 船的类""" def __init__(self, - main_window: "ClientWindow", - scale: float): + main_window: "ClientWindow"): super().__init__(main_window) self.rendered = False - self.scale = scale self.focus = True self.need_draw = False self.drawing = False @@ -155,7 +153,6 @@ class SR1ShipRender(BaseScreen): cache_sprite.scale_x = -1 # 就是直接取反缩放,应该没问题····吧?(待会试试就知道了 if part.flip_y: cache_sprite.scale_y = -1 - cache_sprite.scale = self.scale * DR_option.gui_scale cache_sprite.x = cache_sprite.x - cache_sprite.scale_x / 2 cache_sprite.y = cache_sprite.y - cache_sprite.scale_y / 2 self.parts_sprite[part.id] = cache_sprite @@ -269,7 +266,6 @@ class SR1ShipRender(BaseScreen): self.debug_mouse_label.position = x, y + 10, 0 self.need_update_parts = True # self.update_parts() - # print(f'{self.scale=} {self.dx=} {self.dy=} {x=} {y=} {scroll_x=} {scroll_y=} {1 - (0.5 ** scroll_y)=}') def on_command(self, command: CommandText): if command.re_match('render'): diff --git a/build_rs.ps1 b/build_rs.ps1 index b2ec631..ce21769 100644 --- a/build_rs.ps1 +++ b/build_rs.ps1 @@ -1,8 +1,25 @@ Set-Location .\libs\Difficult_Rocket_rs\src -python3.8 setup.py build -python3.9 setup.py build -python3.11 setup.py build +Write-Output $args[0] + +$do = 0 + +if ("38" -notin $args -and "39" -notin $args -and "310" -notin $args -and "311" -notin $args) { + $do = 1 +} + +if ($do -or "38" -in $args) { + python3.8 setup.py build +} +if ($do -or "39" -in $args) { + python3.9 setup.py build +} +if ($do -or "310" -in $args) { + python3.10 setup.py build +} +if ($do -or "311" -in $args) { + python3.11 setup.py build +} python3.8 after_build.py diff --git a/configs/main.toml b/configs/main.toml index 4819852..906e5a2 100644 --- a/configs/main.toml +++ b/configs/main.toml @@ -8,8 +8,8 @@ fonts_folder = "libs/fonts" [window] style = "None" -width = 928 -height = 1532 +width = 1242 +height = 884 visible = true gui_scale = 1 caption = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}" diff --git a/docs/src/update_logs.md b/docs/src/update_logs.md index e80f101..44db412 100644 --- a/docs/src/update_logs.md +++ b/docs/src/update_logs.md @@ -24,6 +24,16 @@ - `get_buf` - 用于截屏 并将文件保存至根目录下面的 `test.png` +### 更新 + +- 更改了 `ClientWindow` 启动参数的设置, 实装 ClientOption 的使用 +- 将 `SR1PartData` 的字段 `type_` 重命名为 `p_type` + +### `DR_Rs` + +- 移动了 `SR1PartData` 的位置 + - 为 `SR1PartData` 添加了 `connections: Option>` 的字段 + ## 20230207 V 0.7.0.2 淦, 忘记步进版本号了( diff --git a/libs/Difficult_Rocket_rs/src/Cargo.lock b/libs/Difficult_Rocket_rs/src/Cargo.lock index 88fddeb..52f23c1 100644 --- a/libs/Difficult_Rocket_rs/src/Cargo.lock +++ b/libs/Difficult_Rocket_rs/src/Cargo.lock @@ -22,16 +22,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "difficult_rocket_rs" -version = "0.1.6" +version = "0.1.10" dependencies = [ "pyo3", ] [[package]] name = "indoc" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da2d6f23ffea9d7e76c53eee25dfb67bcd8fde7f1198b0855350698c9f07c780" +checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" [[package]] name = "libc" @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.6" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba1ef8814b5c993410bb3adfad7a5ed269563e4a2f90c41f5d85be7fb47133bf" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "cfg-if", "libc", @@ -89,18 +89,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" dependencies = [ "unicode-ident", ] [[package]] name = "pyo3" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccd4149c8c3975099622b4e1962dac27565cf5663b76452c3e2b66e0b6824277" +checksum = "06a3d8e8a46ab2738109347433cb7b96dffda2e4a218b03ef27090238886b147" dependencies = [ "cfg-if", "indoc", @@ -115,9 +115,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cd09fe469834db21ee60e0051030339e5d361293d8cb5ec02facf7fdcf52dbf" +checksum = "75439f995d07ddfad42b192dfcf3bc66a7ecfd8b4a1f5f6f046aa5c2c5d7677d" dependencies = [ "once_cell", "target-lexicon", @@ -125,9 +125,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c427c9a96b9c5b12156dbc11f76b14f49e9aae8905ca783ea87c249044ef137" +checksum = "839526a5c07a17ff44823679b68add4a58004de00512a95b6c1c98a6dcac0ee5" dependencies = [ "libc", "pyo3-build-config", @@ -135,9 +135,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b822bbba9d60630a44d2109bc410489bb2f439b33e3a14ddeb8a40b378a7c4" +checksum = "bd44cf207476c6a9760c4653559be4f206efafb924d3e4cbf2721475fc0d6cc5" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -147,9 +147,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84ae898104f7c99db06231160770f3e40dad6eb9021daddc0fedfa3e41dff10a" +checksum = "dc1f43d8e30460f36350d18631ccf85ded64c059829208fe680904c65bcd0a4c" dependencies = [ "proc-macro2", "quote", @@ -199,9 +199,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.5" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9410d0f6853b1d94f0e519fb95df60f29d2c1eff2d921ffdf01a4c8a3b54f12d" +checksum = "8ae9980cab1db3fceee2f6c6f643d5d8de2997c58ee8d25fb0cc8a9e9e7348e5" [[package]] name = "unicode-ident" @@ -217,9 +217,18 @@ checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c" [[package]] name = "windows-sys" -version = "0.42.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", diff --git a/libs/Difficult_Rocket_rs/src/Cargo.toml b/libs/Difficult_Rocket_rs/src/Cargo.toml index 5330204..6abd6be 100644 --- a/libs/Difficult_Rocket_rs/src/Cargo.toml +++ b/libs/Difficult_Rocket_rs/src/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "difficult_rocket_rs" -version = "0.1.6" +version = "0.1.10" edition = "2021" license-file = '../../LICENSE' # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/libs/Difficult_Rocket_rs/src/src/lib.rs b/libs/Difficult_Rocket_rs/src/src/lib.rs index 0e1219b..73e7675 100644 --- a/libs/Difficult_Rocket_rs/src/src/lib.rs +++ b/libs/Difficult_Rocket_rs/src/src/lib.rs @@ -14,7 +14,7 @@ use pyo3::prelude::*; #[pyfunction] fn get_version_str() -> String { - return String::from("0.1.9.0"); + return String::from("0.1.10.0"); } #[pyfunction] diff --git a/libs/Difficult_Rocket_rs/src/src/sr1_render.rs b/libs/Difficult_Rocket_rs/src/src/sr1_render.rs index f2602ac..56b2cf8 100644 --- a/libs/Difficult_Rocket_rs/src/src/sr1_render.rs +++ b/libs/Difficult_Rocket_rs/src/src/sr1_render.rs @@ -11,7 +11,7 @@ use std::time; use pyo3::intern; use pyo3::prelude::*; // use pyo3::types::PyDict; -use crate::sr1_render::types::SR1PartData; +use crate::types::sr1::SR1PartData; #[allow(dead_code)] pub mod types { @@ -20,21 +20,7 @@ pub mod types { use pyo3::prelude::*; use pyo3::types::{PyDict}; - pub struct SR1PartData { - pub x: f64, - pub y: f64, - pub id: i64, - pub type_: String, - pub active: bool, - pub angle: f64, - pub angle_v: f64, - pub editor_angle: usize, - pub flip_x: bool, - pub flip_y: bool, - pub explode: bool, - pub textures: String, - // pub connections: Vec - } + use crate::types::sr1::SR1PartData; pub struct Point { pub x: f64, @@ -65,12 +51,12 @@ pub mod types { #[allow(non_snake_case)] - pub fn part_data_to_SR1PartData(input: &PyAny) -> Result { + pub fn part_data_to_SR1PartData(input: &PyAny) -> PyResult { return Ok(SR1PartData{ x: input.getattr(intern!(input.py(), "x"))?.extract()?, y: input.getattr(intern!(input.py(), "y"))?.extract()?, id: input.getattr(intern!(input.py(), "id"))?.extract()?, - type_: input.getattr(intern!(input.py(), "type_"))?.extract()?, + p_type: input.getattr(intern!(input.py(), "p_type"))?.extract()?, active: input.getattr(intern!(input.py(), "active"))?.extract()?, angle: input.getattr(intern!(input.py(), "angle"))?.extract()?, angle_v: input.getattr(intern!(input.py(), "angle_v"))?.extract()?, @@ -79,12 +65,13 @@ pub mod types { flip_y: input.getattr(intern!(input.py(), "flip_y"))?.extract()?, explode: input.getattr(intern!(input.py(), "explode"))?.extract()?, textures: input.getattr(intern!(input.py(), "textures"))?.extract()?, + connections: None // connections: input.getattr(intern!(input.py(), "connections"))?.extract()?, }) } #[allow(non_snake_case)] - pub fn part_data_tp_SR1PartDatas(input: &PyDict) -> Result, PyErr> { + pub fn part_data_tp_SR1PartDatas(input: &PyDict) -> PyResult> { let mut result: HashMap = HashMap::with_capacity(input.len()); for key in input.iter() { result.insert(key.0.extract()?, part_data_to_SR1PartData(key.1)?); @@ -92,23 +79,6 @@ pub mod types { return Ok(result) } - pub fn part_data_to_point(input: &PyAny) -> Result { - return Ok(Point{ - x: input.getattr(intern!(input.py(), "x"))?.extract()?, - y: input.getattr(intern!(input.py(), "y"))?.extract()?, - id: input.getattr(intern!(input.py(), "id"))?.extract()?, - type_: input.getattr(intern!(input.py(), "type_"))?.extract()? - }) - } - - pub fn part_datas_to_points(input: &PyDict) -> Result, PyErr> { - let mut result: HashMap = HashMap::with_capacity(input.len()); - for key in input.iter() { - result.insert(key.0.extract()?, part_data_to_point(key.1)?); - } - return Ok(result); - } - } @@ -127,23 +97,15 @@ pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny, let y_center: f32 = y_center / 2.0; let datas: &HashMap = &parts.part_structs; let part_sprites = render.getattr(intern!(render.py(), "parts_sprite"))?; - // let part_sprites: &PyDict = part_sprites.downcast::()?; let get_stuf_time = start_time.elapsed(); - // println!("get stuf took {} second", get_stuf_time.as_secs_f64()); for keys in datas { - // let index = keys.0.to_string(); let sprite = part_sprites.get_item(keys.0)?; let new_x: f64 = keys.1.x * sr1_xml_scale as f64 + x_center as f64; let new_y: f64 = keys.1.y * sr1_xml_scale as f64 + y_center as f64; sprite.setattr(intern!(sprite.py(), "x"), new_x)?; sprite.setattr(intern!(sprite.py(), "y"), new_y)?; - // part_sprites.set_item(keys.0, sprite)?; - // println!("{}", keys.0); } let run_time = start_time.elapsed(); - // println!("run took {} second or {} fps", run_time.as_secs_f64(), 1 as f64 / run_time.as_secs_f64()); - // render.setattr(intern!(render.py(), "parts_sprite"), part_sprites)?; - // println!("dx: {} dy: {} scale: {}", dx, dy, render_scale); Ok(true) } \ No newline at end of file diff --git a/libs/Difficult_Rocket_rs/src/src/types.rs b/libs/Difficult_Rocket_rs/src/src/types.rs index fed5cb8..176c304 100644 --- a/libs/Difficult_Rocket_rs/src/src/types.rs +++ b/libs/Difficult_Rocket_rs/src/src/types.rs @@ -6,10 +6,94 @@ * ------------------------------- */ - +#[allow(dead_code)] pub mod sr1 { - pub mod data { + use std::collections::HashMap; + pub fn map_ptype_textures(ptype: String) -> String { + let mut value_map: HashMap<&str, &str> = HashMap::with_capacity(27 * 2); + value_map.insert("pod-1", "Pod"); + value_map.insert("detacher-1", "DetacherVertical"); + value_map.insert("detacher-2", "DetacherRadial"); + value_map.insert("wheel-1", "Wheel"); + value_map.insert("wheel-2", "Wheel"); + value_map.insert("fuselage-1", "Fuselage"); + value_map.insert("strut-1", "Beam"); + value_map.insert("fueltank-0", "TankTiny"); + value_map.insert("fueltank-1", "TankSmall"); + value_map.insert("fueltank-2", "TankMedium"); + value_map.insert("fueltank-3", "TankLarge"); + value_map.insert("fueltank-4", "Puffy750"); + value_map.insert("fueltank-5", "SideTank"); + value_map.insert("engine-0", "EngineTiny"); + value_map.insert("engine-1", "EngineSmall"); + value_map.insert("engine-2", "EngineMedium"); + value_map.insert("engine-3", "EngineLarge"); + value_map.insert("engine-4", "SolidRocketBooster"); + value_map.insert("ion-0", "EngineIon"); + value_map.insert("parachute-1", "ParachuteCanister"); + value_map.insert("nosecone-1", "NoseCone"); + value_map.insert("rcs-1", "RcsBlock"); + value_map.insert("solar-1", "SolarPanelBase"); + value_map.insert("battery-0", "Battery"); + value_map.insert("dock-1", "DockingConnector"); + value_map.insert("port-1", "DockingPort"); + value_map.insert("lander-1", "LanderLegPreview"); + let result = value_map.get(ptype.as_str()); + match result { + None => "Pod".to_string(), + Some(i) => { + let i = *i; + i.to_string() + } + } + } + + pub struct SR1PartData { + pub x: f64, + pub y: f64, + pub id: i64, + pub p_type: String, + pub active: bool, + pub angle: f64, // 弧度制 + pub angle_v: f64, + pub editor_angle: usize, + pub flip_x: bool, + pub flip_y: bool, + pub explode: bool, + pub textures: String, + pub connections: Option> + } +} + +#[allow(dead_code)] +pub mod dr { + pub enum PartType { + Pod, + Separator, + Wheel, + Fuselage, + Beam, + Engine, + FuelTank, + Parachute, + Nosecone, + SolarPanel, + Battery, + Dock, + Port, + Lander + } + + pub struct DRPartData { + pub x: f64, + pub y: f64, + pub id: i64, + pub p_type: PartType, + pub active: bool, + pub angle: f64, // 角度制 + pub angle_v: f64, + pub editor_angle: usize, } } diff --git a/requirement-build.txt b/requirement-build.txt index 892d1eb..972bba7 100644 --- a/requirement-build.txt +++ b/requirement-build.txt @@ -20,9 +20,9 @@ defusedxml >= 0.7.1 objprint >= 0.2.2 # for compile -nuitka >= 1.3.8 +nuitka >= 1.4.5 ordered-set >= 4.1.0 imageio >= 2.25.0 wheel >= 0.38.4 -setuptools >= 66.1.1 +setuptools >= 67.2.0 setuptools-rust >= 1.5.2 diff --git a/requirement-dev.txt b/requirement-dev.txt index abdc9fa..1f2639c 100644 --- a/requirement-dev.txt +++ b/requirement-dev.txt @@ -20,12 +20,12 @@ defusedxml >= 0.7.1 # for debug objprint >= 0.2.2 viztracer >= 0.15.6 -vizplugins +vizplugins >= 0.1.3 # for compile -nuitka >= 1.3.8 +nuitka >= 1.4.5 ordered-set >= 4.1.0 imageio >= 2.25.0 wheel >= 0.38.4 -setuptools >= 66.1.1 +setuptools >= 67.2.0 setuptools-rust >= 1.5.2