support DR_rust

This commit is contained in:
shenjack 2023-01-24 23:59:07 +08:00
parent b3f262e817
commit c158db62f9
9 changed files with 55 additions and 28 deletions

View File

@ -23,12 +23,14 @@ from libs.MCDR.version import Version
game_version = Version("0.6.5.0") # 游戏版本 game_version = Version("0.6.5.0") # 游戏版本
build_version = Version("1.1.0.0") # 编译文件版本(与游戏本体无关) build_version = Version("1.1.0.0") # 编译文件版本(与游戏本体无关)
DR_rust_version = Version("0.0.5.2") # DR 的 Rust 编写部分的版本 DR_rust_version = Version("0.0.6.4") # DR 的 Rust 编写部分的版本
__version__ = game_version __version__ = game_version
long_version: int = 10 long_version: int = 11
""" """
long_version: 一个用于标记内部协议的整数 long_version: 一个用于标记内部协议的整数
11: DR_option 添加 use_DR_rust
修复了一些拼写错误
10: DR_runtime 添加 DR_Rust_get_version 10: DR_runtime 添加 DR_Rust_get_version
9 : DR_option 添加 pyglet_macosx_dev_test 9 : DR_option 添加 pyglet_macosx_dev_test
8 : DR_runtime 添加 DR_rust_version 8 : DR_runtime 添加 DR_rust_version
@ -53,11 +55,12 @@ class _DR_option(Options):
# runtime options # runtime options
InputBox_use_TextEntry: bool = True InputBox_use_TextEntry: bool = True
record_threads: bool = True record_threads: bool = True
report_translate_not_found: bool = True
use_multiprocess: bool = False
DR_rust_available: bool = False
use_DR_rust: bool = True
use_cProfile: bool = False use_cProfile: bool = False
use_local_logging: bool = False use_local_logging: bool = False
report_translate_no_found: bool = True
use_muitprocess: bool = False
DR_rust_available: bool = False
# tests # tests
playing: bool = False playing: bool = False
@ -79,6 +82,7 @@ class _DR_option(Options):
if not __name__ == '__main__': if not __name__ == '__main__':
traceback.print_exc() traceback.print_exc()
self.DR_rust_available = False self.DR_rust_available = False
self.use_DR_rust = self.use_DR_rust and self.DR_rust_available
self.flush_option() self.flush_option()
def draw(self): def draw(self):

View File

