Feature/get named logger #29

Merged
shenjackyuanjie merged 4 commits from feature/get_named_logger into main 2023-06-17 00:09:26 +08:00
21 changed files with 194 additions and 207 deletions

4
DR.py
View File

@ -52,7 +52,7 @@ def main() -> int:
from Difficult_Rocket.exception import TestError from Difficult_Rocket.exception import TestError
from Difficult_Rocket import crash from Difficult_Rocket import crash
from Difficult_Rocket import DR_option from Difficult_Rocket import DR_status
try: try:
from libs import pyglet # 导入pyglet from libs import pyglet # 导入pyglet
pyglet.resource.path = ['/textures/'] pyglet.resource.path = ['/textures/']
@ -72,7 +72,7 @@ def main() -> int:
cProfile.run('game.start()', sort='calls') # 使用 cprofile 启动 cProfile.run('game.start()', sort='calls') # 使用 cprofile 启动
else: else:
game.start() # 直接启动 game.start() # 直接启动
if DR_option.crash_report_test: if DR_status.crash_report_test:
raise TestError('debugging') # debug 嘛试试crash raise TestError('debugging') # debug 嘛试试crash
except Exception as exp: # 出毛病了 except Exception as exp: # 出毛病了
# 解析错误信息 # 解析错误信息

View File

@ -19,43 +19,21 @@ build_version = Version("2.1.0.0") # 编译文件版本(与游戏本体无关)
Api_version = Version("0.1.1.0") # API 版本 Api_version = Version("0.1.1.0") # API 版本
__version__ = game_version __version__ = game_version
long_version: int = 15
"""
long_version: 一个用于标记内部协议的整数
15: 完全移除 DR_rust 相关内容 解耦完成
14: BaseScreen 的每一个函数都添加了一个参数: window: "ClientWindow"
13: DR_runtime 添加 API_version
12: 去除 DR_runtime global_logger
logging 自己拿去
11: DR_option 添加 use_DR_rust
修复了一些拼写错误
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
以后就有 DR_rust
7 : DR_option 添加 std_font_size
6 : 事实证明, 不如直接用int
5 : 添加 build_version 信息,用于标记编译文件版本,
游戏版本改为四位数终于有一个可以让我随便刷的版本号位数了
4 : translate 的字体常量位置改了一下,顺便调换顺序
3 : 就是试试改一下正好 compiler 要用
2 : longlong 好耶
1 : 我可算想起来还有这回事了 v0.6.4
"""
class _DR_status(Options):
class _DR_option(Options):
""" """
DR 一般配置/状态 DR 的特性开关 / 基本状态
""" """
name = 'DR Option' name = 'DR Option'
# runtime options # run status
client_running: bool = False
server_running: bool = False
# feature switch
InputBox_use_TextEntry: bool = True InputBox_use_TextEntry: bool = True
record_threads: bool = True record_threads: bool = True
report_translate_not_found: bool = True report_translate_not_found: bool = True
use_multiprocess: bool = False use_multiprocess: bool = False
DR_rust_available: bool = False
use_cProfile: bool = False use_cProfile: bool = False
use_local_logging: bool = False use_local_logging: bool = False
@ -64,6 +42,14 @@ class _DR_option(Options):
debugging: bool = False debugging: bool = False
crash_report_test: bool = False crash_report_test: bool = False
# game version status
DR_version: Version = game_version # DR SDK 版本
Build_version: Version = build_version # DR 构建 版本
API_version: Version = Api_version # DR SDK API 版本
# game options
default_language: str = 'zh-CN'
# window option # window option
gui_scale: float = 1.0 # default 1.0 2.0 -> 2x 3 -> 3x gui_scale: float = 1.0 # default 1.0 2.0 -> 2x 3 -> 3x
@ -77,29 +63,16 @@ class _DR_runtime(Options):
DR 的运行时配置 / 状态 DR 的运行时配置 / 状态
""" """
name = 'DR Runtime' name = 'DR Runtime'
# 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我也在考虑
language: str = 'zh-CN'
mod_path: str = './mods'
DR_Mod_List: List[Tuple[str, Version]] = [] # DR Mod 列表 (name, version) DR_Mod_List: List[Tuple[str, Version]] = [] # DR Mod 列表 (name, version)
# run status # run status
running: bool = False
start_time_ns: Optional[int] = None start_time_ns: Optional[int] = None
client_setup_cause_ns: Optional[int] = None client_setup_cause_ns: Optional[int] = None
server_setup_cause_ns: Optional[int] = None server_setup_cause_ns: Optional[int] = None
# game runtimes
# global_logger: logging.Logger
# game options
mod_path: str = './mods'
language: str = 'zh-CN'
default_language: str = 'zh-CN'
def load_file(self) -> bool: def load_file(self) -> bool:
with contextlib.suppress(FileNotFoundError): with contextlib.suppress(FileNotFoundError):
with open('./configs/main.toml', 'r', encoding='utf-8') as f: with open('./configs/main.toml', 'r', encoding='utf-8') as f:
@ -141,10 +114,10 @@ class _DR_runtime(Options):
return mods return mods
DR_option = _DR_option() DR_status = _DR_status()
DR_runtime = _DR_runtime() DR_runtime = _DR_runtime()
if DR_option.playing: if DR_status.playing:
from Difficult_Rocket.utils.thread import new_thread from Difficult_Rocket.utils.thread import new_thread
def think_it(something): def think_it(something):

