Add log api
This commit is contained in:
parent
bf3e598369
commit
d0ac5c06cf
@ -14,4 +14,15 @@ gitee: @shenjackyuanjie
|
||||
|
||||
# from Difficult_Rocket.api import screen, mod, exception
|
||||
|
||||
__all__ = ['screen', 'mod', 'exception']
|
||||
__all__ = [
|
||||
'exception',
|
||||
# 错误类定义
|
||||
'screen',
|
||||
# screen api
|
||||
'types',
|
||||
# 类型定义
|
||||
'mod',
|
||||
# mod api
|
||||
'log'
|
||||
# log api
|
||||
]
|
||||
|
16
Difficult_Rocket/api/log.py
Normal file
16
Difficult_Rocket/api/log.py
Normal file
@ -0,0 +1,16 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
from Difficult_Rocket.utils.log import (get_named_client_logger,
|
||||
get_named_server_logger,
|
||||
get_named_main_logger)
|
||||
|
||||
|
||||
__all__ = [
|
||||
'get_named_client_logger',
|
||||
'get_named_server_logger',
|
||||
'get_named_main_logger',
|
||||
]
|
@ -12,9 +12,9 @@ gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
# system function
|
||||
import warnings
|
||||
from typing import Tuple, List, Optional, TypeVar, TYPE_CHECKING
|
||||
|
||||
|
||||
# from DR
|
||||
if TYPE_CHECKING:
|
||||
from Difficult_Rocket.main import Game
|
||||
@ -59,9 +59,15 @@ class ModInfo(Options):
|
||||
config: Options = Options() # mod 配置存储
|
||||
old_mod: Optional["ModInfo"] = None # 旧的mod实例
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
if not self.DR_version[0] <= DR_status.DR_version <= self.DR_version[1]:
|
||||
warnings.warn(f"mod {self.mod_id} version {self.version} is not support by DR {DR_status.DR_version}\nDR {self.DR_version} is required")
|
||||
if not self.DR_Api_version[0] <= DR_status.API_version <= self.DR_Api_version[1]:
|
||||
warnings.warn(f"mod {self.mod_id} version {self.version} is not support by DR {DR_status.API_version}\nDR {self.DR_Api_version} is required")
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def on_load(self, game: Game, old_self: Optional["ModInfo"] = None) -> bool:
|
||||
""" 加载时调用 """
|
||||
print(f'Mod {self.mod_id} loaded')
|
||||
return True
|
||||
|
||||
def on_client_start(self, game: Game, client: ClientWindow):
|
||||
|
34
Difficult_Rocket/utils/log.py
Normal file
34
Difficult_Rocket/utils/log.py
Normal file
@ -0,0 +1,34 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
import logging
|
||||
|
||||
from typing import Callable
|
||||
|
||||
|
||||
__all__ = [
|
||||
'get_named_client_logger',
|
||||
'get_named_server_logger',
|
||||
'get_named_main_logger',
|
||||
]
|
||||
|
||||
|
||||
def _gen_get_named_logger(from_name: str) -> Callable[[str], logging.Logger]:
|
||||
|
||||
def get_named_logger(name: str) -> logging.Logger:
|
||||
logger = logging.getLogger(from_name)
|
||||
logger.name = f'{from_name}.{name}'
|
||||
return logger
|
||||
|
||||
return get_named_logger
|
||||
|
||||
|
||||
get_named_client_logger = _gen_get_named_logger('client')
|
||||
# 用于获取一个基于 client 配置的 logger
|
||||
get_named_server_logger = _gen_get_named_logger('server')
|
||||
# 用于获取一个基于 server 配置的 logger
|
||||
get_named_main_logger = _gen_get_named_logger('main')
|
||||
# 用于获取一个基于 main 配置的 logger
|
@ -17,6 +17,16 @@
|
||||
- `server_running`
|
||||
- 服务器是否在运行
|
||||
- Is server running
|
||||
- Mod loader
|
||||
- 添加了对支持版本号的 warnings
|
||||
- Added warnings for supporting version numbers
|
||||
- API
|
||||
- `Difficult_Rocket.api.log`
|
||||
- `get_named_client_logger`
|
||||
- `get_named_server_logger`
|
||||
- `get_named_main_logger`
|
||||
- 分别用于获取 基于 对应名称配置的 logger
|
||||
- Get the logger for the corresponding name configuration
|
||||
|
||||
### 移动
|
||||
|
||||
|
@ -9,6 +9,7 @@ import traceback
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from Difficult_Rocket import DR_status
|
||||
from Difficult_Rocket.main import Game
|
||||
from Difficult_Rocket.api.mod import ModInfo
|
||||
from Difficult_Rocket.api.types import Options, Version
|
||||
@ -58,7 +59,7 @@ class DR_mod(ModInfo):
|
||||
|
||||
config = DR_mod_runtime
|
||||
|
||||
# DR_version = # DR SDK 兼容版本
|
||||
DR_version = (DR_status.DR_version, DR_status.DR_version) # DR SDK 兼容版本
|
||||
# 反正是内置 mod 跟着最新版本的 DR 走就行了
|
||||
# DR_Api_version = # DR Api版本
|
||||
# 同理 不管 API 版本 这东西要是不兼容了才是大问题
|
||||
|
@ -4,12 +4,11 @@
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
import math
|
||||
# import math
|
||||
import time
|
||||
import random
|
||||
import logging
|
||||
import traceback
|
||||
from xml.etree import ElementTree
|
||||
# from xml.etree import ElementTree
|
||||
from xml.etree.ElementTree import Element
|
||||
from typing import List, TYPE_CHECKING, Union, Dict, Optional, Generator
|
||||
|
||||
@ -21,7 +20,7 @@ from pyglet.math import Vec4
|
||||
from pyglet.text import Label
|
||||
from pyglet.shapes import Line, Rectangle
|
||||
from pyglet.sprite import Sprite
|
||||
from pyglet.image import Texture
|
||||
# from pyglet.image import Texture
|
||||
from pyglet.graphics import Batch, Group
|
||||
|
||||
from . import DR_mod_runtime
|
||||
@ -32,6 +31,7 @@ from Difficult_Rocket.utils.translate import tr
|
||||
from Difficult_Rocket.api.types import Fonts, Options
|
||||
from Difficult_Rocket.command.line import CommandText
|
||||
from Difficult_Rocket.client.screen import BaseScreen
|
||||
from Difficult_Rocket.api.log import get_named_client_logger
|
||||
from .types import SR1Textures, SR1PartTexture, SR1PartData, SR1Rotation, xml_bool
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -40,7 +40,7 @@ if TYPE_CHECKING:
|
||||
if DR_mod_runtime.use_DR_rust:
|
||||
from .Difficult_Rocket_rs import CenterCamera_rs, SR1PartList_rs, SR1Ship_rs
|
||||
|
||||
logger = logging.getLogger('client')
|
||||
logger = get_named_client_logger('dr_game_sr1_ship')
|
||||
|
||||
|
||||
def get_sr1_part(part_xml: Element) -> Optional[SR1PartData]:
|
||||
|
Loading…
Reference in New Issue
Block a user