pyglet_rs making
This commit is contained in:
parent
71f0def9e9
commit
a1aa251ce5
@ -22,7 +22,6 @@ setup(
|
|||||||
author='shenjackyuanjie',
|
author='shenjackyuanjie',
|
||||||
author_email='3695888@qq.com',
|
author_email='3695888@qq.com',
|
||||||
rust_extensions=[RustExtension(target="Difficult_Rocket_rs.Difficult_Rocket_rs",
|
rust_extensions=[RustExtension(target="Difficult_Rocket_rs.Difficult_Rocket_rs",
|
||||||
# rust_version='2021',
|
|
||||||
binding=Binding.PyO3)],
|
binding=Binding.PyO3)],
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
)
|
)
|
||||||
|
41
libs/pyglet_rs/src/post_build.py
Normal file
41
libs/pyglet_rs/src/post_build.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import warnings
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
package_path = 'pyglet_rs'
|
||||||
|
lib_path = '../lib'
|
||||||
|
build_path = 'build'
|
||||||
|
|
||||||
|
if not os.path.exists(lib_path):
|
||||||
|
os.mkdir(lib_path)
|
||||||
|
|
||||||
|
builds = os.listdir(build_path)
|
||||||
|
print(os.path.abspath('.'))
|
||||||
|
|
||||||
|
try:
|
||||||
|
shutil.copy('src/__init__.py', os.path.join(lib_path, '__init__.py'))
|
||||||
|
except shutil.SameFileError:
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
for build_dir in builds:
|
||||||
|
if not os.path.exists(os.path.join(build_path, build_dir, package_path)):
|
||||||
|
warnings.warn(f'package not found at {build_path}/{build_dir}')
|
||||||
|
continue
|
||||||
|
for file in os.listdir(os.path.join(build_path, build_dir, package_path)):
|
||||||
|
# file_name = os.path.join(lib_path, file.replace(package_path, f'{package_path}.{DR_runtime.DR_Rust_version}'))
|
||||||
|
file_name = os.path.join(lib_path, file)
|
||||||
|
shutil.rmtree(file_name, ignore_errors=True)
|
||||||
|
try:
|
||||||
|
shutil.copy(os.path.join(build_path, build_dir, package_path, file), file_name)
|
||||||
|
except (shutil.SameFileError, PermissionError):
|
||||||
|
# print(os.path.exists(os.path))
|
||||||
|
print(os.listdir(lib_path))
|
||||||
|
traceback.print_exc()
|
||||||
|
continue
|
||||||
|
print(os.path.abspath(file_name))
|
39
libs/pyglet_rs/src/setup.py
Normal file
39
libs/pyglet_rs/src/setup.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import rtoml
|
||||||
|
import shutil
|
||||||
|
from setuptools import setup
|
||||||
|
from setuptools_rust import Binding, RustExtension
|
||||||
|
|
||||||
|
sys.path.append('../../../')
|
||||||
|
sys.path.append(os.curdir)
|
||||||
|
|
||||||
|
package_path = 'pyglet_rs'
|
||||||
|
|
||||||
|
# 版本号从 cargo.toml 中读取
|
||||||
|
with open(f'Cargo.toml', 'r') as f:
|
||||||
|
cargo_toml = rtoml.load(f)
|
||||||
|
version = cargo_toml['package']['version']
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='pyglet_rs',
|
||||||
|
version=version,
|
||||||
|
author='shenjackyuanjie',
|
||||||
|
author_email='3695888@qq.com',
|
||||||
|
rust_extensions=[RustExtension(target="pyglet_rs.pyglet_rs",
|
||||||
|
binding=Binding.PyO3)],
|
||||||
|
zip_safe=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
lib_path = '../lib'
|
||||||
|
build_path = 'build'
|
||||||
|
|
||||||
|
if 'clean' in sys.argv:
|
||||||
|
shutil.rmtree(build_path, ignore_errors=True)
|
||||||
|
shutil.rmtree(f'{package_path}.egg-info', ignore_errors=True)
|
||||||
|
sys.exit(0)
|
10
libs/pyglet_rs/src/src/__init__.py
Normal file
10
libs/pyglet_rs/src/src/__init__.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
if not TYPE_CHECKING:
|
||||||
|
from .pyglet_rs import *
|
@ -10,8 +10,7 @@ mod sprite;
|
|||||||
|
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
|
|
||||||
|
#[pymodule]
|
||||||
#[pymoudule]
|
|
||||||
#[pyo3(name = "pyglet_rs")]
|
#[pyo3(name = "pyglet_rs")]
|
||||||
fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
|
fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
|
||||||
m.add_class::<sprite::Sprite>()?;
|
m.add_class::<sprite::Sprite>()?;
|
||||||
|
@ -6,12 +6,14 @@
|
|||||||
* -------------------------------
|
* -------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
|
|
||||||
/// Instance of an on-screen image
|
/// Instance of an on-screen image
|
||||||
/// See the module documentation for usage.
|
/// See the module documentation for usage.
|
||||||
#[pyclass(name = "Sprite", subclass)]
|
#[pyclass(name = "Sprite", subclass)]
|
||||||
|
#[pyo3(text_signature = "(img, x=0.0, y=0.0, z=0.0, \
|
||||||
|
batch=None, group=None, \
|
||||||
|
subpixel=False, program=None)")]
|
||||||
pub struct Sprite {
|
pub struct Sprite {
|
||||||
// render
|
// render
|
||||||
pub batch: Py<PyAny>,
|
pub batch: Py<PyAny>,
|
||||||
@ -28,33 +30,42 @@ pub struct Sprite {
|
|||||||
// frame
|
// frame
|
||||||
pub frame_index: u32,
|
pub frame_index: u32,
|
||||||
pub animation: Option<Py<PyAny>>,
|
pub animation: Option<Py<PyAny>>,
|
||||||
|
pub texture: Option<Py<PyAny>>,
|
||||||
pub paused: bool,
|
pub paused: bool,
|
||||||
// other
|
// other
|
||||||
pub rgba: (i8, i8, i8, i8),
|
pub rgba: (u8, u8, u8, u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pymethods]
|
#[pymethods]
|
||||||
impl Sprite {
|
impl Sprite {
|
||||||
#[new]
|
#[new]
|
||||||
#[pyo3(text_signature = "(img, x=0.0, y=0.0, z=0.0, \
|
fn new(py_: Python, img: &PyAny, x: f64, y: f64, z: f64, batch: &PyAny, group: &PyAny) -> Self {
|
||||||
batch=None, group=None, \
|
// let img_class = PyModule::from_code(py_, "pyglet.image.Animation", "", "")?.getattr();
|
||||||
subpixel=False, program=None)")]
|
let animation_class =
|
||||||
fn new(img: &PyAny, x: f64, y:, batch: &PyAny, group: &PyAny) -> Self {
|
PyModule::import(py_, "pyglet.image.Animation").unwrap().getattr("Animation").unwrap();
|
||||||
|
let mut texture: Option<Py<PyAny>> = None;
|
||||||
|
let mut animation: Option<Py<PyAny>> = None;
|
||||||
|
if img.is_instance(animation_class).unwrap() {
|
||||||
|
animation = Some(img.into());
|
||||||
|
} else {
|
||||||
|
texture = Some(img.into());
|
||||||
|
}
|
||||||
Sprite {
|
Sprite {
|
||||||
batch: batch.into(),
|
batch: batch.into(),
|
||||||
x, y, z,
|
x,
|
||||||
|
y,
|
||||||
|
z,
|
||||||
scale: 1.0,
|
scale: 1.0,
|
||||||
scale_x: 1.0,
|
scale_x: 1.0,
|
||||||
scale_y: 1.0,
|
scale_y: 1.0,
|
||||||
visible: true,
|
visible: true,
|
||||||
vertex_list: None,
|
vertex_list: None,
|
||||||
frame_index: 0,
|
frame_index: 0,
|
||||||
animation: None,
|
animation,
|
||||||
|
texture,
|
||||||
paused: false,
|
paused: false,
|
||||||
rgba: (255, 255, 255, 255),
|
rgba: (255, 255, 255, 255),
|
||||||
group_class: group.into(),
|
group_class: group.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user