diff --git a/docs/src/change_log/dr_game.md b/docs/src/change_log/dr_game.md index 14630c6..3315aee 100644 --- a/docs/src/change_log/dr_game.md +++ b/docs/src/change_log/dr_game.md @@ -3,7 +3,27 @@ - 最新版本号 - DR game: 0.2.0.0 - - DR rs: 0.2.11.0 + - DR rs: 0.2.13.0 + +## DR game 0.2.1.0 + +### 修改 + +- 将 `sr1_ship` 中的 `Camera_rs` 改为 `Difficult_Rocket.utils.camera.Camera` + +## DR rs 0.2.13.0 + +### 删除 + +- 删除了 `render.rs` + - 没必要拿 rust 写这玩意( + - 用 `DR game` 的 `camera` 代替 + +## DR rs 0.2.12.0 + +### 添加 + +- 添加了 xml 的读取测试 ## DR game 0.1.2.0 diff --git a/docs/src/change_log/dr_sdk.md b/docs/src/change_log/dr_sdk.md index 34e437a..bca9a98 100644 --- a/docs/src/change_log/dr_sdk.md +++ b/docs/src/change_log/dr_sdk.md @@ -4,11 +4,21 @@ - 最新版本号 - DR sdk: 0.8.4.0 +## DR sdk 0.8.4.1 + +### Add + +- `utils.camera` + - `Camera` + - 一个 2D 摄影机,可以用于高效变换渲染坐标 + - `CenterCamera` + - 一个中心对器的 2D 摄影机,可以用于高效变换渲染坐标 + ## DR sdk 0.8.4.0 ### Fix -- issue #33 (https://github.com/shenjackyuanjie/Difficult-Rocket/issues/33) +- issue #33 () - 修复了实际上并不会加载 `.otf` 格式的字体文件的问题 ### language diff --git a/mods/dr_game/Difficult_Rocket_rs/__init__.py b/mods/dr_game/Difficult_Rocket_rs/__init__.py index 2f19ca3..d3ac426 100644 --- a/mods/dr_game/Difficult_Rocket_rs/__init__.py +++ b/mods/dr_game/Difficult_Rocket_rs/__init__.py @@ -24,46 +24,6 @@ if TYPE_CHECKING: def load_and_save_test(file_name: str): ... - class Camera_rs: - """ 用于闲的没事 用 rust 写一个 camera """ - - def __new__(cls, window: Window, - zoom: float = 1.0, - dx: float = 1.0, dy: float = 1.0, - min_zoom: float = 1.0, - max_zoom: float = 1.0): ... - - @property - def dx(self) -> float: ... - @property - def dy(self) -> float: ... - @property - def zoom(self) -> float: ... - @property - def position(self) -> Tuple[float, float]: ... - @dx.setter - def dx(self, value: float) -> None: ... - @dy.setter - def dy(self, value: float) -> None: ... - @zoom.setter - def zoom(self, value: float) -> None: ... - - def begin(self) -> None: ... - - def end(self) -> None: ... - - def __enter__(self, window) -> None: ... - - def __exit__(self, exc_type, exc_val, exc_tb) -> None: ... - - - class CenterCamera_rs(Camera_rs): - """ 用于依旧闲的没事 用 rust 写一个中央对齐的 camera """ - - - class PartFrame_rs: - ... - class SR1PartType_rs: """ 用于从 rust 中读取 SR1PartType 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 ec4bd7a..767b240 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs @@ -9,7 +9,6 @@ mod logger; mod plugin; mod python; -mod render; mod simulator; mod sr1_data; mod types; @@ -26,7 +25,7 @@ enum LoadState { } #[pyfunction] -fn get_version_str() -> String { "0.2.12.0".to_string() } +fn get_version_str() -> String { "0.2.13.0".to_string() } #[pyfunction] fn test_call(py_obj: &PyAny) -> PyResult { @@ -46,9 +45,6 @@ fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(sr1_data::ship::py_raw_ship_from_file, m)?)?; m.add_function(wrap_pyfunction!(python::data::load_and_save_test, m)?)?; m.add_function(wrap_pyfunction!(python::serde_test::test_ship_read_and_write, m)?)?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; m.add_class::()?; m.add_class::()?; m.add_class::()?; 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 894a194..f36ada7 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs @@ -290,6 +290,7 @@ pub mod serde_test { use pyo3::prelude::*; use quick_xml::de::from_str; use quick_xml::se::to_string; + use quick_xml::Writer; use serde::{Deserialize, Serialize}; use std::fs; diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/render.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/render.rs deleted file mode 100644 index 7d560f6..0000000 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/render.rs +++ /dev/null @@ -1,212 +0,0 @@ -/* - * ------------------------------- - * Difficult Rocket - * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com - * All rights reserved - * ------------------------------- - */ - -pub mod camera { - - use pyo3::intern; - use pyo3::prelude::*; - - #[pyclass(name = "Camera_rs", subclass)] - pub struct CameraRs { - pub window: Py, - #[pyo3(get, set)] - pub dx: f64, - #[pyo3(get, set)] - pub dy: f64, - pub zoom: f64, - #[pyo3(get, set)] - pub max_zoom: f64, - #[pyo3(get, set)] - pub min_zoom: f64, - } - - #[pyclass(extends = CameraRs, name = "CenterCamera_rs")] - pub struct CenterCameraRs; - - #[pymethods] - impl CenterCameraRs { - #[new] - #[pyo3(signature = (window, zoom=1.0, dx=1.0, dy=1.0, min_zoom=1.0, max_zoom=1.0))] - pub fn py_new(window: &PyAny, zoom: f64, dx: f64, dy: f64, min_zoom: f64, max_zoom: f64) -> PyResult<(Self, CameraRs)> { - return Ok(( - CenterCameraRs {}, - CameraRs { - dx, - dy, - zoom, - min_zoom, - max_zoom, - window: window.into(), - }, - )); - } - - // pub fn __enter__(py_self: PyRef) -> PyResult> { - // // println!("enter!"); - // CenterCameraRs::begin()?; - // Ok(py_self) - // } - - pub fn begin(self_: PyRef<'_, Self>) -> PyResult<()> { - println!("begin!"); - let super_: &CameraRs = self_.as_ref(); - // 获取父类 - Python::with_gil(|py| -> PyResult<()> { - let view = super_.window.getattr(py, intern!(py, "view"))?; - // 获取存储的 view - let x: f64 = super_.window.getattr(py, intern!(py, "width"))?.extract(py)?; - let y: f64 = super_.window.getattr(py, intern!(py, "height"))?.extract(py)?; - let x: f64 = x / 2.0 / super_.zoom + (super_.dx / super_.zoom); - let y: f64 = y / 2.0 / super_.zoom + (super_.dy / super_.zoom); - // 计算中心点 - - // view.call_method1(py, "translate", (x, y))?; - // view.call_method1(py, "scale", (super_.zoom, super_.zoom))?; - - let args = ((x * super_.zoom, y * super_.zoom, 0),); - let view_matrix = view.call_method1(py, intern!(py, "translate"), args)?; - // view_matrix = self.view.translate((x * zoom, y * zoom, 0)) - - let args = ((super_.zoom, super_.zoom, 1),); - let view_matrix = view_matrix.call_method1(py, intern!(py, "scale"), args)?; - // view_matrix = view_matrix.scale((zoom, zoom, 1)) - - super_.window.setattr(py, intern!(py, "view"), view_matrix)?; - // self.view = view_matrix - Ok(()) - })?; - Ok(()) - } - } - - #[pymethods] - impl CameraRs { - #[new] - #[pyo3(signature = (window, zoom=1.0, dx=1.0, dy=1.0, min_zoom=1.0, max_zoom=1.0))] - pub fn py_new(window: &PyAny, zoom: f64, dx: f64, dy: f64, min_zoom: f64, max_zoom: f64) -> PyResult { - return Ok(CameraRs { - dx, - dy, - zoom, - min_zoom, - max_zoom, - window: window.into(), - }); - } - - pub fn get_view(&self) -> PyResult { - Ok(Python::with_gil(|py| -> PyResult { - Ok(self.window.getattr(py, intern!(py, "view"))?) - })?) - } - - #[getter] - pub fn get_position(&self) -> (f64, f64) { return (self.dx, self.dy); } - - #[setter] - pub fn set_position(&mut self, value: (f64, f64)) -> () { - self.dx = value.0; - self.dy = value.1; - } - - #[getter] - pub fn get_zoom(&self) -> PyResult { Ok(self.zoom) } - - #[setter] - pub fn set_zoom(&mut self, value: f64) -> PyResult<()> { - self.zoom = value.min(self.max_zoom).max(self.min_zoom); - Ok(()) - } - - pub fn begin(&self) -> PyResult<()> { - Python::with_gil(|py| -> PyResult<()> { - let view = self.window.getattr(py, intern!(py, "view"))?; - - let x: f64 = self.window.getattr(py, intern!(py, "width"))?.extract(py)?; - let y: f64 = self.window.getattr(py, intern!(py, "height"))?.extract(py)?; - let x: f64 = x / 2.0 / self.zoom + (self.dx / self.zoom); - let y: f64 = y / 2.0 / self.zoom + (self.dy / self.zoom); - // use to get center of the screen - - let args = ((x * self.zoom, y * self.zoom, 0),); - let view_matrix = view.call_method1(py, intern!(py, "translate"), args)?; - // view_matrix = self.view.translate((x * zoom, y * zoom, 0)) - - let args = ((self.zoom, self.zoom, 1),); - let view_matrix = view_matrix.call_method1(py, intern!(py, "scale"), args)?; - // view_matrix = view_matrix.scale((zoom, zoom, 1)) - - self.window.setattr(py, intern!(py, "view"), view_matrix)?; - // self.view = view_matrix - Ok(()) - })?; - return Ok(()); - } - - pub fn end(&self) -> PyResult<()> { - Python::with_gil(|py| -> PyResult<()> { - let view = self.window.getattr(py, intern!(py, "view"))?; - - let x: f64 = self.window.getattr(py, intern!(py, "width"))?.extract(py)?; - let y: f64 = self.window.getattr(py, intern!(py, "height"))?.extract(py)?; - let x: f64 = x / 2.0 / self.zoom + (self.dx / self.zoom); - let y: f64 = y / 2.0 / self.zoom + (self.dy / self.zoom); - - let args = ((1.0 / self.zoom, 1.0 / self.zoom, 1),); - let view_matrix = view.call_method1(py, intern!(py, "scale"), args)?; - - let args = ((-x * self.zoom, -y * self.zoom, 0),); - let view_matrix = view_matrix.call_method1(py, intern!(py, "translate"), args)?; - - self.window.setattr(py, intern!(py, "view"), view_matrix)?; - Ok(()) - })?; - return Ok(()); - } - - /// https://github.com/PyO3/pyo3/discussions/2931#discussioncomment-4820729 for finding this - /// https://github.com/PyO3/pyo3/issues/1205#issuecomment-1164096251 for advice on `__enter__` - pub fn __enter__(py_self: PyRef) -> PyResult> { - // println!("enter!"); - py_self.begin()?; - Ok(py_self) - } - - pub fn __exit__(&self, _exc_type: PyObject, _exc_value: PyObject, _traceback: PyObject) -> PyResult<()> { - // println!("exit!"); - self.end()?; - return Ok(()); - } - } -} - -pub mod screen { - use pyo3::prelude::*; - // use crate::types::sr1::SR1PartData; - - #[pyclass] - #[pyo3(name = "PartFrame_rs")] - pub struct PartFrame { - pub box_size: i32, - pub width: i64, - pub height: i64, - // pub frame_box: Vec> - } - - #[pymethods] - impl PartFrame { - #[new] - pub fn py_new() -> PyResult { - Ok(PartFrame { - box_size: 111, - width: 111, - height: 111, - }) - } - } -}