diff --git a/src/Modules/CurrentMapModule/Config/ICurrentMapSettings.cs b/src/Modules/CurrentMapModule/Config/ICurrentMapSettings.cs new file mode 100644 index 000000000..b4cbd2f24 --- /dev/null +++ b/src/Modules/CurrentMapModule/Config/ICurrentMapSettings.cs @@ -0,0 +1,18 @@ +using System.ComponentModel; +using Config.Net; +using EvoSC.Modules.Attributes; + +namespace EvoSC.Modules.Official.CurrentMapModule.Config; + +[Settings] +public interface ICurrentMapSettings +{ + [Option(DefaultValue = 80.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 string Position { get; set; } +} diff --git a/src/Modules/CurrentMapModule/Controllers/CurrentMapController.cs b/src/Modules/CurrentMapModule/Controllers/CurrentMapEventController.cs similarity index 89% rename from src/Modules/CurrentMapModule/Controllers/CurrentMapController.cs rename to src/Modules/CurrentMapModule/Controllers/CurrentMapEventController.cs index 7c6b5dd13..8021163be 100644 --- a/src/Modules/CurrentMapModule/Controllers/CurrentMapController.cs +++ b/src/Modules/CurrentMapModule/Controllers/CurrentMapEventController.cs @@ -10,7 +10,7 @@ namespace EvoSC.Modules.Official.CurrentMapModule.Controllers; [Controller] -public class CurrentMapController(ICurrentMapService service) : EvoScController +public class CurrentMapEventController(ICurrentMapService service) : EvoScController { [Subscribe(GbxRemoteEvent.BeginMatch)] public Task OnBeginMatchAsync(object sender, EventArgs args) diff --git a/src/Modules/CurrentMapModule/Services/CurrentMapService.cs b/src/Modules/CurrentMapModule/Services/CurrentMapService.cs index e203b9e57..5ce9d636f 100644 --- a/src/Modules/CurrentMapModule/Services/CurrentMapService.cs +++ b/src/Modules/CurrentMapModule/Services/CurrentMapService.cs @@ -4,16 +4,21 @@ using EvoSC.Common.Services.Attributes; using EvoSC.Common.Services.Models; using EvoSC.Manialinks.Interfaces; +using EvoSC.Modules.Official.CurrentMapModule.Config; using EvoSC.Modules.Official.CurrentMapModule.Interfaces; -using EvoSC.Modules.Official.WorldRecordModule.Interfaces; using GbxRemoteNet.Events; using Microsoft.Extensions.Logging; namespace EvoSC.Modules.Official.CurrentMapModule.Services; [Service(LifeStyle = ServiceLifeStyle.Transient)] -public class CurrentMapService(IManialinkManager manialinkManager, ILogger logger, - IMapRepository mapRepository, IServerClient client, IWorldRecordService worldRecordService) +public class CurrentMapService( + IManialinkManager manialinkManager, + ILogger logger, + IMapRepository mapRepository, + IServerClient client, + ICurrentMapSettings settings +) : ICurrentMapService { [ExcludeFromCodeCoverage(Justification = "GBXRemoteClient cannot be mocked.")] @@ -37,24 +42,22 @@ public async Task HideWidgetAsync() private async Task ShowManialinkAsync(string mapUId) { var dbMap = await mapRepository.GetMapByUidAsync(mapUId); - string author; - var worldRecord = await worldRecordService.GetRecordAsync(); - if (dbMap?.Author?.NickName == dbMap?.Author?.AccountId) + + if (dbMap == null) { - var serverMap = await client.Remote.GetCurrentMapInfoAsync(); - author = serverMap.AuthorNickname.Length > 0 ? serverMap.AuthorNickname : serverMap.Author; + return; } - else + + var author = dbMap.Author?.NickName; + + if (dbMap.Author?.NickName == dbMap.Author?.AccountId) { - author = dbMap.Author?.NickName; + var serverMap = await client.Remote.GetCurrentMapInfoAsync(); + author = serverMap.AuthorNickname.Length > 0 ? serverMap.AuthorNickname : serverMap.Author; } + await manialinkManager.SendPersistentManialinkAsync("CurrentMapModule.CurrentMapWidget", - new - { - map = dbMap, - mapauthor = author, - record = worldRecord - }); + new { map = dbMap, mapAuthor = author, settings }); logger.LogDebug("Showing current map widget"); } } diff --git a/src/Modules/CurrentMapModule/Templates/CurrentMapWidget.mt b/src/Modules/CurrentMapModule/Templates/CurrentMapWidget.mt index db5e60ec5..eb3816eb2 100644 --- a/src/Modules/CurrentMapModule/Templates/CurrentMapWidget.mt +++ b/src/Modules/CurrentMapModule/Templates/CurrentMapWidget.mt @@ -1,123 +1,36 @@  - + - - - + + - - - - - + + + \ No newline at end of file diff --git a/src/Modules/CurrentMapModule/info.toml b/src/Modules/CurrentMapModule/info.toml index 63d9103ad..d98a863e6 100644 --- a/src/Modules/CurrentMapModule/info.toml +++ b/src/Modules/CurrentMapModule/info.toml @@ -2,8 +2,5 @@ name = "CurrentMapModule" title = "Current Map Module" summary = "A module for showing the current map" -version = "1.0.0" +version = "1.0.1" author = "Evo" - -[dependencies] -WorldRecordModule = "1.0.0" diff --git a/src/Modules/NextMapModule/Config/INextMapSettings.cs b/src/Modules/NextMapModule/Config/INextMapSettings.cs new file mode 100644 index 000000000..4ca1eb12a --- /dev/null +++ b/src/Modules/NextMapModule/Config/INextMapSettings.cs @@ -0,0 +1,18 @@ +using System.ComponentModel; +using Config.Net; +using EvoSC.Modules.Attributes; + +namespace EvoSC.Modules.Official.NextMapModule.Config; + +[Settings] +public interface INextMapSettings +{ + [Option(DefaultValue = 80.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 string Position { get; set; } +} diff --git a/src/Modules/NextMapModule/Controllers/NextMapEventController.cs b/src/Modules/NextMapModule/Controllers/NextMapEventController.cs index f854671c1..924198a57 100644 --- a/src/Modules/NextMapModule/Controllers/NextMapEventController.cs +++ b/src/Modules/NextMapModule/Controllers/NextMapEventController.cs @@ -5,13 +5,18 @@ using EvoSC.Common.Remote; using EvoSC.Common.Remote.EventArgsModels; using EvoSC.Manialinks.Interfaces; +using EvoSC.Modules.Official.NextMapModule.Config; using EvoSC.Modules.Official.NextMapModule.Interfaces; +using GbxRemoteNet.Events; namespace EvoSC.Modules.Official.NextMapModule.Controllers; [Controller] -public class NextMapEventController(INextMapService nextMapService, IManialinkManager manialinkManager) - : EvoScController +public class NextMapEventController( + INextMapService nextMapService, + IManialinkManager manialinkManager, + INextMapSettings settings +) : EvoScController { private const string Template = "NextMapModule.NextMap"; @@ -20,27 +25,11 @@ public async Task ShowNextMapOnPodiumStartAsync(object sender, PodiumEventArgs a { var nextMap = await nextMapService.GetNextMapAsync(); await manialinkManager.SendManialinkAsync(Template, - new - { - mapName = nextMap.Name, - author = nextMap.Author?.NickName - }); + new { mapName = nextMap.Name, author = nextMap.Author?.NickName, settings }); } - [Subscribe(ModeScriptEvent.PodiumEnd)] - public async Task HideNextMapOnPodiumEndAsync(object sender, PodiumEventArgs args) - { - await manialinkManager.HideManialinkAsync(Template); - } - - [Subscribe(ModeScriptEvent.StartMapStart)] - public async Task HideNextMapOnMapStartAsync(object sender, MapEventArgs args) - { - await manialinkManager.HideManialinkAsync(Template); - } - - [Subscribe(ModeScriptEvent.EndMapEnd)] - public async Task HideNextMapOnMapEndAsync(object sender, MapEventArgs args) + [Subscribe(GbxRemoteEvent.BeginMap)] + public async Task HideNextMapOnBeginMapAsync(object sender, MapGbxEventArgs args) { await manialinkManager.HideManialinkAsync(Template); } diff --git a/src/Modules/NextMapModule/Templates/NextMap.mt b/src/Modules/NextMapModule/Templates/NextMap.mt index e847b17cb..a601d30e8 100644 --- a/src/Modules/NextMapModule/Templates/NextMap.mt +++ b/src/Modules/NextMapModule/Templates/NextMap.mt @@ -1,107 +1,36 @@  + + + + - - - - - - - - - - - - - - + + + \ No newline at end of file diff --git a/tests/Modules/CurrentMapModule.Tests/CurrentMapControllerTest.cs b/tests/Modules/CurrentMapModule.Tests/CurrentMapEventControllerTest.cs similarity index 53% rename from tests/Modules/CurrentMapModule.Tests/CurrentMapControllerTest.cs rename to tests/Modules/CurrentMapModule.Tests/CurrentMapEventControllerTest.cs index fb4b5626b..d75daeb11 100644 --- a/tests/Modules/CurrentMapModule.Tests/CurrentMapControllerTest.cs +++ b/tests/Modules/CurrentMapModule.Tests/CurrentMapEventControllerTest.cs @@ -1,44 +1,44 @@ -using EvoSC.Common.Remote.EventArgsModels; -using EvoSC.Modules.Official.CurrentMapModule.Controllers; -using EvoSC.Modules.Official.CurrentMapModule.Interfaces; -using GbxRemoteNet.Events; -using Moq; - -namespace EvoSC.Modules.Official.CurrentMapModule.Tests; - -public class CurrentMapControllerTest -{ - private readonly CurrentMapController _controller; - private readonly Mock _service = new(); - - public CurrentMapControllerTest() - { - _controller = new CurrentMapController(_service.Object); - } - - [Fact] - private async void Should_On_Begin_Match_Async() - { - await _controller.OnBeginMatchAsync(new object(), EventArgs.Empty); - - _service.Verify(service => service.ShowWidgetAsync()); - } - - [Fact] - private async void Should_On_Begin_Map_Async() - { - var args = new MapGbxEventArgs(); - await _controller.OnBeginMapAsync(new object(), args); - - _service.Verify(service => service.ShowWidgetAsync(args)); - } - - [Fact] - private async void Should_On_Podium_Start_Async() - { - var args = new PodiumEventArgs { Time = 0 }; - await _controller.OnPodiumStartAsync(new object(), args); - - _service.Verify(service => service.HideWidgetAsync()); - } -} +using EvoSC.Common.Remote.EventArgsModels; +using EvoSC.Modules.Official.CurrentMapModule.Controllers; +using EvoSC.Modules.Official.CurrentMapModule.Interfaces; +using GbxRemoteNet.Events; +using Moq; + +namespace EvoSC.Modules.Official.CurrentMapModule.Tests; + +public class CurrentMapEventControllerTest +{ + private readonly CurrentMapEventController _eventController; + private readonly Mock _service = new(); + + public CurrentMapEventControllerTest() + { + _eventController = new CurrentMapEventController(_service.Object); + } + + [Fact] + private async Task Should_On_Begin_Match_Async() + { + await _eventController.OnBeginMatchAsync(new object(), EventArgs.Empty); + + _service.Verify(service => service.ShowWidgetAsync()); + } + + [Fact] + private async Task Should_On_Begin_Map_Async() + { + var args = new MapGbxEventArgs(); + await _eventController.OnBeginMapAsync(new object(), args); + + _service.Verify(service => service.ShowWidgetAsync(args)); + } + + [Fact] + private async Task Should_On_Podium_Start_Async() + { + var args = new PodiumEventArgs { Time = 0 }; + await _eventController.OnPodiumStartAsync(new object(), args); + + _service.Verify(service => service.HideWidgetAsync()); + } +} diff --git a/tests/Modules/CurrentMapModule.Tests/CurrentMapServiceTest.cs b/tests/Modules/CurrentMapModule.Tests/CurrentMapServiceTest.cs index 51f028926..40beaeb48 100644 --- a/tests/Modules/CurrentMapModule.Tests/CurrentMapServiceTest.cs +++ b/tests/Modules/CurrentMapModule.Tests/CurrentMapServiceTest.cs @@ -1,13 +1,8 @@ -using EvoSC.Common.Config.Models; -using EvoSC.Common.Interfaces; +using EvoSC.Common.Interfaces; using EvoSC.Common.Interfaces.Database.Repository; -using EvoSC.Common.Interfaces.Models; -using EvoSC.Common.Interfaces.Themes; -using EvoSC.Common.Models.Maps; -using EvoSC.Common.Models.Players; using EvoSC.Manialinks.Interfaces; +using EvoSC.Modules.Official.CurrentMapModule.Config; using EvoSC.Modules.Official.CurrentMapModule.Services; -using EvoSC.Modules.Official.WorldRecordModule.Interfaces; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Moq; @@ -20,22 +15,17 @@ public class CurrentMapServiceTest private readonly CurrentMapService _currentMapService; private readonly ILogger _logger = new NullLogger(); private readonly Mock _manialinkManager = new(); - - private readonly IMap _map = new Map { Author = new Player { Zone = "||Germany" } }; + private readonly Mock _settings = new(); private readonly Mock _mapRepositoryMock = new(); - private readonly Mock _configMock = new(); - private readonly Mock _worldRecordServiceMock = new(); - private readonly Mock _themeManagerMock = new(); public CurrentMapServiceTest() { _currentMapService = - new CurrentMapService(_manialinkManager.Object, _logger, _mapRepositoryMock.Object, _clientMock.Object, - _worldRecordServiceMock.Object); + new CurrentMapService(_manialinkManager.Object, _logger, _mapRepositoryMock.Object, _clientMock.Object, _settings.Object); } [Fact] - async void Should_Hide_Widget() + async Task Should_Hide_Widget() { await _currentMapService.HideWidgetAsync(); _manialinkManager.Verify(manager => manager.HideManialinkAsync("CurrentMapModule.CurrentMapWidget")); diff --git a/tests/Modules/NextMapModule.Tests/Controllers/NextMapEventControllerTests.cs b/tests/Modules/NextMapModule.Tests/Controllers/NextMapEventControllerTests.cs index 089f13da2..3ad726458 100644 --- a/tests/Modules/NextMapModule.Tests/Controllers/NextMapEventControllerTests.cs +++ b/tests/Modules/NextMapModule.Tests/Controllers/NextMapEventControllerTests.cs @@ -3,9 +3,11 @@ using EvoSC.Common.Interfaces.Models; using EvoSC.Common.Remote.EventArgsModels; using EvoSC.Manialinks.Interfaces; +using EvoSC.Modules.Official.NextMapModule.Config; using EvoSC.Modules.Official.NextMapModule.Controllers; using EvoSC.Modules.Official.NextMapModule.Interfaces; using EvoSC.Testing.Controllers; +using GbxRemoteNet.Events; using Moq; using Xunit; @@ -17,13 +19,13 @@ public class NextMapEventControllerTests : ControllerMock _nextMapService = new(); private readonly Mock _manialinkManager = new(); + private readonly Mock _settings = new(); public NextMapEventControllerTests() { - InitMock(_nextMapService, _manialinkManager); + InitMock(_nextMapService, _manialinkManager, _settings); } - [Fact] public async Task OnPodiumStart_Shows_Next_Map() { @@ -47,7 +49,7 @@ public async Task OnPodiumStart_Shows_Next_Map() } [Fact] - public async Task OnPodiumEnd_Hides_Next_Map() + public async Task OnBeginMap_Hides_Next_Map() { var map = new DbMap { @@ -60,7 +62,7 @@ public async Task OnPodiumEnd_Hides_Next_Map() }; _nextMapService.Setup(r => r.GetNextMapAsync()).Returns(Task.FromResult((IMap) map)); - await Controller.HideNextMapOnPodiumEndAsync(new(), null); + await Controller.HideNextMapOnBeginMapAsync(null, new MapGbxEventArgs()); _manialinkManager.Verify(r => r.HideManialinkAsync(Template), Times.Once); } }