mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 11:34:59 +08:00
165 lines
4.1 KiB
Rust
165 lines
4.1 KiB
Rust
//! 游戏客户端领域对象
|
|
|
|
use std::path::PathBuf;
|
|
|
|
/// 游戏区域
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
|
pub enum GameRegion {
|
|
/// 日本服
|
|
Japan,
|
|
/// 国际服
|
|
Global,
|
|
/// 韩国服
|
|
Korea,
|
|
/// 国服
|
|
China,
|
|
}
|
|
|
|
impl GameRegion {
|
|
/// 获取区域代码
|
|
pub fn code(&self) -> &'static str {
|
|
match self {
|
|
Self::Japan => "JP",
|
|
Self::Global => "GLOBAL",
|
|
Self::Korea => "KR",
|
|
Self::China => "CN",
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 客户端状态
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
|
pub enum ClientStatus {
|
|
/// 原始状态(未修改)
|
|
Pristine,
|
|
/// 已应用翻译
|
|
Translated,
|
|
/// 损坏(需要修复)
|
|
Corrupted,
|
|
/// 未知状态
|
|
Unknown,
|
|
}
|
|
|
|
/// 游戏客户端
|
|
///
|
|
/// 代表用户本地安装的 Blue Archive 游戏客户端
|
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
pub struct GameClient {
|
|
/// 安装路径
|
|
pub install_path: PathBuf,
|
|
|
|
/// 游戏区域
|
|
pub region: GameRegion,
|
|
|
|
/// 当前状态
|
|
pub status: ClientStatus,
|
|
}
|
|
|
|
impl GameClient {
|
|
/// 创建新的游戏客户端实例
|
|
///
|
|
/// # 参数
|
|
/// - `install_path`: 游戏安装目录
|
|
/// - `region`: 游戏区域
|
|
pub fn new(install_path: PathBuf, region: GameRegion) -> Self {
|
|
Self {
|
|
install_path,
|
|
region,
|
|
status: ClientStatus::Unknown,
|
|
}
|
|
}
|
|
|
|
/// 发现本地安装的客户端
|
|
///
|
|
/// # 返回
|
|
/// - 成功:返回找到的所有客户端
|
|
/// - 失败:返回错误
|
|
///
|
|
/// # 注意
|
|
/// 此功能将在 Phase 3 实现
|
|
pub fn discover() -> crate::Result<Vec<GameClient>> {
|
|
Err(crate::Error::NotImplemented(
|
|
"客户端发现功能将在 Phase 3 实现".to_string(),
|
|
))
|
|
}
|
|
|
|
/// 验证客户端完整性
|
|
///
|
|
/// # 返回
|
|
/// - true: 客户端完整
|
|
/// - false: 客户端损坏
|
|
///
|
|
/// # 注意
|
|
/// 此功能将在 Phase 3 实现
|
|
pub fn verify_integrity(&self) -> crate::Result<bool> {
|
|
Err(crate::Error::NotImplemented(
|
|
"完整性验证将在 Phase 3 实现".to_string(),
|
|
))
|
|
}
|
|
|
|
/// 获取 StreamingAssets 目录路径
|
|
pub fn streaming_assets_path(&self) -> PathBuf {
|
|
self.install_path
|
|
.join("BlueArchive_Data")
|
|
.join("StreamingAssets")
|
|
}
|
|
|
|
/// 获取 AssetBundles 目录路径
|
|
pub fn asset_bundles_path(&self) -> PathBuf {
|
|
self.streaming_assets_path().join("AssetBundles")
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_game_region_code() {
|
|
assert_eq!(GameRegion::Japan.code(), "JP");
|
|
assert_eq!(GameRegion::Global.code(), "GLOBAL");
|
|
assert_eq!(GameRegion::Korea.code(), "KR");
|
|
assert_eq!(GameRegion::China.code(), "CN");
|
|
}
|
|
|
|
#[test]
|
|
fn test_new_game_client() {
|
|
let path = PathBuf::from("/test/path");
|
|
let client = GameClient::new(path.clone(), GameRegion::Japan);
|
|
|
|
assert_eq!(client.install_path, path);
|
|
assert_eq!(client.region, GameRegion::Japan);
|
|
assert_eq!(client.status, ClientStatus::Unknown);
|
|
}
|
|
|
|
#[test]
|
|
fn test_streaming_assets_path() {
|
|
let client = GameClient::new(PathBuf::from("/game/BlueArchive_JP"), GameRegion::Japan);
|
|
|
|
assert_eq!(
|
|
client.streaming_assets_path(),
|
|
PathBuf::from("/game/BlueArchive_JP/BlueArchive_Data/StreamingAssets")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_asset_bundles_path() {
|
|
let client = GameClient::new(PathBuf::from("/game/BlueArchive_JP"), GameRegion::Japan);
|
|
|
|
assert_eq!(
|
|
client.asset_bundles_path(),
|
|
PathBuf::from("/game/BlueArchive_JP/BlueArchive_Data/StreamingAssets/AssetBundles")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_discover_not_implemented() {
|
|
let result = GameClient::discover();
|
|
assert!(result.is_err());
|
|
assert!(matches!(
|
|
result.unwrap_err(),
|
|
crate::Error::NotImplemented(_)
|
|
));
|
|
}
|
|
}
|