From 2abd3460591f186d1ec95f2d636dc0912c73926c Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Tue, 28 Mar 2023 19:23:41 +0800 Subject: [PATCH] still in dev pyglet_rs --- libs/pyglet_rs/__init__.py | 29 +++++++++++++++++++++++++++-- libs/pyglet_rs/src/src/lib.rs | 2 ++ libs/pyglet_rs/src/src/pymath.rs | 10 +++++----- libs/pyglet_rs/src/src/sprite.rs | 2 +- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/libs/pyglet_rs/__init__.py b/libs/pyglet_rs/__init__.py index c5c4c3e..b613044 100644 --- a/libs/pyglet_rs/__init__.py +++ b/libs/pyglet_rs/__init__.py @@ -14,10 +14,35 @@ if TYPE_CHECKING: def get_version_str() -> str: ... - class Sprite_rs(EventDispatcher): - ... + class Sprite_rs(EventDispatcher): ... + + class Vector2_rs: ... + class Vector3_rs: ... + class Vector4_rs: ... + + class Matrix3_rs: ... + class Matrix4_rs: ... def patch_sprite(): from pyglet import sprite sprite.Sprite = Sprite_rs + + +def patch_vector(): + from pyglet import math + math.Vector2 = Vector2_rs + math.Vector3 = Vector3_rs + math.Vector4 = Vector4_rs + + +def patch_matrix(): + from pyglet import math + math.Matrix3 = Matrix3_rs + math.Matrix4 = Matrix4_rs + + +def patch_all(): + patch_sprite() + patch_vector() + patch_matrix() diff --git a/libs/pyglet_rs/src/src/lib.rs b/libs/pyglet_rs/src/src/lib.rs index 7ca4343..ad4f006 100644 --- a/libs/pyglet_rs/src/src/lib.rs +++ b/libs/pyglet_rs/src/src/lib.rs @@ -22,5 +22,7 @@ fn get_version_str() -> String { fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(get_version_str, m)?)?; m.add_class::()?; + // vector + m.add_class::()?; Ok(()) } diff --git a/libs/pyglet_rs/src/src/pymath.rs b/libs/pyglet_rs/src/src/pymath.rs index 8e60e0b..3646d59 100644 --- a/libs/pyglet_rs/src/src/pymath.rs +++ b/libs/pyglet_rs/src/src/pymath.rs @@ -12,27 +12,27 @@ pub mod python_class { use crate::math::matrix::{Matrix3, Matrix4}; use crate::math::vector::{Vector2, Vector3, Vector4, VectorTrait}; - #[pyclass(name = "Vector2")] + #[pyclass(name = "Vector2_rs")] pub struct PyVector2 { pub data: Vector2, } - #[pyclass(name = "Vector3")] + #[pyclass(name = "Vector3_rs")] pub struct PyVector3 { pub data: Vector3, } - #[pyclass(name = "Vector4")] + #[pyclass(name = "Vector4_rs")] pub struct PyVector4 { pub data: Vector4, } - #[pyclass(name = "Matrix3")] + #[pyclass(name = "Matrix3_rs")] pub struct PyMatrix3 { pub data: Matrix3, } - #[pyclass(name = "Matrix4")] + #[pyclass(name = "Matrix4_rs")] pub struct PyMatrix4 { pub data: Matrix4, } diff --git a/libs/pyglet_rs/src/src/sprite.rs b/libs/pyglet_rs/src/src/sprite.rs index 0aebd53..4d877c4 100644 --- a/libs/pyglet_rs/src/src/sprite.rs +++ b/libs/pyglet_rs/src/src/sprite.rs @@ -8,7 +8,7 @@ use pyo3::intern; use pyo3::prelude::*; -use pyo3::types::PyDict; +// use pyo3::types::PyDict; /// Instance of an on-screen image /// See the module documentation for usage.