@ -177,6 +177,7 @@ class ClientWindow(Window):
self.input_box = InputBox(x=50, y=30, width=300, self.input_box = InputBox(x=50, y=30, width=300,
batch=self.label_batch, text='') # 实例化 batch=self.label_batch, text='') # 实例化
self.input_box.push_handlers(self) self.input_box.push_handlers(self)
self.input_box.set_handler('on_commit', self.on_input)
self.push_handlers(self.input_box) self.push_handlers(self.input_box)
self.input_box.enabled = True self.input_box.enabled = True
# 设置刷新率 # 设置刷新率
@ -282,6 +283,11 @@ class ClientWindow(Window):
command line event command line event
""" """
def on_input(self, message: str) -> None:
command_text = line.CommandText(message)
self.on_command(command_text)
self.input_box.value = ''
@_call_screen_after @_call_screen_after
def on_command(self, command: line.CommandText): def on_command(self, command: line.CommandText):
self.logger.info(tr.lang('window', 'command.text').format(command)) self.logger.info(tr.lang('window', 'command.text').format(command))

View File

@ -4,7 +4,7 @@
# All rights reserved # All rights reserved
# ------------------------------- # -------------------------------
import math import random
from xml.etree import ElementTree from xml.etree import ElementTree
from xml.etree.ElementTree import Element from xml.etree.ElementTree import Element
from typing import List, TYPE_CHECKING, Union, Dict, Optional from typing import List, TYPE_CHECKING, Union, Dict, Optional
@ -28,7 +28,7 @@ from Difficult_Rocket.api.types.SR1 import SR1Textures, SR1PartTexture, SR1PartD
if TYPE_CHECKING: if TYPE_CHECKING:
from Difficult_Rocket.client import ClientWindow from Difficult_Rocket.client import ClientWindow
if DR_option.DR_rust_available: if DR_option.use_DR_rust:
from libs.Difficult_Rocket_rs import better_update_parts, PartDatas from libs.Difficult_Rocket_rs import better_update_parts, PartDatas
@ -115,7 +115,7 @@ class SR1ShipRender(BaseScreen):
batch=self.part_batch) batch=self.part_batch)
self.part_data: Dict[int, SR1PartData] = {} self.part_data: Dict[int, SR1PartData] = {}
self.parts_sprite: Dict[int, Sprite] = {} self.parts_sprite: Dict[int, Sprite] = {}
if DR_option.DR_rust_available: if DR_option.use_DR_rust:
self.rust_parts = None self.rust_parts = None
def load_xml(self, file_path: str) -> bool: def load_xml(self, file_path: str) -> bool:
@ -172,7 +172,7 @@ class SR1ShipRender(BaseScreen):
self.parts_sprite[part.id].visible = False self.parts_sprite[part.id].visible = False
self.parts_sprite[part.id] = cache_sprite self.parts_sprite[part.id] = cache_sprite
self.need_draw = False self.need_draw = False
if DR_option.DR_rust_available: if DR_option.use_DR_rust:
print(type(self.part_data)) print(type(self.part_data))
self.rust_parts = PartDatas(self.part_data) self.rust_parts = PartDatas(self.part_data)
# print(self.rust_parts.get_rust_pointer()) # print(self.rust_parts.get_rust_pointer())
@ -181,8 +181,12 @@ class SR1ShipRender(BaseScreen):
def update_parts(self) -> bool: def update_parts(self) -> bool:
if not self.rendered: if not self.rendered:
return False return False
if DR_option.DR_rust_available: if DR_option.use_DR_rust:
return better_update_parts(self, SR1ShipRender_Option, self.window_pointer, self.rust_parts) # print(f'{self.dx=} {self.dy=} {self.scale=}')
# from objprint import op
# op(random.choices(self.parts_sprite), indent=1)
return better_update_parts(self, SR1ShipRender_Option, self.window_pointer,
self.rust_parts, DR_option.gui_scale, 60)
self.debug_line.x2, self.debug_line.y2 = self.dx + (self.window_pointer.width / 2), self.dy + ( self.debug_line.x2, self.debug_line.y2 = self.dx + (self.window_pointer.width / 2), self.dy + (
self.window_pointer.height / 2) self.window_pointer.height / 2)
self.debug_d_pos_label.text = f'x: {self.dx} y: {self.dy}' self.debug_d_pos_label.text = f'x: {self.dx} y: {self.dy}'

View File

@ -70,7 +70,7 @@ class Game:
# @new_thread('main') # @new_thread('main')
def _start(self): def _start(self):
self.server.run() self.server.run()
if DR_option.use_muitprocess: if DR_option.use_multiprocess:
try: try:
game_process = multiprocessing.Process(target=self.client.start(), name='pyglet app') game_process = multiprocessing.Process(target=self.client.start(), name='pyglet app')
game_process.start() game_process.start()

View File

@ -78,7 +78,7 @@ class Translates:
def _raise_no_value(self, e: Exception, item: key_type): def _raise_no_value(self, e: Exception, item: key_type):
if self.config.raise_error: if self.config.raise_error:
raise TranslateKeyNotFound(self.value, [x[1] for x in self.get_list]) from None raise TranslateKeyNotFound(self.value, [x[1] for x in self.get_list]) from None
elif DR_option.report_translate_no_found: elif DR_option.report_translate_not_found:
frame = inspect.currentframe() frame = inspect.currentframe()
if frame is not None: if frame is not None:
frame = frame.f_back frame = frame.f_back

View File

