2022-02-16 13:36:26 +08:00
|
|
|
# -------------------------------
|
|
|
|
# Difficult Rocket
|
2023-01-20 14:08:12 +08:00
|
|
|
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
2022-02-16 13:36:26 +08:00
|
|
|
# All rights reserved
|
|
|
|
# -------------------------------
|
|
|
|
|
2023-05-03 18:03:07 +08:00
|
|
|
# system function
|
2023-06-17 00:06:39 +08:00
|
|
|
import warnings
|
2023-05-03 18:03:07 +08:00
|
|
|
from typing import Tuple, List, Optional, TypeVar, TYPE_CHECKING
|
2023-04-19 00:42:31 +08:00
|
|
|
|
2023-05-03 18:03:07 +08:00
|
|
|
# from DR
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from Difficult_Rocket.main import Game
|
|
|
|
from Difficult_Rocket.client import ClientWindow
|
|
|
|
else:
|
|
|
|
Game = TypeVar("Game")
|
|
|
|
ClientWindow = TypeVar("ClientWindow")
|
2023-06-16 23:36:24 +08:00
|
|
|
from Difficult_Rocket import DR_status
|
2023-06-10 18:08:40 +08:00
|
|
|
from Difficult_Rocket.api.types import Options, Version
|
2023-05-03 18:03:07 +08:00
|
|
|
|
|
|
|
RequireVersion = Tuple[Version, Version]
|
|
|
|
# 第一个是最低兼容版本,第二个是最高兼容版本
|
|
|
|
# 例如: ("1.0.0", "1.1.0") 表示从1.0.0版本开始兼容,到1.1.0版本结束兼容
|
|
|
|
ForceRequire = bool
|
|
|
|
|
|
|
|
|
|
|
|
class ModInfo(Options):
|
|
|
|
"""
|
|
|
|
加载mod时候的参数
|
|
|
|
"""
|
2023-12-03 16:54:07 +08:00
|
|
|
|
2023-05-03 18:03:07 +08:00
|
|
|
"""基本信息"""
|
|
|
|
mod_id: str # mod id
|
|
|
|
name: str # mod 名称
|
|
|
|
version: Version # mod 版本
|
|
|
|
|
|
|
|
"""作者、描述"""
|
|
|
|
writer: str # 作者
|
|
|
|
link: str = "" # 作者链接
|
|
|
|
description: str = "" # 描述 (务必简洁明了)
|
|
|
|
info: str = "" # 其他信息 (可以很多很多)
|
|
|
|
|
|
|
|
"""版本相关信息"""
|
2023-12-03 16:54:07 +08:00
|
|
|
DR_version: RequireVersion = (
|
|
|
|
DR_status.DR_version,
|
|
|
|
DR_status.DR_version,
|
|
|
|
) # DR SDK 兼容版本
|
|
|
|
DR_Api_version: RequireVersion = (
|
|
|
|
DR_status.API_version,
|
|
|
|
DR_status.API_version,
|
|
|
|
) # DR Api版本
|
|
|
|
Mod_Require_version: List[
|
|
|
|
Tuple[str, ForceRequire, RequireVersion]
|
|
|
|
] = [] # mod 依赖版本
|
2023-05-03 18:03:07 +08:00
|
|
|
|
|
|
|
"""mod 状态"""
|
|
|
|
is_enable: bool = True # 是否启用
|
|
|
|
is_loaded: bool = False # 是否加载
|
|
|
|
|
|
|
|
"""mod 配置"""
|
|
|
|
config: Options = Options() # mod 配置存储
|
|
|
|
old_mod: Optional["ModInfo"] = None # 旧的mod实例
|
|
|
|
|
2023-06-17 00:06:39 +08:00
|
|
|
def __init__(self, **kwargs):
|
|
|
|
if not self.DR_version[0] <= DR_status.DR_version <= self.DR_version[1]:
|
2023-12-03 16:54:07 +08:00
|
|
|
warnings.warn(
|
2024-05-26 14:01:48 +08:00
|
|
|
f"mod {self.mod_id} version {self.version} "
|
|
|
|
f"is not support by DR {DR_status.DR_version}\n"
|
2023-12-03 16:54:07 +08:00
|
|
|
f"DR {self.DR_version} is required"
|
|
|
|
)
|
2023-06-17 00:06:39 +08:00
|
|
|
if not self.DR_Api_version[0] <= DR_status.API_version <= self.DR_Api_version[1]:
|
2023-12-03 16:54:07 +08:00
|
|
|
warnings.warn(
|
2024-05-26 14:01:48 +08:00
|
|
|
f"mod {self.mod_id} version {self.version} "
|
|
|
|
f"is not support by DR {DR_status.API_version}\n"
|
2023-12-03 16:54:07 +08:00
|
|
|
f"DR {self.DR_Api_version} is required"
|
|
|
|
)
|
2023-06-17 00:06:39 +08:00
|
|
|
super().__init__(**kwargs)
|
|
|
|
|
2023-05-03 18:03:07 +08:00
|
|
|
def on_load(self, game: Game, old_self: Optional["ModInfo"] = None) -> bool:
|
2023-12-03 16:54:07 +08:00
|
|
|
"""加载时调用"""
|
2023-05-03 18:03:07 +08:00
|
|
|
return True
|
|
|
|
|
|
|
|
def on_client_start(self, game: Game, client: ClientWindow):
|
2023-12-03 16:54:07 +08:00
|
|
|
"""客户端启动时调用"""
|
|
|
|
print(f"Mod {self.mod_id} client start")
|
2023-05-03 18:03:07 +08:00
|
|
|
|
2023-12-03 16:54:07 +08:00
|
|
|
def on_client_stop(self, game: Game, client: ClientWindow, source: str = "window"):
|
|
|
|
"""客户端停止时调用"""
|
|
|
|
print(f"Mod {self.mod_id} client stop")
|
2023-05-03 18:03:07 +08:00
|
|
|
|
|
|
|
def on_server_start(self, game: Game):
|
2023-12-03 16:54:07 +08:00
|
|
|
"""服务器启动时调用"""
|
|
|
|
print(f"Mod {self.mod_id} server start")
|
2023-05-03 18:03:07 +08:00
|
|
|
|
|
|
|
def on_server_stop(self, game: Game):
|
2023-12-03 16:54:07 +08:00
|
|
|
"""服务器停止时调用"""
|
|
|
|
print(f"Mod {self.mod_id} server stop")
|
2023-05-03 18:03:07 +08:00
|
|
|
|
|
|
|
def on_unload(self, game: Game):
|
2023-12-03 16:54:07 +08:00
|
|
|
"""卸载时调用"""
|
|
|
|
print(f"Mod {self.mod_id} unloaded")
|