Skip to content

Commit

Permalink
Adjusted Senka leaderboard logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Jebzou committed Dec 12, 2024
1 parent 5878540 commit eeb65a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class SenkaLeaderboardManager : ObservableObject

[ObservableProperty]
private partial SenkaLeaderboardRefreshKind CurrentSenkaLeaderboardRefreshKind { get; set; }

public SenkaLeaderboardManager(TimeChangeService timeChangeService, Tracker tracker)
{
APIObserver.Instance.ApiReqRanking_Mxltvkpyuklh.ResponseReceived += HandleData;
Expand Down Expand Up @@ -74,6 +74,15 @@ private void HandleData(dynamic data)
{
CurrentCutoffData.HandleEntry(entry);
}

// Due to how we parse data to guess a key, we have to run the decoding twice for the first "batch" for data to be accurate
if (CurrentCutoffData.LoadedEntriesCount is 10)
{
foreach (ApiList entry in parsedData.ApiList)
{
CurrentCutoffData.HandleEntry(entry);
}
}
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public partial class SenkaLeaderboardViewModel : AnchorableViewModel
[ObservableProperty]
private partial List<SenkaEntryModel> SenkaData { get; set; }

private Dictionary<int, ApiList> SenkaRawData { get; set; } = [];

public PagingControlViewModel PagingViewModel { get; }

public DataGridViewModel<SenkaEntryModel> DataGridViewModel { get; }
Expand Down Expand Up @@ -66,7 +64,6 @@ public void Update()
public void Reset()
{
SenkaData = NewLeaderboard();
SenkaRawData = [];
Update();
UpdateEntryCount();
}
Expand Down Expand Up @@ -100,15 +97,8 @@ public void HandleEntry(ApiList entry)

SenkaData[entry.ApiMxltvkpyuklh - 1] = parsedEntry;

SenkaRawData.Add(entry.ApiMxltvkpyuklh, entry);

UpdateEntryCount();

if (LoadedEntriesCount % 10 is 0)
{
RunAnotherRoundOfDecoding();
}

PagingViewModel.DisplayPageFromElementKey(entry.ApiMxltvkpyuklh - 1);
}

Expand Down Expand Up @@ -154,18 +144,6 @@ public void HandleEntry(ApiList entry)
};
}

private void RunAnotherRoundOfDecoding()
{
foreach (SenkaEntryModel entry in SenkaData.Where(entry => entry.IsKnown).OrderByDescending(entry => entry.Position))
{
if (SenkaRawData.TryGetValue(entry.Position, out ApiList? rawData) && ConvertApiToSenkaModel(rawData) is SenkaEntryModel parsedEntry)
{
entry.MedalCount = parsedEntry.MedalCount;
entry.Points = parsedEntry.Points;
}
}
}

private void UpdateEntryCount()
{
LoadedEntriesCount = SenkaData.Count(entry => entry.IsKnown);
Expand Down

0 comments on commit eeb65a9

Please sign in to comment.