From 854585574f063413a5e602fdf710b5e71eafadd6 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Thu, 25 May 2023 00:40:20 +0800 Subject: [PATCH] imp max_box --- mods/dr_game/Difficult_Rocket_rs/__init__.py | 1 + mods/dr_game/Difficult_Rocket_rs/src/setup.py | 2 +- mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs | 2 +- .../dr_game/Difficult_Rocket_rs/src/src/python.rs | 15 ++++++++++++--- mods/dr_game/__init__.py | 4 ++-- mods/dr_game/sr1_ship.py | 11 ++++++++++- 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/mods/dr_game/Difficult_Rocket_rs/__init__.py b/mods/dr_game/Difficult_Rocket_rs/__init__.py index 94c6dd5..f39ce2c 100644 --- a/mods/dr_game/Difficult_Rocket_rs/__init__.py +++ b/mods/dr_game/Difficult_Rocket_rs/__init__.py @@ -90,6 +90,7 @@ if TYPE_CHECKING: class SR1Ship_rs: """ 用于高效且省内存的读取 SR1Ship """ + def __init__(self, file_path = './configs/dock1.xml', part_list = './configs/PartList.xml', ship_name = 'NewShip'): ... @property def name(self) -> str: ... @property diff --git a/mods/dr_game/Difficult_Rocket_rs/src/setup.py b/mods/dr_game/Difficult_Rocket_rs/src/setup.py index d321a1b..17dff12 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/setup.py +++ b/mods/dr_game/Difficult_Rocket_rs/src/setup.py @@ -12,7 +12,7 @@ package_path = 'Difficult_Rocket_rs' setup( name='Difficult_Rocket_rs', - version="0.2.9.1", + version="0.2.9.2", author='shenjackyuanjie', author_email='3695888@qq.com', rust_extensions=[RustExtension(target="Difficult_Rocket_rs.Difficult_Rocket_rs", diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs index cf265f8..3f0f8a1 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs @@ -28,7 +28,7 @@ enum LoadState { } #[pyfunction] -fn get_version_str() -> String { "0.2.9.1".to_string() } +fn get_version_str() -> String { "0.2.9.2".to_string() } #[pyfunction] fn test_call(py_obj: &PyAny) -> PyResult { diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs index 68cc498..12ab425 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs @@ -87,21 +87,30 @@ pub mod data { Self { ship, part_list } } + #[getter] fn get_img_pos(&self) -> (i64, i64, i64, i64) { - let mut img_pos = (0, 0, 0, 0); + // let mut img_pos = (0, 0, 0, 0); // -x, -y, +x, +y // 左下角,右上角 let mut max_box = get_max_box(&self.ship.parts, &self.part_list); - todo!(); - // img_pos + // 每个坐标 * 60 + max_box.0 *= 60.0; + max_box.1 *= 60.0; + max_box.2 *= 60.0; + max_box.3 *= 60.0; + (max_box.0 as i64, max_box.1 as i64, max_box.2 as i64, max_box.3 as i64) } + #[getter] fn get_name(&self) -> String { self.ship.name.clone() } + #[getter] fn get_description(&self) -> String { self.ship.description.clone() } + #[getter] fn get_lift_off(&self) -> bool { self.ship.lift_off.to_owned() } + #[getter] fn get_touch_ground(&self) -> bool { self.ship.touch_ground.to_owned() } } } diff --git a/mods/dr_game/__init__.py b/mods/dr_game/__init__.py index c53c46d..75514c2 100644 --- a/mods/dr_game/__init__.py +++ b/mods/dr_game/__init__.py @@ -10,12 +10,12 @@ import traceback from typing import Optional from libs.MCDR.version import Version -from Difficult_Rocket.main import Game, Console +from Difficult_Rocket.main import Game from Difficult_Rocket.api.mod import ModInfo from Difficult_Rocket.api.types import Options from Difficult_Rocket.client import ClientWindow -DR_rust_version = Version("0.2.9.0") # DR_mod 的 Rust 编写部分的兼容版本 +DR_rust_version = Version("0.2.9.2") # DR_mod 的 Rust 编写部分的兼容版本 class _DR_mod_runtime(Options): diff --git a/mods/dr_game/sr1_ship.py b/mods/dr_game/sr1_ship.py index 65e9dec..b863725 100644 --- a/mods/dr_game/sr1_ship.py +++ b/mods/dr_game/sr1_ship.py @@ -7,6 +7,7 @@ import time import random import logging +import traceback from xml.etree import ElementTree from xml.etree.ElementTree import Element from typing import List, TYPE_CHECKING, Union, Dict, Optional, Generator @@ -36,7 +37,7 @@ if TYPE_CHECKING: from Difficult_Rocket.client import ClientWindow if DR_mod_runtime.use_DR_rust: - from .Difficult_Rocket_rs import CenterCamera_rs, SR1PartList_rs + from .Difficult_Rocket_rs import CenterCamera_rs, SR1PartList_rs, SR1Ship_rs logger = logging.getLogger('client') @@ -144,6 +145,13 @@ class SR1ShipRender(BaseScreen): self.xml_doc = cache_doc self.xml_root = self.xml_doc.getroot() self.xml_name = file_path + if DR_mod_runtime.use_DR_rust: + try: + self.rust_ship = SR1Ship_rs(file_path, 'configs/PartList.xml', 'a_new_ship') + print(self.rust_ship.name) + print(self.rust_ship.img_pos) + except Exception: + traceback.print_exc() logger.info(tr().client.sr1_render.xml.load_done()) logger.info(tr().client.sr1_render.xml.load_time().format( (time.time_ns() - start_time) / 1000000000)) @@ -179,6 +187,7 @@ class SR1ShipRender(BaseScreen): 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 + # if not part_render: # 如果不渲染(渲染有毛病) # self.parts_sprite[part.id].visible = False count += 1