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

219 redo live ranking module #268

Merged
merged 14 commits into from
Aug 10, 2024
Merged
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
7 changes: 7 additions & 0 deletions EvoSC.sln
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameModeUiModule", "src\Mod
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameModeUiModule.Tests", "tests\Modules\GameModeUiModule.Tests\GameModeUiModule.Tests.csproj", "{5B515690-0F0B-44D1-B644-3524A83A17CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveRankingModule.Tests", "tests\Modules\LiveRankingModule.Tests\LiveRankingModule.Tests.csproj", "{4AA1890A-1423-4831-95B2-E29B9A7A58D1}"
EndProject



Expand Down Expand Up @@ -411,6 +413,10 @@ Global
{5B515690-0F0B-44D1-B644-3524A83A17CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B515690-0F0B-44D1-B644-3524A83A17CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B515690-0F0B-44D1-B644-3524A83A17CE}.Release|Any CPU.Build.0 = Release|Any CPU
{4AA1890A-1423-4831-95B2-E29B9A7A58D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AA1890A-1423-4831-95B2-E29B9A7A58D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AA1890A-1423-4831-95B2-E29B9A7A58D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AA1890A-1423-4831-95B2-E29B9A7A58D1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -475,5 +481,6 @@ Global
{F8C7FE5E-B389-4BA8-B0DF-6D9D0A9B0949} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A}
{5BA1FF1B-8CB0-4FF5-B6C0-4E2E323D446E} = {DC47658A-F421-4BA4-B617-090A7DFB3900}
{5B515690-0F0B-44D1-B644-3524A83A17CE} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A}
{4AA1890A-1423-4831-95B2-E29B9A7A58D1} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A}
EndGlobalSection
EndGlobal
18 changes: 18 additions & 0 deletions src/EvoSC.Common/Util/Manialinks/WidgetPosition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using EvoSC.Common.Util.EnumIdentifier;

namespace EvoSC.Common.Util.Manialinks;

public enum WidgetPosition
{
[Identifier(Name = "left", NoPrefix = true)]
Left,

[Identifier(Name = "right", NoPrefix = true)]
Right,

[Identifier(Name = "center", NoPrefix = true)]
Center,

[Identifier(Name = "", NoPrefix = true)]
Undefined,
}
22 changes: 22 additions & 0 deletions src/Modules/LiveRankingModule/Config/ILiveRankingSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.ComponentModel;
using Config.Net;
using EvoSC.Common.Util.Manialinks;
using EvoSC.Modules.Attributes;

namespace EvoSC.Modules.Official.LiveRankingModule.Config;

