Compare commits

...

3 Commits

Author SHA1 Message Date
18b8ba1531
0.9.1.0! 2024-05-26 13:16:52 +08:00
5fa04bd47c
用box重写了一遍外框 2024-05-26 11:25:33 +08:00
160ad716c2
update dr rs and compile_mod.py 2024-05-26 10:47:05 +08:00
7 changed files with 49 additions and 79 deletions

View File

@ -8,7 +8,7 @@ from pathlib import Path
from Difficult_Rocket.api.types import Options, Version from Difficult_Rocket.api.types import Options, Version
sdk_version = Version("0.9.0.1") # SDK 版本 sdk_version = Version("0.9.1.0") # SDK 版本
build_version = Version("3.0.0.0") # 编译文件版本(与游戏本体无关) build_version = Version("3.0.0.0") # 编译文件版本(与游戏本体无关)
api_version = Version("0.1.2.1") # API 版本 api_version = Version("0.1.2.1") # API 版本
__version__ = sdk_version __version__ = sdk_version

View File

@ -341,8 +341,11 @@ class ClientWindow(Window):
def add_sub_screen(self, title: str, sub_screen: Type[BaseScreen]): def add_sub_screen(self, title: str, sub_screen: Type[BaseScreen]):
self.screen_list[title] = sub_screen(self) self.screen_list[title] = sub_screen(self)
def remove_sub_screen(self, title: str): def remove_sub_screen(self, title: str) -> BaseScreen:
self.screen_list.pop(title) """
去除一个页面, 返回被去掉的页面
"""
return self.screen_list.pop(title)
""" """
draws and some event draws and some event

View File

@ -19,7 +19,8 @@ setup(
RustExtension( RustExtension(
target="Difficult_Rocket_rs.Difficult_Rocket_rs", target="Difficult_Rocket_rs.Difficult_Rocket_rs",
binding=Binding.PyO3, binding=Binding.PyO3,
strip=Strip.All, rustc_flags=["-Ctarget-cpu=native"],
strip=Strip.No,
) )
], ],
zip_safe=False, zip_safe=False,

View File

@ -115,9 +115,6 @@ class DR_mod(ModInfo): # NOQA
client.add_sub_screen("DR_game_menu", Menu) client.add_sub_screen("DR_game_menu", Menu)
logger.info("added dr_game_menu screen", tag="dr_game") logger.info("added dr_game_menu screen", tag="dr_game")
# client.add_sub_screen("SR1_ship", SR1ShipRender)
# logger.info("added SR1_ship screen", tag="dr_game")
def on_unload(self, game: Game): def on_unload(self, game: Game):
game.client.window.screen_list.pop("SR1_ship") game.client.window.screen_list.pop("SR1_ship")

View File