View File

@ -14,4 +14,15 @@ gitee: @shenjackyuanjie
# from Difficult_Rocket.api import screen, mod, exception # from Difficult_Rocket.api import screen, mod, exception
__all__ = ['screen', 'mod', 'exception'] __all__ = [
'exception',
# 错误类定义
'screen',
# screen api
'types',
# 类型定义
'mod',
# mod api
'log'
# log api
]

View File

@ -0,0 +1,16 @@
# -------------------------------
# Difficult Rocket
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
# All rights reserved
# -------------------------------
from Difficult_Rocket.utils.log import (get_named_client_logger,
get_named_server_logger,
get_named_main_logger)
__all__ = [
'get_named_client_logger',
'get_named_server_logger',
'get_named_main_logger',
]

View File

@ -31,7 +31,7 @@ from pyglet.text.layout import IncrementalTextLayout
from Difficult_Rocket.api.types import FontData, Fonts from Difficult_Rocket.api.types import FontData, Fonts
# from Difficult_Rocket.client.guis.format import html # from Difficult_Rocket.client.guis.format import html
from Difficult_Rocket import DR_option from Difficult_Rocket import DR_status
__all__ = ['InputBox'] __all__ = ['InputBox']
@ -59,7 +59,7 @@ class TextButton(widgets.WidgetBase):
... ...
if not DR_option.InputBox_use_TextEntry: if not DR_status.InputBox_use_TextEntry:
class InputBox(widgets.TextEntry): class InputBox(widgets.TextEntry):
""" 自定义的输入框 """ """ 自定义的输入框 """
@ -134,7 +134,7 @@ if not DR_option.InputBox_use_TextEntry:
# dpi=font_dpi) # dpi=font_dpi)
# self.font_height = self.font.ascent - self.font.descent # self.font_height = self.font.ascent - self.font.descent
# self.out_bound = out_line # self.out_bound = out_line
# if DR_option.InputBox_use_TextEntry: # if DR_status.InputBox_use_TextEntry:
# # 基于IncrementalTextLayout的处理系统 # # 基于IncrementalTextLayout的处理系统
# self._doc = FormattedDocument(message) # self._doc = FormattedDocument(message)
# # self._doc.set_style() # # self._doc.set_style()

View File

