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
|
|
|
|
2023-12-13 13:57:32 +08:00
|
|
|
sdk_version = Version("0.9.0.0") # SDK 版本
|
2023-08-27 01:52:45 +08:00
|
|
|
build_version = Version("2.2.0.0") # 编译文件版本(与游戏本体无关)
|
2023-12-03 18:16:57 +08:00
|
|
|
api_version = Version("0.1.1.0") # API 版本
|
2023-07-01 00:25:41 +08:00
|
|
|
__version__ = sdk_version
|
2021-01-24 18:26:56 +08:00
|
|
|
|
2023-06-17 00:47:00 +08:00
|
|
|
__all__ = [
|
|
|
|
# __init__
|
2023-12-03 16:54:07 +08:00
|
|
|
"DR_status",
|
2023-06-17 00:47:00 +08:00
|
|
|
# folder
|
2023-12-03 16:54:07 +08:00
|
|
|
"api",
|
2023-12-13 09:43:29 +08:00
|
|
|
"data",
|
2023-12-03 16:54:07 +08:00
|
|
|
"client",
|
|
|
|
"command",
|
|
|
|
"crash",
|
|
|
|
"exception",
|
2023-12-13 09:43:29 +08:00
|
|
|
"server",
|
2023-12-03 16:54:07 +08:00
|
|
|
"mod",
|
|
|
|
"utils",
|
2023-06-17 00:47:00 +08:00
|
|
|
# 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",
|
2023-06-17 00:47:00 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2023-12-13 09:43:29 +08:00
|
|
|
class _DRStatus(Options):
|
2022-08-12 21:07:36 +08:00
|
|
|
"""
|
2023-06-16 23:23:19 +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"
|
2023-06-16 23:23:19 +08:00
|
|
|
# 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
|
|
|
|
2023-06-16 23:23:19 +08:00
|
|
|
# game version status
|
2023-07-01 00:25:41 +08:00
|
|
|
DR_version: Version = sdk_version # DR SDK 版本
|
2023-06-16 23:23:19 +08:00
|
|
|
Build_version: Version = build_version # DR 构建 版本
|
2023-12-03 18:16:57 +08:00
|
|
|
API_version: Version = api_version # DR SDK API 版本
|
2023-06-16 23:23:19 +08:00
|
|
|
|
|
|
|
# game options
|
2023-12-03 16:54:07 +08:00
|
|
|
default_language: str = "zh-CN"
|
2023-06-16 23:23:19 +08:00
|
|
|
|
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
|
|
|
|
2023-12-13 09:43:29 +08:00
|
|
|
DR_status = _DRStatus()
|
2022-08-12 21:07:36 +08:00
|
|
|
|
2023-06-22 13:34:14 +08:00
|
|
|
|
2023-12-13 12:04:30 +08:00
|
|
|
def load_logger():
|
2023-12-13 09:43:29 +08:00
|
|
|
log_config_path = Path("./config/lndl-logger.toml")
|
|
|
|
|
|
|
|
import rtoml
|
|
|
|
|
2023-12-13 11:29:14 +08:00
|
|
|
warn_config = False
|
2023-12-13 09:43:29 +08:00
|
|
|
if not log_config_path.is_file():
|
|
|
|
# 生成默认配置文件
|
|
|
|
from Difficult_Rocket.data import log_config
|
2023-12-13 12:38:26 +08:00
|
|
|
|
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
|
2023-12-13 09:43:29 +08:00
|
|
|
logger_config = rtoml.loads(log_config.default_config)
|
|
|
|
else:
|
|
|
|
# 读取配置文件
|
2023-12-13 12:38:26 +08:00
|
|
|
with open(log_config_path, encoding="utf-8") as f:
|
2023-12-13 09:43:29 +08:00
|
|
|
logger_config = rtoml.load(f)
|
|
|
|
# 输入 lndl 进行配置
|
2023-12-13 12:04:30 +08:00
|
|
|
from lib_not_dr.loggers.config import read_config, get_logger
|
2023-12-13 12:38:26 +08:00
|
|
|
|
2023-12-13 09:43:29 +08:00
|
|
|
read_config(logger_config)
|
2023-12-13 11:02:48 +08:00
|
|
|
logger = get_logger("main")
|
2023-12-13 12:38:26 +08:00
|
|
|
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:
|
2023-12-13 12:38:26 +08:00
|
|
|
logger.warn("Failed to load log config file, use default config", tag="DR-init")
|
2023-12-13 11:02:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
# 读取日志配置
|
|
|
|
# 也保证可以直接运行,不带日志 ( 因为有默认配置 )
|
2023-12-13 12:04:30 +08:00
|
|
|
load_logger()
|
2023-06-22 13:34:14 +08:00
|
|
|
|
2023-06-16 23:23:19 +08:00
|
|
|
if DR_status.playing:
|
2023-05-28 01:03:46 +08:00
|
|
|
from Difficult_Rocket.utils.thread import new_thread
|
|
|
|
|
2023-12-13 12:38:26 +08:00
|
|
|
|
2022-06-21 10:17:13 +08:00
|
|
|
def think_it(something):
|
|
|
|
return something
|
|
|
|
|
2023-12-13 12:38:26 +08:00
|
|
|
|
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):
|
2022-06-21 10:17:13 +08:00
|
|
|
gotcha = think_it(some_thing_to_think)
|
2023-12-03 16:54:07 +08:00
|
|
|
return gotcha
|