实现了未连接零件的渲染

This commit is contained in:
ssssssssboom 2024-05-23 21:09:04 +08:00
parent 0baaf3df34
commit a8be1eadd8

View File

@ -188,12 +188,15 @@ class SR1ShipRender(BaseScreen):
traceback.print_exc() traceback.print_exc()
self.logger.error(traceback.format_exc(), tag="load_xml") self.logger.error(traceback.format_exc(), tag="load_xml")
return False return False
def draw_parts(self, def draw_parts(
self,
cache: List[Tuple[SR1PartType_rs, SR1PartData_rs]], cache: List[Tuple[SR1PartType_rs, SR1PartData_rs]],
count: int, count: int,
each_count: int, each_count: int,
draw_part_box: bool): draw_part_box: bool,
#渲染传入的parts draw_alpha: int
):
# 渲染传入的parts
part_group = Group(2, parent=self.part_group) part_group = Group(2, parent=self.part_group)
line_box_group = Group(6, parent=self.part_group) line_box_group = Group(6, parent=self.part_group)
for p_id, parts in cache: for p_id, parts in cache:
@ -201,9 +204,7 @@ class SR1ShipRender(BaseScreen):
parts: List[Tuple[SR1PartType_rs, SR1PartData_rs]] parts: List[Tuple[SR1PartType_rs, SR1PartData_rs]]
batch = [] batch = []
for p_type, p_data in parts: for p_type, p_data in parts:
sprite_name = self.part_list_rs.get_part_type( sprite_name = self.part_list_rs.get_part_type(p_data.part_type_id).sprite
p_data.part_type_id
).sprite
part_sprite = Sprite( part_sprite = Sprite(
img=self.textures.get_texture(sprite_name), img=self.textures.get_texture(sprite_name),
x=p_data.x * 60, x=p_data.x * 60,
@ -212,6 +213,7 @@ class SR1ShipRender(BaseScreen):
batch=self.main_batch, batch=self.main_batch,
group=part_group, group=part_group,
) )
part_sprite.opacity = draw_alpha
part_sprite.rotation = p_data.angle_r part_sprite.rotation = p_data.angle_r
part_sprite.scale_x = -1 if p_data.flip_x else 1 part_sprite.scale_x = -1 if p_data.flip_x else 1
part_sprite.scale_y = -1 if p_data.flip_y else 1 part_sprite.scale_y = -1 if p_data.flip_y else 1
@ -301,18 +303,12 @@ class SR1ShipRender(BaseScreen):
#渲染所有未连接零件 #渲染所有未连接零件
all_disconnected_groups = self.rust_ship.disconnected_parts() all_disconnected_groups = self.rust_ship.disconnected_parts()
logger.info(type(all_disconnected_groups)) for parts_groups, connections in all_disconnected_groups:
for cache, connections in all_disconnected_groups:
logger.info(type(cache))
logger.info(type(connections))
draw_part_box = False draw_part_box = False
count=self.draw_parts(cache, cache = []
count, for p_type, p_data in parts_groups:
each_count, cache.append((p_data.id,parts_groups))
draw_part_box) count=self.draw_parts(cache, count, each_count, draw_part_box, 128)
if count >= each_count: if count >= each_count:
count = 0 count = 0
yield yield
@ -320,18 +316,14 @@ class SR1ShipRender(BaseScreen):
#渲染所有已连接零件 # 渲染所有已连接零件
draw_part_box = False draw_part_box = False
cache = self.rust_ship.as_dict() cache = self.rust_ship.as_dict()
count=self.draw_parts(cache.items(), count=self.draw_parts(cache.items(), count, each_count, draw_part_box, 255)
count,
each_count,
draw_part_box)
if count >= each_count: if count >= each_count:
count = 0 count = 0
yield yield
connect_line_group = Group(7, parent=self.part_group) connect_line_group = Group(7, parent=self.part_group)
for connect in self.rust_ship.connections().get_raw_data(): for connect in self.rust_ship.connections().get_raw_data():
# 连接线 # 连接线