dr rs compat
This commit is contained in:
parent
505d68c67b
commit
5406e7f5c7
@ -7,6 +7,13 @@
|
|||||||
|
|
||||||
## 20230721 DR rs 0.2.17.0
|
## 20230721 DR rs 0.2.17.0
|
||||||
|
|
||||||
|
### Add
|
||||||
|
|
||||||
|
- 导出了 export
|
||||||
|
- `PySR1PartData`
|
||||||
|
- `PySaveStatus`
|
||||||
|
- `map_ptype_textures(part_type: str) -> str`
|
||||||
|
|
||||||
### BreakingChanges
|
### BreakingChanges
|
||||||
|
|
||||||
- `SR1Ship_rs`
|
- `SR1Ship_rs`
|
||||||
|
@ -15,15 +15,37 @@ if TYPE_CHECKING:
|
|||||||
py_obj.draw()
|
py_obj.draw()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_version_str() -> str: ...
|
def get_version_str() -> str:
|
||||||
|
"""
|
||||||
|
获取版本号
|
||||||
|
:return: 版本号
|
||||||
|
"""
|
||||||
|
|
||||||
def part_list_read_test(file_name: Optional[str] = "./assets/builtin/PartList.xml") -> None: ...
|
def part_list_read_test(file_name: Optional[str] = "./assets/builtin/PartList.xml") -> None:
|
||||||
|
"""
|
||||||
|
PartList 读取测试
|
||||||
|
:param file_name:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
def read_ship_test(path: Optional[str] = "./assets/builtin/dock1.xml") -> None: ...
|
def read_ship_test(path: Optional[str] = "./assets/builtin/dock1.xml") -> None:
|
||||||
|
"""
|
||||||
|
飞船存档读取测试
|
||||||
|
:param path:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
def map_ptype_textures(part_type: str) -> str:
|
||||||
|
"""
|
||||||
|
获取零件的贴图 (写死的)
|
||||||
|
:param part_type:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class SR1PartType_rs:
|
class SR1PartType_rs: # NOQA
|
||||||
""" 用于从 rust 中读取 SR1PartType
|
"""
|
||||||
|
用于从 rust 中读取 SR1PartType
|
||||||
不能从 Python 端创建
|
不能从 Python 端创建
|
||||||
自带一些可从 Python 端读取的属性 (实际上就是一个接口)
|
自带一些可从 Python 端读取的属性 (实际上就是一个接口)
|
||||||
"""
|
"""
|
||||||
@ -50,7 +72,7 @@ if TYPE_CHECKING:
|
|||||||
""" 零件是否隐藏 """
|
""" 零件是否隐藏 """
|
||||||
|
|
||||||
|
|
||||||
class SR1PartList_rs:
|
class SR1PartList_rs: # NOQA
|
||||||
""" 用于从 rust 中读取 SR1PartList """
|
""" 用于从 rust 中读取 SR1PartList """
|
||||||
def __init__(self, file_name: Optional[str] = "./assets/builtin/PartList.xml",
|
def __init__(self, file_name: Optional[str] = "./assets/builtin/PartList.xml",
|
||||||
list_name: Optional[str] = 'NewPartList'): ...
|
list_name: Optional[str] = 'NewPartList'): ...
|
||||||
@ -59,8 +81,9 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
def get_part_type(self, name: str) -> SR1PartType_rs: ...
|
def get_part_type(self, name: str) -> SR1PartType_rs: ...
|
||||||
|
|
||||||
class SR1PartData_rs:
|
class SR1PartData_rs: # NOQA
|
||||||
""" 用于从 rust 中读取 SR1PartData (其实好像也没啥用哈)
|
"""
|
||||||
|
用于从 rust 中读取 SR1PartData (其实好像也没啥用哈)
|
||||||
"""
|
"""
|
||||||
@property
|
@property
|
||||||
def id(self) -> int: ...
|
def id(self) -> int: ...
|
||||||
@ -85,10 +108,10 @@ if TYPE_CHECKING:
|
|||||||
@property
|
@property
|
||||||
def flip_y(self) -> bool: ...
|
def flip_y(self) -> bool: ...
|
||||||
|
|
||||||
class SaveStatus_rs:
|
class SaveStatus_rs: # NOQA
|
||||||
def __init__(self, save_default: Optional[bool] = False) -> None: ...
|
def __init__(self, save_default: Optional[bool] = False) -> None: ...
|
||||||
|
|
||||||
class SR1Ship_rs:
|
class SR1Ship_rs: # NOQA
|
||||||
""" 用于高效且省内存的读取 SR1Ship """
|
""" 用于高效且省内存的读取 SR1Ship """
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
file_path: Optional[str] = './assets/builtin/dock1.xml',
|
file_path: Optional[str] = './assets/builtin/dock1.xml',
|
||||||
@ -113,7 +136,7 @@ if TYPE_CHECKING:
|
|||||||
"""用于返回一个包含所有已连接零件的字典"""
|
"""用于返回一个包含所有已连接零件的字典"""
|
||||||
def save(self, file_path: str, save_status: Optional[SaveStatus_rs] = None) -> None: ...
|
def save(self, file_path: str, save_status: Optional[SaveStatus_rs] = None) -> None: ...
|
||||||
|
|
||||||
class Console_rs:
|
class Console_rs: # NOQA
|
||||||
def __init__(self) -> None: ...
|
def __init__(self) -> None: ...
|
||||||
def start(self) -> None: ...
|
def start(self) -> None: ...
|
||||||
def stop(self) -> bool: ...
|
def stop(self) -> bool: ...
|
||||||
|
@ -16,7 +16,7 @@ from Difficult_Rocket.api.mod import ModInfo
|
|||||||
from Difficult_Rocket.client import ClientWindow
|
from Difficult_Rocket.client import ClientWindow
|
||||||
from Difficult_Rocket.api.types import Options, Version
|
from Difficult_Rocket.api.types import Options, Version
|
||||||
|
|
||||||
DR_rust_version = Version("0.2.17.0") # DR_mod 的 Rust 编写部分的兼容版本
|
DR_rust_version = Version("0.2.18.0") # DR_mod 的 Rust 编写部分的兼容版本
|
||||||
|
|
||||||
logger = logging.getLogger('client.dr_game')
|
logger = logging.getLogger('client.dr_game')
|
||||||
|
|
||||||
|
@ -40,7 +40,10 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
if DR_mod_runtime.use_DR_rust:
|
if DR_mod_runtime.use_DR_rust:
|
||||||
from .Difficult_Rocket_rs import (SR1PartList_rs,
|
from .Difficult_Rocket_rs import (SR1PartList_rs,
|
||||||
SR1Ship_rs)
|
SR1Ship_rs,
|
||||||
|
SR1PartData_rs,
|
||||||
|
SR1PartType_rs,
|
||||||
|
map_ptype_textures)
|
||||||
|
|
||||||
logger = logging.getLogger('client.dr_game_sr1_ship')
|
logger = logging.getLogger('client.dr_game_sr1_ship')
|
||||||
logger.level = logging.DEBUG
|
logger.level = logging.DEBUG
|
||||||
@ -117,8 +120,8 @@ class SR1ShipRender(BaseScreen):
|
|||||||
self.camera = CenterCamera(main_window, min_zoom=(1 / 2) ** 10, max_zoom=10)
|
self.camera = CenterCamera(main_window, min_zoom=(1 / 2) ** 10, max_zoom=10)
|
||||||
|
|
||||||
# Optional data
|
# Optional data
|
||||||
|
self.textures: SR1Textures = SR1Textures()
|
||||||
self.gen_draw: Optional[Generator] = None
|
self.gen_draw: Optional[Generator] = None
|
||||||
self.textures: Union[SR1Textures, None] = None
|
|
||||||
self.xml_name: Optional[str] = None # 准备移除, 更换为基于 rust 的 xml 解析
|
self.xml_name: Optional[str] = None # 准备移除, 更换为基于 rust 的 xml 解析
|
||||||
self.xml_doc: Optional[ElementTree] = None # 准备移除, 更换为基于 rust 的 xml 解析
|
self.xml_doc: Optional[ElementTree] = None # 准备移除, 更换为基于 rust 的 xml 解析
|
||||||
self.xml_root: Optional[Element] = None # 准备移除, 更换为基于 rust 的 xml 解析
|
self.xml_root: Optional[Element] = None # 准备移除, 更换为基于 rust 的 xml 解析
|
||||||
@ -163,13 +166,6 @@ class SR1ShipRender(BaseScreen):
|
|||||||
print(e)
|
print(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def load_textures(self):
|
|
||||||
"""
|
|
||||||
初始化纹理加载
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
self.textures = SR1Textures()
|
|
||||||
|
|
||||||
def gen_sprite(self, part_datas: Dict[int, SR1PartData], each_count: int = 100) -> Generator:
|
def gen_sprite(self, part_datas: Dict[int, SR1PartData], each_count: int = 100) -> Generator:
|
||||||
"""
|
"""
|
||||||
生成 sprite
|
生成 sprite
|
||||||
@ -181,7 +177,23 @@ class SR1ShipRender(BaseScreen):
|
|||||||
count = 0
|
count = 0
|
||||||
self.drawing = True
|
self.drawing = True
|
||||||
# rust 渲染
|
# rust 渲染
|
||||||
|
if DR_mod_runtime.use_DR_rust:
|
||||||
|
for p_id, parts in self.rust_ship.as_dict().items():
|
||||||
|
p_id: int
|
||||||
|
parts: List[Tuple[SR1PartType_rs, SR1PartData_rs]]
|
||||||
|
part_group = Group(20, parent=self.part_group)
|
||||||
|
batch = []
|
||||||
|
for p_type, p_data in parts:
|
||||||
|
part_sprite = Sprite(img=self.textures.get_texture(map_ptype_textures(p_data.part_type_id)),
|
||||||
|
x=p_data.x * 60, y=p_data.y * 60, z=random.random(),
|
||||||
|
batch=self.main_batch, group=part_group)
|
||||||
|
|
||||||
|
batch.append(part_sprite)
|
||||||
|
|
||||||
|
count += 1
|
||||||
|
if count >= each_count:
|
||||||
|
count = 0
|
||||||
|
yield
|
||||||
|
|
||||||
# python 渲染
|
# python 渲染
|
||||||
for part_id, part in part_datas.items():
|
for part_id, part in part_datas.items():
|
||||||
@ -252,8 +264,6 @@ class SR1ShipRender(BaseScreen):
|
|||||||
"""
|
"""
|
||||||
渲染船
|
渲染船
|
||||||
"""
|
"""
|
||||||
if self.textures is None:
|
|
||||||
self.load_textures()
|
|
||||||
logger.info(sr_tr().sr1.ship.ship.load().format(self.xml_name))
|
logger.info(sr_tr().sr1.ship.ship.load().format(self.xml_name))
|
||||||
start_time = time.perf_counter_ns()
|
start_time = time.perf_counter_ns()
|
||||||
self.part_data: Dict[int, SR1PartData] = {}
|
self.part_data: Dict[int, SR1PartData] = {}
|
||||||
|
@ -33,10 +33,8 @@ class SR1PartData:
|
|||||||
|
|
||||||
class SR1Textures(Options):
|
class SR1Textures(Options):
|
||||||
""" 存储 sr1 的材质 img """
|
""" 存储 sr1 的材质 img """
|
||||||
def __init__(self, **kwargs):
|
def load_file(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
for image_name in self.flush_option():
|
||||||
self.flush_option()
|
|
||||||
for image_name in self.cached_options:
|
|
||||||
img = load(f'assets/textures/parts/{image_name}.png')
|
img = load(f'assets/textures/parts/{image_name}.png')
|
||||||
img.anchor_x = img.width // 2
|
img.anchor_x = img.width // 2
|
||||||
img.anchor_y = img.height // 2
|
img.anchor_y = img.height // 2
|
||||||
@ -49,8 +47,10 @@ class SR1Textures(Options):
|
|||||||
:param name:
|
:param name:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
assert name in self.cached_options
|
if name in self.cached_options:
|
||||||
return self.cached_options.get(name)
|
return self.cached_options.get(name)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
Battery: AbstractImage = None
|
Battery: AbstractImage = None
|
||||||
Beam: AbstractImage = None
|
Beam: AbstractImage = None
|
||||||
@ -134,6 +134,11 @@ class SR1Rotation(Options):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_rotation(cls, radian: float) -> float:
|
def get_rotation(cls, radian: float) -> float:
|
||||||
|
"""
|
||||||
|
实际上就是将弧度转换为角度 (同时自带一个映射表)
|
||||||
|
:param radian:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
if radian in cls.radian_angle_map:
|
if radian in cls.radian_angle_map:
|
||||||
return cls.radian_angle_map[radian]
|
return cls.radian_angle_map[radian]
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user