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

GH-284 improve team info behaviour #285

Merged
merged 26 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ba756b1
Refactor live rankings
araszka Aug 7, 2024
027375b
Undo dependencies on live ranking
araszka Aug 7, 2024
8caf938
Use custom nicknames in live ranking widget
araszka Aug 9, 2024
0d6174e
Make live ranking detect points based game modes
araszka Aug 9, 2024
a4d31a7
Add no finishes info to live ranking widget
araszka Aug 9, 2024
c2e652f
Add LiveRankingModule controller tests
araszka Aug 9, 2024
5d00798
Add LiveRankingService doc comments
araszka Aug 9, 2024
e163431
Add live ranking service tests
araszka Aug 9, 2024
9deba0f
Add missing async method name suffix
araszka Aug 9, 2024
d6ffc45
Make utility classes non-async and add more tests for LiveRankingService
araszka Aug 10, 2024
8f166f9
Move live ranking styles to own component and create component for no…
araszka Aug 10, 2024
a2005ba
Add WidgetPosition enum
araszka Aug 10, 2024
048cc3e
Merge remote-tracking branch 'origin/master' into 219-redo-live-ranki…
araszka Aug 10, 2024
81528ec
Merge remote-tracking branch 'origin/master' into 284-improve-team-in…
araszka Aug 14, 2024
f7b9a34
Update points earlier in team info widget
araszka Aug 14, 2024
6f27369
Update team info module tests
araszka Aug 14, 2024
21fb769
Add TeamSettingsModule.SettingsUpdated event
araszka Aug 14, 2024
11c183f
Re-send team info widget if team settings have been updated
araszka Aug 14, 2024
073335e
Wording
araszka Aug 14, 2024
db018f9
Wording
araszka Aug 14, 2024
e65d865
Resolve code issues
araszka Aug 14, 2024
41ef09a
Update src/Modules/TeamInfoModule/Controllers/TeamInfoEventController.cs
araszka Aug 15, 2024
44e1a25
Raise team settings updated event async and delayed
araszka Aug 16, 2024
0da594a
Merge remote-tracking branch 'origin/284-improve-team-info-behaviour'…
araszka Aug 16, 2024
a9e6b43
Fix test
araszka Aug 16, 2024
9ed8eaf
Await delay instead of using ContinueWith
araszka Aug 16, 2024
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
3 changes: 3 additions & 0 deletions src/Modules/TeamInfoModule/Config/ITeamInfoSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public interface ITeamInfoSettings

[Option(DefaultValue = 80.0), Description("Specifies the vertical top edge position of the wigdet. Values from -90 to 90 allowed.")]
public double Y { get; set; }

[Option(DefaultValue = 1.0), Description("Specifies the scale of the widget.")]
public double Scale { get; set; }

[Option(DefaultValue = false), Description("If enabled a smaller version of the widget is shown, without the large team name.")]
public bool CompactMode { get; set; }
Expand Down
37 changes: 31 additions & 6 deletions src/Modules/TeamInfoModule/Controllers/TeamInfoEventController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
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.TeamInfoModule.Interfaces;
using EvoSC.Modules.Official.TeamSettingsModule.Events;
using EvoSC.Modules.Official.TeamSettingsModule.Events.EventArgs;
using GbxRemoteNet.Events;

namespace EvoSC.Modules.Official.TeamInfoModule.Controllers;
Expand Down Expand Up @@ -36,14 +37,27 @@ public async Task OnScoresAsync(object sender, ScoresEventArgs eventArgs)
await teamInfoService.SetModeIsTeamsAsync(true);
}

var teamInfos = eventArgs.Teams.ToList();
var team1Points = teamInfos[0]!.MatchPoints;
var team2Points = teamInfos[1]!.MatchPoints;
if (teamInfoService.ShouldUpdateTeamPoints(eventArgs.Section))
{
var teamInfos = eventArgs.Teams.ToList();

await teamInfoService.UpdatePointsAsync(
teamInfos[0]!.MatchPoints,
teamInfos[1]!.MatchPoints,
teamInfoService.ShouldExecuteManiaScript(eventArgs.Section)
);
araszka marked this conversation as resolved.
Show resolved Hide resolved
}
}

