Skip to content

Commit

Permalink
Bugfixes alex (#214)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Raszka <[email protected]>
  • Loading branch information
araszka and Alexander Raszka authored Sep 23, 2023
1 parent 111c1de commit 8e48e38
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 88 deletions.
31 changes: 13 additions & 18 deletions src/Modules/LiveRankingModule/Services/LiveRankingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
using EvoSC.Manialinks.Interfaces;
using EvoSC.Modules.Official.LiveRankingModule.Interfaces;
using EvoSC.Modules.Official.LiveRankingModule.Models;
using EvoSC.Modules.Official.LiveRankingModule.Utils;
using GbxRemoteNet.Events;
using LinqToDB.Common;
using Microsoft.Extensions.Logging;

namespace EvoSC.Modules.Official.LiveRankingModule.Services;
Expand Down Expand Up @@ -73,34 +71,30 @@ public async Task OnPlayerWaypointAsync(WayPointEventArgs args)
_logger.LogTrace("Player crossed a checkpoint: {ArgsAccountId} - RoundsMode: {IsRoundsMode}",
args.AccountId, _isRoundsMode);

var previousRanking = (await _liveRankingStore.GetFullLiveRankingAsync()).ToList();
//var previousRanking = (await _liveRankingStore.GetFullLiveRankingAsync()).ToList();
_liveRankingStore.RegisterTime(args.AccountId, args.CheckpointInRace, args.RaceTime, args.IsEndRace);

await _manialinkManager.SendPersistentManialinkAsync("LiveRankingModule.LiveRanking",
await GetWidgetData(previousRanking));
await GetWidgetData());
}
}

private async Task<dynamic> GetWidgetData(List<ExpandedLiveRankingPosition>? previousRanking = null)
private async Task<dynamic> GetWidgetData()
{
var currentRanking = (await _liveRankingStore.GetFullLiveRankingAsync()).Take(ShowRows).ToList();
await CalculateDiffs(currentRanking);
var widgetCurrentRanking = GetLiveRankingForWidget(currentRanking);

if (previousRanking.IsNullOrEmpty())
return new
{
return new
{
previousRankings = widgetCurrentRanking,
rankingsExisting = new List<LiveRankingWidgetPosition>(),
rankingsNew = new List<LiveRankingWidgetPosition>(),
headerColor = _config.Theme.UI.HeaderBackgroundColor,
primaryColor = _config.Theme.UI.PrimaryColor,
logoUrl = _config.Theme.UI.LogoWhiteUrl,
playerRowBackgroundColor = _config.Theme.UI.PlayerRowBackgroundColor
};
}
rankings = widgetCurrentRanking,
headerColor = _config.Theme.UI.HeaderBackgroundColor,
primaryColor = _config.Theme.UI.PrimaryColor,
logoUrl = _config.Theme.UI.LogoWhiteUrl,
playerRowBackgroundColor = _config.Theme.UI.PlayerRowBackgroundColor
};

/*
//Map ranking entries for widget
var widgetPreviousRanking = GetLiveRankingForWidget(previousRanking.Take(ShowRows).ToList());
Expand All @@ -119,6 +113,7 @@ private async Task<dynamic> GetWidgetData(List<ExpandedLiveRankingPosition>? pre
logoUrl = _config.Theme.UI.LogoWhiteUrl,
playerRowBackgroundColor = _config.Theme.UI.PlayerRowBackgroundColor
};
*/
}

public Task CalculateDiffs(List<ExpandedLiveRankingPosition> rankings)
Expand Down Expand Up @@ -147,7 +142,7 @@ public async Task OnPlayerGiveupAsync(PlayerUpdateEventArgs args)
_liveRankingStore.RegisterPlayerGiveUp(args.AccountId);

await _manialinkManager.SendPersistentManialinkAsync("LiveRankingModule.LiveRanking",
await GetWidgetData(previousRanking));
await GetWidgetData());
}
}

Expand Down
18 changes: 3 additions & 15 deletions src/Modules/LiveRankingModule/Templates/Components/PlayerScore.mt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<using namespace="EvoSC.Modules.Official.LiveRankingModule.Models"/>

<property type="LiveRankingWidgetPosition?" name="ranking" default="null"/>
<property type="LiveRankingWidgetPosition?" name="newRanking" default="null"/>

<property type="double" name="y" default="0.0"/>
<property type="double" name="w" default="66.0"/>
Expand All @@ -12,8 +11,8 @@
<property type="string" name="playerRowBackgroundColor" default="999999"/>

