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 #1212

Open
wants to merge 5 commits into
base: main
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 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());

Check warning on line 23 in src/Starward.Core/Gacha/StarRail/StarRailGachaItem.cs

View workflow job for this annotation

GitHub Actions / build (Debug, x64)

Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(String, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.

Check warning on line 23 in src/Starward.Core/Gacha/StarRail/StarRailGachaItem.cs

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(String, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.

Check warning on line 23 in src/Starward.Core/Gacha/StarRail/StarRailGachaItem.cs

View workflow job for this annotation

GitHub Actions / build (Release, x64)

Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(String, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.

Check warning on line 23 in src/Starward.Core/Gacha/StarRail/StarRailGachaItem.cs

View workflow job for this annotation

GitHub Actions / build (Release, arm64)

Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(String, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
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);

Check warning on line 42 in src/Starward.Core/Gacha/StarRail/StarRailGachaItem.cs

View workflow job for this annotation

GitHub Actions / build (Debug, x64)

Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.

Check warning on line 42 in src/Starward.Core/Gacha/StarRail/StarRailGachaItem.cs

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.

Check warning on line 42 in src/Starward.Core/Gacha/StarRail/StarRailGachaItem.cs

View workflow job for this annotation

GitHub Actions / build (Release, x64)

Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.

Check warning on line 42 in src/Starward.Core/Gacha/StarRail/StarRailGachaItem.cs

View workflow job for this annotation

GitHub Actions / build (Release, arm64)

Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
}
}

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 @@ -1719,4 +1719,7 @@ Do you accept the risk and continue to use it?</value>
<data name="SettingPage_KeepRPCServiceRunningInTheBackground" xml:space="preserve">
<value>Keep RPC service running in the background</value>
</data>
<data name="ZZZGachaService_ImportSignalSearchSuccessfully" xml:space="preserve">
<value>Import {0} signal search(es) successfully.</value>
</data>
</root>
5 changes: 4 additions & 1 deletion src/Starward.Language/Lang.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1716,5 +1716,8 @@
</data>
<data name="GachaLogPage_SpecificTimePeriod" xml:space="preserve">
<value>指定时间段</value>
</data>
</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 @@ -1609,4 +1609,7 @@
<data name="InterKnotMonthlyReportPage_OtherRewards" xml:space="preserve">
<value>Other Rewards</value>
</data>
<data name="ZZZGachaService_ImportSignalSearchSuccessfully" xml:space="preserve">
<value>成功匯入 {0} 條調頻記錄</value>
</data>
</root>
10 changes: 9 additions & 1 deletion src/Starward/Features/Gacha/GachaLogPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button x:Name="Button_Export_Excel"
HorizontalAlignment="Stretch"
Expand All @@ -172,7 +173,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/Features/Gacha/GachaLogPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
EnableStarRailGachaItemStats = true;
_gachaLogService = AppService.GetService<StarRailGachaService>();
Image_Emoji.Source = new BitmapImage(AppConfig.EmojiPom);
Button_Export_JSON_old.Content = "SRGF";
}
if (CurrentGameBiz.Game == GameBiz.nap)
{
IsZZZGachaStatsCardVisible = true;
_gachaLogService = AppService.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 (CurrentGameBiz.IsGlobalServer())
{
Expand Down Expand Up @@ -684,6 +684,7 @@ private async Task ExportGachaLogAsync(string format)
{
"excel" => "xlsx",
"json" => "json",
"json_old" => "json",
_ => "json"
};
var suggestName = $"Starward_Export_{CurrentGameBiz.Game}_{uid}_{DateTime.Now:yyyyMMddHHmmss}.{ext}";
Expand Down Expand Up @@ -715,19 +716,16 @@ private async Task ImportGachaLogAsync()
var file = await FileDialogHelper.PickSingleFileAsync(this.XamlRoot, ("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/Features/Gacha/GachaLogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,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 @@ -275,7 +279,7 @@ public virtual int DeleteGachaLogByTime(long uid, DateTime begin, DateTime end)



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



Expand Down
Loading
Loading