diff --git a/Difficult_Rocket/__init__.py b/Difficult_Rocket/__init__.py index 035302d..9afe2e2 100644 --- a/Difficult_Rocket/__init__.py +++ b/Difficult_Rocket/__init__.py @@ -23,12 +23,14 @@ from libs.MCDR.version import Version game_version = Version("0.6.5.0") # 游戏版本 build_version = Version("1.1.0.0") # 编译文件版本(与游戏本体无关) -DR_rust_version = Version("0.0.5.2") # DR 的 Rust 编写部分的版本 +DR_rust_version = Version("0.0.6.4") # DR 的 Rust 编写部分的版本 __version__ = game_version -long_version: int = 10 +long_version: int = 11 """ long_version: 一个用于标记内部协议的整数 +11: 为 DR_option 添加 use_DR_rust + 修复了一些拼写错误 10: 为 DR_runtime 添加 DR_Rust_get_version 9 : 为 DR_option 添加 pyglet_macosx_dev_test 8 : 为 DR_runtime 添加 DR_rust_version @@ -51,13 +53,14 @@ class _DR_option(Options): """ name = 'DR Option' # runtime options - InputBox_use_TextEntry: bool = True - record_threads: bool = True - use_cProfile: bool = False - use_local_logging: bool = False - report_translate_no_found: bool = True - use_muitprocess: bool = False - DR_rust_available: bool = False + InputBox_use_TextEntry: bool = True + record_threads: bool = True + report_translate_not_found: bool = True + use_multiprocess: bool = False + DR_rust_available: bool = False + use_DR_rust: bool = True + use_cProfile: bool = False + use_local_logging: bool = False # tests playing: bool = False @@ -79,6 +82,7 @@ class _DR_option(Options): if not __name__ == '__main__': traceback.print_exc() self.DR_rust_available = False + self.use_DR_rust = self.use_DR_rust and self.DR_rust_available self.flush_option() def draw(self): diff --git a/Difficult_Rocket/client/__init__.py b/Difficult_Rocket/client/__init__.py index 78be364..97f4f8f 100644 --- a/Difficult_Rocket/client/__init__.py +++ b/Difficult_Rocket/client/__init__.py @@ -177,6 +177,7 @@ class ClientWindow(Window): self.input_box = InputBox(x=50, y=30, width=300, batch=self.label_batch, text='') # 实例化 self.input_box.push_handlers(self) + self.input_box.set_handler('on_commit', self.on_input) self.push_handlers(self.input_box) self.input_box.enabled = True # 设置刷新率 @@ -282,6 +283,11 @@ class ClientWindow(Window): command line event """ + def on_input(self, message: str) -> None: + command_text = line.CommandText(message) + self.on_command(command_text) + self.input_box.value = '' + @_call_screen_after def on_command(self, command: line.CommandText): self.logger.info(tr.lang('window', 'command.text').format(command)) diff --git a/Difficult_Rocket/client/render/sr1_ship.py b/Difficult_Rocket/client/render/sr1_ship.py index 1437a42..6240e53 100644 --- a/Difficult_Rocket/client/render/sr1_ship.py +++ b/Difficult_Rocket/client/render/sr1_ship.py @@ -4,7 +4,7 @@ # All rights reserved # ------------------------------- -import math +import random from xml.etree import ElementTree from xml.etree.ElementTree import Element from typing import List, TYPE_CHECKING, Union, Dict, Optional @@ -28,7 +28,7 @@ from Difficult_Rocket.api.types.SR1 import SR1Textures, SR1PartTexture, SR1PartD if TYPE_CHECKING: from Difficult_Rocket.client import ClientWindow -if DR_option.DR_rust_available: +if DR_option.use_DR_rust: from libs.Difficult_Rocket_rs import better_update_parts, PartDatas @@ -115,7 +115,7 @@ class SR1ShipRender(BaseScreen): batch=self.part_batch) self.part_data: Dict[int, SR1PartData] = {} self.parts_sprite: Dict[int, Sprite] = {} - if DR_option.DR_rust_available: + if DR_option.use_DR_rust: self.rust_parts = None def load_xml(self, file_path: str) -> bool: @@ -172,7 +172,7 @@ class SR1ShipRender(BaseScreen): self.parts_sprite[part.id].visible = False self.parts_sprite[part.id] = cache_sprite self.need_draw = False - if DR_option.DR_rust_available: + if DR_option.use_DR_rust: print(type(self.part_data)) self.rust_parts = PartDatas(self.part_data) # print(self.rust_parts.get_rust_pointer()) @@ -181,8 +181,12 @@ class SR1ShipRender(BaseScreen): def update_parts(self) -> bool: if not self.rendered: return False - if DR_option.DR_rust_available: - return better_update_parts(self, SR1ShipRender_Option, self.window_pointer, self.rust_parts) + if DR_option.use_DR_rust: + # print(f'{self.dx=} {self.dy=} {self.scale=}') + # from objprint import op + # op(random.choices(self.parts_sprite), indent=1) + return better_update_parts(self, SR1ShipRender_Option, self.window_pointer, + self.rust_parts, DR_option.gui_scale, 60) self.debug_line.x2, self.debug_line.y2 = self.dx + (self.window_pointer.width / 2), self.dy + ( self.window_pointer.height / 2) self.debug_d_pos_label.text = f'x: {self.dx} y: {self.dy}' diff --git a/Difficult_Rocket/main.py b/Difficult_Rocket/main.py index eae4ca5..3877d4f 100644 --- a/Difficult_Rocket/main.py +++ b/Difficult_Rocket/main.py @@ -70,7 +70,7 @@ class Game: # @new_thread('main') def _start(self): self.server.run() - if DR_option.use_muitprocess: + if DR_option.use_multiprocess: try: game_process = multiprocessing.Process(target=self.client.start(), name='pyglet app') game_process.start() diff --git a/Difficult_Rocket/utils/translate.py b/Difficult_Rocket/utils/translate.py index 433a36a..a96e1d4 100644 --- a/Difficult_Rocket/utils/translate.py +++ b/Difficult_Rocket/utils/translate.py @@ -78,7 +78,7 @@ class Translates: def _raise_no_value(self, e: Exception, item: key_type): if self.config.raise_error: raise TranslateKeyNotFound(self.value, [x[1] for x in self.get_list]) from None - elif DR_option.report_translate_no_found: + elif DR_option.report_translate_not_found: frame = inspect.currentframe() if frame is not None: frame = frame.f_back diff --git a/configs/main.toml b/configs/main.toml index d68d5c3..9c345a0 100644 --- a/configs/main.toml +++ b/configs/main.toml @@ -9,7 +9,7 @@ fonts_folder = "libs/fonts" [window] style = "None" width = 1520 -height = 1133 +height = 868 visible = true gui_scale = 1 caption = "Difficult Rocket {version}" diff --git a/libs/Difficult_Rocket_rs/__init__.py b/libs/Difficult_Rocket_rs/__init__.py index 7fafc06..afca79c 100644 --- a/libs/Difficult_Rocket_rs/__init__.py +++ b/libs/Difficult_Rocket_rs/__init__.py @@ -26,6 +26,8 @@ if TYPE_CHECKING: def better_update_parts(render: SR1ShipRender, option: SR1ShipRender_Option, window: BaseScreen, - parts: PartDatas) -> bool: ... + parts: PartDatas, + global_scale: float, + sr1_xml_scale: int) -> bool: ... diff --git a/libs/Difficult_Rocket_rs/src/src/lib.rs b/libs/Difficult_Rocket_rs/src/src/lib.rs index 243aaa0..51e414d 100644 --- a/libs/Difficult_Rocket_rs/src/src/lib.rs +++ b/libs/Difficult_Rocket_rs/src/src/lib.rs @@ -12,7 +12,7 @@ use pyo3::prelude::*; #[pyfunction] fn get_version_str() -> String { - return String::from("0.0.5.2"); + return String::from("0.0.6.4"); } #[pyfunction] diff --git a/libs/Difficult_Rocket_rs/src/src/sr1_render.rs b/libs/Difficult_Rocket_rs/src/src/sr1_render.rs index 822c7a2..7f6e866 100644 --- a/libs/Difficult_Rocket_rs/src/src/sr1_render.rs +++ b/libs/Difficult_Rocket_rs/src/src/sr1_render.rs @@ -9,6 +9,7 @@ use std::collections::HashMap; use pyo3::intern; use pyo3::prelude::*; +// use pyo3::types::PyDict; use crate::sr1_render::types::SR1PartData; #[allow(dead_code)] @@ -115,7 +116,9 @@ pub mod types { #[pyfunction] #[allow(unused_variables)] -pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny, parts: &types::PartDatas) -> PyResult { +pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny, + parts: &types::PartDatas, + global_scale: f64, sr1_xml_scale: i32) -> PyResult { if !render.getattr(intern!(render.py(), "rendered"))?.is_true()? { return Ok(false); } @@ -125,16 +128,24 @@ pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny, parts let y_center: f32 = window.getattr(intern!(window.py(), "height"))?.extract()?; let x_center: f32 = x_center / 2.0; let y_center: f32 = y_center / 2.0; + let render_scale: f32 = render.getattr(intern!(render.py(), "scale"))?.extract()?; let datas: &HashMap = &parts.part_structs; + let part_sprites = render.getattr(intern!(render.py(), "parts_sprite"))?; + // let part_sprites: &PyDict = part_sprites.downcast::()?; for keys in datas { - - println!("{}", keys.0); + // let index = keys.0.to_string(); + let sprite = part_sprites.get_item(keys.0)?; + let new_x: f64 = keys.1.x * global_scale * render_scale as f64 * sr1_xml_scale as f64 + x_center as f64 + dx; + let new_y: f64 = keys.1.y * global_scale * render_scale as f64 * sr1_xml_scale as f64 + x_center as f64 + dy; + let new_scale: f32 = render_scale * global_scale as f32; + sprite.setattr(intern!(sprite.py(), "x"), new_x)?; + sprite.setattr(intern!(sprite.py(), "y"), new_y)?; + sprite.setattr(intern!(sprite.py(), "scale"), new_scale)?; + part_sprites.set_item(keys.0, sprite)?; + // println!("{}", keys.0); } - - if option.getattr("debug_d_pos")?.is_true()? { - let line = render.getattr(intern!(render.py(), "debug_line"))?; - } - // for part in parts. + 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