update Options

This commit is contained in:
shenjack 2023-05-10 00:52:56 +08:00
parent 6737473dd4
commit d26f8d0d91
4 changed files with 36 additions and 24 deletions

View File

@ -19,7 +19,7 @@ import traceback
import threading import threading
import multiprocessing import multiprocessing
from pathlib import Path from pathlib import Path
from typing import Optional, Union, TextIO from typing import Optional, Union
# import psutil # import psutil
# for more system info # for more system info
@ -73,18 +73,6 @@ def to_code(string: str):
return f'`{string}`' return f'`{string}`'
def write_markdown_tablet(crash_file: TextIO, tablet: list) -> None:
a_len = max(tablet[1], 6)
b_len = max(tablet[2], 5)
c_len = max(tablet[3], 10)
crash_file.write(f'\n| Option{" " * (a_len - 4)} | Value{" " * (b_len - 3)} | Value Type{" " * (c_len - 8)} |\n')
crash_file.write(f'|:{"-" * (a_len + 3)}|:{"-" * (b_len + 3)}|:{"-" * (c_len + 3)}|\n')
for a, b, c in tablet[0]:
b, c = str(b), str(c)
crash_file.write(
f'| `{a}`{" " * (a_len - len(a))} | `{b}`{" " * (b_len - len(b))} | `{c}`{" " * (c_len - len(c))} |\n')
def create_crash_report(info: Optional[str] = None) -> None: def create_crash_report(info: Optional[str] = None) -> None:
crash_info = crash_info_handler(info) crash_info = crash_info_handler(info)
if 'crash_report' not in os.listdir('./'): if 'crash_report' not in os.listdir('./'):
@ -116,8 +104,10 @@ def write_info_to_cache(cache_stream):
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))
write_options(DR_runtime, cache_stream, DR_configs) cache_stream.write(f"\n{DR_runtime.as_markdown()}")
write_options(DR_option, cache_stream, Process_message) cache_stream.write(DR_configs)
cache_stream.write(f"\n{DR_option.as_markdown()}")
cache_stream.write(Process_message)
for process in all_process: for process in all_process:
process: multiprocessing.Process process: multiprocessing.Process
cache_stream.write(markdown_line_handler(f'{process.name}', code=True)) cache_stream.write(markdown_line_handler(f'{process.name}', code=True))
@ -148,13 +138,6 @@ def write_info_to_cache(cache_stream):
cache_stream.write(markdown_line_handler(f'version: {to_code(platform.version())}', level=1)) cache_stream.write(markdown_line_handler(f'version: {to_code(platform.version())}', level=1))
def write_options(arg0, cache_stream, arg2):
result = arg0.option_with_len()
write_markdown_tablet(crash_file=cache_stream, tablet=result)
# # DR 的游戏设置
cache_stream.write(arg2)
if __name__ == '__main__': if __name__ == '__main__':
os.chdir('../../') os.chdir('../../')
try: try:

View File

@ -5,6 +5,7 @@
# ------------------------------- # -------------------------------
import traceback import traceback
from io import StringIO
from dataclasses import dataclass from dataclasses import dataclass
from typing import get_type_hints, Type, List, Union, Dict, Any, Callable, Tuple, Optional, TYPE_CHECKING from typing import get_type_hints, Type, List, Union, Dict, Any, Callable, Tuple, Optional, TYPE_CHECKING
@ -137,6 +138,22 @@ class Options:
option_list.append((key, value, value_t)) option_list.append((key, value, value_t))
return [option_list, max_len_key, max_len_value, max_len_value_t] return [option_list, max_len_key, max_len_value, max_len_value_t]
def as_markdown(self) -> str:
value = self.option_with_len()
cache = StringIO()
option_len = max(value[1], len('Option'))
value_len = max(value[2], len('Value'))
value_type_len = max(value[3], len('Value Type'))
cache.write(f"| Option{' '*(option_len-3)}| Value{' '*(value_len-2)}| Value Type{' '*(value_type_len-7)}|\n")
cache.write(f'|:{"-" * (option_len+3)}|:{"-" * (value_len+3)}|:{"-" * (value_type_len + 3)}|\n')
for option, value, value_t in value[0]:
cache.write(f"| `{option}`{' '* (option_len - len(option))} "
f"| `{value}`{' '* (value_len - len(str(value)))} "
f"| `{value_t}`{' '* (value_type_len - len(str(value_t)))} |\n")
result = cache.getvalue()
cache.close()
return result
@classmethod @classmethod
def add_option(cls, name: str, value: Union[Callable, object]) -> Dict: def add_option(cls, name: str, value: Union[Callable, object]) -> Dict:
if not hasattr(cls, 'options'): if not hasattr(cls, 'options'):

View File

@ -7,8 +7,8 @@ fonts_folder = "libs/fonts"
[window] [window]
style = "None" style = "None"
width = 1920 width = 1261
height = 1017 height = 935
visible = true visible = true
gui_scale = 1 gui_scale = 1
caption = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}" caption = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}"

View File

@ -70,6 +70,10 @@
- Completely removed the `DR_rust` part - Completely removed the `DR_rust` part
- 现在 `client` 不会在 `setup()` 中调用 `DR_runtime``find_mods()` 方法 - 现在 `client` 不会在 `setup()` 中调用 `DR_runtime``find_mods()` 方法
- Now `client` will not call the `find_mods()` method of `DR_runtime` in `setup()` - Now `client` will not call the `find_mods()` method of `DR_runtime` in `setup()`
- `Difficult_Rocket.crash`
- Remove `write_options` method
- Remove `write_markdown_tablet` method
- Replace with `Option().as_markdown()`
### Changes ### Changes
@ -101,6 +105,14 @@
- 大重构,移除定义,改为引用 - 大重构,移除定义,改为引用
- Big refactoring, remove definition, change to reference - Big refactoring, remove definition, change to reference
### Add
- `Difficult_Rocket.api.types.Options`
- 添加 `as_markdown` 方法
- 用于方便的用人类可读的 Markdown 格式 直接输出一个已经实例化的 `Options` 类的所有字段
- Add `as_markdown` method
- Used to easily output all fields of an instantiated `Options` class in a human-readable Markdown format
### Docs ### Docs
- `howto/translate.md` - `howto/translate.md`