feat: sr1 render

This commit is contained in:
shenjack 2022-12-26 18:27:39 +08:00
parent a937f0a3fa
commit 47e0d52975
4 changed files with 65 additions and 7 deletions

View File

@ -20,10 +20,11 @@ from libs.MCDR.version import Version
game_version = Version("0.6.4") game_version = Version("0.6.4")
__version__ = game_version __version__ = game_version
long_version: int = 1 long_version: ctypes.c_longlong = ctypes.c_longlong(2)
""" """
long_version: 一个用于标记内部协议的整数 long_version: 一个用于标记内部协议的整数
1: 我可算想起来还有这回事了 v0.6.4 1: 我可算想起来还有这回事了 v0.6.4
2: longlong 好耶
""" """
@ -92,7 +93,7 @@ class _DR_runtime(Options):
_DR_runtime.add_option('language', _DR_runtime.language) _DR_runtime.add_option('language', _DR_runtime.language)
dDR_option = DR_option() DR_option = DR_option()
DR_runtime = _DR_runtime() DR_runtime = _DR_runtime()
if DR_option.playing: if DR_option.playing:

View File

@ -4,8 +4,10 @@
# All rights reserved # All rights reserved
# ------------------------------- # -------------------------------
from typing import Dict, Union
# pyglet # pyglet
import pyglet # import pyglet
from pyglet.image import load, AbstractImage from pyglet.image import load, AbstractImage
# Difficult Rocket # Difficult Rocket
@ -13,12 +15,14 @@ from Difficult_Rocket.utils.typings import Options
class SR1Textures(Options): class SR1Textures(Options):
""" 存储 sr1 的材质 img """
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.flush_option() self.flush_option()
for image_name in self.cached_options: for image_name in self.cached_options:
setattr(self, image_name, load(f'textures/parts/{image_name}.png')) setattr(self, image_name, load(f'textures/parts/{image_name}.png'))
self.flush_option() self.flush_option()
Battery: AbstractImage = None Battery: AbstractImage = None
Beam: AbstractImage = None Beam: AbstractImage = None
CoverBottom: AbstractImage = None CoverBottom: AbstractImage = None
@ -57,5 +61,57 @@ class SR1Textures(Options):
Wing: AbstractImage = None Wing: AbstractImage = None
class SR1PartTexture:
part_type_sprite: Dict[str, str] = {'pod-1 ': 'Pod',
'detacher-1 ': 'DetacherVertical',
'detacher-2 ': 'DetacherRadial',
'wheel-1 ': 'Wheel',
'wheel-2 ': 'Wheel',
'fuselage-1 ': 'Fuselage',
'strut-1 ': 'Beam',
'fueltank-0 ': 'TankTiny',
'fueltank-1 ': 'TankSmall',
'fueltank-2 ': 'TankMedium',
'fueltank-3 ': 'TankLarge',
'fueltank-4 ': 'Puffy750',
'fueltank-5 ': 'SideTank',
'engine-0 ': 'EngineTiny',
'engine-1 ': 'EngineSmall',
'engine-2 ': 'EngineMedium',
'engine-3 ': 'EngineLarge',
'engine-4 ': 'SolidRocketBooster',
'ion-0 ': 'EngineIon',
'parachute-1': 'ParachuteCanister',
'nosecone-1 ': 'NoseCone',
'rcs-1 ': 'RcsBlock',
'solar-1 ': 'SolarPanelBase',
'battery-0 ': 'Battery',
'dock-1 ': 'DockingConnector',
'port-1 ': 'DockingPort',
'lander-1 ': 'LanderLegPreview'}
@classmethod
def get_sprite_from_type(cls, name: str) -> Union[None, str]:
if name not in cls.part_type_sprite:
return None
return cls.part_type_sprite[name]
#
#
# from xml.etree.ElementTree import Element, ElementTree
# from defusedxml.ElementTree import parse
#
# part_list = parse("../../../../textures/PartList.xml")
# part_list_root: Element = part_list.getroot()
# print(part_list_root.tag, part_list_root.attrib)
#
# part_types = part_list_root.find('PartTypes')
#
# for x in list(part_list_root):
# print(f'tag: {x.tag} attr: {x.attrib}')
#
# for part_type in list(part_list_root):
# part_type: Element
# print(f'\'{part_type.attrib.get("id"):<11}\': \'{part_type.attrib.get("sprite")}\'')
#
#

View File

@ -25,7 +25,7 @@ from decimal import Decimal
import tomlkit import tomlkit
import pyglet import pyglet
# from pyglet import gl # from pyglet import gl
from pyglet.gl import * from pyglet.gl import glClearColor
# from pyglet.libs.win32 import _user32 # from pyglet.libs.win32 import _user32
from pyglet.window import Window from pyglet.window import Window
from pyglet.window import key, mouse from pyglet.window import key, mouse

View File

@ -16,7 +16,7 @@ from pyglet.resource import texture
# Difficult Rocket # Difficult Rocket
from Difficult_Rocket import DR_option from Difficult_Rocket import DR_option
from Difficult_Rocket.api.types.SR1 import SR1Textures from Difficult_Rocket.api.types.SR1 import SR1Textures, SR1PartTexture
from Difficult_Rocket.command.line import CommandText from Difficult_Rocket.command.line import CommandText
from Difficult_Rocket.client.screen import BaseScreen from Difficult_Rocket.client.screen import BaseScreen
@ -59,11 +59,12 @@ class SR1ShipRender(BaseScreen):
part_flip_x = part.attrib.get('flippedX') or 0 part_flip_x = part.attrib.get('flippedX') or 0
part_flip_y = part.attrib.get('flippedY') or 0 part_flip_y = part.attrib.get('flippedY') or 0
part_explode = part.attrib.get('exploded') or 0 part_explode = part.attrib.get('exploded') or 0
if part_id not in self.textures.cached_options: if part_type not in SR1PartTexture.part_type_sprite:
print('Textures None found!') print('Textures None found!')
print(f'id: {part_id:<4} type: {part_type:<10} x: {part_x} y: {part_y} activated: {part_activate} ' print(f'id: {part_id:<4} type: {part_type:<10} x: {part_x} y: {part_y} activated: {part_activate} '
f'angle: {part_angle} angle_v: {part_angle_v} editor_angle: {part_editor_angle} ' f'angle: {part_angle} angle_v: {part_angle_v} editor_angle: {part_editor_angle} '
f'flip_x: {part_flip_x} flip_y: {part_flip_y} explode: {part_explode}') f'flip_x: {part_flip_x} flip_y: {part_flip_y} explode: {part_explode} '
f'textures: {SR1PartTexture.get_sprite_from_type(part_type)}')
def on_draw(self): def on_draw(self):
... ...