@ -38,6 +38,7 @@ class Menu(BaseScreen):
# 占位, 高二看看能不能咕出来点啥 (20230911) # 占位, 高二看看能不能咕出来点啥 (20230911)
# 欸呀, 正好是 911 纪念日哦 # 欸呀, 正好是 911 纪念日哦
# 好, 高二 第一学期 期末都考完了, 我过来做测试了 (20240119) # 好, 高二 第一学期 期末都考完了, 我过来做测试了 (20240119)
# 高二, 马上要研学了, 似乎做了点啥, 但似乎又没做点啥 (20240526)
# self.wiki_button1 = PressTextButton( # self.wiki_button1 = PressTextButton(
# x=200, # x=200,
@ -126,7 +127,7 @@ class PressEnterShipEditorButton(PressTextButton):
batch: Optional[Batch] = None, batch: Optional[Batch] = None,
group: Optional[Group] = None, group: Optional[Group] = None,
theme: Optional[ButtonThemeOptions] = None, theme: Optional[ButtonThemeOptions] = None,
draw_theme: Optional[type(BaseButtonTheme)] = None, draw_theme: Optional[BaseButtonTheme] = None,
dict_theme: Optional[dict] = None, dict_theme: Optional[dict] = None,
): ):
super().__init__( super().__init__(

View File

@ -16,7 +16,7 @@ from pyglet.math import Mat4
from pyglet.text import Label from pyglet.text import Label
from pyglet.sprite import Sprite from pyglet.sprite import Sprite
from pyglet.graphics import Batch, Group from pyglet.graphics import Batch, Group
from pyglet.shapes import Line, Rectangle from pyglet.shapes import Line, Box
from . import DR_mod_runtime from . import DR_mod_runtime
from .types import SR1Textures, SR1Rotation from .types import SR1Textures, SR1Rotation
@ -121,8 +121,8 @@ class SR1ShipRender(BaseScreen):
self.render_d_label = Label( self.render_d_label = Label(
"debug label NODATA", "debug label NODATA",
font_name=Fonts.微软等宽无线, font_name=Fonts.微软等宽无线,
x=main_window.width / 2, x=main_window.width // 2,
y=main_window.height / 2, y=main_window.height // 2,
) )
self.render_d_label.visible = self.status.draw_d_pos self.render_d_label.visible = self.status.draw_d_pos
@ -133,8 +133,7 @@ class SR1ShipRender(BaseScreen):
self.ship_name: Optional[str] = None self.ship_name: Optional[str] = None
# List/Dict data # List/Dict data
self.part_sprites: Dict[int, List[Sprite]] = {} self.part_sprites: Dict[int, Tuple[Sprite, Box]] = {}
self.part_box_dict: Dict[int, Rectangle] = {}
self.part_outlines: Dict[int, List[Line]] = {} self.part_outlines: Dict[int, List[Line]] = {}
self.connection_lines: List[Line] = [] self.connection_lines: List[Line] = []
@ -196,7 +195,7 @@ class SR1ShipRender(BaseScreen):
part_group: Group, part_group: Group,
line_group: Group, line_group: Group,
batch: Batch, batch: Batch,
) -> Tuple[Sprite, List[Line]]: ) -> Tuple[Sprite, Box]:
""" """
还是重写一下渲染逻辑 还是重写一下渲染逻辑
把渲染单个部件的逻辑提取出来放到这里 把渲染单个部件的逻辑提取出来放到这里
@ -219,58 +218,20 @@ class SR1ShipRender(BaseScreen):
random.randrange(0, 255), random.randrange(0, 255),
200, 200,
) )
part_line_box = []
width = 4 width = 4
(x, y), (x2, y2) = part_data.get_part_box_by_type(part_type) (x, y), (x2, y2) = part_data.get_part_box_by_type(part_type)
part_line_box.append( box = Box(
Line(
x=x * 30, x=x * 30,
y=y * 30, y=y * 30,
x2=x * 30, width=part_type.width * 30,
y2=y2 * 30, height=part_type.height * 30,
batch=batch, thickness=width,
width=width,
color=line_colors, color=line_colors,
batch=batch,
group=line_group, group=line_group,
) )
) box.rotation = part_data.angle_r
part_line_box.append( return part_sprite, box
Line(
x=x * 30,
y=y2 * 30,
x2=x2 * 30,
y2=y2 * 30,
batch=batch,
width=width,
color=line_colors,
group=line_group,
)
)
part_line_box.append(
Line(
x=x2 * 30,
y=y2 * 30,
x2=x2 * 30,
y2=y * 30,
batch=batch,
width=width,
color=line_colors,
group=line_group,
)
)
part_line_box.append(
Line(
x=x2 * 30,
y=y * 30,
x2=x * 30,
y2=y * 30,
batch=batch,
width=width,
color=line_colors,
group=line_group,
)
)
return part_sprite, part_line_box
def sprite_batch(self, draw_batch: int = 100) -> Generator: def sprite_batch(self, draw_batch: int = 100) -> Generator:
""" """
@ -283,6 +244,7 @@ class SR1ShipRender(BaseScreen):
self.status.draw_done = False self.status.draw_done = False
# rust 渲染 # rust 渲染
if DR_mod_runtime.use_DR_rust: if DR_mod_runtime.use_DR_rust:
self.rust_ship: SR1Ship_rs
# 2 先渲染 # 2 先渲染
# 6 后渲染 # 6 后渲染
# 保证部件不会遮盖住连接线 # 保证部件不会遮盖住连接线
@ -292,13 +254,11 @@ class SR1ShipRender(BaseScreen):
# 渲染连接的部件 # 渲染连接的部件
for part_type, part_data in self.rust_ship.as_list(): for part_type, part_data in self.rust_ship.as_list():
# 渲染部件 # 渲染部件
part_sprite, part_line_box = self.part_render_init( part_sprite, part_box = self.part_render_init(
part_data, part_type, part_group, line_group, self.main_batch part_data, part_type, part_group, line_group, self.main_batch
) )
for line in part_line_box: part_box.opacity = 100
line.opacity = 100 self.part_sprites[part_data.id] = (part_sprite, part_box)
self.part_sprites[part_data.id] = part_sprite
self.part_outlines[part_data.id] = part_line_box
# TODO: 连接线渲染 # TODO: 连接线渲染
count += 2 count += 2
if count >= draw_batch: if count >= draw_batch:
@ -306,19 +266,17 @@ class SR1ShipRender(BaseScreen):
count = 0 count = 0
# 渲染未连接的部件 # 渲染未连接的部件
for part_group, part_connections in self.rust_ship.disconnected_parts(): for part_groups, part_connections in self.rust_ship.disconnected_parts():
for part_type, part_data in part_group[0]: for part_type, part_data in part_groups[0]:
# 未连接的需要同时把连接线也给渲染了 # 未连接的需要同时把连接线也给渲染了
# TODO: 连接线渲染 # TODO: 连接线渲染
part_sprite, part_line_box = self.part_render_init( part_sprite, part_box = self.part_render_init(
part_data, part_type, part_group, line_group, self.main_batch part_data, part_type, part_group, line_group, self.main_batch
) )
for line in part_line_box: part_box.opacity = 100
line.opacity = 100
# 未连接的部件透明度降低 # 未连接的部件透明度降低
part_sprite.opacity = 100 part_sprite.opacity = 100
self.part_sprites[part_data.id] = part_sprite self.part_sprites[part_data.id] = (part_sprite, part_box)
self.part_outlines[part_data.id] = part_line_box
count += 2 count += 2
if count >= draw_batch: if count >= draw_batch:
yield count yield count
@ -361,8 +319,7 @@ class SR1ShipRender(BaseScreen):
self.status.draw_done = False self.status.draw_done = False
logger.info(sr_tr().sr1.ship.ship.load().format(self.ship_name), tag="ship") logger.info(sr_tr().sr1.ship.ship.load().format(self.ship_name), tag="ship")
start_time = time.perf_counter_ns() start_time = time.perf_counter_ns()
self.part_sprites: Dict[int, Sprite] = {} self.part_sprites = {}
self.part_outlines: Dict[int, List[Line]] = {}
self.connection_lines: List[Line] = [] self.connection_lines: List[Line] = []
self.group_camera.reset() self.group_camera.reset()
# 调用生成器 减少卡顿 # 调用生成器 减少卡顿

View File

@ -1,13 +1,16 @@
import os
import sys
import argparse import argparse
import subprocess import subprocess
import sys
import os from pathlib import Path
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
# script -py <py_version> (3.8 ~ 3.12) # script -py <py_version> (3.8 ~ 3.12)
parser.add_argument("-py", type=str, help="python version") parser.add_argument("-py", type=str, help="python version")
parser.add_argument("-all", help="用所有的python版本编译", action="store_true") parser.add_argument("-all", help="用所有的python版本编译", action="store_true")
parser.add_argument("-clean", help="清理编译文件", action="store_true")
args = parser.parse_args() args = parser.parse_args()
@ -17,8 +20,16 @@ if __name__ == "__main__":
subprocess.run(["cargo", "fmt", "--all"]) subprocess.run(["cargo", "fmt", "--all"])
if args.clean:
subprocess.run(["cargo", "clean"])
os.chdir("../") os.chdir("../")
if args.clean:
subprocess.run([sys.executable, "setup.py", "clean"])
sys.exit(0)
if not args.py: if not args.py:
if args.all: if args.all:
all_version = ("38", "39", "310", "311", "312") all_version = ("38", "39", "310", "311", "312")