Difficult-Rocket/Difficult_Rocket/__init__.py

124 lines
3.1 KiB
Python
Raw Normal View History

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-06-22 13:34:14 +08:00
from pathlib import Path
2023-06-10 18:08:40 +08:00
from Difficult_Rocket.api.types import Options, Version
2022-02-16 13:36:26 +08:00
2024-05-26 13:16:52 +08:00
sdk_version = Version("0.9.1.0") # SDK 版本
2023-12-16 22:24:44 +08:00
build_version = Version("3.0.0.0") # 编译文件版本(与游戏本体无关)
2024-05-26 14:01:48 +08:00
api_version = Version("0.1.2.2") # API 版本
2023-07-01 00:25:41 +08:00
__version__ = sdk_version
2021-01-24 18:26:56 +08:00
__all__ = [
# __init__
2023-12-03 16:54:07 +08:00
"DR_status",
# folder
2023-12-03 16:54:07 +08:00
"api",
"data",
2023-12-03 16:54:07 +08:00
"client",
"command",
"crash",
"exception",
"server",
2023-12-03 16:54:07 +08:00
"mod",
"utils",
# file
2023-12-03 16:54:07 +08:00
"main",
"runtime",
2023-12-03 18:16:57 +08:00
"sdk_version",
"build_version",
"api_version",
]
class _DRStatus(Options):
2022-08-12 21:07:36 +08:00
"""
DR 的特性开关 / 基本状态
2022-08-12 21:07:36 +08:00
"""
2023-12-03 16:54:07 +08:00
2023-12-13 11:02:48 +08:00
name = "DR Status"
# run status
client_running: bool = False
server_running: bool = False
# feature switch
2023-12-03 16:54:07 +08:00
InputBox_use_TextEntry: bool = True
record_threads: bool = True
2023-01-24 23:59:07 +08:00
report_translate_not_found: bool = True
2023-12-03 16:54:07 +08:00
use_multiprocess: bool = False
use_cProfile: bool = False
2022-08-12 21:07:36 +08:00
# tests
2023-12-03 16:54:07 +08:00
playing: bool = False
debugging: bool = False
crash_report_test: bool = False
2022-08-12 21:07:36 +08:00
# game version status
2023-07-01 00:25:41 +08:00
DR_version: Version = sdk_version # DR SDK 版本
Build_version: Version = build_version # DR 构建 版本
2023-12-03 18:16:57 +08:00
API_version: Version = api_version # DR SDK API 版本
# game options
2023-12-03 16:54:07 +08:00
default_language: str = "zh-CN"
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
@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
DR_status = _DRStatus()
2022-08-12 21:07:36 +08:00
2023-06-22 13:34:14 +08:00
def load_logger():
log_config_path = Path("./config/lndl-logger.toml")
import tomli
2023-12-13 11:29:14 +08:00
warn_config = False
if not log_config_path.is_file():
# 生成默认配置文件
from Difficult_Rocket.data import log_config
2023-12-13 11:02:48 +08:00
try:
log_config_path.write_text(log_config.default_config)
except (FileNotFoundError, OSError, PermissionError):
print("\033[31mFailed to write default log config file\033[0m")
2023-12-13 11:29:14 +08:00
warn_config = True
logger_config = tomli.loads(log_config.default_config)
else:
# 读取配置文件
2024-03-09 17:41:53 +08:00
with open(log_config_path, "rb") as f:
logger_config = tomli.load(f)
# 输入 lndl 进行配置
from lib_not_dr.loggers.config import read_config, get_logger
read_config(logger_config)
2023-12-13 11:02:48 +08:00
logger = get_logger("main")
logger.info("Logger config loaded", tag="DR-init")
logger.info(f"DR status:\n{DR_status.as_markdown()}", tag="DR-init")
2023-12-13 11:29:14 +08:00
if warn_config:
logger.warn("Failed to load log config file, use default config", tag="DR-init")
2023-12-13 11:02:48 +08:00
# 读取日志配置
# 也保证可以直接运行,不带日志 ( 因为有默认配置 )
load_logger()
2023-06-22 13:34:14 +08:00
if DR_status.playing:
2023-05-28 01:03:46 +08:00
from Difficult_Rocket.utils.thread import new_thread
def think_it(something):
return something
2023-12-03 16:54:07 +08:00
@new_thread("think")
2021-10-31 23:26:32 +08:00
def think(some_thing_to_think):
gotcha = think_it(some_thing_to_think)
2023-12-03 16:54:07 +08:00
return gotcha