From 0e7adcb3a0b0674e5c482230072230e95a26bce5 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Fri, 16 Jun 2023 23:23:19 +0800 Subject: [PATCH 1/4] [build skip] [build rs skip] rename+remove --- Difficult_Rocket/__init__.py | 65 ++++++++-------------------- Difficult_Rocket/main.py | 4 +- configs/sys_value/basic_config.json5 | 31 ------------- configs/sys_value/parts.json5 | 49 --------------------- configs/sys_value/planet.json5 | 17 -------- configs/textures.toml | 27 ------------ docs/src/change_log/dr_sdk.md | 58 +++++++++++++++++++++++++ 7 files changed, 79 insertions(+), 172 deletions(-) delete mode 100644 configs/sys_value/basic_config.json5 delete mode 100644 configs/sys_value/parts.json5 delete mode 100644 configs/sys_value/planet.json5 delete mode 100644 configs/textures.toml diff --git a/Difficult_Rocket/__init__.py b/Difficult_Rocket/__init__.py index 4ea2210..201f00a 100644 --- a/Difficult_Rocket/__init__.py +++ b/Difficult_Rocket/__init__.py @@ -19,43 +19,21 @@ build_version = Version("2.1.0.0") # 编译文件版本(与游戏本体无关) Api_version = Version("0.1.1.0") # API 版本 __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_option(Options): +class _DR_status(Options): """ - DR 的一般配置/状态 + DR 的特性开关 / 基本状态 """ name = 'DR Option' - # runtime options + # run status + client_running: bool = False + server_running: bool = False + + # feature switch 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 @@ -64,6 +42,16 @@ class _DR_option(Options): debugging: 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 + language: str = 'zh-CN' + mod_path: str = './mods' + default_language: str = 'zh-CN' + # window option gui_scale: float = 1.0 # default 1.0 2.0 -> 2x 3 -> 3x @@ -77,29 +65,14 @@ class _DR_runtime(Options): DR 的运行时配置/状态 """ 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,我也在考虑) DR_Mod_List: List[Tuple[str, Version]] = [] # DR Mod 列表 (name, version) # run status - running: bool = False start_time_ns: Optional[int] = None client_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: with contextlib.suppress(FileNotFoundError): with open('./configs/main.toml', 'r', encoding='utf-8') as f: @@ -141,10 +114,10 @@ class _DR_runtime(Options): return mods -DR_option = _DR_option() +DR_status = _DR_status() DR_runtime = _DR_runtime() -if DR_option.playing: +if DR_status.playing: from Difficult_Rocket.utils.thread import new_thread def think_it(something): diff --git a/Difficult_Rocket/main.py b/Difficult_Rocket/main.py index 5f186bc..d888ea1 100644 --- a/Difficult_Rocket/main.py +++ b/Difficult_Rocket/main.py @@ -37,7 +37,7 @@ from Difficult_Rocket.api.types import Options from Difficult_Rocket.utils.translate import tr from Difficult_Rocket.utils.thread import new_thread 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): @@ -154,7 +154,7 @@ class Game(Options): def start(self): self.server.run() - if DR_option.use_multiprocess: + if DR_status.use_multiprocess: try: game_process = multiprocessing.Process(target=self.client.start, name='pyglet app') game_process.start() diff --git a/configs/sys_value/basic_config.json5 b/configs/sys_value/basic_config.json5 deleted file mode 100644 index b66dda2..0000000 --- a/configs/sys_value/basic_config.json5 +++ /dev/null @@ -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': [ - ] -} \ No newline at end of file diff --git a/configs/sys_value/parts.json5 b/configs/sys_value/parts.json5 deleted file mode 100644 index c75dfd2..0000000 --- a/configs/sys_value/parts.json5 +++ /dev/null @@ -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 - ] - ] -} diff --git a/configs/sys_value/planet.json5 b/configs/sys_value/planet.json5 deleted file mode 100644 index fc1a7ec..0000000 --- a/configs/sys_value/planet.json5 +++ /dev/null @@ -1,17 +0,0 @@ -{ - 'Solar System': { - 'description': '', - 'planets': { - 'earth': { - 'description': '', - 'gravity': 9.81, - 'radius': 63710000, - 'map_color': [ - 103, - 157, - 255 - ] - } - } - } -} \ No newline at end of file diff --git a/configs/textures.toml b/configs/textures.toml deleted file mode 100644 index 07370af..0000000 --- a/configs/textures.toml +++ /dev/null @@ -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" diff --git a/docs/src/change_log/dr_sdk.md b/docs/src/change_log/dr_sdk.md index 1ec87e8..e391237 100644 --- a/docs/src/change_log/dr_sdk.md +++ b/docs/src/change_log/dr_sdk.md @@ -4,6 +4,64 @@ - 最新版本号 - 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 + +### 移动 + +- `Difficult_Rocket.DR_runtime` + - `DR_version` -> `DR_status.DR_version` + - `Build_version` -> `DR_status.Build_version` + - `API_version` -> `DR_status.API_version` + - `language` -> `DR_status.language` + - `mod_path` -> `DR_status.mod_path` + +### 删除 + +- `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 ### Fix -- 2.45.2 From bf3e59836946dbb17a1c201551785d9d3b1837f3 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Fri, 16 Jun 2023 23:36:24 +0800 Subject: [PATCH 2/4] a lot --- DR.py | 4 ++-- Difficult_Rocket/__init__.py | 6 +++--- Difficult_Rocket/client/guis/widgets.py | 6 +++--- Difficult_Rocket/crash/__init__.py | 4 ++-- Difficult_Rocket/mod/api/__init__.py | 6 +++--- Difficult_Rocket/mod/loader/__init__.py | 2 +- Difficult_Rocket/utils/translate.py | 6 +++--- docs/src/change_log/dr_game.md | 8 +++++++- docs/src/change_log/dr_sdk.md | 5 ++--- mods/dr_game/Difficult_Rocket_rs/src/mac-build.ps1 | 3 --- mods/dr_game/__init__.py | 2 +- mods/dr_game/sr1_ship.py | 6 +++--- 12 files changed, 30 insertions(+), 28 deletions(-) delete mode 100644 mods/dr_game/Difficult_Rocket_rs/src/mac-build.ps1 diff --git a/DR.py b/DR.py index 9c5addc..4a235cf 100644 --- a/DR.py +++ b/DR.py @@ -52,7 +52,7 @@ def main() -> int: from Difficult_Rocket.exception import TestError from Difficult_Rocket import crash - from Difficult_Rocket import DR_option + from Difficult_Rocket import DR_status try: from libs import pyglet # 导入pyglet pyglet.resource.path = ['/textures/'] @@ -72,7 +72,7 @@ def main() -> int: cProfile.run('game.start()', sort='calls') # 使用 cprofile 启动 else: game.start() # 直接启动 - if DR_option.crash_report_test: + if DR_status.crash_report_test: raise TestError('debugging') # debug 嘛,试试crash except Exception as exp: # 出毛病了 # 解析错误信息 diff --git a/Difficult_Rocket/__init__.py b/Difficult_Rocket/__init__.py index 201f00a..ee92659 100644 --- a/Difficult_Rocket/__init__.py +++ b/Difficult_Rocket/__init__.py @@ -48,8 +48,6 @@ class _DR_status(Options): API_version: Version = Api_version # DR SDK API 版本 # game options - language: str = 'zh-CN' - mod_path: str = './mods' default_language: str = 'zh-CN' # window option @@ -62,10 +60,12 @@ class _DR_status(Options): class _DR_runtime(Options): """ - DR 的运行时配置/状态 + DR 的运行时配置 / 状态 """ name = 'DR Runtime' + language: str = 'zh-CN' + mod_path: str = './mods' DR_Mod_List: List[Tuple[str, Version]] = [] # DR Mod 列表 (name, version) # run status diff --git a/Difficult_Rocket/client/guis/widgets.py b/Difficult_Rocket/client/guis/widgets.py index 343453b..c1ab651 100644 --- a/Difficult_Rocket/client/guis/widgets.py +++ b/Difficult_Rocket/client/guis/widgets.py @@ -31,7 +31,7 @@ from pyglet.text.layout import IncrementalTextLayout from Difficult_Rocket.api.types import FontData, Fonts # from Difficult_Rocket.client.guis.format import html -from Difficult_Rocket import DR_option +from Difficult_Rocket import DR_status __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): """ 自定义的输入框 """ @@ -134,7 +134,7 @@ if not DR_option.InputBox_use_TextEntry: # dpi=font_dpi) # self.font_height = self.font.ascent - self.font.descent # self.out_bound = out_line - # if DR_option.InputBox_use_TextEntry: + # if DR_status.InputBox_use_TextEntry: # # 基于IncrementalTextLayout的处理系统 # self._doc = FormattedDocument(message) # # self._doc.set_style() diff --git a/Difficult_Rocket/crash/__init__.py b/Difficult_Rocket/crash/__init__.py index e7a8316..daad3ae 100644 --- a/Difficult_Rocket/crash/__init__.py +++ b/Difficult_Rocket/crash/__init__.py @@ -99,14 +99,14 @@ def write_cache(cache_stream, crash_info): 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(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'Running Dir: {Path(os.curdir).resolve()}', level=1)) cache_stream.write(f"\n{DR_runtime.as_markdown()}") 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) for process in all_process: process: multiprocessing.Process diff --git a/Difficult_Rocket/mod/api/__init__.py b/Difficult_Rocket/mod/api/__init__.py index 4ebc331..02192ee 100644 --- a/Difficult_Rocket/mod/api/__init__.py +++ b/Difficult_Rocket/mod/api/__init__.py @@ -22,7 +22,7 @@ if TYPE_CHECKING: else: Game = TypeVar("Game") ClientWindow = TypeVar("ClientWindow") -from Difficult_Rocket import DR_runtime +from Difficult_Rocket import DR_status from Difficult_Rocket.api.types import Options, Version RequireVersion = Tuple[Version, Version] @@ -47,8 +47,8 @@ class ModInfo(Options): info: str = "" # 其他信息 (可以很多很多) """版本相关信息""" - DR_version: RequireVersion = (DR_runtime.DR_version, DR_runtime.DR_version) # DR SDK 兼容版本 - DR_Api_version: RequireVersion = (DR_runtime.API_version, DR_runtime.API_version) # DR Api版本 + DR_version: RequireVersion = (DR_status.DR_version, DR_status.DR_version) # DR SDK 兼容版本 + DR_Api_version: RequireVersion = (DR_status.API_version, DR_status.API_version) # DR Api版本 Mod_Require_version: List[Tuple[str, ForceRequire, RequireVersion]] = [] # mod 依赖版本 """mod 状态""" diff --git a/Difficult_Rocket/mod/loader/__init__.py b/Difficult_Rocket/mod/loader/__init__.py index 58d54c4..c44d821 100644 --- a/Difficult_Rocket/mod/loader/__init__.py +++ b/Difficult_Rocket/mod/loader/__init__.py @@ -11,7 +11,7 @@ from typing import List, Dict, Optional from Difficult_Rocket.api.screen import BaseScreen from Difficult_Rocket.api.types import Options, Version 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): diff --git a/Difficult_Rocket/utils/translate.py b/Difficult_Rocket/utils/translate.py index 63f5de1..e7ffaa6 100644 --- a/Difficult_Rocket/utils/translate.py +++ b/Difficult_Rocket/utils/translate.py @@ -17,7 +17,7 @@ import inspect from dataclasses import dataclass 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.exception.language import (LanguageNotFound, TranslateKeyNotFound) @@ -82,7 +82,7 @@ class Translates: def _raise_no_value(self, e: Exception, item: key_type): if self._config.raise_error: 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() if frame is not None: 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.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.translates_cache = Translates(value=self.translates, config=self.default_config.copy()) diff --git a/docs/src/change_log/dr_game.md b/docs/src/change_log/dr_game.md index 5b9b8fd..94a7ada 100644 --- a/docs/src/change_log/dr_game.md +++ b/docs/src/change_log/dr_game.md @@ -2,9 +2,15 @@ # DR game/DR rs 更新日志 - 最新版本号 - - DR game: 0.1.1.0 + - DR game: 0.2.0.0 - DR rs: 0.2.10.1 +## DR game 0.2.0.0 + +### 适配 + +- 适配了 `DR_sdk` `0.8.3.0` 的修改 + ## DR game 0.1.1.0 ### 添加 diff --git a/docs/src/change_log/dr_sdk.md b/docs/src/change_log/dr_sdk.md index e391237..0f9a752 100644 --- a/docs/src/change_log/dr_sdk.md +++ b/docs/src/change_log/dr_sdk.md @@ -22,10 +22,9 @@ - `Difficult_Rocket.DR_runtime` - `DR_version` -> `DR_status.DR_version` - - `Build_version` -> `DR_status.Build_version` - `API_version` -> `DR_status.API_version` - - `language` -> `DR_status.language` - - `mod_path` -> `DR_status.mod_path` + - `Build_version` -> `DR_status.Build_version` + - `default_language` -> `DR_status.default_language` ### 删除 diff --git a/mods/dr_game/Difficult_Rocket_rs/src/mac-build.ps1 b/mods/dr_game/Difficult_Rocket_rs/src/mac-build.ps1 deleted file mode 100644 index f7e1730..0000000 --- a/mods/dr_game/Difficult_Rocket_rs/src/mac-build.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -python3.8 setup.py build -python3.9 setup.py build -python3.9 post_build.py diff --git a/mods/dr_game/__init__.py b/mods/dr_game/__init__.py index 3b247a6..3fd777a 100644 --- a/mods/dr_game/__init__.py +++ b/mods/dr_game/__init__.py @@ -49,7 +49,7 @@ class DR_mod(ModInfo): mod_id = "difficult_rocket_mod" name = "Difficult Rocket mod" - version = Version("0.1.0.0") + version = Version("0.2.0.0") writer = "shenjackyuanjie" link = "shenjack.top" diff --git a/mods/dr_game/sr1_ship.py b/mods/dr_game/sr1_ship.py index 746c05b..2019883 100644 --- a/mods/dr_game/sr1_ship.py +++ b/mods/dr_game/sr1_ship.py @@ -27,7 +27,7 @@ from pyglet.graphics import Batch, Group from . import DR_mod_runtime # Difficult Rocket -from Difficult_Rocket import DR_option +from Difficult_Rocket import DR_status from Difficult_Rocket.utils.translate import tr from Difficult_Rocket.api.types import Fonts, Options from Difficult_Rocket.command.line import CommandText @@ -124,7 +124,7 @@ class SR1ShipRender(BaseScreen): self.part_box_batch = Batch() self.part_batch = Batch() 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.微软等宽无线, width=main_window.width - 20, height=20, anchor_x='left', anchor_y='top') @@ -171,7 +171,7 @@ class SR1ShipRender(BaseScreen): self.drawing = True for part_id, part in part_datas.items(): # 下面就是调用 pyglet 去渲染的部分 - # render_scale = DR_option.gui_scale # 这个是 DR 的缩放比例 可以调节的( + # render_scale = DR_status.gui_scale # 这个是 DR 的缩放比例 可以调节的( # 主要是 Windows 下有一个缩放系数嘛,我待会试试这玩意能不能获取(估计得 ctypes # 在不缩放的情况下,XML的1个单位长度对应60个像素 render_x = part.x * 60 -- 2.45.2 From d0ac5c06cf049c8e8f736c31134f952f0e2d96a1 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sat, 17 Jun 2023 00:06:39 +0800 Subject: [PATCH 3/4] Add log api --- Difficult_Rocket/api/__init__.py | 13 ++++++++++- Difficult_Rocket/api/log.py | 16 +++++++++++++ Difficult_Rocket/mod/api/__init__.py | 10 ++++++-- Difficult_Rocket/utils/log.py | 34 ++++++++++++++++++++++++++++ docs/src/change_log/dr_sdk.md | 10 ++++++++ mods/dr_game/__init__.py | 3 ++- mods/dr_game/sr1_ship.py | 10 ++++---- 7 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 Difficult_Rocket/api/log.py create mode 100644 Difficult_Rocket/utils/log.py diff --git a/Difficult_Rocket/api/__init__.py b/Difficult_Rocket/api/__init__.py index ae9f186..9101f1c 100644 --- a/Difficult_Rocket/api/__init__.py +++ b/Difficult_Rocket/api/__init__.py @@ -14,4 +14,15 @@ gitee: @shenjackyuanjie # from Difficult_Rocket.api import screen, mod, exception -__all__ = ['screen', 'mod', 'exception'] +__all__ = [ + 'exception', + # 错误类定义 + 'screen', + # screen api + 'types', + # 类型定义 + 'mod', + # mod api + 'log' + # log api +] diff --git a/Difficult_Rocket/api/log.py b/Difficult_Rocket/api/log.py new file mode 100644 index 0000000..78af126 --- /dev/null +++ b/Difficult_Rocket/api/log.py @@ -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', +] \ No newline at end of file diff --git a/Difficult_Rocket/mod/api/__init__.py b/Difficult_Rocket/mod/api/__init__.py index 02192ee..5d068a7 100644 --- a/Difficult_Rocket/mod/api/__init__.py +++ b/Difficult_Rocket/mod/api/__init__.py @@ -12,9 +12,9 @@ gitee: @shenjackyuanjie """ # system function +import warnings from typing import Tuple, List, Optional, TypeVar, TYPE_CHECKING - # from DR if TYPE_CHECKING: from Difficult_Rocket.main import Game @@ -59,9 +59,15 @@ class ModInfo(Options): config: Options = Options() # 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: """ 加载时调用 """ - print(f'Mod {self.mod_id} loaded') return True def on_client_start(self, game: Game, client: ClientWindow): diff --git a/Difficult_Rocket/utils/log.py b/Difficult_Rocket/utils/log.py new file mode 100644 index 0000000..0b94859 --- /dev/null +++ b/Difficult_Rocket/utils/log.py @@ -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 diff --git a/docs/src/change_log/dr_sdk.md b/docs/src/change_log/dr_sdk.md index 0f9a752..d6f0880 100644 --- a/docs/src/change_log/dr_sdk.md +++ b/docs/src/change_log/dr_sdk.md @@ -17,6 +17,16 @@ - `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 ### 移动 diff --git a/mods/dr_game/__init__.py b/mods/dr_game/__init__.py index 3fd777a..ebd731e 100644 --- a/mods/dr_game/__init__.py +++ b/mods/dr_game/__init__.py @@ -9,6 +9,7 @@ import traceback from typing import Optional +from Difficult_Rocket import DR_status from Difficult_Rocket.main import Game from Difficult_Rocket.api.mod import ModInfo from Difficult_Rocket.api.types import Options, Version @@ -58,7 +59,7 @@ class DR_mod(ModInfo): config = DR_mod_runtime - # DR_version = # DR SDK 兼容版本 + DR_version = (DR_status.DR_version, DR_status.DR_version) # DR SDK 兼容版本 # 反正是内置 mod 跟着最新版本的 DR 走就行了 # DR_Api_version = # DR Api版本 # 同理 不管 API 版本 这东西要是不兼容了才是大问题 diff --git a/mods/dr_game/sr1_ship.py b/mods/dr_game/sr1_ship.py index 2019883..46af75d 100644 --- a/mods/dr_game/sr1_ship.py +++ b/mods/dr_game/sr1_ship.py @@ -4,12 +4,11 @@ # All rights reserved # ------------------------------- -import math +# import math import time import random -import logging import traceback -from xml.etree import ElementTree +# from xml.etree import ElementTree from xml.etree.ElementTree import Element from typing import List, TYPE_CHECKING, Union, Dict, Optional, Generator @@ -21,7 +20,7 @@ from pyglet.math import Vec4 from pyglet.text import Label from pyglet.shapes import Line, Rectangle from pyglet.sprite import Sprite -from pyglet.image import Texture +# from pyglet.image import Texture from pyglet.graphics import Batch, Group from . import DR_mod_runtime @@ -32,6 +31,7 @@ from Difficult_Rocket.utils.translate import tr from Difficult_Rocket.api.types import Fonts, Options from Difficult_Rocket.command.line import CommandText 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 if TYPE_CHECKING: @@ -40,7 +40,7 @@ if TYPE_CHECKING: if DR_mod_runtime.use_DR_rust: 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]: -- 2.45.2 From 4e882b69252fbed67f0eeab227b52420bb7ca2ba Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sat, 17 Jun 2023 00:09:03 +0800 Subject: [PATCH 4/4] make nuitka compile script compath DR status changes --- libs/utils/nuitka.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/utils/nuitka.py b/libs/utils/nuitka.py index 4aeeeea..e58c003 100644 --- a/libs/utils/nuitka.py +++ b/libs/utils/nuitka.py @@ -69,9 +69,9 @@ class CompilerHelper(Options): def load_file(self) -> bool: try: - from Difficult_Rocket import DR_runtime - self.product_version = DR_runtime.DR_version - self.file_version = DR_runtime.Build_version + from Difficult_Rocket import DR_status + self.product_version = DR_status.DR_version + self.file_version = DR_status.Build_version return True except ImportError: traceback.print_exc() -- 2.45.2