if (eventArgs.Section is ModeScriptSection.EndRound or ModeScriptSection.Undefined)
[Subscribe(ModeScriptEvent.StartMatchStart)]
public async Task OnMatchStartAsync(object sender, MatchEventArgs args)
{
if (!await teamInfoService.GetModeIsTeamsAsync())
{
await teamInfoService.UpdatePointsAsync(team1Points, team2Points);
return;
}

await teamInfoService.UpdatePointsAsync(0, 0, false);
}

[Subscribe(ModeScriptEvent.StartRoundStart)]
Expand Down Expand Up @@ -78,4 +92,15 @@ public async Task OnEndMapAsync(object sender, MapGbxEventArgs args)

await teamInfoService.HideTeamInfoWidgetEveryoneAsync();
}

[Subscribe(TeamSettingsEvents.SettingsUpdated)]
public async Task OnTeamSettingsUpdatedAsync(object sender, TeamSettingsEventArgs args)
{
if (!await teamInfoService.GetModeIsTeamsAsync())
{
return;
}

await Task.Delay(250).ContinueWith(t => teamInfoService.SendTeamInfoWidgetEveryoneAsync());
araszka marked this conversation as resolved.
Show resolved Hide resolved
}
}
20 changes: 18 additions & 2 deletions src/Modules/TeamInfoModule/Interfaces/ITeamInfoService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EvoSC.Common.Util.MatchSettings.Models.ModeScriptSettingsModels;
using EvoSC.Common.Models;
using EvoSC.Common.Util.MatchSettings.Models.ModeScriptSettingsModels;

namespace EvoSC.Modules.Official.TeamInfoModule.Interfaces;

Expand Down Expand Up @@ -63,8 +64,9 @@ public interface ITeamInfoService
/// </summary>
/// <param name="team1Points"></param>
/// <param name="team2Points"></param>
/// <param name="executeManiaScript"></param>
/// <returns></returns>
public Task UpdatePointsAsync(int team1Points, int team2Points);
public Task UpdatePointsAsync(int team1Points, int team2Points, bool executeManiaScript);

/// <summary>
/// Tells whether the service is currently active for teams mode.
Expand All @@ -78,4 +80,18 @@ public interface ITeamInfoService
/// <param name="modeIsTeams"></param>
/// <returns></returns>
public Task SetModeIsTeamsAsync(bool modeIsTeams);

/// <summary>
/// Determines whether the team points need to be updated.
/// </summary>
/// <param name="section"></param>
/// <returns></returns>
public bool ShouldUpdateTeamPoints(ModeScriptSection section);

/// <summary>
/// Determines when to execute the ManiaScript that updates team points client side.
/// </summary>
/// <param name="section"></param>
/// <returns></returns>
public bool ShouldExecuteManiaScript(ModeScriptSection section);
}
16 changes: 15 additions & 1 deletion src/Modules/TeamInfoModule/Services/TeamInfoService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EvoSC.Common.Interfaces;
using EvoSC.Common.Models;
using EvoSC.Common.Services.Attributes;
using EvoSC.Common.Services.Models;
using EvoSC.Common.Util.MatchSettings.Models.ModeScriptSettingsModels;
Expand All @@ -22,6 +23,7 @@ ITeamInfoSettings settings
private int _currentRound;
private int _team1Points;
private int _team2Points;
private bool _executeManiaScript;

public async Task InitializeModuleAsync()
{
Expand Down Expand Up @@ -52,6 +54,7 @@ public async Task<dynamic> GetWidgetDataAsync()
roundNumber = _currentRound,
team1Points = _team1Points,
team2Points = _team2Points,
executeManiaScript = _executeManiaScript,
neutralEmblemUrl = modeScriptSettings.NeutralEmblemUrl
};
}
Expand Down Expand Up @@ -125,10 +128,11 @@ public async Task UpdateRoundNumberAsync(int round)
await SendTeamInfoWidgetEveryoneAsync();
}

