Commit 4482d224 authored by SherryChaos's avatar SherryChaos

cache mycard_apps.json

parent 04a89db7
......@@ -61,3 +61,4 @@ Data/ur.ydk
/Assets/StreamingAssets/
/Assets/Wallpaper/
Data/lflist_genesys.conf
Data/mycard_apps.json
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -11837,7 +11837,7 @@ MonoBehaviour:
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_TextWrappingMode: 1
m_TextWrappingMode: 0
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
......@@ -12409,7 +12409,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 7446650972608614846}
m_Direction: 2
m_Value: 1
m_Size: 0.7315
m_Size: 0.7195
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
......@@ -53106,7 +53106,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 6524435541314575836}
m_Direction: 2
m_Value: 0
m_Size: 1
m_Size: 0.64285713
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
......@@ -63866,7 +63866,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 4664753718165055069}
m_Direction: 2
m_Value: 0
m_Size: 1
m_Size: 0.6923077
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
......@@ -69434,6 +69434,10 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3036679950856914851, guid: d4403fd2f98246942bb4edbb4b732ea1, type: 3}
propertyPath: m_Size
value: 0.9531484
objectReference: {fileID: 0}
- target: {fileID: 3039851360208839043, guid: d4403fd2f98246942bb4edbb4b732ea1, type: 3}
propertyPath: m_AnchorMax.y
value: 0
using Cysharp.Threading.Tasks;
using Newtonsoft.Json;
using Percy;
using System;
using System.Collections.Generic;
using System.IO;
......@@ -13,6 +15,7 @@ namespace MDPro3.Net
public static void Initialize()
{
_ = InitializeGenesysLflist();
_ = InitializeMyCardAppsAsync();
}
#region Genesys lflist
......@@ -21,6 +24,7 @@ namespace MDPro3.Net
private const string PATH_GENESYS_LFLIST = "Data/lflist_genesys.conf";
private static readonly List<int> genesysBannedCards = new();
private static readonly List<GenesysPoint> genesysPoints = new();
private static int officialGenesysLimit = 100;
private static async UniTask InitializeGenesysLflist()
{
......@@ -34,9 +38,7 @@ namespace MDPro3.Net
await DownloadGenesysLflist(eTag);
}
else
{
Program.Debug("Genesys Lflist do not need update.");
}
}
ParseGenesysLflist();
......@@ -138,19 +140,17 @@ namespace MDPro3.Net
/// <summary>
/// color for Genesys Points one card score
/// </summary>
/// <param name="gp"></param>
/// <returns></returns>
public static Color GetGenesysPointColor(int gp)
{
if (gp < 0)
return Color.red;
if (gp == 0)
return Color.gray;
if (gp < 10)
if (gp <= officialGenesysLimit / 10)
return Color.green;
if (gp < 50)
if (gp <= officialGenesysLimit / 2)
return Color.yellow;
if (gp < 100)
if (gp <= officialGenesysLimit)
return Color.magenta;
return Color.red;
}
......@@ -158,17 +158,74 @@ namespace MDPro3.Net
/// <summary>
/// color for Genesys Points total score
/// </summary>
/// <param name="gp"></param>
/// <returns></returns>
public static Color GetGenesysPointsColor(int gp)
{
if (gp < 100)
if (gp <= officialGenesysLimit)
return Color.white;
return Color.red;
}
#endregion
#region MyCard Apps
private const string URL_MYCARD_APPS = "https://cdntx.moecube.com/apps.json";
private const string PATH_MYCARD_APPS = "Data/mycard_apps.json";
public static MyCardNews myCardNews;
private static async UniTask InitializeMyCardAppsAsync()
{
var eTag = await GetETagAsync(URL_MYCARD_APPS);
if (!string.IsNullOrEmpty(eTag))
{
var configTag = Config.Get(GetLocalETagKey(URL_MYCARD_APPS), Config.EMPTY_STRING);
if (!string.Equals(eTag, configTag, StringComparison.Ordinal))
{
Program.Debug("Update MyCard Apps.");
await DownloadMyCardApps(eTag);
}
else
Program.Debug("MyCard Apps do not need update.");
}
ParseMyCardNews();
}
private static async UniTask DownloadMyCardApps(string ETag)
{
using var request = UnityWebRequest.Get(URL_MYCARD_APPS);
request.timeout = 15;
await request.SendWebRequest();
if (request.result == UnityWebRequest.Result.Success)
{
File.WriteAllText(PATH_MYCARD_APPS, request.downloadHandler.text);
Config.Set(GetLocalETagKey(URL_MYCARD_APPS), ETag);
Config.Save();
}
else
Program.Debug("下载MyCard apps.json失败。");
}
private static void ParseMyCardNews()
{
if (!File.Exists(PATH_MYCARD_APPS))
return;
var json = File.ReadAllText(PATH_MYCARD_APPS);
json = json.Replace("\"news\":[]", "\"news\":{}");
var apps = JsonConvert.DeserializeObject<MyCardApp[]>(json);
foreach (var app in apps)
if (app.id == "ygopro")
{
myCardNews = app.news;
return;
}
}
#endregion
#region Online Tools
private static string GetLocalETagKey(string url) => $"ETag_{url.GetHashCode()}";
......
......@@ -140,10 +140,10 @@ namespace MDPro3.Servant
private IEnumerator LoadMyCardNewsAsync()
{
var news = MyCard.GetNews();
while (!news.IsCompleted)
while(OnlineService.myCardNews == null)
yield return null;
GetUI<MainMenuUI>().News.news = news.Result;
var news = OnlineService.myCardNews;
GetUI<MainMenuUI>().News.news = news;
GetUI<MainMenuUI>().News.LoadNews();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment