adapt for rust render

This commit is contained in:
shenjack 2023-07-23 11:03:22 +08:00
parent ad83def45e
commit 7fed4032e0
Signed by: shenjack
GPG Key ID: 7B1134A979775551

View File

@ -362,7 +362,7 @@ class SR1ShipRender(BaseScreen):
# 这个功能依赖于 DR rs (简称,我懒得在Python端实现) # 这个功能依赖于 DR rs (简称,我懒得在Python端实现)
return return
img_box = self.rust_ship.img_pos img_box = self.rust_ship.img_pos
img_size = (img_box[2] - img_box[0] + 1000, img_box[3] - img_box[1] + 1000) img_size = (img_box[2] - img_box[0], img_box[3] - img_box[1])
# 中心点是左上角坐标 # 中心点是左上角坐标
img_center = (abs(img_box[0]), abs(img_box[3])) img_center = (abs(img_box[0]), abs(img_box[3]))
try: try:
@ -372,24 +372,30 @@ class SR1ShipRender(BaseScreen):
print('PIL not found') print('PIL not found')
return return
img = Image.new('RGBA', img_size) img = Image.new('RGBA', img_size)
for part, sprite in self.parts_sprite.items(): part_data = self.rust_ship.as_dict()
for part, sprites in self.parts_sprite.items():
for index, sprite in enumerate(sprites):
sprite_img = sprite.image sprite_img = sprite.image
print(f"sprite_img: {sprite_img} {sprite_img.width} {sprite_img.height}") print(f"sprite_img: {sprite_img} {part_data[part][index][1].x * 60} {part_data[part][index][1].y * 60}")
img_data = sprite_img.get_image_data() img_data = sprite_img.get_image_data()
fmt = img_data.format fmt = img_data.format
if fmt != 'RGB': if fmt != 'RGB':
fmt = 'RGBA' fmt = 'RGBA'
pitch = -(img_data.width * len(fmt)) pitch = -(img_data.width * len(fmt))
pil_image = Image.frombytes(fmt, (img_data.width, img_data.height), img_data.get_data(fmt, pitch)) pil_image = Image.frombytes(fmt, (img_data.width, img_data.height), img_data.get_data(fmt, pitch))
pil_image = pil_image.rotate(SR1Rotation.get_rotation(self.part_data[part].angle), expand=True)
if self.part_data[part].flip_y: pil_image = pil_image.rotate(-SR1Rotation.get_rotation(part_data[part][index][1].angle), expand=True)
if part_data[part][index][1].flip_y:
pil_image.transpose(Image.FLIP_TOP_BOTTOM) pil_image.transpose(Image.FLIP_TOP_BOTTOM)
if self.part_data[part].flip_x: if part_data[part][index][1].flip_x:
pil_image.transpose(Image.FLIP_LEFT_RIGHT) pil_image.transpose(Image.FLIP_LEFT_RIGHT)
pil_image.show()
img.paste(pil_image, ( img.paste(pil_image, (
int(self.part_data[part].x * 60 + img_center[0]), int(part_data[part][index][1].x * 60 + img_center[0]),
int(-self.part_data[part].y * 60 + img_center[1])), int(-part_data[part][index][1].y * 60 + img_center[1])))
pil_image) img.show("???")
img.save(f'test{time.time()}.png', 'PNG') img.save(f'test{time.time()}.png', 'PNG')
elif command.find('test'): elif command.find('test'):