From 07dfc2b5e96d07fe297260d41b037f05182a4d1b Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Thu, 20 Apr 2023 23:51:28 +0800 Subject: [PATCH] add some --- Difficult_Rocket/api/screen.py | 10 ++++++++++ Difficult_Rocket/client/__init__.py | 5 +++-- Difficult_Rocket/client/render/sr1_ship.py | 4 +++- libs/Difficult_Rocket_rs/src/src/lib.rs | 1 + libs/Difficult_Rocket_rs/src/src/plugin.rs | 7 +++++++ libs/Difficult_Rocket_rs/src/src/simulator.rs | 4 +++- 6 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 libs/Difficult_Rocket_rs/src/src/plugin.rs diff --git a/Difficult_Rocket/api/screen.py b/Difficult_Rocket/api/screen.py index ab1564b..2d37657 100644 --- a/Difficult_Rocket/api/screen.py +++ b/Difficult_Rocket/api/screen.py @@ -33,11 +33,21 @@ class BaseScreen(EventDispatcher): 命令输入事件 """ + def on_message(self, message: CommandText, window: "ClientWindow"): + """ + 消息输入事件 + """ + def draw_update(self, tick: float, window: "ClientWindow"): """ 画面更新 """ + def draw_batch(self, window: "ClientWindow"): + """ + 画面绘制 + """ + """ Pyglet 定义的事件 """ diff --git a/Difficult_Rocket/client/__init__.py b/Difficult_Rocket/client/__init__.py index ef4888a..ef998d6 100644 --- a/Difficult_Rocket/client/__init__.py +++ b/Difficult_Rocket/client/__init__.py @@ -168,7 +168,6 @@ class ClientWindow(Window): self.net_mode = net_mode self.run_input = False # configs - self.set_icon(pyglet.image.load('./textures/icon.png')) self.main_config = tools.load_file('./configs/main.toml') self.game_config = tools.load_file('./configs/game.config') # FPS @@ -205,6 +204,7 @@ class ClientWindow(Window): self.count = 0 def setup(self): + self.set_icon(pyglet.image.load('./textures/icon.png')) self.load_fonts() # TODO 读取配置文件,加载不同的屏幕,解耦 self.screen_list.append(DRDEBUGScreen(self)) @@ -218,6 +218,7 @@ class ClientWindow(Window): pyglet_load_fonts_folder(fonts_folder_path) def start_game(self) -> None: + self.set_icon(pyglet.image.load('./textures/icon.png')) self.run_input = True self.read_input() pyglet.app.event_loop.run(1 / self.main_config['runtime']['fps']) @@ -329,7 +330,7 @@ class ClientWindow(Window): # self.command_tree.parse(command.plain_command) @_call_screen_after - def on_message(self, message: line.CommandLine.text): + def on_message(self, message: line.CommandText): self.logger.info(tr().window.message.text().format(message)) """ diff --git a/Difficult_Rocket/client/render/sr1_ship.py b/Difficult_Rocket/client/render/sr1_ship.py index 9a03800..d60fd5d 100644 --- a/Difficult_Rocket/client/render/sr1_ship.py +++ b/Difficult_Rocket/client/render/sr1_ship.py @@ -5,6 +5,7 @@ # ------------------------------- import time +import random import logging from xml.etree import ElementTree from xml.etree.ElementTree import Element @@ -19,6 +20,7 @@ from pyglet.text import Label from pyglet.shapes import Line from pyglet.sprite import Sprite from pyglet.graphics import Batch, Group +from pyglet.image import load as load_image # Difficult Rocket from Difficult_Rocket import DR_option @@ -163,7 +165,7 @@ class SR1ShipRender(BaseScreen): render_y = part.y * 60 # 你就这里改吧 cache_sprite = Sprite(img=self.textures.get_texture(part.textures), - x=render_x, y=render_y, + x=render_x, y=render_y, z=random.random(), batch=self.part_batch, group=self.part_group) # 你得帮我换算一下 XML 里的 x y 和这里的屏幕像素的关系(OK # 旋转啥的不是大问题, 我找你要那个渲染代码就是要 x y 的换算逻辑 diff --git a/libs/Difficult_Rocket_rs/src/src/lib.rs b/libs/Difficult_Rocket_rs/src/src/lib.rs index cf5ee5d..9b447cf 100644 --- a/libs/Difficult_Rocket_rs/src/src/lib.rs +++ b/libs/Difficult_Rocket_rs/src/src/lib.rs @@ -7,6 +7,7 @@ */ mod logger; +mod plugin; mod python; mod render; mod simulator; diff --git a/libs/Difficult_Rocket_rs/src/src/plugin.rs b/libs/Difficult_Rocket_rs/src/src/plugin.rs new file mode 100644 index 0000000..72f16f6 --- /dev/null +++ b/libs/Difficult_Rocket_rs/src/src/plugin.rs @@ -0,0 +1,7 @@ +/* + * ------------------------------- + * Difficult Rocket + * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com + * All rights reserved + * ------------------------------- + */ diff --git a/libs/Difficult_Rocket_rs/src/src/simulator.rs b/libs/Difficult_Rocket_rs/src/src/simulator.rs index 31d67ce..01afd11 100644 --- a/libs/Difficult_Rocket_rs/src/src/simulator.rs +++ b/libs/Difficult_Rocket_rs/src/src/simulator.rs @@ -9,6 +9,7 @@ use pyo3::prelude::*; use rapier2d_f64::prelude::*; + #[pyfunction] #[pyo3(name = "simluation")] pub fn simluation() -> PyResult<()> { @@ -59,7 +60,8 @@ pub fn simluation() -> PyResult<()> { ); let ball_body = &rigid_body_set[ball_body_handle]; - println!("Ball altitude: {}", ball_body.translation()); + println!("Ball altitude: {} {}", ball_body.translation().x, ball_body.translation().y); } Ok(()) } +