@ -99,14 +99,14 @@ def write_cache(cache_stream, crash_info):
def write_info_to_cache(cache_stream): def write_info_to_cache(cache_stream):
# 运行状态信息 # 运行状态信息
from Difficult_Rocket import DR_option, DR_runtime from Difficult_Rocket import DR_status, DR_runtime
cache_stream.write(Run_message) cache_stream.write(Run_message)
cache_stream.write(markdown_line_handler(f'DR Version: {Difficult_Rocket.game_version}', level=1)) cache_stream.write(markdown_line_handler(f'DR Version: {Difficult_Rocket.game_version}', level=1))
cache_stream.write(markdown_line_handler(f'DR language: {DR_runtime.language}', level=1)) cache_stream.write(markdown_line_handler(f'DR language: {DR_runtime.language}', level=1))
cache_stream.write(markdown_line_handler(f'Running Dir: {Path(os.curdir).resolve()}', level=1)) cache_stream.write(markdown_line_handler(f'Running Dir: {Path(os.curdir).resolve()}', level=1))
cache_stream.write(f"\n{DR_runtime.as_markdown()}") cache_stream.write(f"\n{DR_runtime.as_markdown()}")
cache_stream.write(DR_configs) cache_stream.write(DR_configs)
cache_stream.write(f"\n{DR_option.as_markdown()}") cache_stream.write(f"\n{DR_status.as_markdown()}")
cache_stream.write(Process_message) cache_stream.write(Process_message)
for process in all_process: for process in all_process:
process: multiprocessing.Process process: multiprocessing.Process

View File

@ -37,7 +37,7 @@ from Difficult_Rocket.api.types import Options
from Difficult_Rocket.utils.translate import tr from Difficult_Rocket.utils.translate import tr
from Difficult_Rocket.utils.thread import new_thread from Difficult_Rocket.utils.thread import new_thread
from Difficult_Rocket.crash import write_info_to_cache from Difficult_Rocket.crash import write_info_to_cache
from Difficult_Rocket import client, server, DR_option, DR_runtime from Difficult_Rocket import client, server, DR_status, DR_runtime
class Console(Options): class Console(Options):
@ -154,7 +154,7 @@ class Game(Options):
def start(self): def start(self):
self.server.run() self.server.run()
if DR_option.use_multiprocess: if DR_status.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

@ -12,9 +12,9 @@ gitee: @shenjackyuanjie
""" """
# system function # system function
import warnings
from typing import Tuple, List, Optional, TypeVar, TYPE_CHECKING from typing import Tuple, List, Optional, TypeVar, TYPE_CHECKING
# from DR # from DR
if TYPE_CHECKING: if TYPE_CHECKING:
from Difficult_Rocket.main import Game from Difficult_Rocket.main import Game
@ -22,7 +22,7 @@ if TYPE_CHECKING:
else: else:
Game = TypeVar("Game") Game = TypeVar("Game")
ClientWindow = TypeVar("ClientWindow") ClientWindow = TypeVar("ClientWindow")
from Difficult_Rocket import DR_runtime from Difficult_Rocket import DR_status
from Difficult_Rocket.api.types import Options, Version from Difficult_Rocket.api.types import Options, Version
RequireVersion = Tuple[Version, Version] RequireVersion = Tuple[Version, Version]
@ -47,8 +47,8 @@ class ModInfo(Options):
info: str = "" # 其他信息 (可以很多很多) info: str = "" # 其他信息 (可以很多很多)
"""版本相关信息""" """版本相关信息"""
DR_version: RequireVersion = (DR_runtime.DR_version, DR_runtime.DR_version) # DR SDK 兼容版本 DR_version: RequireVersion = (DR_status.DR_version, DR_status.DR_version) # DR SDK 兼容版本
DR_Api_version: RequireVersion = (DR_runtime.API_version, DR_runtime.API_version) # DR Api版本 DR_Api_version: RequireVersion = (DR_status.API_version, DR_status.API_version) # DR Api版本
Mod_Require_version: List[Tuple[str, ForceRequire, RequireVersion]] = [] # mod 依赖版本 Mod_Require_version: List[Tuple[str, ForceRequire, RequireVersion]] = [] # mod 依赖版本
"""mod 状态""" """mod 状态"""
@ -59,9 +59,15 @@ class ModInfo(Options):
config: Options = Options() # mod 配置存储 config: Options = Options() # mod 配置存储
old_mod: Optional["ModInfo"] = None # 旧的mod实例 old_mod: Optional["ModInfo"] = None # 旧的mod实例
def __init__(self, **kwargs):
if not self.DR_version[0] <= DR_status.DR_version <= self.DR_version[1]:
warnings.warn(f"mod {self.mod_id} version {self.version} is not support by DR {DR_status.DR_version}\nDR {self.DR_version} is required")
if not self.DR_Api_version[0] <= DR_status.API_version <= self.DR_Api_version[1]:
warnings.warn(f"mod {self.mod_id} version {self.version} is not support by DR {DR_status.API_version}\nDR {self.DR_Api_version} is required")
super().__init__(**kwargs)
def on_load(self, game: Game, old_self: Optional["ModInfo"] = None) -> bool: def on_load(self, game: Game, old_self: Optional["ModInfo"] = None) -> bool:
""" 加载时调用 """ """ 加载时调用 """
print(f'Mod {self.mod_id} loaded')
return True return True
def on_client_start(self, game: Game, client: ClientWindow): def on_client_start(self, game: Game, client: ClientWindow):

