说实话,改一些东西,文档也要跟着改有点烦人(

This commit is contained in:
shenjack 2023-06-06 18:58:07 +08:00
parent 20f3810623
commit 76a4823201
7 changed files with 82 additions and 15 deletions

View File

@ -7,8 +7,8 @@ fonts_folder = "libs/fonts"
[window]
style = "None"
width = 1311
height = 1165
width = 1355
height = 1213
visible = true
gui_scale = 1
caption = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}"

View File

@ -18,6 +18,24 @@
- 基于 `PyConsole`
- 用于替换 `DR sdk` 的默认控制台方法
## DR rs 0.2.10.0
## `python::PySR1PartType`
- 添加可从 Python 端获取的部件信息
- `get_descriptiton -> String`
- 部件描述 (Part description)
- `get_sprite -> String`
- 部件贴图 (Part sprite)
- `get_width -> u32`
- 部件宽度 (Part width)
- `get_height -> u32`
- 部件高度 (Part height)
- `get_friction`
- 部件摩擦系数 (Part friction)
- `get_hidden`
- 部件是否隐藏 (Part hidden)
## DR rs 0.2.9.3
### `sr1_data`

View File

@ -72,11 +72,30 @@ if TYPE_CHECKING:
class SR1PartType_rs:
""" 用于从 rust 中读取 SR1PartType
不能从 Python 端创建"""
不能从 Python 端创建
自带一些可从 Python 端读取的属性 (实际上就是一个接口)
"""
@property
def name(self) -> str: ...
def name(self) -> str:
""" 零件的名字 """
@property
def mass(self) -> float: ...
def description(self) -> str:
""" 零件的描述 """
@property
def mass(self) -> float:
""" 零件的质量 """
@property
def width(self) -> int:
""" 零件的宽度 """
@property
def height(self) -> int:
""" 零件的高度 """
@property
def friction(self) -> float:
""" 零件的摩擦系数 """
@property
def hidden(self) -> bool:
""" 零件是否隐藏 """
class SR1PartList_rs:

View File

@ -28,7 +28,7 @@ enum LoadState {
}
#[pyfunction]
fn get_version_str() -> String { "0.2.9.3".to_string() }
fn get_version_str() -> String { "0.2.10.0".to_string() }
#[pyfunction]
fn test_call(py_obj: &PyAny) -> PyResult<bool> {

View File

@ -27,7 +27,25 @@ pub mod data {
fn get_name(&self) -> String { self.data.name.clone() }
#[getter]
fn get_mass(&self) -> f64 { self.data.mass.to_owned() }
fn get_description(&self) -> String { self.data.description.clone() }
#[getter]
fn get_sprite(&self) -> String { self.data.sprite.clone() }
#[getter]
fn get_mass(&self) -> f64 { self.data.mass }
#[getter]
fn get_width(&self) -> u32 { self.data.width }
#[getter]
fn get_height(&self) -> u32 { self.data.height }
#[getter]
fn get_friction(&self) -> f64 { self.data.friction }
#[getter]
fn get_hidden(&self) -> bool { self.data.hidden }
}
impl PySR1PartType {

View File

@ -15,7 +15,7 @@ from Difficult_Rocket.api.mod import ModInfo
from Difficult_Rocket.api.types import Options
from Difficult_Rocket.client import ClientWindow
DR_rust_version = Version("0.2.9.3") # DR_mod 的 Rust 编写部分的兼容版本
DR_rust_version = Version("0.2.10.0") # DR_mod 的 Rust 编写部分的兼容版本
class _DR_mod_runtime(Options):

View File

@ -19,7 +19,7 @@ from defusedxml.ElementTree import parse
# pyglet
from pyglet.math import Vec4
from pyglet.text import Label
from pyglet.shapes import Line
from pyglet.shapes import Line, Rectangle
from pyglet.sprite import Sprite
from pyglet.image import Texture
from pyglet.graphics import Batch, Group
@ -40,7 +40,6 @@ if TYPE_CHECKING:
if DR_mod_runtime.use_DR_rust:
from .Difficult_Rocket_rs import CenterCamera_rs, SR1PartList_rs, SR1Ship_rs
logger = logging.getLogger('client')
@ -122,6 +121,7 @@ class SR1ShipRender(BaseScreen):
# self.xml_doc: ElementTree = parse('configs/dock1.xml')
# self.xml_root: ElementTree.Element = self.xml_doc.getroot()
self.load_xml('configs/dock1.xml')
self.part_box_batch = Batch()
self.part_batch = Batch()
self.part_group = Group()
self.debug_label = Label(x=20, y=main_window.height - 20, font_size=DR_option.std_font_size,
@ -130,6 +130,7 @@ class SR1ShipRender(BaseScreen):
anchor_x='left', anchor_y='top')
self.part_data: Dict[int, SR1PartData] = {}
self.parts_sprite: Dict[int, Sprite] = {}
self.part_box_dict: Dict[int, Rectangle] = {}
load_end_time = time.time_ns()
logger.info(tr().client.sr1_render.setup.use_time().format(
(load_end_time - load_start_time) / 1000000000))
@ -190,6 +191,18 @@ class SR1ShipRender(BaseScreen):
cache_sprite.y = cache_sprite.y - cache_sprite.scale_y / 2
self.parts_sprite[part.id] = cache_sprite
part_width = 100
part_height = 100
if DR_mod_runtime.use_DR_rust:
part_type = self.rust_parts.get_part_type(part.type_id)
if part_type is not None:
part_width = part_type.width
part_height = part_type.height
part_box = Rectangle(x=render_x, y=render_y,
width=100, height=100,
batch=self.part_box_batch, group=self.part_group)
part_box.opacity = 50
self.part_box_dict[part.id] = part_box
# if not part_render: # 如果不渲染(渲染有毛病)
# self.parts_sprite[part.id].visible = False
count += 1
@ -235,9 +248,6 @@ class SR1ShipRender(BaseScreen):
len(self.part_data), f'{full_mass}kg' if DR_mod_runtime.use_DR_rust else tr().game.require_DR_rs()))
self.rendered = True
def get_ship_size(self) -> (int, int):
...
def update_parts(self) -> bool:
if not self.rendered:
return False
@ -269,6 +279,7 @@ class SR1ShipRender(BaseScreen):
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
self.part_batch.draw()
self.part_box_batch.draw()
glDisable(GL_DEPTH_TEST)
self.debug_label.draw()
@ -355,6 +366,7 @@ class SR1ShipRender(BaseScreen):
SR1ShipRender_Option.debug_mouse_d_pos = not SR1ShipRender_Option.debug_mouse_d_pos
self.debug_mouse_delta_line.visible = SR1ShipRender_Option.debug_mouse_d_pos
# print('sr1 mouse')
elif command.find('get_buf'):
def screenshot(window):
@ -400,7 +412,7 @@ class SR1ShipRender(BaseScreen):
# 碰撞箱是居中的
# -x, -y, +x, +y
part_data = self.part_data[part]
bound_box = [-sprite_img.width / 2 + part_data.x, -sprite_img.height / 2 + part_data.y,
bound_box = [-sprite_img.width / 2 + part_data.x, -sprite_img.height / 2 + part_data.y,
sprite_img.width / 2 + part_data.x, sprite_img.height / 2 + part_data.y]
min_x = min(min_x, bound_box[0])
min_y = min(min_y, bound_box[1])
@ -422,7 +434,7 @@ class SR1ShipRender(BaseScreen):
pil_image.transpose(Image.FLIP_TOP_BOTTOM)
if self.part_data[part].flip_x:
pil_image.transpose(Image.FLIP_LEFT_RIGHT)
img.paste(pil_image, (int(self.part_data[part].x*60 + img_center[0]), int(-self.part_data[part].y*60 + img_center[1])), pil_image)
img.paste(pil_image, (int(self.part_data[part].x * 60 + img_center[0]), int(-self.part_data[part].y * 60 + img_center[1])), pil_image)
img.save(f'test{time.time()}.png', 'PNG')
def on_mouse_drag(self, x: int, y: int, dx: int, dy: int, buttons: int, modifiers: int, window: "ClientWindow"):