[Settings]
public interface ILiveRankingSettings
{
[Option(DefaultValue = 10), Description("Max of rows to show in the live ranking widget.")]
public int MaxWidgetRows { get; set; }

[Option(DefaultValue = 63.0), Description("Specifies the Y position of the widget.")]
public double Y { get; set; }

[Option(DefaultValue = 36.0), Description("Specifies the width of the widget.")]
public double Width { get; set; }

[Option(DefaultValue = "right"), Description("Specifies on which side the widget is displayed.")]
public WidgetPosition Position { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using EvoSC.Common.Controllers.Attributes;
using EvoSC.Common.Events.Attributes;
using EvoSC.Common.Interfaces.Controllers;
using EvoSC.Common.Models;
using EvoSC.Common.Remote;
using EvoSC.Common.Remote.EventArgsModels;
using EvoSC.Modules.Official.LiveRankingModule.Interfaces;
Expand All @@ -12,30 +13,38 @@ namespace EvoSC.Modules.Official.LiveRankingModule.Controllers;
[Controller]
public class LiveRankingEventController(ILiveRankingService service) : EvoScController<IEventControllerContext>
{
[Subscribe(ModeScriptEvent.WayPoint)]
public Task OnPlayerWaypointAsync(object sender, WayPointEventArgs args) => service.OnPlayerWaypointAsync(args);

[Subscribe(ModeScriptEvent.GiveUp)]
public Task OnPlayerGiveUpAsync(object sender, PlayerUpdateEventArgs args) => service.OnPlayerGiveupAsync(args);

[Subscribe(ModeScriptEvent.StartRoundStart)]
public Task OnStartRoundAsync(object sender, RoundEventArgs args) => service.OnStartRoundAsync(args);

[Subscribe(ModeScriptEvent.EndMapStart)]
public Task OnEndMapAsync(object sender, MapEventArgs args) => service.OnEndMapAsync(args);
[Subscribe(GbxRemoteEvent.BeginMap)]
public Task OnBeginMapAsync(object sender, MapGbxEventArgs args)
=> service.DetectModeAndRequestScoreAsync();

[Subscribe(ModeScriptEvent.Scores)]
public async Task OnScoresAsync(object sender, ScoresEventArgs args)
{
if (args.Section is not (ModeScriptSection.EndRound or ModeScriptSection.Undefined))
{
return;
}

await service.MapScoresAndSendWidgetAsync(args);
}

[Subscribe(ModeScriptEvent.PodiumStart)]
public Task OnPodiumStartAsync(object sender, PodiumEventArgs args) => service.OnPodiumStartAsync(args);
public Task OnPodiumStartAsync(object sender, PodiumEventArgs args)
=> service.HideWidgetAsync();

[Subscribe(ModeScriptEvent.EndRoundStart)]
public Task OnEndRoundAsync(object sender, RoundEventArgs args) => service.OnEndRoundAsync(args);

[Subscribe(GbxRemoteEvent.BeginMatch)]
public Task OnBeginMatchAsync(object sender, EventArgs args) => service.OnBeginMatchAsync();

[Subscribe(GbxRemoteEvent.EndMatch)]
public Task OnEndMatchAsync(object sender, EndMatchGbxEventArgs args) => service.OnEndMatchAsync(args);

[Subscribe(GbxRemoteEvent.PlayerConnect)]
public Task OnPlayerConnectAsync(object sender, PlayerConnectGbxEventArgs args) => service.SendManialinkAsync();
[Subscribe(ModeScriptEvent.WayPoint)]
public async Task OnWayPointAsync(object sender, WayPointEventArgs args)
{
if (!args.IsEndLap)
{
return;
}

if (await service.CurrentModeIsPointsBasedAsync())
{
return;
}

await service.RequestScoresAsync();
}
}
76 changes: 22 additions & 54 deletions src/Modules/LiveRankingModule/Interfaces/ILiveRankingService.cs
Original file line number Diff line number Diff line change
@@ -1,92 +1,60 @@
using EvoSC.Common.Remote.EventArgsModels;
using EvoSC.Common.Models.Callbacks;
using EvoSC.Common.Remote.EventArgsModels;
using EvoSC.Modules.Official.LiveRankingModule.Models;
using GbxRemoteNet.Events;

namespace EvoSC.Modules.Official.LiveRankingModule.Interfaces;

public interface ILiveRankingService
{
/// <summary>
/// Called on when module is enabled
/// Determines if current mode is points based and requests scores.
/// </summary>
/// <returns></returns>
Task OnEnableAsync();
public Task DetectModeAndRequestScoreAsync();

/// <summary>
/// Called on when module is disabled
/// Requests scores from the game mode.
/// </summary>
/// <returns></returns>
Task OnDisableAsync();
public Task RequestScoresAsync();

/// <summary>
/// Called when a player passes a checkpoint.
/// Maps the scores and displays the widget.
/// </summary>
/// <param name="scores"></param>
/// <returns></returns>
Task OnPlayerWaypointAsync(WayPointEventArgs args);
public Task MapScoresAndSendWidgetAsync(ScoresEventArgs scores);

/// <summary>
/// Called when a player retires from the current round.
/// Maps the given ScoresEventArgs to LiveRankingPositions.
/// </summary>
/// <param name="scores"></param>
/// <returns></returns>
Task OnPlayerGiveupAsync(PlayerUpdateEventArgs args);
public Task<IEnumerable<LiveRankingPosition>> MapScoresAsync(ScoresEventArgs scores);

/// <summary>
/// Called when a new map starts.
/// Hides the live ranking widget for everyone.
/// </summary>
/// <returns></returns>
Task OnBeginMapAsync(MapEventArgs args);
public Task HideWidgetAsync();

/// <summary>
/// Called when a map ends.
/// Returns whether the current mode is points based.
/// </summary>
/// <returns></returns>
Task OnEndMapAsync(MapEventArgs args);
public Task<bool> CurrentModeIsPointsBasedAsync();

/// <summary>
/// Called when a round ends.
/// Determines whether a score should be displayed in the widget.
/// </summary>
/// <param name="score"></param>
/// <returns></returns>
Task OnEndRoundAsync(RoundEventArgs args);
public bool ScoreShouldBeDisplayed(PlayerScore score);

/// <summary>
/// Called when a new round starts.
/// Converts a PlayerScore to a LiveRankingPosition object.
/// </summary>
/// <param name="score"></param>
/// <returns></returns>
Task OnStartRoundAsync(RoundEventArgs args);

/// <summary>
/// Called when the podium sequence starts.
/// </summary>
/// <returns></returns>
Task OnPodiumStartAsync(PodiumEventArgs args);

/// <summary>
/// Sends a manialink.
/// </summary>
/// <returns></returns>
Task SendManialinkAsync();

/// <summary>
/// Called when a new match starts.
/// </summary>
/// <returns></returns>
Task OnBeginMatchAsync();

/// <summary>
/// Called when a match ends.
/// </summary>
/// <returns></returns>
Task OnEndMatchAsync(EndMatchGbxEventArgs args);

/// <summary>
/// Calculates and sets the diffs of given live ranking positions.
/// </summary>
/// <returns></returns>
Task CalculateDiffsAsync(List<ExpandedLiveRankingPosition> rankings);

/// <summary>
/// Resets the live ranking data.
/// </summary>
/// <returns></returns>
Task ResetLiveRankingAsync();
public LiveRankingPosition PlayerScoreToLiveRankingPosition(PlayerScore score);
}
5 changes: 2 additions & 3 deletions src/Modules/LiveRankingModule/LiveRankingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace EvoSC.Modules.Official.LiveRankingModule;
[Module(IsInternal = true)]
public class LiveRankingModule(ILiveRankingService service) : EvoScModule, IToggleable
{
public Task EnableAsync() => service.OnEnableAsync();
public Task EnableAsync() => service.DetectModeAndRequestScoreAsync();

// if no cleaning for the classes needed to be done, return here a completed task, otherwise clean the classes, and then complete the task.
public Task DisableAsync() => service.OnDisableAsync();
public Task DisableAsync() => Task.CompletedTask;
}
4 changes: 4 additions & 0 deletions src/Modules/LiveRankingModule/LiveRankingModule.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<ProjectReference Include="..\..\EvoSC.Modules.SourceGeneration\EvoSC.Modules.SourceGeneration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\..\EvoSC.Modules\EvoSC.Modules.csproj" />
<EmbeddedResource Include="Templates\**\*" />
<EmbeddedResource Update="Localization.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Localization.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>


Expand Down
19 changes: 19 additions & 0 deletions src/Modules/LiveRankingModule/Localization.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
<xsd:element name="root" msdata:IsDataSet="true">
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

This file was deleted.

10 changes: 1 addition & 9 deletions src/Modules/LiveRankingModule/Models/LiveRankingPosition.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
namespace EvoSC.Modules.Official.LiveRankingModule.Models;

/// <summary>
/// The live ranking position of a player.
/// </summary>
/// <param name="AccountId">Account Id of the player.</param>
/// <param name="CpTime">The checkpoint time of the player.</param>
/// <param name="CpIndex">The checkpoint index that was driven through.</param>
/// <param name="IsDnf">Whether the player has given up or not.</param>
/// <param name="IsFinish">Whether the player has finished.</param>
public record LiveRankingPosition(string AccountId, int CpTime, int CpIndex, bool IsDnf, bool IsFinish);
public record LiveRankingPosition(string AccountId, string Name, int Position, int Time, int Points);
Loading
Loading