View File

@ -11,7 +11,7 @@ from typing import List, Dict, Optional
from Difficult_Rocket.api.screen import BaseScreen from Difficult_Rocket.api.screen import BaseScreen
from Difficult_Rocket.api.types import Options, Version from Difficult_Rocket.api.types import Options, Version
from Difficult_Rocket.mod.api import ModInfo from Difficult_Rocket.mod.api import ModInfo
# from Difficult_Rocket import DR_option, DR_runtime # from Difficult_Rocket import DR_status, DR_runtime
class ModManager(Options): class ModManager(Options):

View File

@ -0,0 +1,34 @@
# -------------------------------
# Difficult Rocket
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
# All rights reserved
# -------------------------------
import logging
from typing import Callable
__all__ = [
'get_named_client_logger',
'get_named_server_logger',
'get_named_main_logger',
]
def _gen_get_named_logger(from_name: str) -> Callable[[str], logging.Logger]:
def get_named_logger(name: str) -> logging.Logger:
logger = logging.getLogger(from_name)
logger.name = f'{from_name}.{name}'
return logger
return get_named_logger
get_named_client_logger = _gen_get_named_logger('client')
# 用于获取一个基于 client 配置的 logger
get_named_server_logger = _gen_get_named_logger('server')
# 用于获取一个基于 server 配置的 logger
get_named_main_logger = _gen_get_named_logger('main')
# 用于获取一个基于 main 配置的 logger

View File

@ -17,7 +17,7 @@ import inspect
from dataclasses import dataclass from dataclasses import dataclass
from typing import Union, Tuple, Any, List, Dict, Hashable, Optional from typing import Union, Tuple, Any, List, Dict, Hashable, Optional
from Difficult_Rocket import DR_runtime, DR_option from Difficult_Rocket import DR_runtime, DR_status
from Difficult_Rocket.utils import tools from Difficult_Rocket.utils import tools
from Difficult_Rocket.exception.language import (LanguageNotFound, from Difficult_Rocket.exception.language import (LanguageNotFound,
TranslateKeyNotFound) TranslateKeyNotFound)
@ -82,7 +82,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_not_found: elif DR_status.report_translate_not_found:
frame = inspect.currentframe() frame = inspect.currentframe()
if frame is not None: if frame is not None:
frame = frame.f_back.f_back frame = frame.f_back.f_back
@ -160,7 +160,7 @@ class Tr:
""" """
self.language_name = language if language is not None else DR_runtime.language self.language_name = language if language is not None else DR_runtime.language
self.translates: Dict[str, Union[str, Dict]] = tools.load_file(f'configs/lang/{self.language_name}.toml') self.translates: Dict[str, Union[str, Dict]] = tools.load_file(f'configs/lang/{self.language_name}.toml')
self.default_translate: Dict = tools.load_file(f'configs/lang/{DR_runtime.default_language}.toml') self.default_translate: Dict = tools.load_file(f'configs/lang/{DR_status.default_language}.toml')
self.default_config = config.set('source', self) if config is not None else TranslateConfig(source=self) self.default_config = config.set('source', self) if config is not None else TranslateConfig(source=self)
self.translates_cache = Translates(value=self.translates, config=self.default_config.copy()) self.translates_cache = Translates(value=self.translates, config=self.default_config.copy())

