diff --git a/.github/workflows/nuitka.yml b/.github/workflows/nuitka.yml index 6d07f11..d994995 100644 --- a/.github/workflows/nuitka.yml +++ b/.github/workflows/nuitka.yml @@ -131,6 +131,16 @@ jobs: Rename-Item ./build/DR.dist Difficult-Rocket + - name: DR-rs build + shell: pwsh + run: | + cd libs/Difficult_Rocket_rs/src + python setup.py build + python after_build.py + python setup.py clean + cd .. + rm src + - name: after build shell: pwsh run: python ./.github/workflows/after_compile.py diff --git a/libs/Difficult_Rocket_rs/__init__.py b/libs/Difficult_Rocket_rs/__init__.py index a2f420b..5b26bb0 100644 --- a/libs/Difficult_Rocket_rs/__init__.py +++ b/libs/Difficult_Rocket_rs/__init__.py @@ -18,3 +18,8 @@ if TYPE_CHECKING: def test_call(py_obj) -> bool: ... def better_update_parts(render: SR1ShipRender, option: SR1ShipRender_Option, window: BaseScreen) -> bool: ... + + class PartDatas: + """ 用于在 PyObj 里塞一个浓眉大眼的 HashMap""" + def __new__(cls, py_part_data) -> "PartDatas": ... + diff --git a/libs/Difficult_Rocket_rs/src/Cargo.toml b/libs/Difficult_Rocket_rs/src/Cargo.toml index ee589b9..0af6c2f 100644 --- a/libs/Difficult_Rocket_rs/src/Cargo.toml +++ b/libs/Difficult_Rocket_rs/src/Cargo.toml @@ -9,8 +9,8 @@ license-file = '../../LICENSE' [lib] name = 'Difficult_Rocket_rs' -crate-type = ["cdylib", "rlib"] +crate-type = ["cdylib"] [dependencies.pyo3] version = "0.18.0" -features = ["extension-module"] \ No newline at end of file +features = ["extension-module"] diff --git a/libs/Difficult_Rocket_rs/src/src/lib.rs b/libs/Difficult_Rocket_rs/src/src/lib.rs index 4decf2d..74232ab 100644 --- a/libs/Difficult_Rocket_rs/src/src/lib.rs +++ b/libs/Difficult_Rocket_rs/src/src/lib.rs @@ -7,7 +7,6 @@ */ mod sr1_render; -mod types; use pyo3::prelude::*; diff --git a/libs/Difficult_Rocket_rs/src/src/sr1_render.rs b/libs/Difficult_Rocket_rs/src/src/sr1_render.rs index b2cfee8..180f1a9 100644 --- a/libs/Difficult_Rocket_rs/src/src/sr1_render.rs +++ b/libs/Difficult_Rocket_rs/src/src/sr1_render.rs @@ -12,6 +12,7 @@ use pyo3::prelude::*; use pyo3::types::PyDict; use crate::sr1_render::types::Point; +#[allow(dead_code)] pub mod types { use std::collections::HashMap; use pyo3::intern; @@ -41,7 +42,7 @@ pub mod types { pub type_: String } - #[pyclass] + #[pyclass(name = "PartDatas")] pub struct PartDatas { pub part_structs: HashMap } @@ -49,14 +50,20 @@ pub mod types { #[pymethods] impl PartDatas { #[new] - pub fn py_new(py_part_data: &PyDict) -> PyResult{ - let mut datas: HashMap = HashMap::with_capacity(py_part_data.len()); - return Ok(PartDatas{part_structs: datas}) + pub fn py_new(py_part_data: &PyDict) -> PyResult { + let datas: HashMap = part_data_tp_SR1PartDatas(py_part_data)?; + return Ok(PartDatas { part_structs: datas }) } } - #[allow(dead_code)] - pub fn convert_py_any_sr1_part_data(input: &PyAny) -> Result { + impl PartDatas{ + pub fn get_rust_data(&self) -> &HashMap { + return &self.part_structs; + } + } + + #[allow(non_snake_case)] + pub fn part_data_to_SR1PartData(input: &PyAny) -> Result { return Ok(SR1PartData{ x: input.getattr(intern!(input.py(), "x"))?.extract()?, y: input.getattr(intern!(input.py(), "y"))?.extract()?, @@ -74,7 +81,16 @@ pub mod types { }) } - pub fn get_point_from_sr1_part_data(input: &PyAny) -> Result { + #[allow(non_snake_case)] + pub fn part_data_tp_SR1PartDatas(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_SR1PartData(key.1)?); + } + 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()?, @@ -83,11 +99,10 @@ pub mod types { }) } - pub fn point_dict_from_part_datas(input: &PyDict) -> Result, PyErr> { + pub fn part_datas_to_points(input: &PyDict) -> Result, PyErr> { let mut result: HashMap = HashMap::with_capacity(input.len()); for key in input.iter() { - println!("aaa"); - // key[] + result.insert(key.0.extract()?, part_data_to_point(key.1)?); } return Ok(result); } @@ -98,7 +113,7 @@ pub mod types { #[pyfunction] -#[allow(non_snake_case)] +#[allow(unused_variables)] pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny) -> PyResult { if !render.getattr(intern!(render.py(), "rendered"))?.is_true()? { return Ok(false); @@ -110,7 +125,7 @@ pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny) -> Py let x_center: usize = x_center / 2; let y_center: usize = y_center / 2; let part_datas: &PyDict = render.getattr(intern!(render.py(), "part_data"))?.extract()?; - let parts: HashMap = types::point_dict_from_part_datas(part_datas)?; + let parts: HashMap = types::part_datas_to_points(part_datas)?; if option.getattr("debug_d_pos")?.is_true()? { let line = render.getattr(intern!(render.py(), "debug_line"))?; } diff --git a/libs/Difficult_Rocket_rs/src/src/types.rs b/libs/Difficult_Rocket_rs/src/src/types.rs deleted file mode 100644 index 72f16f6..0000000 --- a/libs/Difficult_Rocket_rs/src/src/types.rs +++ /dev/null @@ -1,7 +0,0 @@ -/* - * ------------------------------- - * Difficult Rocket - * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com - * All rights reserved - * ------------------------------- - */