public async Task UpdatePointsAsync(int team1Points, int team2Points)
public async Task UpdatePointsAsync(int team1Points, int team2Points, bool executeManiaScript)
{
_team1Points = team1Points;
_team2Points = team2Points;
_executeManiaScript = executeManiaScript;
await SendTeamInfoWidgetEveryoneAsync();
}

Expand All @@ -143,4 +147,14 @@ public Task SetModeIsTeamsAsync(bool modeIsTeams)

return Task.CompletedTask;
}

public bool ShouldUpdateTeamPoints(ModeScriptSection section)
{
return section is ModeScriptSection.EndRound or ModeScriptSection.PreEndRound or ModeScriptSection.Undefined;
}

public bool ShouldExecuteManiaScript(ModeScriptSection section)
{
return section is ModeScriptSection.PreEndRound;
}
}
1 change: 1 addition & 0 deletions src/Modules/TeamInfoModule/TeamInfoModule.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Localization.Designer.cs</LastGenOutput>
</EmbeddedResource>
<ProjectReference Include="..\TeamSettingsModule\TeamSettingsModule.csproj" />
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletion src/Modules/TeamInfoModule/Templates/Components/PointsBox.mt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<component>
<property type="string" name="id" default="evosc_points_box"/>
<property type="double" name="width" default="12.0"/>
<property type="double" name="height" default="10.0"/>
<property type="double" name="x" default="0.0"/>
Expand All @@ -13,7 +14,8 @@
bgcolor="{{ color }}"
/>

<label pos="{{ width / 2.0 }} {{ height / -2.0 + 0.5 }}"
<label id="{{ id }}"
pos="{{ width / 2.0 }} {{ height / -2.0 + 0.5 }}"
class="text-3xl"
text="{{ points }}"
textcolor="{{ Theme.UI_TextPrimary }}"
Expand Down
30 changes: 26 additions & 4 deletions src/Modules/TeamInfoModule/Templates/TeamInfoWidget.mt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<using namespace="GbxRemoteNet.Structs"/>
<using namespace="EvoSC.Modules.Official.TeamInfoModule.Config"/>

<import component="EvoSC.Style.UIStyle" as="UIStyle" />
<import component="EvoSC.Style.UIStyle" as="UIStyle"/>
<import component="TeamInfoModule.Components.RoundCounter" as="RoundCounter"/>
<import component="TeamInfoModule.Components.PointsBox" as="PointsBox"/>
<import component="TeamInfoModule.Components.BottomInfoBox" as="BottomInfoBox"/>
Expand All @@ -16,6 +16,7 @@
<property type="TmTeamInfo" name="team1"/>
<property type="TmTeamInfo" name="team2"/>
<property type="string?" name="infoBoxText"/>
<property type="bool" name="executeManiaScript"/>
<property type="int" name="roundNumber" default="-1"/>
<property type="int" name="team1Points" default="0"/>
<property type="int" name="team2Points" default="0"/>
Expand All @@ -27,7 +28,7 @@
<template>
<UIStyle/>

<frame pos="{{ settings.X }} {{ settings.Y }}">
<frame pos="{{ settings.X }} {{ settings.Y }}" scale="{{ settings.Scale }}">
<BottomInfoBox if="infoBoxText != null"
y="-10"
text="{{ infoBoxText }}"
Expand All @@ -36,7 +37,8 @@
<RoundCounter roundNumber="{{ roundNumber }}"/>

<!-- TEAM 1 -->
<PointsBox x="-10.0"
<PointsBox id="pointsBox1"
x="-10.0"
points="{{ team1Points }}"
color="{{ team1.RGB }}"
halign="right"
Expand Down Expand Up @@ -64,7 +66,8 @@
</frame>

