Skip to content

Commit

Permalink
support to change gacha items' name language
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jul 24, 2023
1 parent 8fc1752 commit 29c1383
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Starward.Language/Lang.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Starward.Language/Lang.resx
Original file line number Diff line number Diff line change
Expand Up @@ -999,4 +999,8 @@ Do you accept the risk and continue to use it?</value>
<data name="ScreenshotPage_ScreenshotFolderDoesNotExist" xml:space="preserve">
<value>Screenshot folder does not exist</value>
</data>
<data name="GachaLogPage_0GachaItemsHaveBeenChangedToLanguage1" xml:space="preserve">
<value>{0} gacha items have been changed to language ({1}).</value>
<comment>123 gacha items have been changed to language (en-us).</comment>
</data>
</root>
8 changes: 8 additions & 0 deletions Starward/Pages/GachaLogPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@
</Button>
</StackPanel>
<TextBox Text="{x:Bind GachaLanguage, Mode=TwoWay}" />
<Button HorizontalAlignment="Stretch" Command="{x:Bind ChangeGachaItemNameCommand}">
<StackPanel Orientation="Horizontal" Spacing="8">
<FontIcon Margin="0,2,0,0"
FontSize="16"
Glyph="&#xE8FB;" />
<TextBlock Text="{x:Bind lang:Lang.Common_Apply}" />
</StackPanel>
</Button>
<!-- 导出为 -->
<TextBlock Margin="0,8,0,0"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Expand Down
18 changes: 18 additions & 0 deletions Starward/Pages/GachaLogPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,24 @@ private async Task CopyUrlAsync()



[RelayCommand]
private async Task ChangeGachaItemNameAsync()
{
try
{
string lang = string.IsNullOrWhiteSpace(GachaLanguage) ? System.Globalization.CultureInfo.CurrentUICulture.Name : GachaLanguage;
(lang, int count) = await _gachaLogService.ChangeGachaItemNameAsync(gameBiz, lang);
NotificationBehavior.Instance.Success(null, string.Format(Lang.GachaLogPage_0GachaItemsHaveBeenChangedToLanguage1, count, lang), 5000);
UpdateGachaTypeStats(SelectUid);
}
catch (Exception ex)
{
_logger.LogError(ex, "Change gacha item name");
}
}



[RelayCommand]
private async Task DeleteUidAsync()
{
Expand Down
2 changes: 1 addition & 1 deletion Starward/Pages/SettingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,5 +572,5 @@ private async Task DeleteAllSettingAsync()

#endregion


}
34 changes: 33 additions & 1 deletion Starward/Services/DatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void SetValue<T>(string key, T value, DateTime? time = null)
#region Database Structure


private static readonly List<string> DatabaseSqls = new() { Sql_v1, Sql_v2, Sql_v3, Sql_v4 };
private static readonly List<string> DatabaseSqls = new() { Sql_v1, Sql_v2, Sql_v3, Sql_v4, Sql_v5 };


private const string Sql_v1 = """
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions Starward/Services/Gacha/GachaLogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,8 @@ public virtual int DeleteUid(long uid)
public abstract Task<string> UpdateGachaInfoAsync(GameBiz gameBiz, string lang, CancellationToken cancellationToken = default);



public abstract Task<(string Language, int Count)> ChangeGachaItemNameAsync(GameBiz gameBiz, string lang, CancellationToken cancellationToken = default);


}
14 changes: 14 additions & 0 deletions Starward/Services/Gacha/GenshinGachaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }
Expand Down
12 changes: 12 additions & 0 deletions Starward/Services/Gacha/StarRailGachaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29c1383

Please sign in to comment.