View File

@ -1,31 +0,0 @@
{
'language': 'zh-cn',
'textures': {
'back_ground_space': 'back_ground_space.png',
'planet': {
'earth_ground': 'earth_ground.png'
},
'flame': {
'liquid': 'liquid_engine_flame.png',
'solid': 'solid_engine_flame.png',
'ion': 'ion_engine_flame.png'
}
},
'basic_number': {
'G': [
6.67,
-11,
[
'N',
'm',
'm'
],
[
'kg',
'kg'
]
]
},
'default ship': [
]
}

View File

@ -1,49 +0,0 @@
{
/*
'part id': [
[
'part name', // part name can be reuse
'description', // 描述
], // about names and other
[ 'float', // mass
'bool', // hidden in part list
'bool', // hidden in mission (even thought that is not done yet)
'float' // buoyancy(浮力) in the water
], // about config
[ 'xxx.png', // texture file name
//可以为包含文件夹的 比如:./engine/xxx.png
[ 'float', // 贴图偏移量
'float' ] // 指的是部件的碰撞箱左上角到贴图左上角的距离
], // about texture
[ 'float',
'float' ],
// 碰撞箱大小 (暂时只支持方形碰撞箱)
// 坐标轴也是从左下开始
[
'特殊值(懒得写)'
]
],
*/
'test1': [
[
'test-1',
'一个测试用部件'
],
[
1.0,
false,
0.1
],
[
'parts/Beam.png',
[
0.0,
0.0
]
],
[
3.0,
2.0
]
]
}

View File

@ -1,17 +0,0 @@
{
'Solar System': {
'description': '',
'planets': {
'earth': {
'description': '',
'gravity': 9.81,
'radius': 63710000,
'map_color': [
103,
157,
255
]
}
}
}
}

View File

@ -1,27 +0,0 @@
[Runtime]
[Parts]
battery = "Battery.png"
beam = "Beam.png"
cover_bottom = "CoverBottom.png"
nose_cone = "NoseCone.png"
[Editor]
[[runtime]]
"toolbar.dark" = "ToolbarDark.png"
"toolbar.light" = "ToolbarLight.png"
"button_side.dark" = "ButtonDarkSide.png"
"button_side.light" = "ButtonLightSide.png"
[[toggle_button]]
stage = "ToolbarIconStaging.png"
add_part = "ToolbarIconAddPart.png"
menu = "ToolbarIconMenu.png"
[[push_button]]
zoom = "ToolbarIconZoom.png"
"zoom.in" = "ToolbarIconZoomIn.png"
"zoom.out" = "ToolbarIconZoomOut.png"
play = "ToolbarIconPlay.png"
rotate = "RotateButton.png"
trash_can = "TrashCan.png"

View File

@ -2,9 +2,15 @@
# DR game/DR rs 更新日志 # DR game/DR rs 更新日志
- 最新版本号 - 最新版本号
- DR game: 0.1.1.0 - DR game: 0.2.0.0
- DR rs: 0.2.10.1 - DR rs: 0.2.10.1
## DR game 0.2.0.0
### 适配
- 适配了 `DR_sdk` `0.8.3.0` 的修改
## DR game 0.1.1.0 ## DR game 0.1.1.0
### 添加 ### 添加

View File

