diff --git a/src/MaaWpfGui/Extensions/DateTimeExtension.cs b/src/MaaWpfGui/Extensions/DateTimeExtension.cs index d25053c601..fb9ca898aa 100644 --- a/src/MaaWpfGui/Extensions/DateTimeExtension.cs +++ b/src/MaaWpfGui/Extensions/DateTimeExtension.cs @@ -28,13 +28,12 @@ public static class DateTimeExtension private static readonly Dictionary _clientTypeTimezone = new() { - { string.Empty, 8 }, - { "Official", 8 }, - { "Bilibili", 8 }, - { "txwy", 8 }, - { "YoStarEN", -7 }, - { "YoStarJP", 9 }, - { "YoStarKR", 9 }, + { Constants.Enums.ClientType.Official, 8 }, + { Constants.Enums.ClientType.Bilibili, 8 }, + { Constants.Enums.ClientType.Txwy, 8 }, + { Constants.Enums.ClientType.EN, -7 }, + { Constants.Enums.ClientType.JP, 9 }, + { Constants.Enums.ClientType.KR, 9 }, }; public static DateTime ToYjDateTime(this DateTime dt) diff --git a/src/MaaWpfGui/Helper/DataHelper.cs b/src/MaaWpfGui/Helper/DataHelper.cs index e19bb6f30d..fc565c4a40 100644 --- a/src/MaaWpfGui/Helper/DataHelper.cs +++ b/src/MaaWpfGui/Helper/DataHelper.cs @@ -30,20 +30,20 @@ public static class DataHelper { public static readonly Dictionary ClientDirectoryMapper = new() { - { "zh-tw", "txwy" }, - { "en-us", "YoStarEN" }, - { "ja-jp", "YoStarJP" }, - { "ko-kr", "YoStarKR" }, + { "zh-tw", ClientType.Txwy }, + { "en-us", ClientType.EN }, + { "ja-jp", ClientType.JP }, + { "ko-kr", ClientType.KR }, }; public static readonly Dictionary ClientLanguageMapper = new() { - { "Official", "zh-cn" }, - { "Bilibili", "zh-cn" }, - { "YoStarEN", "en-us" }, - { "YoStarJP", "ja-jp" }, - { "YoStarKR", "ko-kr" }, - { "txwy", "zh-tw" }, + { ClientType.Official, "zh-cn" }, + { ClientType.Bilibili, "zh-cn" }, + { ClientType.EN, "en-us" }, + { ClientType.JP, "ja-jp" }, + { ClientType.KR, "ko-kr" }, + { ClientType.Txwy, "zh-tw" }, }; /// @@ -191,15 +191,15 @@ public static class DataHelper { return str switch { - "zh-cn" or "Official" or "Bilibili" => + "zh-cn" or ClientType.Official or ClientType.Bilibili => v => CharacterNames.Add(v.Name ?? string.Empty), - "zh-tw" or "txwy" => + "zh-tw" or ClientType.Txwy => v => CharacterNames.Add(v.NameTw ?? string.Empty), - "en-us" or "YoStarEN" => + "en-us" or ClientType.EN => v => CharacterNames.Add(v.NameEn ?? string.Empty), - "ja-jp" or "YoStarJP" => + "ja-jp" or ClientType.JP => v => CharacterNames.Add(v.NameJp ?? string.Empty), - "ko-kr" or "YoStarKR" => + "ko-kr" or ClientType.KR => v => CharacterNames.Add(v.NameKr ?? string.Empty), _ => v => CharacterNames.Add(v.Name ?? string.Empty), @@ -295,10 +295,10 @@ public static class DataHelper return clientType switch { - "zh-tw" or "txwy" => !character.NameTwUnavailable, - "en-us" or "YoStarEN" => !character.NameEnUnavailable, - "ja-jp" or "YoStarJP" => !character.NameJpUnavailable, - "ko-kr" or "YoStarKR" => !character.NameKrUnavailable, + "zh-tw" or ClientType.Txwy => !character.NameTwUnavailable, + "en-us" or ClientType.EN => !character.NameEnUnavailable, + "ja-jp" or ClientType.JP => !character.NameJpUnavailable, + "ko-kr" or ClientType.KR => !character.NameKrUnavailable, _ => true, }; } diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index a6eda438b4..cb51e90aa7 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -474,7 +474,7 @@ public class AsstProxy string globalCacheRes = Path.Combine(mainCacheRes, "global", clientType, "resource"); bool loaded; - if (clientType is "" or "Official" or "Bilibili") + if (clientType is ClientType.Official or ClientType.Bilibili) { // Read resources first, then read cache CopyTasksJson(mainCacheRes); diff --git a/src/MaaWpfGui/Services/StageManager.cs b/src/MaaWpfGui/Services/StageManager.cs index 2498a08800..2d652b43e5 100644 --- a/src/MaaWpfGui/Services/StageManager.cs +++ b/src/MaaWpfGui/Services/StageManager.cs @@ -22,6 +22,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using HandyControl.Controls; using HandyControl.Data; +using MaaWpfGui.Constants.Enums; using MaaWpfGui.Helper; using MaaWpfGui.Models; using MaaWpfGui.ViewModels.UI; @@ -114,9 +115,9 @@ public class StageManager var clientType = SettingsViewModel.GameSettings.ClientType; // 官服和B服使用同样的资源 - if (clientType is "Bilibili" or "") + if (clientType is ClientType.Bilibili) { - clientType = "Official"; + clientType = ClientType.Official; } return clientType; @@ -162,7 +163,7 @@ public class StageManager var activityJson = await activityTask; var tasksJson = await tasksTask; JObject? globalTasksJson = null; - if (clientType != "Official" && tasksJson != null) + if (clientType != ClientType.Official && tasksJson != null) { var tasksPath = "resource/global/" + clientType + '/' + TasksApi; @@ -177,7 +178,7 @@ public class StageManager return null; } - if (clientType != "Official" && globalTasksJson is null) + if (clientType != ClientType.Official && globalTasksJson is null) { return null; } diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index d59b681b45..00259b139b 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -27,6 +27,7 @@ using JetBrains.Annotations; using MaaWpfGui.Configuration.Factory; using MaaWpfGui.Configuration.Single.MaaTask; using MaaWpfGui.Constants; +using MaaWpfGui.Constants.Enums; using MaaWpfGui.Extensions; using MaaWpfGui.Helper; using MaaWpfGui.Main; @@ -959,13 +960,12 @@ public class SettingsViewModel : Screen private static readonly Dictionary _serverMapping = new() { - { string.Empty, "CN" }, - { "Official", "CN" }, - { "Bilibili", "CN" }, - { "YoStarEN", "US" }, - { "YoStarJP", "JP" }, - { "YoStarKR", "KR" }, - { "txwy", "ZH_TW" }, + { ClientType.Official, "CN" }, + { ClientType.Bilibili, "CN" }, + { ClientType.EN, "US" }, + { ClientType.JP, "JP" }, + { ClientType.KR, "KR" }, + { ClientType.Txwy, "ZH_TW" }, }; /// diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs index 54db824e07..20dc445d7e 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs @@ -58,15 +58,15 @@ public class GameSettingsUserControlModel : PropertyChangedBase /// public List ClientTypeList { get; } = [ - new() { Display = LocalizationHelper.GetString("Official"), Value = "Official" }, - new() { Display = LocalizationHelper.GetString("Bilibili"), Value = "Bilibili" }, - new() { Display = LocalizationHelper.GetString("YoStarEN"), Value = "YoStarEN" }, - new() { Display = LocalizationHelper.GetString("YoStarJP"), Value = "YoStarJP" }, - new() { Display = LocalizationHelper.GetString("YoStarKR"), Value = "YoStarKR" }, - new() { Display = LocalizationHelper.GetString("Txwy"), Value = "txwy" }, + new() { Display = LocalizationHelper.GetString("Official"), Value = Constants.Enums.ClientType.Official }, + new() { Display = LocalizationHelper.GetString("Bilibili"), Value = Constants.Enums.ClientType.Bilibili }, + new() { Display = LocalizationHelper.GetString("YoStarEN"), Value = Constants.Enums.ClientType.EN }, + new() { Display = LocalizationHelper.GetString("YoStarJP"), Value = Constants.Enums.ClientType.JP }, + new() { Display = LocalizationHelper.GetString("YoStarKR"), Value = Constants.Enums.ClientType.KR }, + new() { Display = LocalizationHelper.GetString("Txwy"), Value = Constants.Enums.ClientType.Txwy }, ]; - private string _clientType = ConfigurationHelper.GetValue(ConfigurationKeys.ClientType, "Official"); + private string _clientType = ConfigurationHelper.GetValue(ConfigurationKeys.ClientType, Constants.Enums.ClientType.Official); /// /// Gets or sets the client type. diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs index 632c87d0bd..12af449921 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs @@ -41,7 +41,7 @@ namespace MaaWpfGui.ViewModels.UserControl.TaskQueue; /// public class FightSettingsUserControlModel : TaskSettingsViewModel, FightSettingsUserControlModel.ISerialize { - public static readonly string AnnihilationName = "Annihilation"; + public const string AnnihilationName = "Annihilation"; private static readonly ILogger _logger = Log.ForContext(); private static readonly Lock _lock = new();