diff --git a/docs/en-us/protocol/task-schema.md b/docs/en-us/protocol/task-schema.md index 3998b43eb7..81bffe6157 100644 --- a/docs/en-us/protocol/task-schema.md +++ b/docs/en-us/protocol/task-schema.md @@ -65,7 +65,7 @@ Usage of `resource/tasks.json` and description of each field // Auto-scaling to 1280x720; default when not filled [ 0, 0, 1280, 720 ] // Fill in as much as possible, reducing the recognition range can reduce performance consumption and speed up recognition - "cache": true, // Optional, indicates whether the task uses caching or not, default is true; + "cache": false, // Optional, indicates whether the task uses caching or not, default is false; // After the first recognition, only the first recognized position will be recognized forever, enable to save performance significantly // but only for tasks where the location of the target to be recognized will not change at all, set to false if the location of the target to be recognized will change diff --git a/docs/ja-jp/protocol/task-schema.md b/docs/ja-jp/protocol/task-schema.md index dd1760bc20..65884bf86c 100644 --- a/docs/ja-jp/protocol/task-schema.md +++ b/docs/ja-jp/protocol/task-schema.md @@ -69,7 +69,7 @@ JSONファイルはコメントをサポートしていません。テキスト // 1280 * 720 に自動スケーリングします;指定されていない場合はデフォルトで [ 0, 0, 1280, 720 ] // できるだけ記入し、認識範囲を縮小するとパフォーマンス消費が低下し、認識が高速化されます - "cache": true, // オプション、タスクがキャッシュを使用するかどうかを示します、デフォルトは true です; + "cache": false, // オプション、タスクがキャッシュを使用するかどうかを示します、デフォルトは false です; // 最初の認識後、常に最初に認識された位置のみが永久に認識されます。パフォーマンスを著しく向上させるために有効にします // ただし、特定する対象場所が全く変わらないタスクのみ適用され、特定する対象場所が変わる場合は false に設定してください diff --git a/docs/ko-kr/protocol/task-schema.md b/docs/ko-kr/protocol/task-schema.md index 292b0d4046..86ccaa5136 100644 --- a/docs/ko-kr/protocol/task-schema.md +++ b/docs/ko-kr/protocol/task-schema.md @@ -69,7 +69,7 @@ icon: material-symbols:task // 자동으로 1280 * 720으로 확장됩니다. 입력하지 않으면 기본값은 [ 0, 0, 1280, 720 ]입니다. // 가능한 한 많이 작성하고 인식 범위를 축소하면 성능 소비가 줄어들고 인식 속도가 빨라질 수 있습니다. - "cache": true, // 선택 사항, 작업이 캐싱을 사용하는지 여부를 나타냅니다. 기본값은 true입니다. + "cache": false, // 선택 사항, 작업이 캐싱을 사용하는지 여부를 나타냅니다. 기본값은 false입니다. // 최초 인식 이후에는 해당 위치만 인식하며, 성능을 크게 개선할 수 있습니다. diff --git a/docs/zh-cn/protocol/task-schema.md b/docs/zh-cn/protocol/task-schema.md index cecf86dfec..be3ee05b9a 100644 --- a/docs/zh-cn/protocol/task-schema.md +++ b/docs/zh-cn/protocol/task-schema.md @@ -69,7 +69,7 @@ icon: material-symbols:task // 以 1280 * 720 为基准自动缩放;不填写时默认 [ 0, 0, 1280, 720 ] // 尽量填写,减小识别范围可以减少性能消耗,加快识别速度 - "cache": true, // 可选项,表示该任务是否使用缓存,默认为 true; + "cache": false, // 可选项,表示该任务是否使用缓存,默认为 false; // 第一次识别到后,以后永远只在第一次识别到的位置进行识别,开启可大幅节省性能 // 但仅适用于待识别目标位置完全不会变的任务,若待识别目标位置会变请设为 false diff --git a/docs/zh-tw/protocol/task-schema.md b/docs/zh-tw/protocol/task-schema.md index b72b01decc..f49b6ad9e8 100644 --- a/docs/zh-tw/protocol/task-schema.md +++ b/docs/zh-tw/protocol/task-schema.md @@ -68,7 +68,7 @@ icon: material-symbols:task // 以 1280 * 720 為基準自動縮放,不填寫時預設 [ 0, 0, 1280, 720 ] // 儘量填寫,減小辨識範圍可以減少性能消耗,加快辨識速度 - "cache": true, // 可選項,表示該任務是否使用快取,預設為 true + "cache": false, // 可選項,表示該任務是否使用快取,預設為 false // 第一次辨識到後,以後永遠只在第一次辨識到的位置進行辨識,開啟可大幅節省性能 // 但僅適用於待辨識目標位置完全不會變的任務,若待辨識目標位置會變請設為 false diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index c9a93c660a..2167a7a145 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -10,7 +10,7 @@ // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY // - +#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; @@ -153,7 +153,7 @@ namespace MaaWpfGui.Main } */ - public static unsafe BitmapImage AsstGetImage(AsstHandle handle) + public static unsafe BitmapImage? AsstGetImage(AsstHandle handle) { byte[] buff = new byte[1280 * 720 * 3]; ulong readSize; @@ -182,7 +182,7 @@ namespace MaaWpfGui.Main } } - public BitmapImage AsstGetImage() + public BitmapImage? AsstGetImage() { return AsstGetImage(_handle); } @@ -324,7 +324,7 @@ namespace MaaWpfGui.Main [DllImport("ucrtbase.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] internal static extern int strlen(AsstHandle ptr); - private static string PtrToStringCustom(AsstHandle ptr, Encoding enc) + private static string? PtrToStringCustom(AsstHandle ptr, Encoding enc) { if (ptr == AsstHandle.Zero) { @@ -348,7 +348,7 @@ namespace MaaWpfGui.Main string jsonStr = PtrToStringCustom(jsonBuffer, Encoding.UTF8); // Console.WriteLine(json_str); - var json = (JObject)JsonConvert.DeserializeObject(jsonStr); + var json = (JObject?)JsonConvert.DeserializeObject(jsonStr); MaaService.ProcCallbackMsg dlg = ProcMsg; Execute.OnUIThread( () => @@ -431,7 +431,7 @@ namespace MaaWpfGui.Main break; case "Reconnecting": - Instances.TaskQueueViewModel.AddLog($"{LocalizationHelper.GetString("TryToReconnect")} ({Convert.ToUInt32(details["details"]["times"]) + 1})", UiLogColor.Error); + Instances.TaskQueueViewModel.AddLog($"{LocalizationHelper.GetString("TryToReconnect")} ({Convert.ToUInt32(details!["details"]!["times"]) + 1})", UiLogColor.Error); break; case "Reconnected": @@ -556,9 +556,9 @@ namespace MaaWpfGui.Main } } - private DispatcherTimer _toastNotificationTimer; + private DispatcherTimer? _toastNotificationTimer; - private void OnToastNotificationTimerTick(object sender, EventArgs e) + private void OnToastNotificationTimerTick(object? sender, EventArgs e) { var sanityReport = LocalizationHelper.GetString("SanityReport"); var recoveryTime = SanityReport.ReportTime.AddMinutes(SanityReport.Sanity[0] < SanityReport.Sanity[1] ? (SanityReport.Sanity[1] - SanityReport.Sanity[0]) * 6 : 0); @@ -623,7 +623,7 @@ namespace MaaWpfGui.Main { Instances.TaskQueueViewModel.Stage1, Instances.TaskQueueViewModel.Stage2, - Instances.TaskQueueViewModel.Stage3 + Instances.TaskQueueViewModel.Stage3, }.Any(stage => Instances.TaskQueueViewModel.IsStageOpen(stage) && (stage != "Annihilation"))) { Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AnnihilationTaskFailed"), UiLogColor.Warning); @@ -942,7 +942,7 @@ namespace MaaWpfGui.Main case "ReportToPenguinStats": { - var why = details["why"].ToString(); + var why = details!["why"].ToString(); Instances.TaskQueueViewModel.AddLog(why + "," + LocalizationHelper.GetString("GiveUpUploadingPenguins"), UiLogColor.Error); break; } @@ -980,7 +980,7 @@ namespace MaaWpfGui.Main { case "ProcessTask": { - string taskName = details["details"]?["task"]?.ToString(); + string taskName = details!["details"]?["task"]?.ToString(); int execTimes = (int)details["details"]["exec_times"]; switch (taskName) @@ -1113,7 +1113,7 @@ namespace MaaWpfGui.Main case "CombatRecordRecognitionTask": { - string what = details["what"]?.ToString(); + var what = details["what"]?.ToString(); if (!string.IsNullOrEmpty(what)) { Instances.CopilotViewModel.AddLog(what); @@ -1162,12 +1162,12 @@ namespace MaaWpfGui.Main case "StageDrops": { string allDrops = string.Empty; - var statistics = subTaskDetails["stats"] ?? new JArray(); + var statistics = subTaskDetails!["stats"] ?? new JArray(); int curTimes = (int)(subTaskDetails["cur_times"] ?? -1); foreach (var item in statistics) { - string itemName = item["itemName"]?.ToString(); + var itemName = item["itemName"]?.ToString(); if (itemName == "furni") { itemName = LocalizationHelper.GetString("FurnitureDrop"); @@ -1193,7 +1193,7 @@ namespace MaaWpfGui.Main } case "EnterFacility": - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("ThisFacility") + subTaskDetails["facility"] + " " + (int)subTaskDetails["index"]); + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("ThisFacility") + subTaskDetails!["facility"] + " " + (int)subTaskDetails["index"]); break; case "ProductIncorrect": @@ -1210,7 +1210,7 @@ namespace MaaWpfGui.Main case "RecruitTagsDetected": { - var tags = subTaskDetails["tags"] ?? new JArray(); + var tags = subTaskDetails!["tags"] ?? new JArray(); string logContent = tags.Select(tagName => tagName.ToString()) .Aggregate(string.Empty, (current, tagStr) => current + (tagStr + "\n")); @@ -1222,7 +1222,7 @@ namespace MaaWpfGui.Main case "RecruitSpecialTag": { - string special = subTaskDetails["tag"]?.ToString(); + string special = subTaskDetails!["tag"]?.ToString(); if (special == "支援机械" && Instances.SettingsViewModel.NotChooseLevel1 == false) { break; @@ -1236,7 +1236,7 @@ namespace MaaWpfGui.Main case "RecruitRobotTag": { - string special = subTaskDetails["tag"]?.ToString(); + string special = subTaskDetails!["tag"]?.ToString(); using var toast = new ToastNotification(LocalizationHelper.GetString("RecruitingTips")); toast.AppendContentText(special).ShowRecruitRobot(); @@ -1245,7 +1245,7 @@ namespace MaaWpfGui.Main case "RecruitResult": { - int level = (int)subTaskDetails["level"]; + int level = (int)subTaskDetails!["level"]!; if (level >= 5) { using (var toast = new ToastNotification(string.Format(LocalizationHelper.GetString("RecruitmentOfStar"), level))) @@ -1290,14 +1290,14 @@ namespace MaaWpfGui.Main case "RecruitTagsRefreshed": { - int refreshCount = (int)subTaskDetails["count"]; + int refreshCount = (int)subTaskDetails!["count"]!; Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("Refreshed") + refreshCount + LocalizationHelper.GetString("UnitTime")); break; } case "RecruitNoPermit": { - bool continueRefresh = (bool)subTaskDetails["continue"]; + bool continueRefresh = (bool)subTaskDetails!["continue"]!; Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString(continueRefresh ? "ContinueRefresh" : "NoRecruitmentPermit")); break; } @@ -1308,18 +1308,18 @@ namespace MaaWpfGui.Main case "CreditFullOnlyBuyDiscount": { - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("CreditFullOnlyBuyDiscount") + subTaskDetails["credit"], UiLogColor.Message); + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("CreditFullOnlyBuyDiscount") + subTaskDetails!["credit"], UiLogColor.Message); break; } case "RoguelikeInvestment": - Instances.TaskQueueViewModel.AddLog(string.Format(LocalizationHelper.GetString("RoguelikeInvestment"), subTaskDetails["count"], subTaskDetails["total"], subTaskDetails["deposit"]), UiLogColor.Info); + Instances.TaskQueueViewModel.AddLog(string.Format(LocalizationHelper.GetString("RoguelikeInvestment"), subTaskDetails!["count"], subTaskDetails["total"], subTaskDetails["deposit"]), UiLogColor.Info); break; case "RoguelikeSettlement": {// 肉鸽结算 var report = subTaskDetails; - bool pass = (bool)report["game_pass"]; + var pass = (bool)report!["game_pass"]!; StringBuilder roguelikeInfo = new(); roguelikeInfo.AppendFormat( LocalizationHelper.GetString("RoguelikeSettlement"), @@ -1343,7 +1343,7 @@ namespace MaaWpfGui.Main /* Roguelike */ case "StageInfo": { - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("StartCombat") + subTaskDetails["name"]); + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("StartCombat") + subTaskDetails!["name"]); if (Instances.SettingsViewModel.RoguelikeDelayAbortUntilCombatComplete) { Instances.TaskQueueViewModel.RoguelikeInCombatAndShowWait = true; @@ -1362,35 +1362,35 @@ namespace MaaWpfGui.Main break; case "RoguelikeEvent": - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("RoguelikeEvent") + $" {subTaskDetails["name"]}"); + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("RoguelikeEvent") + $" {subTaskDetails!["name"]}"); break; case "FoldartalGainOcrNextLevel": - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("FoldartalGainOcrNextLevel") + $" {subTaskDetails["foldartal"]}"); + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("FoldartalGainOcrNextLevel") + $" {subTaskDetails!["foldartal"]}"); break; case "PenguinId": { - string id = subTaskDetails["id"]?.ToString(); + string id = subTaskDetails!["id"]?.ToString(); Instances.SettingsViewModel.PenguinId = id; break; } case "BattleFormation": - Instances.CopilotViewModel.AddLog(LocalizationHelper.GetString("BattleFormation") + "\n" + JsonConvert.SerializeObject(subTaskDetails["formation"])); + Instances.CopilotViewModel.AddLog(LocalizationHelper.GetString("BattleFormation") + "\n" + JsonConvert.SerializeObject(subTaskDetails!["formation"])); break; case "BattleFormationSelected": - Instances.CopilotViewModel.AddLog(LocalizationHelper.GetString("BattleFormationSelected") + subTaskDetails["selected"]); + Instances.CopilotViewModel.AddLog(LocalizationHelper.GetString("BattleFormationSelected") + subTaskDetails!["selected"]); break; case "CopilotAction": { - string doc = subTaskDetails["doc"]?.ToString(); + var doc = subTaskDetails!["doc"]?.ToString(); if (!string.IsNullOrEmpty(doc)) { - string color = subTaskDetails["doc_color"]?.ToString(); + var color = subTaskDetails["doc_color"]?.ToString(); Instances.CopilotViewModel.AddLog(doc, string.IsNullOrEmpty(color) ? UiLogColor.Message : color); } @@ -1404,15 +1404,15 @@ namespace MaaWpfGui.Main } case "CopilotListLoadTaskFileSuccess": - Instances.CopilotViewModel.AddLog($"Parse {subTaskDetails["file_name"]}[{subTaskDetails["stage_name"]}] Success"); + Instances.CopilotViewModel.AddLog($"Parse {subTaskDetails!["file_name"]}[{subTaskDetails["stage_name"]}] Success"); break; case "SSSStage": - Instances.CopilotViewModel.AddLog("CurrentStage: " + subTaskDetails["stage"], UiLogColor.Info); + Instances.CopilotViewModel.AddLog("CurrentStage: " + subTaskDetails!["stage"], UiLogColor.Info); break; case "SSSSettlement": - Instances.CopilotViewModel.AddLog(details["why"].ToString(), UiLogColor.Info); + Instances.CopilotViewModel.AddLog(details!["why"].ToString(), UiLogColor.Info); break; case "SSSGamePass": @@ -1420,17 +1420,17 @@ namespace MaaWpfGui.Main break; case "UnsupportedLevel": - Instances.CopilotViewModel.AddLog(LocalizationHelper.GetString("UnsupportedLevel") + subTaskDetails["level"], UiLogColor.Error); + Instances.CopilotViewModel.AddLog(LocalizationHelper.GetString("UnsupportedLevel") + subTaskDetails!["level"], UiLogColor.Error); break; case "CustomInfrastRoomGroupsMatch": // 选用xxx组编组 - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("RoomGroupsMatch") + subTaskDetails["group"]); + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("RoomGroupsMatch") + subTaskDetails!["group"]); break; case "CustomInfrastRoomGroupsMatchFailed": // 干员编组匹配失败 - JArray groups = (JArray)subTaskDetails["groups"]; + var groups = (JArray?)subTaskDetails!["groups"]; if (groups != null) { Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("RoomGroupsMatchFailed") + string.Join(", ", groups)); @@ -1439,7 +1439,7 @@ namespace MaaWpfGui.Main break; case "CustomInfrastRoomOperators": - string nameStr = (subTaskDetails["names"] ?? new JArray()) + string nameStr = (subTaskDetails!["names"] ?? new JArray()) .Aggregate(string.Empty, (current, name) => current + name + ", "); if (nameStr != string.Empty) @@ -1456,7 +1456,7 @@ namespace MaaWpfGui.Main case "InfrastTrainingCompleted": { - var operatorName = DataHelper.GetLocalizedCharacterName(subTaskDetails["operator"]?.ToString()) ?? "UnKnown"; + var operatorName = DataHelper.GetLocalizedCharacterName(subTaskDetails!["operator"]?.ToString()) ?? "UnKnown"; var skillName = subTaskDetails["skill"]?.ToString() ?? "UnKnown"; Instances.TaskQueueViewModel.AddLog( $"[{operatorName}]{skillName}\n" + @@ -1467,7 +1467,7 @@ namespace MaaWpfGui.Main case "InfrastTrainingTimeLeft": { - var operatorName = DataHelper.GetLocalizedCharacterName(subTaskDetails["operator"]?.ToString()) ?? "UnKnown"; + var operatorName = DataHelper.GetLocalizedCharacterName(subTaskDetails!["operator"]?.ToString()) ?? "UnKnown"; var skillName = subTaskDetails["skill"]?.ToString() ?? "UnKnown"; Instances.TaskQueueViewModel.AddLog( $"[{operatorName}]{skillName}\n" + @@ -1481,21 +1481,21 @@ namespace MaaWpfGui.Main case "ReclamationReport": Instances.TaskQueueViewModel.AddLog( LocalizationHelper.GetString("AlgorithmFinish") + "\n" + - LocalizationHelper.GetString("AlgorithmBadge") + ": " + $"{(int)subTaskDetails["total_badges"]}(+{(int)subTaskDetails["badges"]})" + "\n" + + LocalizationHelper.GetString("AlgorithmBadge") + ": " + $"{(int)subTaskDetails!["total_badges"]}(+{(int)subTaskDetails["badges"]})" + "\n" + LocalizationHelper.GetString("AlgorithmConstructionPoint") + ": " + $"{(int)subTaskDetails["total_construction_points"]}(+{(int)subTaskDetails["construction_points"]})"); break; case "ReclamationProcedureStart": - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("MissionStart") + $" {(int)subTaskDetails["times"]} " + LocalizationHelper.GetString("UnitTime"), UiLogColor.Info); + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("MissionStart") + $" {(int)subTaskDetails!["times"]} " + LocalizationHelper.GetString("UnitTime"), UiLogColor.Info); break; case "ReclamationSmeltGold": - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AlgorithmDoneSmeltGold") + $" {(int)subTaskDetails["times"]} " + LocalizationHelper.GetString("UnitTime")); + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AlgorithmDoneSmeltGold") + $" {(int)subTaskDetails!["times"]} " + LocalizationHelper.GetString("UnitTime")); break; case "SanityBeforeStage": SanityReport.HasSanityReport = false; - var sanityReport = (JObject)subTaskDetails; + var sanityReport = (JObject?)subTaskDetails; if (sanityReport is null || !sanityReport.ContainsKey("current_sanity") || !sanityReport.ContainsKey("max_sanity") || !sanityReport.ContainsKey("report_time")) { break; @@ -1503,7 +1503,7 @@ namespace MaaWpfGui.Main int sanityCur = sanityReport.TryGetValue("current_sanity", out var sanityCurToken) ? (int)sanityCurToken : -1; int sanityMax = sanityReport.TryGetValue("max_sanity", out var sanityMaxToken) ? (int)sanityMaxToken : -1; - var reportTime = sanityReport.TryGetValue("report_time", out var reportTimeToken) ? (string)reportTimeToken : string.Empty; + var reportTime = sanityReport.TryGetValue("report_time", out var reportTimeToken) ? (string?)reportTimeToken : string.Empty; if (sanityCur < 0 || sanityMax < 1 || reportTime?.Length < 12) { break; @@ -1525,7 +1525,7 @@ namespace MaaWpfGui.Main break; case "UseMedicine": - var medicineReport = (JObject)subTaskDetails; + var medicineReport = (JObject?)subTaskDetails; if (medicineReport is null || !medicineReport.ContainsKey("is_expiring") || !medicineReport.ContainsKey("count")) { break; @@ -1556,15 +1556,15 @@ namespace MaaWpfGui.Main break; case "StageQueueUnableToAgent": - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("StageQueue") + $" {subTaskDetails["stage_code"]} " + LocalizationHelper.GetString("UnableToAgent"), UiLogColor.Info); + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("StageQueue") + $" {subTaskDetails!["stage_code"]} " + LocalizationHelper.GetString("UnableToAgent"), UiLogColor.Info); break; case "StageQueueMissionCompleted": - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("StageQueue") + $" {subTaskDetails["stage_code"]} - {subTaskDetails["stars"]} ★", UiLogColor.Info); + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("StageQueue") + $" {subTaskDetails!["stage_code"]} - {subTaskDetails["stars"]} ★", UiLogColor.Info); break; case "AccountSwitch": - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AccountSwitch") + $" {subTaskDetails["current_account"]} -->> {subTaskDetails["account_name"]}", UiLogColor.Info); + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AccountSwitch") + $" {subTaskDetails!["current_account"]} -->> {subTaskDetails["account_name"]}", UiLogColor.Info); break; case "RoguelikeCollapsalParadigms": int deepen_or_weaken = (int)subTaskDetails["deepen_or_weaken"]; @@ -1803,13 +1803,13 @@ namespace MaaWpfGui.Main return ret; } - private AsstTaskId AsstAppendTaskWithEncoding(string type, JObject taskParams = null) + private AsstTaskId AsstAppendTaskWithEncoding(string type, JObject? taskParams = null) { taskParams ??= new(); return AsstAppendTask(_handle, type, JsonConvert.SerializeObject(taskParams)); } - private bool AsstSetTaskParamsWithEncoding(AsstTaskId id, JObject taskParams = null) + private bool AsstSetTaskParamsWithEncoding(AsstTaskId id, JObject? taskParams = null) { if (id == 0) { @@ -1842,7 +1842,7 @@ namespace MaaWpfGui.Main ReclamationAlgorithm2, } - private readonly Dictionary _latestTaskId = new(); + private readonly Dictionary _latestTaskId = []; private static JObject SerializeFightTaskParams( string stage, diff --git a/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs b/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs index 38d8c61f5b..e4e9a68a1b 100644 --- a/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs @@ -10,7 +10,7 @@ // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY // - +#nullable enable using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -46,7 +46,7 @@ namespace MaaWpfGui.ViewModels.UI _runningState.IdleChanged += RunningState_IdleChanged; } - private void RunningState_IdleChanged(object sender, bool e) + private void RunningState_IdleChanged(object? sender, bool e) { Idle = e; } @@ -293,7 +293,7 @@ namespace MaaWpfGui.ViewModels.UI { JArray tags = (JArray)subTaskDetails["tags"]; string infoContent = LocalizationHelper.GetString("RecruitTagsDetected"); - tags ??= new JArray(); + tags ??= []; infoContent = tags.Select(tagName => tagName.ToString()).Aggregate(infoContent, (current, tagStr) => current + (tagStr + " ")); RecruitInfo = infoContent; @@ -306,14 +306,14 @@ namespace MaaWpfGui.ViewModels.UI string resultContent = string.Empty; JArray resultArray = (JArray)subTaskDetails["result"]; /* int level = (int)subTaskDetails["level"]; */ - foreach (var combs in resultArray ?? new JArray()) + foreach (var combs in resultArray ?? []) { int tagLevel = (int)combs["level"]; resultContent += tagLevel + "★ Tags: "; - resultContent = (((JArray)combs["tags"]) ?? new JArray()).Aggregate(resultContent, (current, tag) => current + (tag + " ")); + resultContent = (((JArray?)combs["tags"]) ?? []).Aggregate(resultContent, (current, tag) => current + (tag + " ")); resultContent += "\n\t"; - foreach (var oper in (JArray)combs["opers"] ?? new JArray()) + foreach (var oper in (JArray?)combs["opers"] ?? []) { int operLevel = (int)oper["level"]; string operId = oper["id"]?.ToString(); @@ -579,9 +579,9 @@ namespace MaaWpfGui.ViewModels.UI } } - private Dictionary _operBoxPotential; + private Dictionary? _operBoxPotential; - public Dictionary OperBoxPotential + public Dictionary? OperBoxPotential { get { @@ -612,10 +612,10 @@ namespace MaaWpfGui.ViewModels.UI public bool OperBoxParse(JObject details) { - JArray operBoxes = (JArray)details["all_opers"]; + var operBoxes = (JArray)details["all_opers"]; - List> operHave = new List>(); - List> operNotHave = new List>(); + List> operHave = []; + List> operNotHave = []; string localizedName = ConfigurationHelper.GetValue(ConfigurationKeys.Localization, string.Empty) switch { @@ -818,7 +818,7 @@ namespace MaaWpfGui.ViewModels.UI private static readonly object _lock = new object(); - private BitmapImage _gachaImage; + private BitmapImage? _gachaImage; public BitmapImage GachaImage { @@ -826,7 +826,7 @@ namespace MaaWpfGui.ViewModels.UI set => SetAndNotify(ref _gachaImage, value); } - private void RefreshGachaImage(object sender, EventArgs e) + private void RefreshGachaImage(object? sender, EventArgs? e) { lock (_lock) {