From abd893abe1dc528d184b354352b8abcd546ded0e Mon Sep 17 00:00:00 2001 From: uye <2396806385@qq.com> Date: Wed, 4 Jan 2023 22:25:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=B0=86=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=89=A9=E5=93=81=E5=90=8D=E7=A7=B0=E7=A7=BB=E8=87=B3Utils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Helper/StageManager.cs | 41 +------------------- src/MaaWpfGui/Helper/Utils.cs | 57 ++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 40 deletions(-) diff --git a/src/MaaWpfGui/Helper/StageManager.cs b/src/MaaWpfGui/Helper/StageManager.cs index c75b7499d6..1c7a0943fd 100644 --- a/src/MaaWpfGui/Helper/StageManager.cs +++ b/src/MaaWpfGui/Helper/StageManager.cs @@ -92,40 +92,6 @@ namespace MaaWpfGui // new StageInfo { Display = Localization.GetString("CurrentStage"), Value = string.Empty }, // new StageInfo { Display = Localization.GetString("LastBattle"), Value = "LastBattle" }, }; - - var language = ViewStatusStorage.Get("GUI.Localization", Localization.DefaultLanguage); - string filename = string.Empty; - if (language == "zh-cn") - { - filename = Directory.GetCurrentDirectory() + "\\resource\\item_index.json"; - } - else if (language == "pallas") - { - // DoNothing - } - else - { - Dictionary client = new Dictionary - { - { "zh-tw", "txwy" }, - { "en-us", "YoStarEN" }, - { "ja-jp", "YoStarJP" }, - { "ko-kr", "YoStarKR" }, - }; - filename = Directory.GetCurrentDirectory() + "\\resource\\global\\" + client[language] + "\\resource\\item_index.json"; - } - - if (File.Exists(filename)) - { - try - { - data = JsonConvert.DeserializeObject>>(File.ReadAllText(filename)); - } - catch - { - // DoNothing - } - } } /// @@ -150,8 +116,6 @@ namespace MaaWpfGui return GetStageInfo(stage)?.IsStageOpen(dayOfWeek) == true; } - private readonly Dictionary> data; - /// /// Gets open stage tips at specified day of week /// @@ -183,10 +147,7 @@ namespace MaaWpfGui if (!string.IsNullOrEmpty(item.Value.Drop)) { - if (data != null && data.ContainsKey(item.Value.Drop)) - { - builder.AppendLine(item.Value.Display + ": " + data[item.Value.Drop]["name"]); - } + builder.AppendLine(item.Value.Display + ": " + Utils.GetItemName(item.Value.Drop)); } } } diff --git a/src/MaaWpfGui/Helper/Utils.cs b/src/MaaWpfGui/Helper/Utils.cs index f7a29922ab..3f3bf858fd 100644 --- a/src/MaaWpfGui/Helper/Utils.cs +++ b/src/MaaWpfGui/Helper/Utils.cs @@ -12,11 +12,52 @@ // using System; +using System.Collections.Generic; +using System.IO; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace MaaWpfGui { public static class Utils { + static Utils() + { + var language = ViewStatusStorage.Get("GUI.Localization", Localization.DefaultLanguage); + string filename = string.Empty; + if (language == "zh-cn") + { + filename = Directory.GetCurrentDirectory() + "\\resource\\item_index.json"; + } + else if (language == "pallas") + { + // DoNothing + } + else + { + Dictionary client = new Dictionary + { + { "zh-tw", "txwy" }, + { "en-us", "YoStarEN" }, + { "ja-jp", "YoStarJP" }, + { "ko-kr", "YoStarKR" }, + }; + filename = Directory.GetCurrentDirectory() + "\\resource\\global\\" + client[language] + "\\resource\\item_index.json"; + } + + if (File.Exists(filename)) + { + try + { + _itemList = (JObject)JsonConvert.DeserializeObject(File.ReadAllText(filename)); + } + catch + { + // DoNothing + } + } + } + /// /// 获取yj历时间 /// @@ -62,5 +103,21 @@ namespace MaaWpfGui { return dt.AddHours(4); } + + private static readonly JObject _itemList = new JObject(); + + public static JObject GetItemList() => _itemList; + + public static string GetItemName(string id) + { + if (_itemList.ContainsKey(id)) + { + return _itemList[id]["name"].ToString(); + } + else + { + return id; + } + } } }