Compare commits

..

3 Commits

Author SHA1 Message Date
25b922cc58
display info in github action 2023-12-13 12:59:38 +08:00
7c8721db11
fix github action 2023-12-13 12:54:38 +08:00
c459155cfa
remove old logger, reformat, add tag for new logger 2023-12-13 12:38:26 +08:00
21 changed files with 226 additions and 1453 deletions

View File

@ -7,15 +7,24 @@
import os import os
import sys import sys
import rtoml import rtoml
import io
sys.path.append(os.path.abspath(os.curdir)) sys.path.append(os.path.abspath(os.curdir))
is_github = "-github" in sys.argv
if is_github:
stdout = sys.stdout
sys.stdout = io.StringIO()
try: try:
from Difficult_Rocket import DR_status from Difficult_Rocket import DR_status
except ImportError: except ImportError:
raise raise
args = ["-env", "-github-dev"] if is_github:
sys.stdout = stdout
if sys.argv == [__file__]: # 没有输入参数,直接输出默认信息并输出 if sys.argv == [__file__]: # 没有输入参数,直接输出默认信息并输出
@ -28,10 +37,6 @@ if sys.argv == [__file__]: # 没有输入参数,直接输出默认信息并
config_file["window"]["height"] = 768 config_file["window"]["height"] = 768
rtoml.dump(config_file, open("./config/main.toml", "w")) rtoml.dump(config_file, open("./config/main.toml", "w"))
elif os.path.abspath(os.curdir) in sys.path and "-env" in sys.argv:
with open("./.github/workflows/env.ps1", encoding="utf-8", mode="w") as env_file:
print(f'$env:DR_version = "{DR_status.DR_version}"', file=env_file)
print(f'$env:Build_version = "{DR_status.Build_version}"', file=env_file)
elif os.path.abspath(os.curdir) in sys.path and "-github" in sys.argv: elif os.path.abspath(os.curdir) in sys.path and "-github" in sys.argv:
print(f"DR_version={DR_status.DR_version}") print(f"DR_version={DR_status.DR_version}")
print(f"Build_version={DR_status.Build_version}") print(f"Build_version={DR_status.Build_version}")

View File