@ -4,6 +4,73 @@
- 最新版本号 - 最新版本号
- DR sdk: 0.8.2.0 - DR sdk: 0.8.2.0
## DR sdk 0.8.3.0
### 添加
- `DR_status`
- 实际上就是 `DR_runtime`
- `DR_runtime` -> `DR_status`
- `client_running`
- 客户端是否在运行
- Is client running
- `server_running`
- 服务器是否在运行
- Is server running
- Mod loader
- 添加了对支持版本号的 warnings
- Added warnings for supporting version numbers
- API
- `Difficult_Rocket.api.log`
- `get_named_client_logger`
- `get_named_server_logger`
- `get_named_main_logger`
- 分别用于获取 基于 对应名称配置的 logger
- Get the logger for the corresponding name configuration
### 移动
- `Difficult_Rocket.DR_runtime`
- `DR_version` -> `DR_status.DR_version`
- `API_version` -> `DR_status.API_version`
- `Build_version` -> `DR_status.Build_version`
- `default_language` -> `DR_status.default_language`
### 删除
- `Diffiuclt_Rocket.long_version`
- 不再使用整数标记版本号 (反正 `Version` 有一个完整的版本号比较机制)
- No longer use integer to mark version number (since `Version` has a complete version comparison mechanism)
- `Difficult_Rocket.DR_rust_available`
- 似乎我忘记删掉这个 `DR_rs` 的耦合了
```python
long_version: int = 15
"""
long_version: 一个用于标记内部协议的整数
15: 完全移除 DR_rust 相关内容 解耦完成
14: BaseScreen 的每一个函数都添加了一个参数: window: "ClientWindow"
13: 为 DR_runtime 添加 API_version
12: 去除 DR_runtime 的 global_logger
要 logging 自己拿去(
11: 为 DR_option 添加 use_DR_rust
修复了一些拼写错误
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
以后就有 DR_rust 了
7 : 为 DR_option 添加 std_font_size
6 : 事实证明, 不如直接用int
5 : 添加 build_version 信息,用于标记编译文件版本,
游戏版本改为四位数,终于有一个可以让我随便刷的版本号位数了
4 : 把 translate 的字体常量位置改了一下,顺便调换顺序
3 : 就是试试改一下,正好 compiler 要用
2 : 哦,对 longlong 好耶!
1 : 我可算想起来还有这回事了 v0.6.4
"""
```
## DR sdk 0.8.2.0 ## DR sdk 0.8.2.0
### Fix ### Fix

View File

@ -69,9 +69,9 @@ class CompilerHelper(Options):
def load_file(self) -> bool: def load_file(self) -> bool:
try: try:
from Difficult_Rocket import DR_runtime from Difficult_Rocket import DR_status
self.product_version = DR_runtime.DR_version self.product_version = DR_status.DR_version
self.file_version = DR_runtime.Build_version self.file_version = DR_status.Build_version
return True return True
except ImportError: except ImportError:
traceback.print_exc() traceback.print_exc()

View File

@ -1,3 +0,0 @@
python3.8 setup.py build
python3.9 setup.py build
python3.9 post_build.py

View File

@ -9,6 +9,7 @@ import traceback
from typing import Optional from typing import Optional
from Difficult_Rocket import DR_status
from Difficult_Rocket.main import Game from Difficult_Rocket.main import Game
from Difficult_Rocket.api.mod import ModInfo from Difficult_Rocket.api.mod import ModInfo
from Difficult_Rocket.api.types import Options, Version from Difficult_Rocket.api.types import Options, Version
@ -49,7 +50,7 @@ class DR_mod(ModInfo):
mod_id = "difficult_rocket_mod" mod_id = "difficult_rocket_mod"
name = "Difficult Rocket mod" name = "Difficult Rocket mod"
version = Version("0.1.0.0") version = Version("0.2.0.0")
writer = "shenjackyuanjie" writer = "shenjackyuanjie"
link = "shenjack.top" link = "shenjack.top"
@ -58,7 +59,7 @@ class DR_mod(ModInfo):
config = DR_mod_runtime config = DR_mod_runtime
# DR_version = # DR SDK 兼容版本 DR_version = (DR_status.DR_version, DR_status.DR_version) # DR SDK 兼容版本
# 反正是内置 mod 跟着最新版本的 DR 走就行了 # 反正是内置 mod 跟着最新版本的 DR 走就行了
# DR_Api_version = # DR Api版本 # DR_Api_version = # DR Api版本
# 同理 不管 API 版本 这东西要是不兼容了才是大问题 # 同理 不管 API 版本 这东西要是不兼容了才是大问题

