Skip to content

Commit

Permalink
Added round condition checker
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiScw committed Dec 18, 2023
1 parent 773720c commit a42f1b0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Modules/LiveRankingModule/Services/LiveRankingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class LiveRankingService(ILogger<LiveRankingService> logger, IManialinkMa
public async Task OnEnableAsync()
{
logger.LogTrace("LiveRankingModule enabled");
await CheckIsRoundsModeAsync();
await CheckAndSetRoundsMode();
await HideNadeoScoreboardAsync();
if (_isRoundsMode)
{
Expand All @@ -51,7 +51,7 @@ public async Task OnDisableAsync()

public async Task OnPlayerWaypointAsync(WayPointEventArgs args)
{
await CheckIsRoundsModeAsync();
await CheckAndSetRoundsMode();
if (_isRoundsMode)
{
logger.LogTrace("Player crossed a checkpoint: {ArgsAccountId} - RoundsMode: {IsRoundsMode}",
Expand Down Expand Up @@ -89,7 +89,7 @@ public Task CalculateDiffsAsync(List<ExpandedLiveRankingPosition> rankings)

public async Task OnPlayerGiveupAsync(PlayerUpdateEventArgs args)
{
await CheckIsRoundsModeAsync();
await CheckAndSetRoundsMode();
if (_isRoundsMode)
{
logger.LogTrace("Player gave up: {ArgsAccountId} - RoundsMode: {IsRoundsMode}", args.AccountId,
Expand All @@ -105,7 +105,7 @@ await manialinkManager.SendPersistentManialinkAsync("LiveRankingModule.LiveRanki
public async Task OnBeginMapAsync(MapEventArgs args)
{
logger.LogTrace("Map starts: {MapName}, IsRounds: {IsRoundsMode}", args.Map.Name, _isRoundsMode);
await CheckIsRoundsModeAsync();
await CheckAndSetRoundsMode();
if (!_isRoundsMode)
{
await Task.CompletedTask;
Expand All @@ -121,7 +121,7 @@ public async Task OnBeginMapAsync(MapEventArgs args)

public async Task OnEndMapAsync(MapEventArgs args)
{
await CheckIsRoundsModeAsync();
await CheckAndSetRoundsMode();
logger.LogTrace("Map ends: {MapName} - RoundsMode: {IsRoundsMode}", args.Map.Name, _isRoundsMode);
if (_isRoundsMode)
{
Expand Down Expand Up @@ -175,7 +175,7 @@ public async Task OnEndMatchAsync(EndMatchGbxEventArgs args)

public async Task OnPodiumStartAsync(PodiumEventArgs args)
{
await CheckIsRoundsModeAsync();
await CheckAndSetRoundsMode();
await HideManialinkAsync();
}

Expand Down Expand Up @@ -242,15 +242,18 @@ private LiveRankingWidgetPosition RankingToTime(ExpandedLiveRankingPosition rank
ranking.CheckpointIndex + 1, ranking.IsFinish);
}

private Task<bool> CheckIsRoundsModeAsync()
private async Task CheckAndSetRoundsMode()
{
List<string> validModes = new List<string>
{
"Trackmania/TM_Rounds_Online.Script.txt", "Trackmania/TM_Cup_Online.Script.txt"
};
//TODO: https://github.com/EvoEsports/EvoSC-sharp/issues/234
_isRoundsMode = true;
return Task.FromResult(_isRoundsMode);
var scriptInfo = await client.Remote.GetModeScriptInfoAsync();
if (validModes.Contains(scriptInfo.Name))
{
_isRoundsMode = true;
}
_isRoundsMode = false;
}

public MatchInfo GetMatchInfo()
Expand Down

0 comments on commit a42f1b0

Please sign in to comment.