@ -13,7 +13,6 @@ build_version = Version("2.2.0.0") # 编译文件版本(与游戏本体无关)
api_version = Version("0.1.1.0") # API 版本 api_version = Version("0.1.1.0") # API 版本
__version__ = sdk_version __version__ = sdk_version
__all__ = [ __all__ = [
# __init__ # __init__
"DR_status", "DR_status",
@ -86,6 +85,7 @@ def load_logger():
if not log_config_path.is_file(): if not log_config_path.is_file():
# 生成默认配置文件 # 生成默认配置文件
from Difficult_Rocket.data import log_config from Difficult_Rocket.data import log_config
try: try:
log_config_path.write_text(log_config.default_config) log_config_path.write_text(log_config.default_config)
except (FileNotFoundError, OSError, PermissionError): except (FileNotFoundError, OSError, PermissionError):
@ -94,29 +94,31 @@ def load_logger():
logger_config = rtoml.loads(log_config.default_config) logger_config = rtoml.loads(log_config.default_config)
else: else:
# 读取配置文件 # 读取配置文件
with open(log_config_path, encoding='utf-8') as f: with open(log_config_path, encoding="utf-8") as f:
logger_config = rtoml.load(f) logger_config = rtoml.load(f)
# 输入 lndl 进行配置 # 输入 lndl 进行配置
from lib_not_dr.loggers.config import read_config, get_logger from lib_not_dr.loggers.config import read_config, get_logger
read_config(logger_config) read_config(logger_config)
logger = get_logger("main") logger = get_logger("main")
logger.info("Logger config loaded", tag='DR-init') logger.info("Logger config loaded", tag="DR-init")
logger.info(f"DR status:\n{DR_status.as_markdown()}", tag='DR-init') logger.info(f"DR status:\n{DR_status.as_markdown()}", tag="DR-init")
if warn_config: if warn_config:
logger.warn("Failed to load log config file, use default config", tag='DR-init') logger.warn("Failed to load log config file, use default config", tag="DR-init")
# 读取日志配置 # 读取日志配置
# 也保证可以直接运行,不带日志 ( 因为有默认配置 ) # 也保证可以直接运行,不带日志 ( 因为有默认配置 )
load_logger() load_logger()
if DR_status.playing: if DR_status.playing:
from Difficult_Rocket.utils.thread import new_thread from Difficult_Rocket.utils.thread import new_thread
def think_it(something): def think_it(something):
return something return something
@new_thread("think") @new_thread("think")
def think(some_thing_to_think): def think(some_thing_to_think):
gotcha = think_it(some_thing_to_think) gotcha = think_it(some_thing_to_think)

View File

@ -11,7 +11,6 @@ github: @shenjackyuanjie
gitee: @shenjackyuanjie gitee: @shenjackyuanjie
""" """
__all__ = [ __all__ = [
"exception", "exception",
# 错误类定义 # 错误类定义

View File

@ -33,7 +33,6 @@ class BaseScreen(EventDispatcher, Options):
self.window_pointer = main_window self.window_pointer = main_window
if TYPE_CHECKING: if TYPE_CHECKING:
def on_command(self, command: CommandText, window: ClientWindow): def on_command(self, command: CommandText, window: ClientWindow):
""" """
命令输入事件 命令输入事件

View File

@ -44,7 +44,6 @@ from Difficult_Rocket.exception.language import LanguageNotFound
from lib_not_dr import loggers from lib_not_dr import loggers
logger = loggers.config.get_logger("client") logger = loggers.config.get_logger("client")
@ -129,7 +128,7 @@ def pyglet_load_fonts_folder(folder) -> None:
if not font_path.exists(): if not font_path.exists():
font_path.mkdir(parents=True) font_path.mkdir(parents=True)
return None return None
logger.info(tr().client.load.font.start().format(font_path), tag='font') logger.info(tr().client.load.font.start().format(font_path), tag="font")
start_time = time.time_ns() start_time = time.time_ns()
for dir_path, dir_names, file_names in os.walk(font_path): for dir_path, dir_names, file_names in os.walk(font_path):
dir_path = Path(dir_path) dir_path = Path(dir_path)
@ -137,7 +136,8 @@ def pyglet_load_fonts_folder(folder) -> None:
file_name = Path(file_name) file_name = Path(file_name)
if file_name.suffix in (".ttf", ".otf"): if file_name.suffix in (".ttf", ".otf"):
logger.debug( logger.debug(
tr().client.load.font.file().format(str(dir_path / file_name)), tag='font' tr().client.load.font.file().format(str(dir_path / file_name)),
tag="font",
) )
try: try:
pyglet.font.add_file(str(dir_path / file_name)) pyglet.font.add_file(str(dir_path / file_name))
@ -149,7 +149,9 @@ def pyglet_load_fonts_folder(folder) -> None:
) )
end_time = time.time_ns() end_time = time.time_ns()
use_time = end_time - start_time use_time = end_time - start_time
logger.info(tr().client.load.font.use_time().format(use_time / 1000000000), tag='font') logger.info(
tr().client.load.font.use_time().format(use_time / 1000000000), tag="font"
)
def _call_back(call_back: Callable) -> Callable: def _call_back(call_back: Callable) -> Callable:
@ -308,10 +310,13 @@ class ClientWindow(Window):
# TODO: wait for pyglet 2.1 # TODO: wait for pyglet 2.1
pyglet.app.run(float(self.SPF)) pyglet.app.run(float(self.SPF))
except KeyboardInterrupt: except KeyboardInterrupt:
self.logger.warn("==========client stop. KeyboardInterrupt info==========", tag="starter") self.logger.warn(
"==========client stop. KeyboardInterrupt info==========", tag="starter"
)
traceback.print_exc() traceback.print_exc()
self.logger.warn( self.logger.warn(
"==========client stop. KeyboardInterrupt info end==========", tag="starter" "==========client stop. KeyboardInterrupt info end==========",
tag="starter",
) )
self.dispatch_event("on_close", "input") self.dispatch_event("on_close", "input")
sys.exit(0) sys.exit(0)

View File

@ -36,9 +36,9 @@ class FpsLogger:
else: else:
self.fps_list.append(float(1 / tick)) self.fps_list.append(float(1 / tick))
if len(self.fps_list) > self.count: if len(self.fps_list) > self.count:
self.fps_list = self.fps_list[-self.count + 1 :] # 整个列表往前挪一位 self.fps_list = self.fps_list[-self.count + 1:] # 整个列表往前挪一位
if len(self.get_fps_list) > self.count: if len(self.get_fps_list) > self.count:
self.get_fps_list = self.get_fps_list[-self.count + 1 :] # 整个列表往前挪一位 self.get_fps_list = self.get_fps_list[-self.count + 1:] # 整个列表往前挪一位
try: try:
self._fps = statistics.geometric_mean( self._fps = statistics.geometric_mean(
self.fps_list[-100:] self.fps_list[-100:]

View File

@ -50,9 +50,9 @@ class CommandText:
if find != -1: if find != -1:
if not len(text) == len(self.text): if not len(text) == len(self.text):
self.text = ( self.text = (
self.text[find + len(text) :] self.text[find + len(text):]
if not self.text[find + len(text)] == " " if not self.text[find + len(text)] == " "
else self.text[find + len(text) + 1 :] else self.text[find + len(text) + 1:]
) )
return True return True
return False return False
@ -68,7 +68,7 @@ class CommandText:
# 20230122 我现在也不知道为啥这么写了 # 20230122 我现在也不知道为啥这么写了
# 果然使用正则表达式就是让一个问题变成两个问题 # 果然使用正则表达式就是让一个问题变成两个问题
except IndexError: except IndexError:
self.text = self.text[finding.span()[1] + 1 :] self.text = self.text[finding.span()[1] + 1:]
return True return True
if next_find == " ": if next_find == " ":
return True return True

View File

@ -23,7 +23,6 @@ class BaseTheme(dict):
setattr(self, k, v) setattr(self, k, v)
if TYPE_CHECKING: if TYPE_CHECKING:
def init(self, batch: Batch, group: Group, **kwargs) -> None: def init(self, batch: Batch, group: Group, **kwargs) -> None:
""" """
Init theme Init theme

View File

@ -3,4 +3,3 @@
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com # Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
# All rights reserved # All rights reserved
# ------------------------------- # -------------------------------

View File

@ -74,14 +74,14 @@ class ModManager(Options):
:return: :return:
""" """
if not mod_path.exists(): if not mod_path.exists():
logger.error(tr().mod.load.faild.not_exist().format(mod_path)) logger.error(tr().mod.load.faild.not_exist().format(mod_path), tag="load")
return None return None
_add_path_to_sys([mod_path.parent]) _add_path_to_sys([mod_path.parent])
try: try:
if mod_path.name == "__pycache__": if mod_path.name == "__pycache__":
# 忽略 __pycache__ 文件夹 (Python 编译文件) # 忽略 __pycache__ 文件夹 (Python 编译文件)
return None return None
logger.info(tr().mod.load.loading().format(mod_path)) logger.info(tr().mod.load.loading().format(mod_path), tag="load")
if ( if (
mod_path.is_dir() mod_path.is_dir()
or mod_path.suffix in PACKAGE_SUFFIX or mod_path.suffix in PACKAGE_SUFFIX
@ -92,7 +92,9 @@ class ModManager(Options):
if not hasattr(loading_mod, "mod_class") or not issubclass( if not hasattr(loading_mod, "mod_class") or not issubclass(
loading_mod.mod_class, ModInfo loading_mod.mod_class, ModInfo
): ):
logger.warn(tr().mod.load.faild.no_mod_class().format(mod_path)) logger.warn(
tr().mod.load.faild.no_mod_class().format(mod_path), tag="load"
)
return None return None
mod_class: type(ModInfo) = loading_mod.mod_class # 获取 mod 类 mod_class: type(ModInfo) = loading_mod.mod_class # 获取 mod 类
if mod_class.mod_id not in self.find_mod_paths: if mod_class.mod_id not in self.find_mod_paths:
@ -100,7 +102,8 @@ class ModManager(Options):
return mod_class return mod_class
except ImportError: except ImportError:
logger.warn( logger.warn(
tr().mod.load.faild.error().format(mod_path, traceback.format_exc()) tr().mod.load.faild.error().format(mod_path, traceback.format_exc()),
tag="load",
) )
return None return None
@ -131,7 +134,9 @@ class ModManager(Options):
): ):
# 文件夹 mod # 文件夹 mod
mods_path.append(mod) mods_path.append(mod)
logger.info(tr().mod.finded().format(len(mods_path), time.time() - start_time)) logger.info(
tr().mod.finded().format(len(mods_path), time.time() - start_time), tag="find"
)
return mods_path return mods_path
def load_mods( def load_mods(
@ -149,7 +154,7 @@ class ModManager(Options):
_add_path_to_sys(find_path) _add_path_to_sys(find_path)
mods = [] mods = []
start_time = time.time() start_time = time.time()
logger.info(tr().mod.load.start().format(find_path)) logger.info(tr().mod.load.start().format(find_path), tag="load")
for path in find_path: for path in find_path:
if not path.exists(): if not path.exists():
path.mkdir(parents=True) path.mkdir(parents=True)
@ -161,7 +166,7 @@ class ModManager(Options):
for path in extra_mod_path: for path in extra_mod_path:
if (cache := self.load_mod(path)) is not None: if (cache := self.load_mod(path)) is not None:
mods.append(cache) mods.append(cache)
logger.info(tr().mod.load.use_time().format(time.time() - start_time)) logger.info(tr().mod.load.use_time().format(time.time() - start_time), tag="load")
return mods return mods
def init_mods(self, mods: List[type(ModInfo)]): def init_mods(self, mods: List[type(ModInfo)]):
@ -175,13 +180,16 @@ class ModManager(Options):
try: try:
init_mod = mod_class() init_mod = mod_class()
self.loaded_mod_modules[init_mod.mod_id] = init_mod self.loaded_mod_modules[init_mod.mod_id] = init_mod
logger.info(tr().mod.init.success().format(init_mod, init_mod.version)) logger.info(
tr().mod.init.success().format(init_mod, init_mod.version), tag="init"
)
except Exception as e: except Exception as e:
logger.error( logger.error(
tr().mod.init.faild().format(mod_class, e, traceback.format_exc()) tr().mod.init.faild().format(mod_class, e, traceback.format_exc()),
tag="init",
) )
continue continue
logger.info(tr().mod.init.use_time().format(time.time() - start_time)) logger.info(tr().mod.init.use_time().format(time.time() - start_time), tag="init")
def unload_mod(self, mod_id: str, game: Game) -> Optional[ModInfo]: def unload_mod(self, mod_id: str, game: Game) -> Optional[ModInfo]:
""" """
@ -194,16 +202,17 @@ class ModManager(Options):
not (mod_class := self.loaded_mod_modules.get(mod_id)) not (mod_class := self.loaded_mod_modules.get(mod_id))
and (mod_class := self.get_mod_module(mod_id)) is None and (mod_class := self.get_mod_module(mod_id)) is None
): ):
logger.warn(tr().mod.unload.faild.not_find().format(mod_id)) logger.warn(tr().mod.unload.faild.not_find().format(mod_id), tag="unload")
return None return None
try: try:
mod_class.on_unload(game=game) mod_class.on_unload(game=game)
self.loaded_mod_modules.pop(mod_class.mod_id) self.loaded_mod_modules.pop(mod_class.mod_id)
logger.info(tr().mod.unload.success().format(mod_id)) logger.info(tr().mod.unload.success().format(mod_id), tag="unload")
return mod_class return mod_class
except Exception as e: except Exception as e:
logger.error( logger.error(
tr().mod.unload.faild.error().format(mod_id, e, traceback.format_exc()) tr().mod.unload.faild.error().format(mod_id, e, traceback.format_exc()),
tag="unload",
) )
return None return None
@ -219,7 +228,9 @@ class ModManager(Options):
return return
mod_class: Optional[ModInfo] = None mod_class: Optional[ModInfo] = None
if unload.mod_id not in self.find_mod_paths: if unload.mod_id not in self.find_mod_paths:
logger.warn(tr().mod.reload.faild.not_find().format(unload.mod_id)) logger.warn(
tr().mod.reload.faild.not_find().format(unload.mod_id), tag="reload"
)
paths = self.find_mods_in_path() paths = self.find_mods_in_path()
for path in paths: for path in paths:
mod_class = self.load_mod(path) mod_class = self.load_mod(path)
@ -232,4 +243,4 @@ class ModManager(Options):
self.init_mods([mod_class]) self.init_mods([mod_class])
if mod_id in self.loaded_mod_modules and mod_class is not None: if mod_id in self.loaded_mod_modules and mod_class is not None:
self.loaded_mod_modules[mod_id].on_load(game=game, old_self=mod_class) self.loaded_mod_modules[mod_id].on_load(game=game, old_self=mod_class)
logger.info(tr().mod.reload.success().format(mod_id)) logger.info(tr().mod.reload.success().format(mod_id), tag="reload")

View File

@ -14,7 +14,6 @@ from typing import Optional, List, Tuple
from Difficult_Rocket.api.types import Options, Version from Difficult_Rocket.api.types import Options, Version
__all__ = ["DR_runtime"] __all__ = ["DR_runtime"]

View File

@ -1,123 +0,0 @@
logger_version = '1.0.0'
[Loggers]
[Loggers.root]
level = 'DEBUG'
color = 'main_color'
file = 'main_log_file'
handlers = ['main_std_handler']
[Loggers.client]
level = 'TRACE'
color = 'main_color'
file = 'main_log_file'
handlers = ['main_std_handler']
[Loggers.server]
level = 'TRACE'
color = 'DiGua_color'
file = 'main_log_file'
handlers = ['main_std_handler']
[Files]
[Files.main_log_file]
name = './logs/{long_time}_logs.md'
level = 'TRACE'
cache_len = 20
cache_time = 1
mode = 'a'
encoding = 'utf-8'
[Handler]
[Handler.main_std_handler]
class = 'str handler'
format = 'format.main_format'
[Handler.main_file_hander]
class = 'cached file handler'
format = 'format.main_format'
[Formatter]
main_format = '[{long_time}] [{logger_name}] {level} | {file_name}:{code_line} | {marker} | {message}'
file_name = 'no frame'
code_line = 'no frame'
short_time = '%Y-%m-%d %H-%M-%S'
long_time = '%Y-%m-%d %H-%M-%S:%%S'
[Colors]
[Colors.main_color]
# 翻了三个月的颜色啊
long_time = '\u001b[38;2;201;222;56m'
short_time = '\u001b[38;2;201;222;56m'
code_line = '\u001b[38;2;0;255;180m'
file_name = '\u001b[38;2;0;255;180m'
info = '\u001b[0m'
message = '\u001b[0m'
logger = '\u001b[0m'
marker = '\u001b[0m'
# level colors
TRACE.info = '\u001b[38;2;138;173;244m'
FINE.info = '\u001b[35;48;2;44;44;54m'
DEBUG.info = '\u001b[38;2;133;138;149m'
INFO.info = '\u001b[0m'
WARNING.info = '\u001b[33m'
ERROR.info = '\u001b[31m'
FATAL.info = '\u001b[38;2;255;255;0;48;2;120;10;10m'
FATAL.logger = '\u001b[38;2;245;189;230m'
[Colors.fancy_main_color]
long_time = '\u001b[38;2;201;222;56m'
short_time = '\u001b[38;2;201;222;56m'
file_name = '\u001b[38;2;0;255;180m'
code_line = '\u001b[38;2;0;255;180m'
info = '\u001b[0m'
message = '\u001b[0m'
logger = '\u001b[0m'
marker = '\u001b[0m'
# level colors
TRACE.info = '\u001b[38;2;138;173;244m'
TRACE.message = '\u001b[38;2;138;173;244m'
FINE.info = '\u001b[35;48;2;44;44;54m'
FINE.message = '\u001b[35m'
DEBUG.info = '\u001b[38;2;133;138;149m'
DEBUG.message = '\u001b[38;2;133;138;149m'
INFO.info = '\u001b[0m'
INFO.message = '\u001b[0m'
WARNING.info = '\u001b[33m'
WARNING.message = '\u001b[33m'
ERROR.info = '\u001b[31m'
ERROR.message = '\u001b[31m'
FATAL.info = '\u001b[38;2;255;255;0;48;2;120;10;10m'
FATAL.message = '\u001b[38;2;255;255;0;48;2;120;10;10m'
FATAL.logger = '\u001b[38;2;245;189;230m'
[Colors.DiGua_color]
# catppuccin Macchiato
long_time = '\u001b[38;2;202;211;245m'
short_time = '\u001b[38;2;202;211;245m'
file_name = '\u001b[38;2;139;213;202m'
code_line = '\u001b[38;2;166;218;149m'
info = '\u001b[0m'
logger = '\u001b[0m'
message = '\u001b[0m'
marker = '\u001b[0m'
# level colors
TRACE.info = '\u001b[38;2;138;173;244m'
TRACE.message = '\u001b[38;2;138;173;244m'
FINE.info = '\u001b[38;2;198;160;246m'
FINE.message = '\u001b[38;2;198;160;246m'
DEBUG.info = '\u001b[38;2;133;138;149m'
DEBUG.message = '\u001b[38;2;133;138;149m'
ERROR.info = '\u001b[38;2;237;135;150m'
ERROR.message = '\u001b[38;2;237;135;150m'
WARNING.info = '\u001b[38;2;245;169;127m'
WARNING.message = '\u001b[38;2;245;169;127m'
FATAL.info = '\u001b[38;2;255;255;0;48;2;120;10;10m'
FATAL.message = '\u001b[38;2;255;255;0;48;2;120;10;10m'
FATAL.loggger = '\u001b[38;2;245;189;230m'

File diff suppressed because it is too large Load Diff

View File

@ -13,12 +13,8 @@ from lib_not_dr.nuitka import nuitka_config_type, raw_config_type
def gen_pyglet_no_follow_import() -> list: def gen_pyglet_no_follow_import() -> list:
no_follow_import = [] no_follow_import = []
no_follow_import += [ no_follow_import += [f"pyglet.app.{x}" for x in ["win32", "xlib", "cocoa"]]
f"pyglet.app.{x}" for x in ["win32", "xlib", "cocoa"] no_follow_import += [f"pyglet.input.{x}" for x in ["win32", "linux", "macos"]]
]
no_follow_import += [
f"pyglet.input.{x}" for x in ["win32", "linux", "macos"]
]
no_follow_import += [ no_follow_import += [
f"pyglet.libs.{x}" f"pyglet.libs.{x}"
for x in ["win32", "x11", "wayland", "darwin", "egl", "headless"] for x in ["win32", "x11", "wayland", "darwin", "egl", "headless"]
@ -36,9 +32,7 @@ def gen_pyglet_no_follow_import() -> list:
"headless", "headless",
) )
] ]
no_follow_import += [ no_follow_import += [f"pyglet.gl.{x}" for x in ["win32", "xlib", "cocoa", "headless"]]
f"pyglet.gl.{x}" for x in ["win32", "xlib", "cocoa", "headless"]
]
mult_plat_libs = ["app", "input", "libs", "window", "canvas", "gl"] mult_plat_libs = ["app", "input", "libs", "window", "canvas", "gl"]
if platform.system() == "Windows": if platform.system() == "Windows":
@ -59,15 +53,15 @@ def gen_pyglet_no_follow_import() -> list:
def main(config: raw_config_type) -> nuitka_config_type: def main(config: raw_config_type) -> nuitka_config_type:
print('debug', config) print("debug", config)
config = config['cli'] config = config["cli"]
config['file-version'] = str(build_version) config["file-version"] = str(build_version)
config['product-version'] = str(sdk_version) config["product-version"] = str(sdk_version)
config['macos-app-version'] = str(sdk_version) config["macos-app-version"] = str(sdk_version)
config['nofollow-import-to'] += gen_pyglet_no_follow_import() config["nofollow-import-to"] += gen_pyglet_no_follow_import()
config['output-dir'] = './build/nuitka-' + platform.system().lower() config["output-dir"] = "./build/nuitka-" + platform.system().lower()
print('done', config) print("done", config)
return config return config