Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adapt to UIGF 4.0 #1095

Open
wants to merge 4 commits into
base: dev/features
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions src/Starward.Core/Gacha/StarRail/StarRailGachaItem.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Text.Json.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Starward.Core.Gacha.StarRail;

public class StarRailGachaItem : GachaLogItem
{

[JsonPropertyName("gacha_id")]
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)]
[JsonIgnore]
public int GachaId { get; set; }


Expand All @@ -15,3 +15,31 @@ public class StarRailGachaItem : GachaLogItem

}

public class StarRailGachaItemConverter : JsonConverter<StarRailGachaItem>
{
public override StarRailGachaItem Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var jsonObject = JsonDocument.ParseValue(ref reader).RootElement;
var gachaItem = (JsonSerializer.Deserialize<StarRailGachaItem>(jsonObject.GetRawText()) ?? new StarRailGachaItem());
if (jsonObject.TryGetProperty("gacha_id", out var gachaIdProp))
if (gachaIdProp.ValueKind == JsonValueKind.String && string.IsNullOrEmpty(gachaIdProp.GetString()))
gachaItem.GachaId = gachaItem.GachaType switch
{
1 => 1001,
2 => 4001,
11 => 2003,
12 => 3003,
_ => 1001,
};
else
gachaItem.GachaId = gachaIdProp.GetInt32();

return gachaItem;
}

public override void Write(Utf8JsonWriter writer, StarRailGachaItem value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value, options);
}
}

9 changes: 9 additions & 0 deletions src/Starward.Language/Lang.Designer.cs

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

3 changes: 3 additions & 0 deletions src/Starward.Language/Lang.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1582,4 +1582,7 @@ Do you accept the risk and continue to use it?</value>
<data name="GameLauncherPage_RemovableStorageDeviceNotConnected" xml:space="preserve">
<value>Removable storage device not connected.</value>
</data>
<data name="ZZZGachaService_ImportSignalSearchSuccessfully" xml:space="preserve">
<value>Import {0} signal search(es) successfully.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/Starward.Language/Lang.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1582,4 +1582,7 @@
<data name="GameLauncherPage_RemovableStorageDeviceNotConnected" xml:space="preserve">
<value>可移动存储设备未连接</value>
</data>
<data name="ZZZGachaService_ImportSignalSearchSuccessfully" xml:space="preserve">
<value>成功导入调频记录 {0} 条</value>
</data>
</root>
5 changes: 4 additions & 1 deletion src/Starward.Language/Lang.zh-TW.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@
<value>驗證失敗</value>
</data>
<data name="AboutSettingPage_CurrentVersionIsNotTheLatestVersion" xml:space="preserve">
<value>目前版本不是最新版本({0})。</value>
<value>目前版本不是最新版本({0})。</value>
</data>
<data name="AboutSettingPage_ClickButtonToRepairFiles" xml:space="preserve">
<value>按下按鈕修復檔案</value>
Expand Down Expand Up @@ -1582,4 +1582,7 @@
<data name="GameLauncherPage_RemovableStorageDeviceNotConnected" xml:space="preserve">
<value>Removable storage device not connected.</value>
</data>
<data name="ZZZGachaService_ImportSignalSearchSuccessfully" xml:space="preserve">
<value>成功匯入 {0} 條調頻記錄</value>
</data>
</root>
10 changes: 9 additions & 1 deletion src/Starward/Pages/GachaLogPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button x:Name="Button_Export_Excel"
HorizontalAlignment="Stretch"
Expand All @@ -166,7 +167,14 @@
HorizontalAlignment="Stretch"
Command="{x:Bind ExportGachaLogCommand}"
CommandParameter="json"
Content="Json"
Content="UIGF4.0"
CornerRadius="0,0,0,0" />
<Button x:Name="Button_Export_JSON_old"
Grid.Column="2"
HorizontalAlignment="Stretch"
Command="{x:Bind ExportGachaLogCommand}"
CommandParameter="json_old"
Content="UIGF3.0"
CornerRadius="0,4,4,0" />
</Grid>
<Button x:Name="Button_Import"
Expand Down
28 changes: 13 additions & 15 deletions src/Starward/Pages/GachaLogPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
EnableStarRailGachaItemStats = true;
_gachaLogService = AppConfig.GetService<StarRailGachaService>();
Image_Emoji.Source = new BitmapImage(AppConfig.EmojiPom);
Button_Export_JSON_old.Content = "SRGF";
}
if (biz.ToGame() == GameBiz.nap)
{
IsZZZGachaStatsCardVisible = true;
_gachaLogService = AppConfig.GetService<ZZZGachaService>();
Image_Emoji.Source = new BitmapImage(AppConfig.EmojiBangboo);
MenuFlyoutItem_CloudGame.Visibility = Visibility.Collapsed;
Button_Export_Excel.IsEnabled = false;
Button_Export_JSON.IsEnabled = false;
Button_Import.IsEnabled = false;
Button_Export_JSON_old.Visibility = Visibility.Collapsed;
Button_Export_JSON.CornerRadius = new CornerRadius(0, 4, 4, 0);
}
if (biz.IsGlobalOfficial())
{
Expand Down Expand Up @@ -666,6 +666,7 @@ private async Task ExportGachaLogAsync(string format)
{
"excel" => "xlsx",
"json" => "json",
"json_old" => "json",
_ => "json"
};
var suggestName = $"Starward_Export_{CurrentGameBiz.ToGame()}_{uid}_{DateTime.Now:yyyyMMddHHmmss}.{ext}";
Expand Down Expand Up @@ -697,19 +698,16 @@ private async Task ImportGachaLogAsync()
var file = await FileDialogHelper.PickSingleFileAsync(MainWindow.Current.WindowHandle, ("Json", ".json"));
if (File.Exists(file))
{
var uid = _gachaLogService.ImportGachaLog(file);
if (uid == SelectUid)
var uids = _gachaLogService.ImportGachaLog(file);
foreach (var uid in uids)
{
UpdateGachaTypeStats(uid);
}
else if (UidList.Contains(uid))
{
SelectUid = uid;
}
else
{
UidList.Add(uid);
SelectUid = uid;
if (!UidList.Contains(uid))
UidList.Add(uid);
if (uid == uids.First())
if (uid == SelectUid)
UpdateGachaTypeStats(uid);
else
SelectUid = uid;
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Starward/Services/Gacha/GachaLogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public virtual async Task<long> GetUidFromGachaLogUrl(string url)



public abstract List<GachaLogItem> CheckUIGFItems(List<GachaLogItem> list, long uid, string lang);



protected abstract int InsertGachaLogItems(List<GachaLogItem> items);


Expand Down Expand Up @@ -272,7 +276,7 @@ public virtual int DeleteUid(long uid)



public abstract long ImportGachaLog(string file);
public abstract List<long> ImportGachaLog(string file);



Expand Down
Loading