From 71f0def9e9af5b80b9fed26479daefae8d7deb2c Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Thu, 23 Mar 2023 20:28:58 +0800 Subject: [PATCH] pyglet-rs update no build yet --- libs/pyglet_rs/src/src/lib.rs | 27 ++++++++------ libs/pyglet_rs/src/src/sprite.rs | 60 ++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 libs/pyglet_rs/src/src/sprite.rs diff --git a/libs/pyglet_rs/src/src/lib.rs b/libs/pyglet_rs/src/src/lib.rs index 7d12d9a..88c0672 100644 --- a/libs/pyglet_rs/src/src/lib.rs +++ b/libs/pyglet_rs/src/src/lib.rs @@ -1,14 +1,19 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} +/* + * ------------------------------- + * Difficult Rocket + * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com + * All rights reserved + * ------------------------------- + */ -#[cfg(test)] -mod tests { - use super::*; +mod sprite; - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } +use pyo3::prelude::*; + + +#[pymoudule] +#[pyo3(name = "pyglet_rs")] +fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> { + m.add_class::()?; + Ok(()) } diff --git a/libs/pyglet_rs/src/src/sprite.rs b/libs/pyglet_rs/src/src/sprite.rs new file mode 100644 index 0000000..3f78ff3 --- /dev/null +++ b/libs/pyglet_rs/src/src/sprite.rs @@ -0,0 +1,60 @@ +/* + * ------------------------------- + * Difficult Rocket + * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com + * All rights reserved + * ------------------------------- + */ + + +use pyo3::prelude::*; + +/// Instance of an on-screen image +/// See the module documentation for usage. +#[pyclass(name = "Sprite", subclass)] +pub struct Sprite { + // render + pub batch: Py, + pub group_class: Py, + // view + pub x: f64, + pub y: f64, + pub z: f64, + pub scale: f64, + pub scale_x: f64, + pub scale_y: f64, + pub visible: bool, + pub vertex_list: Option>, + // frame + pub frame_index: u32, + pub animation: Option>, + pub paused: bool, + // other + pub rgba: (i8, i8, i8, i8), +} + +#[pymethods] +impl Sprite { + #[new] + #[pyo3(text_signature = "(img, x=0.0, y=0.0, z=0.0, \ + batch=None, group=None, \ + subpixel=False, program=None)")] + fn new(img: &PyAny, x: f64, y:, batch: &PyAny, group: &PyAny) -> Self { + Sprite { + batch: batch.into(), + x, y, z, + scale: 1.0, + scale_x: 1.0, + scale_y: 1.0, + visible: true, + vertex_list: None, + frame_index: 0, + animation: None, + paused: false, + rgba: (255, 255, 255, 255), + group_class: group.into(), + } + } +} +} +