@ -9,7 +9,7 @@ fonts_folder = "libs/fonts"
[window] [window]
style = "None" style = "None"
width = 1520 width = 1520
height = 1133 height = 868
visible = true visible = true
gui_scale = 1 gui_scale = 1
caption = "Difficult Rocket {version}" caption = "Difficult Rocket {version}"

View File

@ -26,6 +26,8 @@ if TYPE_CHECKING:
def better_update_parts(render: SR1ShipRender, def better_update_parts(render: SR1ShipRender,
option: SR1ShipRender_Option, option: SR1ShipRender_Option,
window: BaseScreen, window: BaseScreen,
parts: PartDatas) -> bool: ... parts: PartDatas,
global_scale: float,
sr1_xml_scale: int) -> bool: ...

View File

@ -12,7 +12,7 @@ use pyo3::prelude::*;
#[pyfunction] #[pyfunction]
fn get_version_str() -> String { fn get_version_str() -> String {
return String::from("0.0.5.2"); return String::from("0.0.6.4");
} }
#[pyfunction] #[pyfunction]

View File

@ -9,6 +9,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use pyo3::intern; use pyo3::intern;
use pyo3::prelude::*; use pyo3::prelude::*;
// use pyo3::types::PyDict;
use crate::sr1_render::types::SR1PartData; use crate::sr1_render::types::SR1PartData;
#[allow(dead_code)] #[allow(dead_code)]
@ -115,7 +116,9 @@ pub mod types {
#[pyfunction] #[pyfunction]
#[allow(unused_variables)] #[allow(unused_variables)]
pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny, parts: &types::PartDatas) -> PyResult<bool> { pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny,
parts: &types::PartDatas,
global_scale: f64, sr1_xml_scale: i32) -> PyResult<bool> {
if !render.getattr(intern!(render.py(), "rendered"))?.is_true()? { if !render.getattr(intern!(render.py(), "rendered"))?.is_true()? {
return Ok(false); return Ok(false);
} }
@ -125,16 +128,24 @@ pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny, parts
let y_center: f32 = window.getattr(intern!(window.py(), "height"))?.extract()?; let y_center: f32 = window.getattr(intern!(window.py(), "height"))?.extract()?;
let x_center: f32 = x_center / 2.0; let x_center: f32 = x_center / 2.0;
let y_center: f32 = y_center / 2.0; let y_center: f32 = y_center / 2.0;
let render_scale: f32 = render.getattr(intern!(render.py(), "scale"))?.extract()?;
let datas: &HashMap<usize, SR1PartData> = &parts.part_structs; let datas: &HashMap<usize, SR1PartData> = &parts.part_structs;
let part_sprites = render.getattr(intern!(render.py(), "parts_sprite"))?;
// let part_sprites: &PyDict = part_sprites.downcast::<PyDict>()?;
for keys in datas { for keys in datas {
// let index = keys.0.to_string();
println!("{}", keys.0); let sprite = part_sprites.get_item(keys.0)?;
let new_x: f64 = keys.1.x * global_scale * render_scale as f64 * sr1_xml_scale as f64 + x_center as f64 + dx;
let new_y: f64 = keys.1.y * global_scale * render_scale as f64 * sr1_xml_scale as f64 + x_center as f64 + dy;
let new_scale: f32 = render_scale * global_scale as f32;
sprite.setattr(intern!(sprite.py(), "x"), new_x)?;
sprite.setattr(intern!(sprite.py(), "y"), new_y)?;
sprite.setattr(intern!(sprite.py(), "scale"), new_scale)?;
part_sprites.set_item(keys.0, sprite)?;
// println!("{}", keys.0);
} }
render.setattr(intern!(render.py(), "parts_sprite"), part_sprites)?;
if option.getattr("debug_d_pos")?.is_true()? { println!("dx: {} dy: {} scale: {}", dx, dy, render_scale);
let line = render.getattr(intern!(render.py(), "debug_line"))?;
}
// for part in parts.
Ok(true) Ok(true)
} }