DR -> DR SDK #16
@ -24,7 +24,7 @@ Api_version = Version("0.0.2.0") # API 版本
|
||||
__version__ = game_version
|
||||
|
||||
# TODO 解耦 DR SDK 与 DR_mod 和 DR_rs
|
||||
DR_rust_version = Version("0.2.6.1") # DR 的 Rust 编写部分的版本
|
||||
DR_rust_version = Version("0.2.6.2") # DR 的 Rust 编写部分的版本
|
||||
# 后面会移除的 DR_rs 相关信息
|
||||
# DR_rs和 DR_mod 的部分正在和 DR SDK 解耦
|
||||
|
||||
@ -71,7 +71,7 @@ class _DR_option(Options):
|
||||
# tests
|
||||
playing: bool = False
|
||||
debugging: bool = False
|
||||
crash_report_test: bool = True
|
||||
crash_report_test: bool = False
|
||||
|
||||
# window option
|
||||
gui_scale: float = 1.0 # default 1.0 2.0 -> 2x 3 -> 3x
|
||||
|
@ -7,8 +7,8 @@ fonts_folder = "libs/fonts"
|
||||
|
||||
[window]
|
||||
style = "None"
|
||||
width = 2048
|
||||
height = 1165
|
||||
width = 1191
|
||||
height = 886
|
||||
visible = true
|
||||
gui_scale = 1
|
||||
caption = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}"
|
||||
|
@ -94,6 +94,12 @@ pub mod translate {
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyDict;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum BoolString {
|
||||
Bool(bool),
|
||||
String(String),
|
||||
}
|
||||
|
||||
#[pyclass]
|
||||
#[pyo3(name = "TranslateConfig_rs")]
|
||||
#[pyo3(text_signature = "(language, raise_error = False, replace_normal = False, add_error = False, is_result = False, keep_get = False)")]
|
||||
@ -121,6 +127,13 @@ pub mod translate {
|
||||
language: language.unwrap_or(default_language),
|
||||
}
|
||||
}
|
||||
|
||||
// fn set(&self, py_: Python, item: String, value: BoolString) -> &Self {
|
||||
// match item.as_str() {
|
||||
// "raise_error" => self,
|
||||
// _ => self,
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
#[pyclass]
|
||||
|
@ -4,15 +4,47 @@
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
import warnings
|
||||
import traceback
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from .sr1_ship import SR1ShipRender
|
||||
|
||||
from MCDR.version import Version
|
||||
from Difficult_Rocket.main import Game
|
||||
from Difficult_Rocket.api.mod import ModInfo
|
||||
from Difficult_Rocket.api.types import Options
|
||||
from Difficult_Rocket.client import ClientWindow
|
||||
|
||||
DR_rust_version = Version("0.2.6.2") # DR_mod 的 Rust 编写部分的兼容版本
|
||||
|
||||
|
||||
class _DR_mod_runtime(Options):
|
||||
|
||||
use_DR_rust: bool = True
|
||||
DR_rust_available: bool = False
|
||||
DR_rust_version: Version = DR_rust_version
|
||||
DR_rust_get_version: Optional[Version] = None
|
||||
|
||||
def init(self, **kwargs) -> None:
|
||||
try:
|
||||
from libs.Difficult_Rocket_rs import get_version_str
|
||||
self.DR_rust_get_version = Version(get_version_str())
|
||||
self.DR_rust_available = True
|
||||
if self.DR_rust_get_version != self.DR_rust_version:
|
||||
relationship = 'larger' if self.DR_rust_version > self.DR_rust_version else 'smaller'
|
||||
warnings.warn(f'DR_rust builtin version is {self.DR_rust_version} but true version is {get_version_str()}.\n'
|
||||
f'Builtin version {relationship} than true version')
|
||||
self.use_DR_rust = self.use_DR_rust and self.DR_rust_available
|
||||
except ImportError as e:
|
||||
traceback.print_exc()
|
||||
self.DR_rust_available = False
|
||||
self.use_DR_rust = False
|
||||
self.flush_option()
|
||||
|
||||
|
||||
DR_mod_runtime = _DR_mod_runtime()
|
||||
|
||||
|
||||
class DR_mod(ModInfo):
|
||||
|
||||
@ -25,6 +57,8 @@ class DR_mod(ModInfo):
|
||||
description = "Difficult Rocket mod (where the game implement)"
|
||||
info = "Difficult Rocket mod (where the game implement)"
|
||||
|
||||
config = DR_mod_runtime
|
||||
|
||||
# DR_version = # DR SDK 兼容版本
|
||||
# 反正是内置 mod 跟着最新版本的 DR 走就行了
|
||||
# DR_Api_version = # DR Api版本
|
||||
@ -32,9 +66,13 @@ class DR_mod(ModInfo):
|
||||
|
||||
def on_load(self, game: Game, old_self: Optional["DR_mod"] = None):
|
||||
if old_self:
|
||||
...
|
||||
game.client.window.add_sub_screen("SR1_ship", old_self.screen)
|
||||
else:
|
||||
self.config.flush_option()
|
||||
|
||||
def on_client_start(self, game: Game, client: ClientWindow):
|
||||
from .sr1_ship import SR1ShipRender
|
||||
self.screen = SR1ShipRender
|
||||
print('DR_mod: on_client_start')
|
||||
client.add_sub_screen("SR1_ship", SR1ShipRender)
|
||||
|
||||
|
@ -21,6 +21,8 @@ from pyglet.shapes import Line
|
||||
from pyglet.sprite import Sprite
|
||||
from pyglet.graphics import Batch, Group
|
||||
|
||||
from . import DR_mod_runtime
|
||||
|
||||
# Difficult Rocket
|
||||
from Difficult_Rocket import DR_option
|
||||
from Difficult_Rocket.utils.translate import tr
|
||||
@ -32,7 +34,7 @@ from Difficult_Rocket.api.types.SR1 import SR1Textures, SR1PartTexture, SR1PartD
|
||||
if TYPE_CHECKING:
|
||||
from Difficult_Rocket.client import ClientWindow
|
||||
|
||||
if DR_option.use_DR_rust:
|
||||
if DR_mod_runtime.use_DR_rust:
|
||||
from libs.Difficult_Rocket_rs import CenterCamera_rs, SR1PartList_rs
|
||||
|
||||
|
||||
@ -127,7 +129,7 @@ class SR1ShipRender(BaseScreen):
|
||||
load_end_time = time.time_ns()
|
||||
logger.info(tr().client.sr1_render.setup.use_time().format(
|
||||
(load_end_time - load_start_time) / 1000000000))
|
||||
if DR_option.use_DR_rust:
|
||||
if DR_mod_runtime.use_DR_rust:
|
||||
self.camera_rs = CenterCamera_rs(main_window,
|
||||
min_zoom=(1 / 2) ** 10, max_zoom=10)
|
||||
self.rust_parts = None
|
||||
@ -193,7 +195,7 @@ class SR1ShipRender(BaseScreen):
|
||||
self.part_data: Dict[int, SR1PartData] = {}
|
||||
self.parts_sprite: Dict[int, Sprite] = {}
|
||||
self.camera_rs.zoom = 1.0
|
||||
if DR_option.use_DR_rust:
|
||||
if DR_mod_runtime.use_DR_rust:
|
||||
self.camera_rs.dx = 0
|
||||
self.camera_rs.dy = 0
|
||||
parts = self.xml_root.find('Parts')
|
||||
@ -212,13 +214,13 @@ class SR1ShipRender(BaseScreen):
|
||||
self.drawing = False
|
||||
self.need_draw = False
|
||||
full_mass = 0
|
||||
if DR_option.use_DR_rust:
|
||||
if DR_mod_runtime.use_DR_rust:
|
||||
for part in self.part_data:
|
||||
full_mass += self.part_list_rs.get_part_type(self.part_data[part].p_type).mass * 500
|
||||
logger.info(tr().client.sr1_render.ship.load_time().format(
|
||||
(time.perf_counter_ns() - start_time) / 1000000000))
|
||||
logger.info(tr().client.sr1_render.ship.info().format(
|
||||
len(self.part_data), f'{full_mass}kg' if DR_option.use_DR_rust else tr().game.require_DR_rs()))
|
||||
len(self.part_data), f'{full_mass}kg' if DR_mod_runtime.use_DR_rust else tr().game.require_DR_rs()))
|
||||
self.rendered = True
|
||||
|
||||
def get_ship_size(self) -> (int, int):
|
||||
|
Loading…
Reference in New Issue
Block a user