diff --git a/Difficult_Rocket/api/types/__init__.py b/Difficult_Rocket/api/types/__init__.py index 350eb55..4d137eb 100644 --- a/Difficult_Rocket/api/types/__init__.py +++ b/Difficult_Rocket/api/types/__init__.py @@ -11,8 +11,9 @@ github: @shenjackyuanjie gitee: @shenjackyuanjie """ +import traceback from dataclasses import dataclass -from typing import get_type_hints, Type, List, Union, Dict, Any, Callable, Tuple, Optional +from typing import get_type_hints, Type, List, Union, Dict, Any, Callable, Tuple, Optional, TYPE_CHECKING # from Difficult Rocket @@ -67,10 +68,23 @@ class Options: setattr(self, option, value) if hasattr(self, 'init'): self.init(**kwargs) + if hasattr(self, 'load_file'): + try: + self.load_file() + except: + traceback.print_exc() self.flush_option() - def init(self, **kwargs) -> None: - ... + if TYPE_CHECKING: + def init(self, **kwargs) -> None: + """ 如果子类定义了这个函数,则会在 __init__ 之后调用这个函数 """ + + def load_file(self) -> bool: + """ + 如果子类定义了这个函数,则会在 __init__ 和 init 之后再调用这个函数 + + 请注意,这个函数请尽量使用 try 包裹住可能出现错误的部分 + 否则会在控制台输出你的报错""" def option(self) -> Dict[str, Any]: """ @@ -98,6 +112,11 @@ class Options: raise OptionNotFound(f'Option {option} is not found in {self.name}') from None return values + def format(self, text: str) -> str: + cache_option = self.flush_option() + for option in cache_option: + text.replace(f'\{{option}\}') + def flush_option(self) -> Dict[str, Any]: """ 刷新缓存 options 的内容 diff --git a/Difficult_Rocket/client/__init__.py b/Difficult_Rocket/client/__init__.py index ab694ac..78be364 100644 --- a/Difficult_Rocket/client/__init__.py +++ b/Difficult_Rocket/client/__init__.py @@ -25,12 +25,13 @@ from decimal import Decimal import rtoml import pyglet # from pyglet import gl -from pyglet.gl import glClearColor +# from pyglet.gl import glClearColor # from pyglet.libs.win32 import _user32 from pyglet.window import Window from pyglet.window import key, mouse # Difficult_Rocket function +from Difficult_Rocket.api.types import Options from Difficult_Rocket.command import line, tree from Difficult_Rocket.utils.translate import tr from Difficult_Rocket import DR_runtime, DR_option @@ -43,6 +44,21 @@ from Difficult_Rocket.client.render.sr1_ship import SR1ShipRender from Difficult_Rocket.client.screen import BaseScreen, DRScreen, DRDEBUGScreen +class ClientOption(Options): + fps: int = 60 + width: int = 1024 + height: int = 768 + file_drop: bool = True + fullscreen: bool = False + resizeable: bool = True + visible: bool = True + gui_scale: float = 1.0 + caption: str = "Difficult Rocket {version}" + + def load_file(self) -> None: + ... + + class Client: def __init__(self, net_mode='local'): start_time = time.time_ns() diff --git a/Difficult_Rocket/client/render/sr1_ship.py b/Difficult_Rocket/client/render/sr1_ship.py index 6af123c..d55175d 100644 --- a/Difficult_Rocket/client/render/sr1_ship.py +++ b/Difficult_Rocket/client/render/sr1_ship.py @@ -260,3 +260,9 @@ class SR1ShipRender(BaseScreen): break self.render_ship() print(paths) + + +if __name__ == '__main__': + from objprint import op + + op(SR1ShipRender_Option) diff --git a/README.md b/README.md index 3e141dd..c0d4353 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ - [discord](https://discord.gg/kWzw2JrG6M) - [kook](https://kook.top/sRPjFG) +996.icu [![Generic badge](https://img.shields.io/badge/SemVer-2.0.0-blue.svg)](https://Semver.org/) [![Generic badge](https://img.shields.io/badge/编写于_Python_版本-3.8.10-blue.svg)](https://Python.org) [![Generic badge](https://img.shields.io/badge/编写于_Pyglet_版本-2.0.2.1-blue.svg)](https://pyglet.org) diff --git a/docs/README-en.md b/docs/README-en.md index 37788be..8c99a52 100644 --- a/docs/README-en.md +++ b/docs/README-en.md @@ -9,6 +9,7 @@ - [discord](https://discord.gg/kWzw2JrG6M) - [kook](https://kook.top/sRPjFG) +996.icu [![Generic badge](https://img.shields.io/badge/SemVer-2.0.0-blue.svg)](https://Semver.org/) [![Generic badge](https://img.shields.io/badge/Write_with_Python-3.8.10-blue.svg)](https://Python.org) [![Generic badge](https://img.shields.io/badge/Write_with_Pyglet-2.0.2.1-blue.svg)](https://pyglet.org) diff --git a/libs/MCDR/version.py b/libs/MCDR/version.py index e7c4982..56e1cb9 100644 --- a/libs/MCDR/version.py +++ b/libs/MCDR/version.py @@ -197,3 +197,14 @@ class VersionRequirement: class VersionParsingError(ValueError): pass + + +if __name__ == '__main__': + from objprint import op + test_list = ['1.1.1', + '1.0', + '1.11.1.11.1'] + + for a_test in test_list: + version_a = Version(a_test) + op(version_a) diff --git a/requirement-build.txt b/requirement-build.txt index 79943d9..892d1eb 100644 --- a/requirement-build.txt +++ b/requirement-build.txt @@ -3,26 +3,26 @@ # DR build (by nuitka) # for phy simulation -pymunk +pymunk >= 6.4.0 # for images -pillow +pillow >= 9.4.0 # for sys info -psutil +psutil >= 5.9.4 # for files -rtoml -tomlkit -defusedxml +rtoml >= 0.9.0 +tomlkit >= 0.11.6 +defusedxml >= 0.7.1 # for report error -objprint +objprint >= 0.2.2 # for compile -nuitka -ordered-set -imageio -setuptools -wheel -setuptools-rust +nuitka >= 1.3.8 +ordered-set >= 4.1.0 +imageio >= 2.25.0 +wheel >= 0.38.4 +setuptools >= 66.1.1 +setuptools-rust >= 1.5.2 diff --git a/requirement-dev.txt b/requirement-dev.txt index f71a706..b050660 100644 --- a/requirement-dev.txt +++ b/requirement-dev.txt @@ -4,27 +4,27 @@ # DR contributing # for phy simulation -pymunk +pymunk >= 6.4.0 # for images -pillow +pillow >= 9.4.0 # for sys info -psutil +psutil >= 5.9.4 # for files -rtoml -tomlkit -defusedxml +rtoml >= 0.9.0 +tomlkit >= 0.11.6 +defusedxml >= 0.7.1 # for debug -objprint -viztracer +objprint >= 0.2.2 +viztracer >= 0.15.6 # for compile -nuitka -ordered-set -imageio -wheel -setuptools -setuptools-rust +nuitka >= 1.3.8 +ordered-set >= 4.1.0 +imageio >= 2.25.0 +wheel >= 0.38.4 +setuptools >= 66.1.1 +setuptools-rust >= 1.5.2 diff --git a/requirement.txt b/requirement.txt index aa4f7c1..708172c 100644 --- a/requirement.txt +++ b/requirement.txt @@ -2,18 +2,18 @@ # DR basic running from source # for phy simulation -pymunk +pymunk >= 6.4.0 # for images -pillow +pillow >= 9.4.0 # for sys info -psutil +psutil >= 5.9.4 # for files -rtoml -tomlkit -defusedxml +rtoml >= 0.9.0 +tomlkit >= 0.11.6 +defusedxml >= 0.7.1 # for report error -objprint \ No newline at end of file +objprint >= 0.2.2