<template>
<frame id="player_row_{{ ranking.player.AccountId }}" pos="0 {{ y }}">
<quad id="player_row_trigger_{{ ranking?.player?.AccountId }}"
<frame id="player_row_{{ ranking?.login }}" pos="0 {{ y }}">
<quad id="player_row_trigger_{{ ranking?.login }}"
size="{{ w + 10.0 }} {{ h }}"
ScriptEvents="1"
/>
Expand Down Expand Up @@ -110,23 +109,12 @@
<!--
*** OnMouseClick ***
***
if(Event.Control.ControlId == "player_row_trigger_{{ ranking?.player?.AccountId }}"){
if(Event.Control.ControlId == "player_row_trigger_{{ ranking?.login }}"){
if(!IsSpectatorClient) RequestSpectatorClient(True);
SetSpectateTarget("{{ ranking?.login }}");
continue;
}
***

*** Animations ***
***
if({{ newRanking != null ? "True" : "False" }}){
declare scoreFrame <=> (Page.MainFrame.GetFirstChild("player_row_{{ ranking?.player.AccountId }}") as CMlFrame);
(scoreFrame.GetFirstChild("position") as CMlLabel).Value = "{{ newRanking?.position }}";
(scoreFrame.GetFirstChild("score") as CMlLabel).Value = "{{ newRanking?.time }}";
(scoreFrame.GetFirstChild("cp_index") as CMlLabel).Value = "{{ newRanking != null ? (newRanking.isFinish ? "" : newRanking.cpIndex) : "" }}";
AnimMgr.Add(scoreFrame, "<frame pos='0 {{ (newRanking?.position - 1) * (rowSpacing + h) * -1.0 }}' />", 320, CAnimManager::EAnimManagerEasing::ExpOut);
}
***
-->
</script>
</component>
17 changes: 2 additions & 15 deletions src/Modules/LiveRankingModule/Templates/LiveRanking.mt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

<import component="LiveRankingModule.Components.PlayerScore" as="PlayerScore"/>

<property type="List<LiveRankingWidgetPosition>" name="previousRankings"/>
<property type="List<LiveRankingWidgetPosition>" name="rankingsExisting"/>
<property type="List<LiveRankingWidgetPosition>" name="rankingsNew"/>
<property type="List<LiveRankingWidgetPosition>" name="rankings"/>

<property type="double" name="scale" default="0.9"/>
<property type="double" name="w" default="68.0"/>
Expand Down Expand Up @@ -73,16 +71,7 @@

<!-- CONTENT -->
<frame id="players" pos="0 {{ -headerHeight - rowSpacing * 2.0 }}" z-index="10">
<PlayerScore foreach="LiveRankingWidgetPosition position in previousRankings"
y="{{ (position.position - 1) * (rowHeight + rowSpacing) * -1.0 }}"
w="{{ w - 8.0 }}"
h="{{ rowHeight }}"
rowSpacing="{{ rowSpacing }}"
playerRowBackgroundColor="{{ playerRowBackgroundColor }}"
ranking="{{ position }}"
newRanking="{{ rankingsExisting.FirstOrDefault(r => r.player.AccountId == position.player.AccountId) }}"
/>
<PlayerScore foreach="LiveRankingWidgetPosition position in rankingsNew"
<PlayerScore foreach="LiveRankingWidgetPosition position in rankings"
y="{{ (position.position - 1) * (rowHeight + rowSpacing) * -1.0 }}"
w="{{ w - 8.0 }}"
h="{{ rowHeight }}"
Expand All @@ -97,8 +86,6 @@
<script>
<!--
main() {
+++ Animations +++

while(True){
yield;

Expand Down
14 changes: 6 additions & 8 deletions src/Modules/MatchRankingModule/Services/MatchRankingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,18 @@ public async Task SendManialinkToPlayer(string accountId)

private async Task<dynamic> GetWidgetData()
{
var mappedScoresPrevious = (await MapScoresForWidget(_matchRankingStore.GetPreviousMatchScores())).ToList()
.Take(ShowRows).ToList();
//var mappedScoresPrevious = (await MapScoresForWidget(_matchRankingStore.GetPreviousMatchScores())).ToList()
// .Take(ShowRows).ToList();
var mappedScoresLatest = (await MapScoresForWidget(_matchRankingStore.GetLatestMatchScores())).ToList()
.Take(ShowRows).ToList();

var mappedScoresExisting = mappedScoresLatest
.Where(ranking => mappedScoresPrevious.Contains(ranking, new RankingComparer())).ToList();
var mappedScoresNew = mappedScoresLatest.Except(mappedScoresExisting).ToList();
//var mappedScoresExisting = mappedScoresLatest
// .Where(ranking => mappedScoresPrevious.Contains(ranking, new RankingComparer())).ToList();
//var mappedScoresNew = mappedScoresLatest.Except(mappedScoresExisting).ToList();

return new
{
NewScores = mappedScoresNew,
ExistingScores = mappedScoresExisting,
PreviousScores = mappedScoresPrevious,
Scores = mappedScoresLatest,
headerColor = _config.Theme.UI.HeaderBackgroundColor,
primaryColor = _config.Theme.UI.PrimaryColor,
logoUrl = _config.Theme.UI.LogoWhiteUrl,
Expand Down
17 changes: 3 additions & 14 deletions src/Modules/MatchRankingModule/Templates/Components/PlayerScore.mt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<using namespace="EvoSC.Modules.Official.LiveRankingModule.Models"/>

<property type="LiveRankingWidgetPosition?" name="ranking" default="null"/>
<property type="LiveRankingWidgetPosition?" name="newRanking" default="null"/>

<property type="double" name="y" default="0.0"/>
<property type="double" name="w" default="66.0"/>
Expand All @@ -12,8 +11,8 @@
<property type="string" name="playerRowBackgroundColor" default="999999"/>

<template>
<frame id="player_row_{{ ranking?.player?.AccountId }}" pos="0 {{ y }}">
<quad id="player_row_trigger_{{ ranking?.player?.AccountId }}"
<frame id="player_row_{{ ranking?.login }}" pos="0 {{ y }}">
<quad id="player_row_trigger_{{ ranking?.login }}"
size="{{ w + 10.0 }} {{ h }}"
ScriptEvents="1"
/>
Expand Down Expand Up @@ -87,22 +86,12 @@
<!--
*** OnMouseClick ***
***
if(Event.Control.ControlId == "player_row_trigger_{{ ranking?.player?.AccountId }}"){
if(Event.Control.ControlId == "player_row_trigger_{{ ranking?.login }}"){
if(!IsSpectatorClient) RequestSpectatorClient(True);
SetSpectateTarget("{{ ranking?.login }}");
continue;
}
***

*** Animations ***
***
if({{ newRanking != null ? "True" : "False" }}){
declare scoreFrame <=> (Page.MainFrame.GetFirstChild("player_row_{{ ranking?.player.AccountId }}") as CMlFrame);
(scoreFrame.GetFirstChild("position") as CMlLabel).Value = "{{ newRanking?.position }}";
(scoreFrame.GetFirstChild("score") as CMlLabel).Value = "{{ newRanking?.time }}";
AnimMgr.Add(scoreFrame, "<frame pos='0 {{ (newRanking?.position - 1) * (rowSpacing + h) * -1.0 }}' />", 320, CAnimManager::EAnimManagerEasing::ExpOut);
}
***
-->
</script>
</component>
17 changes: 2 additions & 15 deletions src/Modules/MatchRankingModule/Templates/MatchRanking.mt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

<import component="MatchRankingModule.Components.PlayerScore" as="PlayerScore"/>

<property type="List<LiveRankingWidgetPosition>" name="PreviousScores"/>
<property type="List<LiveRankingWidgetPosition>" name="NewScores"/>
<property type="List<LiveRankingWidgetPosition>" name="ExistingScores"/>
<property type="List<LiveRankingWidgetPosition>" name="Scores"/>

<property type="double" name="scale" default="0.9"/>
<property type="double" name="w" default="68.0"/>
Expand Down Expand Up @@ -73,16 +71,7 @@

<!-- CONTENT -->
<frame id="players" pos="0 {{ -headerHeight - rowSpacing * 2.0 }}" size="{{ w }} 999" z-index="10">
<PlayerScore foreach="LiveRankingWidgetPosition position in PreviousScores"
y="{{ (position.position - 1) * (rowHeight + rowSpacing) * -1.0 }}"
w="{{ w - 8.0 }}"
h="{{ rowHeight }}"
rowSpacing="{{ rowSpacing }}"
playerRowBackgroundColor="{{ playerRowBackgroundColor }}"
ranking="{{ position }}"
newRanking="{{ ExistingScores.FirstOrDefault(r => r.player.AccountId == position.player.AccountId) }}"
/>
<PlayerScore foreach="LiveRankingWidgetPosition position in NewScores"
<PlayerScore foreach="LiveRankingWidgetPosition position in Scores"
y="{{ (position.position - 1) * (rowHeight + rowSpacing) * -1.0 }}"
w="{{ w - 8.0 }}"
h="{{ rowHeight }}"
Expand All @@ -97,8 +86,6 @@
<script>
<!--
main() {
+++ Animations +++

while(True){
yield;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,8 @@

if(lastCheckpointUpdateCheck != EvoCheckpointTimesUpdate){
lastCheckpointUpdateCheck = EvoCheckpointTimesUpdate;
log("[SpecInfo] CALCULATE RANKS AND DIFFS.");
ranksByAccountId = GetRanksForAccountIds(EvoCheckpointTimes);
diffs = CalculatePlayerDiffs(ranksByAccountId);
log("[SpecInfo] Ranks: " ^ ranksByAccountId);
log("[SpecInfo] Diffs: " ^ diffs);
}

if(!mainFrame.Visible){
Expand Down

0 comments on commit 8e48e38

Please sign in to comment.