From 29c1383711b5c5edacac366ad18259b064d64f08 Mon Sep 17 00:00:00 2001 From: Scighost Date: Mon, 24 Jul 2023 20:47:30 +0800 Subject: [PATCH] support to change gacha items' name language --- Starward.Language/Lang.Designer.cs | 9 +++++ Starward.Language/Lang.resx | 4 +++ Starward/Pages/GachaLogPage.xaml | 8 +++++ Starward/Pages/GachaLogPage.xaml.cs | 18 ++++++++++ Starward/Pages/SettingPage.xaml.cs | 2 +- Starward/Services/DatabaseService.cs | 34 ++++++++++++++++++- Starward/Services/Gacha/GachaLogService.cs | 4 +++ .../Services/Gacha/GenshinGachaService.cs | 14 ++++++++ .../Services/Gacha/StarRailGachaService.cs | 12 +++++++ 9 files changed, 103 insertions(+), 2 deletions(-) diff --git a/Starward.Language/Lang.Designer.cs b/Starward.Language/Lang.Designer.cs index 5b6a5c247..2db2d7a29 100644 --- a/Starward.Language/Lang.Designer.cs +++ b/Starward.Language/Lang.Designer.cs @@ -628,6 +628,15 @@ public static string ForgottenHallPage_TeamSetup { } } + /// + /// 查找类似 {0} gacha items have been changed to language ({1}). 的本地化字符串。 + /// + public static string GachaLogPage_0GachaItemsHaveBeenChangedToLanguage1 { + get { + return ResourceManager.GetString("GachaLogPage_0GachaItemsHaveBeenChangedToLanguage1", resourceCulture); + } + } + /// /// 查找类似 Authkey Timeout always occurs? 的本地化字符串。 /// diff --git a/Starward.Language/Lang.resx b/Starward.Language/Lang.resx index 8ea7adfda..323ae7e95 100644 --- a/Starward.Language/Lang.resx +++ b/Starward.Language/Lang.resx @@ -999,4 +999,8 @@ Do you accept the risk and continue to use it? Screenshot folder does not exist + + {0} gacha items have been changed to language ({1}). + 123 gacha items have been changed to language (en-us). + \ No newline at end of file diff --git a/Starward/Pages/GachaLogPage.xaml b/Starward/Pages/GachaLogPage.xaml index d9c5e936f..b185a149b 100644 --- a/Starward/Pages/GachaLogPage.xaml +++ b/Starward/Pages/GachaLogPage.xaml @@ -117,6 +117,14 @@ + (string key, T value, DateTime? time = null) #region Database Structure - private static readonly List DatabaseSqls = new() { Sql_v1, Sql_v2, Sql_v3, Sql_v4 }; + private static readonly List DatabaseSqls = new() { Sql_v1, Sql_v2, Sql_v3, Sql_v4, Sql_v5 }; private const string Sql_v1 = """ @@ -469,6 +469,38 @@ Number INTEGER NOT NULL COMMIT TRANSACTION; """; + private const string Sql_v5 = """ + BEGIN TRANSACTION; + + CREATE TABLE IF NOT EXISTS GenshinGachaInfo + ( + Id INTEGER NOT NULL PRIMARY KEY, + Name TEXT, + Icon TEXT, + Element INTEGER NOT NULL, + Level INTEGER NOT NULL, + CatId INTEGER NOT NULL, + WeaponCatId INTEGER NOT NULL + ); + CREATE INDEX IF NOT EXISTS IX_GenshinGachaInfo_Name ON GenshinGachaInfo (Name); + + CREATE TABLE IF NOT EXISTS StarRailGachaInfo + ( + ItemId INTEGER NOT NULL PRIMARY KEY, + ItemName TEXT, + IconUrl TEXT, + DamageType INTEGER NOT NULL, + Rarity INTEGER NOT NULL, + AvatarBaseType INTEGER NOT NULL, + WikiUrl TEXT, + IsSystem INTEGER NOT NULL + ); + CREATE INDEX IF NOT EXISTS IX_StarRailGachaInfo_Name ON StarRailGachaInfo (ItemName); + + PRAGMA USER_VERSION = 5; + COMMIT TRANSACTION; + """; + #endregion diff --git a/Starward/Services/Gacha/GachaLogService.cs b/Starward/Services/Gacha/GachaLogService.cs index 72ace4b32..2879d7f21 100644 --- a/Starward/Services/Gacha/GachaLogService.cs +++ b/Starward/Services/Gacha/GachaLogService.cs @@ -243,4 +243,8 @@ public virtual int DeleteUid(long uid) public abstract Task UpdateGachaInfoAsync(GameBiz gameBiz, string lang, CancellationToken cancellationToken = default); + + public abstract Task<(string Language, int Count)> ChangeGachaItemNameAsync(GameBiz gameBiz, string lang, CancellationToken cancellationToken = default); + + } diff --git a/Starward/Services/Gacha/GenshinGachaService.cs b/Starward/Services/Gacha/GenshinGachaService.cs index 5c52b649a..6b70554e1 100644 --- a/Starward/Services/Gacha/GenshinGachaService.cs +++ b/Starward/Services/Gacha/GenshinGachaService.cs @@ -181,6 +181,20 @@ INSERT OR REPLACE INTO GenshinGachaItem (Uid, Id, Name, Time, ItemId, ItemType, } + public override async Task<(string Language, int Count)> ChangeGachaItemNameAsync(GameBiz gameBiz, string lang, CancellationToken cancellationToken = default) + { + lang = await UpdateGachaInfoAsync(gameBiz, lang, cancellationToken); + using var dapper = _database.CreateConnection(); + int count = dapper.Execute(""" + INSERT OR REPLACE INTO GenshinGachaItem (Uid, Id, Name, Time, ItemId, ItemType, RankType, GachaType, Count, Lang) + SELECT item.Uid, item.Id, info.Name, Time, ItemId, ItemType, RankType, GachaType, Count, @Lang + FROM GenshinGachaItem item INNER JOIN GenshinGachaInfo info ON item.ItemId = info.Id; + """, new { Lang = lang }); + return (lang, count); + } + + + private class UIAFObj { public UIAFObj() { } diff --git a/Starward/Services/Gacha/StarRailGachaService.cs b/Starward/Services/Gacha/StarRailGachaService.cs index b46ee529c..281686cc9 100644 --- a/Starward/Services/Gacha/StarRailGachaService.cs +++ b/Starward/Services/Gacha/StarRailGachaService.cs @@ -181,6 +181,18 @@ INSERT OR REPLACE INTO StarRailGachaItem (Uid, Id, Name, Time, ItemId, ItemType, } + public override async Task<(string Language, int Count)> ChangeGachaItemNameAsync(GameBiz gameBiz, string lang, CancellationToken cancellationToken = default) + { + lang = await UpdateGachaInfoAsync(gameBiz, lang, cancellationToken); + using var dapper = _database.CreateConnection(); + int count = dapper.Execute(""" + INSERT OR REPLACE INTO StarRailGachaItem (Uid, Id, Name, Time, ItemId, ItemType, RankType, GachaType, GachaId, Count, Lang) + SELECT item.Uid, Id, info.ItemName, Time, item.ItemId, ItemType, RankType, GachaType, GachaId, Count, @Lang + FROM StarRailGachaItem item INNER JOIN StarRailGachaInfo info ON item.ItemId = info.ItemId; + """, new { Lang = lang }); + return (lang, count); + } + private class SRGFObj