<!-- TEAM 2 -->
<PointsBox x="10.0"
<PointsBox id="pointsBox2"
x="10.0"
points="{{ team2Points }}"
color="{{ team2.RGB }}"
/>
Expand All @@ -91,4 +94,23 @@
</frame>
</frame>
</template>

<script>
<!--
main() {
if({{ !executeManiaScript ? "True" : "False" }}){
return;
}

declare pointsBox1Label <=> (Page.MainFrame.GetFirstChild("pointsBox1") as CMlLabel);
declare pointsBox2Label <=> (Page.MainFrame.GetFirstChild("pointsBox2") as CMlLabel);

while(True){
pointsBox1Label.Value = ClanScores[1] ^ "";
pointsBox2Label.Value = ClanScores[2] ^ "";
sleep(50);
}
}
-->
</script>
</component>
3 changes: 3 additions & 0 deletions src/Modules/TeamInfoModule/info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ summary = "Displays teams and their points in a widget on the screen."
version = "1.0.0"
# The name of the author that created this module
author = "Evo"

[dependencies]
TeamSettingsModule = "1.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using EvoSC.Modules.Official.TeamSettingsModule.Models;

namespace EvoSC.Modules.Official.TeamSettingsModule.Events.EventArgs;

public class TeamSettingsEventArgs: System.EventArgs
{
public required TeamSettingsModel Settings { get; init; }
}
9 changes: 9 additions & 0 deletions src/Modules/TeamSettingsModule/Events/TeamSettingsEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace EvoSC.Modules.Official.TeamSettingsModule.Events;

public enum TeamSettingsEvents
{
/// <summary>
/// Raised after team settings have been changed.
/// </summary>
SettingsUpdated
}
16 changes: 11 additions & 5 deletions src/Modules/TeamSettingsModule/Services/TeamSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
using EvoSC.Common.Services.Attributes;
using EvoSC.Common.Services.Models;
using EvoSC.Manialinks.Interfaces;
using EvoSC.Modules.Official.TeamSettingsModule.Events;
using EvoSC.Modules.Official.TeamSettingsModule.Events.EventArgs;
using EvoSC.Modules.Official.TeamSettingsModule.Interfaces;
using EvoSC.Modules.Official.TeamSettingsModule.Models;

namespace EvoSC.Modules.Official.TeamSettingsModule.Services;

[Service(LifeStyle = ServiceLifeStyle.Singleton)]
public class TeamSettingsService(IServerClient server, IManialinkManager manialinks, Locale locale)
public class TeamSettingsService(IServerClient server, IManialinkManager manialinks, IEventManager events, Locale locale)
: ITeamSettingsService
{
private const string ClubLinkGeneratorUrl = "https://club-link.evotm.workers.dev";
public const string DefaultTeam1Name = "Blue";
public const string DefaultTeam2Name = "Red";
public const string DefaultTeam1Color = "00f";
public const string DefaultTeam2Color = "f00";
public static readonly string DefaultTeam1Name = "Blue";
public static readonly string DefaultTeam2Name = "Red";
public static readonly string DefaultTeam1Color = "00f";
public static readonly string DefaultTeam2Color = "f00";

public async Task<TeamSettingsModel> GetCurrentTeamSettingsModel()
{
Expand Down Expand Up @@ -51,6 +53,10 @@ public async Task SetTeamSettingsAsync(TeamSettingsModel teamSettings)
teamSettings.Team2SecondaryColor, teamSettings.Team2EmblemUrl);

await server.Remote.SetForcedClubLinksAsync(clubLinkUrlTeam1, clubLinkUrlTeam2);
await events.RaiseAsync(TeamSettingsEvents.SettingsUpdated, new TeamSettingsEventArgs
{
Settings = teamSettings
});
}

public Task<NameValueCollection> ParseClubLinkUrl(string? clubLinkUrl)
Expand Down
Loading
Loading