2021-09-08 23:38:34 +08:00
|
|
|
|
# -------------------------------
|
|
|
|
|
# Difficult Rocket
|
2023-01-20 14:08:12 +08:00
|
|
|
|
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
2021-09-08 23:38:34 +08:00
|
|
|
|
# All rights reserved
|
|
|
|
|
# -------------------------------
|
|
|
|
|
|
2023-04-23 00:15:36 +08:00
|
|
|
|
import os
|
2023-01-21 23:05:34 +08:00
|
|
|
|
import sys
|
2023-01-24 12:25:23 +08:00
|
|
|
|
import warnings
|
2023-04-23 00:15:36 +08:00
|
|
|
|
import importlib
|
2023-01-22 17:21:21 +08:00
|
|
|
|
import traceback
|
2023-04-09 03:21:11 +08:00
|
|
|
|
import contextlib
|
2023-04-23 00:15:36 +08:00
|
|
|
|
import importlib.util
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from typing import Optional, List, Tuple
|
2022-11-08 20:18:01 +08:00
|
|
|
|
|
2023-01-01 21:54:59 +08:00
|
|
|
|
from Difficult_Rocket.api.types import Options
|
2022-08-03 20:22:36 +08:00
|
|
|
|
|
2022-04-08 23:07:41 +08:00
|
|
|
|
from libs.MCDR.version import Version
|
2022-02-16 13:36:26 +08:00
|
|
|
|
|
2023-04-22 20:56:50 +08:00
|
|
|
|
game_version = Version("0.7.2.2") # 游戏版本
|
2023-03-02 13:28:48 +08:00
|
|
|
|
build_version = Version("1.2.1.0") # 编译文件版本(与游戏本体无关)
|
2023-04-19 00:42:31 +08:00
|
|
|
|
Api_version = Version("0.0.2.0") # API 版本
|
2022-02-08 17:15:09 +08:00
|
|
|
|
__version__ = game_version
|
2021-01-24 18:26:56 +08:00
|
|
|
|
|
2023-04-23 00:15:36 +08:00
|
|
|
|
# TODO 解耦 DR SDK 与 DR_mod 和 DR_rs
|
|
|
|
|
DR_rust_version = Version("0.2.6.1") # DR 的 Rust 编写部分的版本
|
|
|
|
|
# 后面会移除的 DR_rs 相关信息
|
|
|
|
|
# DR_rs和 DR_mod 的部分正在和 DR SDK 解耦
|
|
|
|
|
|
2023-04-19 00:42:31 +08:00
|
|
|
|
long_version: int = 14
|
2022-11-26 21:48:55 +08:00
|
|
|
|
"""
|
|
|
|
|
long_version: 一个用于标记内部协议的整数
|
2023-04-19 00:42:31 +08:00
|
|
|
|
14: BaseScreen 的每一个函数都添加了一个参数: window: "ClientWindow"
|
2023-02-26 14:24:50 +08:00
|
|
|
|
13: 为 DR_runtime 添加 API_version
|
2023-02-03 00:05:32 +08:00
|
|
|
|
12: 去除 DR_runtime 的 global_logger
|
|
|
|
|
要 logging 自己拿去(
|
2023-01-24 23:59:07 +08:00
|
|
|
|
11: 为 DR_option 添加 use_DR_rust
|
|
|
|
|
修复了一些拼写错误
|
2023-01-24 12:25:23 +08:00
|
|
|
|
10: 为 DR_runtime 添加 DR_Rust_get_version
|
|
|
|
|
9 : 为 DR_option 添加 pyglet_macosx_dev_test
|
|
|
|
|
8 : 为 DR_runtime 添加 DR_rust_version
|
|
|
|
|
为 DR_option 添加 DR_rust_available
|
2023-01-20 20:20:35 +08:00
|
|
|
|
以后就有 DR_rust 了
|
2023-01-24 12:25:23 +08:00
|
|
|
|
7 : 为 DR_option 添加 std_font_size
|
|
|
|
|
6 : 事实证明, 不如直接用int
|
|
|
|
|
5 : 添加 build_version 信息,用于标记编译文件版本,
|
|
|
|
|
游戏版本改为四位数,终于有一个可以让我随便刷的版本号位数了
|
|
|
|
|
4 : 把 translate 的字体常量位置改了一下,顺便调换顺序
|
|
|
|
|
3 : 就是试试改一下,正好 compiler 要用
|
|
|
|
|
2 : 哦,对 longlong 好耶!
|
|
|
|
|
1 : 我可算想起来还有这回事了 v0.6.4
|
2022-11-26 21:48:55 +08:00
|
|
|
|
"""
|
2021-11-06 19:07:32 +08:00
|
|
|
|
|
2022-08-03 20:22:36 +08:00
|
|
|
|
|
2022-12-29 17:45:47 +08:00
|
|
|
|
class _DR_option(Options):
|
2022-08-12 21:07:36 +08:00
|
|
|
|
"""
|
2023-01-21 12:20:50 +08:00
|
|
|
|
DR 的一般配置/状态
|
2022-08-12 21:07:36 +08:00
|
|
|
|
"""
|
2022-11-20 17:46:02 +08:00
|
|
|
|
name = 'DR Option'
|
2022-08-12 21:07:36 +08:00
|
|
|
|
# runtime options
|
2023-01-24 23:59:07 +08:00
|
|
|
|
InputBox_use_TextEntry: bool = True
|
|
|
|
|
record_threads: bool = True
|
|
|
|
|
report_translate_not_found: bool = True
|
|
|
|
|
use_multiprocess: bool = False
|
|
|
|
|
DR_rust_available: bool = False
|
|
|
|
|
use_cProfile: bool = False
|
|
|
|
|
use_local_logging: bool = False
|
2023-04-23 00:15:36 +08:00
|
|
|
|
use_DR_rust: bool = True
|
|
|
|
|
|
2022-08-12 21:07:36 +08:00
|
|
|
|
# tests
|
2023-01-21 12:20:50 +08:00
|
|
|
|
playing: bool = False
|
|
|
|
|
debugging: bool = False
|
2023-04-09 03:21:11 +08:00
|
|
|
|
crash_report_test: bool = True
|
2022-08-12 21:07:36 +08:00
|
|
|
|
|
2022-12-22 10:54:46 +08:00
|
|
|
|
# window option
|
2023-01-19 22:29:43 +08:00
|
|
|
|
gui_scale: float = 1.0 # default 1.0 2.0 -> 2x 3 -> 3x
|
|
|
|
|
|
2023-01-20 20:20:35 +08:00
|
|
|
|
def init(self, **kwargs):
|
|
|
|
|
try:
|
2023-03-02 13:28:48 +08:00
|
|
|
|
from libs.Difficult_Rocket_rs import test_call, get_version_str
|
2023-01-23 00:01:01 +08:00
|
|
|
|
test_call(self)
|
2023-01-24 12:25:23 +08:00
|
|
|
|
print(f'DR_rust available: {get_version_str()}')
|
2023-01-20 20:20:35 +08:00
|
|
|
|
except ImportError:
|
2023-01-27 21:09:37 +08:00
|
|
|
|
if __name__ != '__main__':
|
2023-01-24 08:29:22 +08:00
|
|
|
|
traceback.print_exc()
|
2023-01-20 20:20:35 +08:00
|
|
|
|
self.DR_rust_available = False
|
2023-01-24 23:59:07 +08:00
|
|
|
|
self.use_DR_rust = self.use_DR_rust and self.DR_rust_available
|
2023-01-20 20:20:35 +08:00
|
|
|
|
self.flush_option()
|
|
|
|
|
|
2023-03-02 13:28:48 +08:00
|
|
|
|
def test_rust(self):
|
|
|
|
|
if self.DR_rust_available:
|
|
|
|
|
from libs.Difficult_Rocket_rs import part_list_read_test
|
|
|
|
|
part_list_read_test("./configs/PartList.xml")
|
|
|
|
|
|
2023-01-23 00:01:01 +08:00
|
|
|
|
def draw(self):
|
|
|
|
|
self.DR_rust_available = True
|
|
|
|
|
|
2023-01-19 22:29:43 +08:00
|
|
|
|
@property
|
|
|
|
|
def std_font_size(self) -> int:
|
2023-01-20 20:20:35 +08:00
|
|
|
|
return round(12 * self.gui_scale)
|
2022-12-22 10:54:46 +08:00
|
|
|
|
|
2022-08-12 21:07:36 +08:00
|
|
|
|
|
|
|
|
|
class _DR_runtime(Options):
|
|
|
|
|
"""
|
2023-01-21 12:20:50 +08:00
|
|
|
|
DR 的运行时配置/状态
|
2022-08-12 21:07:36 +08:00
|
|
|
|
"""
|
2022-11-20 17:46:02 +08:00
|
|
|
|
name = 'DR Runtime'
|
2023-04-22 10:39:18 +08:00
|
|
|
|
# game version status
|
|
|
|
|
DR_version: Version = game_version # DR SDK 版本
|
|
|
|
|
Build_version: Version = build_version # DR 构建 版本
|
|
|
|
|
|
|
|
|
|
API_version: Version = Api_version # DR SDK API 版本
|
|
|
|
|
DR_long_version: int = long_version # DR SDK 内部协议版本 (不要问我为什么不用 Version,我也在考虑)
|
2022-08-21 14:59:35 +08:00
|
|
|
|
|
2023-04-23 00:15:36 +08:00
|
|
|
|
DR_Mod_List: List[Tuple[str, Version]] = [] # DR Mod 列表 (name, version)
|
|
|
|
|
|
|
|
|
|
DR_Rust_version: Version = DR_rust_version # 后面要去掉的 DR_rs 版本
|
|
|
|
|
DR_Rust_get_version: Optional[Version] = None # 后面也要去掉的 DR_rs 版本
|
|
|
|
|
|
2022-08-12 21:07:36 +08:00
|
|
|
|
# run status
|
2022-12-25 23:15:49 +08:00
|
|
|
|
running: bool = False
|
2023-04-23 00:15:36 +08:00
|
|
|
|
start_time_ns: Optional[int] = None
|
|
|
|
|
client_setup_cause_ns: Optional[int] = None
|
|
|
|
|
server_setup_cause_ns: Optional[int] = None
|
2022-08-12 21:07:36 +08:00
|
|
|
|
|
2022-12-08 09:53:22 +08:00
|
|
|
|
# game runtimes
|
2023-02-03 00:05:32 +08:00
|
|
|
|
# global_logger: logging.Logger
|
2022-12-08 09:53:22 +08:00
|
|
|
|
|
2022-08-12 21:07:36 +08:00
|
|
|
|
# game options
|
2023-04-23 00:15:36 +08:00
|
|
|
|
mod_path: str = './mods'
|
2023-02-03 20:39:40 +08:00
|
|
|
|
language: str = 'zh-CN'
|
2022-11-26 21:48:55 +08:00
|
|
|
|
default_language: str = 'zh-CN'
|
2022-08-12 21:07:36 +08:00
|
|
|
|
|
2023-01-24 12:25:23 +08:00
|
|
|
|
def init(self, **kwargs) -> None:
|
2023-01-27 21:09:37 +08:00
|
|
|
|
with contextlib.suppress(ImportError):
|
2023-01-24 12:25:23 +08:00
|
|
|
|
from libs.Difficult_Rocket_rs import get_version_str
|
|
|
|
|
self.DR_Rust_get_version = Version(get_version_str())
|
|
|
|
|
if self.DR_Rust_get_version != self.DR_Rust_version:
|
|
|
|
|
relationship = 'larger' if self.DR_Rust_version > self.DR_Rust_get_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')
|
2023-04-23 00:15:36 +08:00
|
|
|
|
|
|
|
|
|
def load_file(self) -> bool:
|
2023-04-05 13:04:57 +08:00
|
|
|
|
with contextlib.suppress(FileNotFoundError):
|
|
|
|
|
with open('./configs/main.toml', 'r', encoding='utf-8') as f:
|
|
|
|
|
import rtoml
|
2023-04-23 00:15:36 +08:00
|
|
|
|
config_file = rtoml.load(f)
|
|
|
|
|
self.language = config_file['runtime']['language']
|
|
|
|
|
self.mod_path = config_file['game']['mods']['path']
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def load_mods(self) -> None:
|
|
|
|
|
mod_list = self.find_mods()
|
|
|
|
|
|
|
|
|
|
def find_mods(self) -> List[str]:
|
|
|
|
|
mods = []
|
|
|
|
|
paths = Path(self.mod_path).iterdir()
|
|
|
|
|
sys.path.append(self.mod_path)
|
|
|
|
|
for mod_path in paths:
|
|
|
|
|
try:
|
|
|
|
|
if mod_path.is_dir() and mod_path.name != '__pycache__': # 处理文件夹 mod
|
|
|
|
|
if importlib.util.find_spec(mod_path.name) is not None:
|
|
|
|
|
module = importlib.import_module(mod_path.name)
|
|
|
|
|
mods.append(mod_path.name)
|
|
|
|
|
else:
|
|
|
|
|
print(f'can not import mod {mod_path} because importlib can not find spec')
|
|
|
|
|
elif mod_path.suffix in ('.pyz', '.zip'): # 处理压缩包 mod
|
|
|
|
|
if importlib.util.find_spec(mod_path.name) is not None:
|
|
|
|
|
module = importlib.import_module(mod_path.name)
|
|
|
|
|
mods.append(mod_path.name)
|
|
|
|
|
elif mod_path.suffix == '.py': # 处理单文件 mod
|
|
|
|
|
print(f'importing mod {mod_path=} {mod_path.stem}')
|
|
|
|
|
module = importlib.import_module(mod_path.stem)
|
|
|
|
|
mods.append(mod_path.stem)
|
|
|
|
|
except ImportError:
|
|
|
|
|
print(f'ImportError when loading mod {mod_path}')
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
self.DR_Mod_List = [(mod, Version('0.0.0-unknown')) for mod in mods]
|
|
|
|
|
return mods
|
2023-01-24 12:25:23 +08:00
|
|
|
|
|
2022-08-12 21:07:36 +08:00
|
|
|
|
|
2022-12-29 17:45:47 +08:00
|
|
|
|
DR_option = _DR_option()
|
2022-08-12 21:07:36 +08:00
|
|
|
|
DR_runtime = _DR_runtime()
|
|
|
|
|
|
|
|
|
|
if DR_option.playing:
|
2022-11-08 20:18:01 +08:00
|
|
|
|
from Difficult_Rocket.utils import new_thread
|
2021-08-13 12:25:29 +08:00
|
|
|
|
|
2022-06-21 20:15:36 +08:00
|
|
|
|
|
2022-06-21 10:17:13 +08:00
|
|
|
|
def think_it(something):
|
|
|
|
|
return something
|
|
|
|
|
|
|
|
|
|
|
2021-10-31 23:26:32 +08:00
|
|
|
|
@new_thread('think')
|
|
|
|
|
def think(some_thing_to_think):
|
2022-06-21 10:17:13 +08:00
|
|
|
|
gotcha = think_it(some_thing_to_think)
|
2021-10-31 23:26:32 +08:00
|
|
|
|
return gotcha
|