View File

@ -4,12 +4,11 @@
# All rights reserved # All rights reserved
# ------------------------------- # -------------------------------
import math # import math
import time import time
import random import random
import logging
import traceback import traceback
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, Generator from typing import List, TYPE_CHECKING, Union, Dict, Optional, Generator
@ -21,17 +20,18 @@ from pyglet.math import Vec4
from pyglet.text import Label from pyglet.text import Label
from pyglet.shapes import Line, Rectangle from pyglet.shapes import Line, Rectangle
from pyglet.sprite import Sprite from pyglet.sprite import Sprite
from pyglet.image import Texture # from pyglet.image import Texture
from pyglet.graphics import Batch, Group from pyglet.graphics import Batch, Group
from . import DR_mod_runtime from . import DR_mod_runtime
# Difficult Rocket # Difficult Rocket
from Difficult_Rocket import DR_option from Difficult_Rocket import DR_status
from Difficult_Rocket.utils.translate import tr from Difficult_Rocket.utils.translate import tr
from Difficult_Rocket.api.types import Fonts, Options from Difficult_Rocket.api.types import Fonts, Options
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
from Difficult_Rocket.api.log import get_named_client_logger
from .types import SR1Textures, SR1PartTexture, SR1PartData, SR1Rotation, xml_bool from .types import SR1Textures, SR1PartTexture, SR1PartData, SR1Rotation, xml_bool
if TYPE_CHECKING: if TYPE_CHECKING:
@ -40,7 +40,7 @@ if TYPE_CHECKING:
if DR_mod_runtime.use_DR_rust: if DR_mod_runtime.use_DR_rust:
from .Difficult_Rocket_rs import CenterCamera_rs, SR1PartList_rs, SR1Ship_rs from .Difficult_Rocket_rs import CenterCamera_rs, SR1PartList_rs, SR1Ship_rs
logger = logging.getLogger('client') logger = get_named_client_logger('dr_game_sr1_ship')
def get_sr1_part(part_xml: Element) -> Optional[SR1PartData]: def get_sr1_part(part_xml: Element) -> Optional[SR1PartData]:
@ -124,7 +124,7 @@ class SR1ShipRender(BaseScreen):
self.part_box_batch = Batch() self.part_box_batch = Batch()
self.part_batch = Batch() self.part_batch = Batch()
self.part_group = Group() self.part_group = Group()
self.debug_label = Label(x=20, y=main_window.height - 20, font_size=DR_option.std_font_size, self.debug_label = Label(x=20, y=main_window.height - 20, font_size=DR_status.std_font_size,
text='SR1 render!', font_name=Fonts.微软等宽无线, text='SR1 render!', font_name=Fonts.微软等宽无线,
width=main_window.width - 20, height=20, width=main_window.width - 20, height=20,
anchor_x='left', anchor_y='top') anchor_x='left', anchor_y='top')
@ -171,7 +171,7 @@ class SR1ShipRender(BaseScreen):
self.drawing = True self.drawing = True
for part_id, part in part_datas.items(): for part_id, part in part_datas.items():
# 下面就是调用 pyglet 去渲染的部分 # 下面就是调用 pyglet 去渲染的部分
# render_scale = DR_option.gui_scale # 这个是 DR 的缩放比例 可以调节的( # render_scale = DR_status.gui_scale # 这个是 DR 的缩放比例 可以调节的(
# 主要是 Windows 下有一个缩放系数嘛,我待会试试这玩意能不能获取(估计得 ctypes # 主要是 Windows 下有一个缩放系数嘛,我待会试试这玩意能不能获取(估计得 ctypes
# 在不缩放的情况下XML的1个单位长度对应60个像素 # 在不缩放的情况下XML的1个单位长度对应60个像素
render_x = part.x * 60 render_x = part.x * 60