Difficult-Rocket/mods/dr_game/__init__.py

110 lines
3.5 KiB
Python
Raw Normal View History

2023-04-22 10:39:18 +08:00
# -------------------------------
2023-04-22 15:18:35 +08:00
# Difficult Rocket Mod
2023-04-22 10:39:18 +08:00
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
# All rights reserved
# -------------------------------
2023-04-22 15:18:35 +08:00
2023-04-30 00:48:42 +08:00
import traceback
2023-04-26 23:37:32 +08:00
from typing import Optional
2023-06-17 00:06:39 +08:00
from Difficult_Rocket import DR_status
2023-05-25 00:40:20 +08:00
from Difficult_Rocket.main import Game
2023-04-26 11:18:11 +08:00
from Difficult_Rocket.api.mod import ModInfo
from Difficult_Rocket.client import ClientWindow
from Difficult_Rocket.api.types import Options, Version
2023-04-24 19:27:36 +08:00
from lib_not_dr import loggers
2024-05-16 00:33:25 +08:00
DR_rust_version = Version("0.3.3") # DR_mod 的 Rust 编写部分的兼容版本
2023-04-30 00:48:42 +08:00
logger = loggers.config.get_logger_from_old("client.dr_game", "client")
2023-06-17 14:34:19 +08:00
2023-07-21 13:10:21 +08:00
class _DR_mod_runtime(Options): # NOQA
2023-12-03 16:54:07 +08:00
name = "DR mod runtime"
2023-04-30 00:48:42 +08:00
use_DR_rust: bool = True
DR_rust_available: bool = False
DR_rust_version: Version = DR_rust_version
DR_rust_get_version: Optional[Version] = None
def init(self) -> None:
2023-04-30 00:48:42 +08:00
try:
2023-05-02 17:23:02 +08:00
from .Difficult_Rocket_rs import get_version_str
2023-12-03 16:54:07 +08:00
2023-04-30 00:48:42 +08:00
self.DR_rust_get_version = Version(get_version_str())
self.DR_rust_available = True
if self.DR_rust_get_version != self.DR_rust_version:
2023-12-03 16:54:07 +08:00
relationship = (
"larger" if self.DR_rust_version > self.DR_rust_version else "smaller"
)
2023-12-23 01:03:36 +08:00
logger.warn(
2024-05-16 00:33:25 +08:00
f"DR_rust builtin version is {self.DR_rust_version} "
f"but true version is {get_version_str()}.\n"
2023-12-30 22:07:01 +08:00
f"Builtin version {relationship} than true version",
tag="load_dll",
2023-12-03 16:54:07 +08:00
)
2023-04-30 00:48:42 +08:00
self.use_DR_rust = self.use_DR_rust and self.DR_rust_available
except Exception:
2023-04-30 00:48:42 +08:00
traceback.print_exc()
self.DR_rust_available = False
self.use_DR_rust = False
2023-12-23 01:03:36 +08:00
logger.warn(f"DR_rust load faild\n{traceback.format_exc()}", tag="load_dll")
2023-04-30 00:48:42 +08:00
self.flush_option()
DR_mod_runtime = _DR_mod_runtime()
2023-04-24 19:27:36 +08:00
2023-07-21 13:10:21 +08:00
class DR_mod(ModInfo): # NOQA
2023-04-26 11:18:11 +08:00
mod_id = "difficult_rocket_mod"
2023-04-24 19:27:36 +08:00
name = "Difficult Rocket mod"
2023-08-12 01:49:01 +08:00
version = Version("0.3.3.0")
2023-04-24 19:27:36 +08:00
writer = "shenjackyuanjie"
link = "shenjack.top"
description = "Difficult Rocket mod (where the game implement)"
info = "Difficult Rocket mod (where the game implement)"
2023-04-30 00:48:42 +08:00
config = DR_mod_runtime
2023-06-17 00:06:39 +08:00
DR_version = (DR_status.DR_version, DR_status.DR_version) # DR SDK 兼容版本
2023-06-17 16:16:55 +08:00
2023-04-24 19:27:36 +08:00
# 反正是内置 mod 跟着最新版本的 DR 走就行了
# DR_Api_version = # DR Api版本
# 同理 不管 API 版本 这东西要是不兼容了才是大问题
def on_load(self, game: Game, old_self: Optional["DR_mod"] = None) -> bool:
if not DR_mod_runtime.DR_rust_available:
return False
from .console import RustConsole
2023-05-14 20:42:18 +08:00
game.console_class = RustConsole # 替换掉原来的 console 类
2023-04-26 23:37:32 +08:00
if old_self:
2023-06-26 10:14:28 +08:00
from .sr1_ship import SR1ShipRender
2023-12-03 16:54:07 +08:00
2023-06-26 10:14:28 +08:00
game.client.window.add_sub_screen("SR1_ship", SR1ShipRender)
2023-04-30 00:48:42 +08:00
else:
self.config.flush_option()
2023-06-17 14:34:19 +08:00
logger.info("on_load")
2023-07-21 23:10:57 +08:00
logger.info(f"\n{self.as_markdown()}")
return True
2023-04-24 19:27:36 +08:00
2023-04-26 11:18:11 +08:00
def on_client_start(self, game: Game, client: ClientWindow):
2023-04-30 00:48:42 +08:00
from .sr1_ship import SR1ShipRender
2024-01-20 00:38:32 +08:00
from .menu import Menu
client.add_sub_screen("DR_game_menu", Menu)
logger.info("added dr_game_menu screen", tag="dr_game")
2023-12-03 16:54:07 +08:00
2023-04-26 11:18:11 +08:00
client.add_sub_screen("SR1_ship", SR1ShipRender)
2024-01-20 00:38:32 +08:00
logger.info("added SR1_ship screen", tag="dr_game")
2023-06-17 14:34:19 +08:00
def on_unload(self, game: Game):
2023-06-26 10:14:28 +08:00
game.client.window.screen_list.pop("SR1_ship")
2023-06-17 14:34:19 +08:00
2023-04-26 11:18:11 +08:00
2023-04-24 19:27:36 +08:00
mod_class = DR_mod