diff --git a/MHFZ_Overlay/Services/TimeService.cs b/MHFZ_Overlay/Services/TimeService.cs index c148381b..98e907a8 100644 --- a/MHFZ_Overlay/Services/TimeService.cs +++ b/MHFZ_Overlay/Services/TimeService.cs @@ -13,6 +13,7 @@ namespace MHFZ_Overlay.Services; using System.Threading.Tasks; using MHFZ_Overlay.Models.Constant; using MHFZ_Overlay.Models.Structures; +using MHFZ_Overlay.Services.Contracts; using NLog; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock; @@ -23,12 +24,12 @@ public static class TimeService { private static readonly Logger LoggerInstance = LogManager.GetCurrentClassLogger(); - public static double GetFramesFromTimeSpan(TimeSpan time) + private static double GetFramesFromTimeSpan(TimeSpan time) { return TimeSpan.FromSeconds(time.TotalSeconds * (double)Numbers.FramesPerSecond).TotalSeconds * (double)Numbers.FramesPerSecond; } - public static TimeSpan GetTimeSpanFromFrames(decimal frames) + private static TimeSpan GetTimeSpanFromFrames(decimal frames) { return TimeSpan.FromSeconds((double)frames / (double)Numbers.FramesPerSecond); } @@ -99,7 +100,7 @@ public static string TestTimerMethods(decimal timeDefInt) Simple: {timer3Result}"; } - public static string SimpleTimer(decimal timeInt, decimal timeDefInt = 0, bool timeLeftPercentShown = false, string timeLeftPercentNumber = "", TimerMode timerMode = TimerMode.Elapsed) + private static string SimpleTimer(decimal timeInt, decimal timeDefInt = 0, bool timeLeftPercentShown = false, string timeLeftPercentNumber = "", TimerMode timerMode = TimerMode.Elapsed) { // TODO wrong conditionals for timeint >= timedefint? decimal time = timerMode == TimerMode.Elapsed && timeInt <= timeDefInt ? time = timeDefInt - timeInt : time = timeInt; @@ -113,7 +114,7 @@ public static string SimpleTimer(decimal timeInt, decimal timeDefInt = 0, bool t return $"{minutes:00}:{seconds:00}.{remainingMilliseconds:000}" + timeLeftPercent; } - public static string StringBuilderTimer(decimal timeInt, TimerFormat timerFormat, bool isFrames = true, decimal timeDefInt = 0, bool timeLeftPercentShown = false, string timeLeftPercentNumber = "", TimerMode timerMode = TimerMode.Elapsed) + private static string StringBuilderTimer(decimal timeInt, TimerFormat timerFormat, bool isFrames = true, decimal timeDefInt = 0, bool timeLeftPercentShown = false, string timeLeftPercentNumber = "", TimerMode timerMode = TimerMode.Elapsed) { decimal time = timerMode == TimerMode.Elapsed && timeInt <= timeDefInt ? time = timeDefInt - timeInt : time = timeInt; decimal framesPerSecond = isFrames ? Numbers.FramesPerSecond : 1; @@ -142,7 +143,7 @@ public static string StringBuilderTimer(decimal timeInt, TimerFormat timerFormat return sb.ToString(); } - public static string TimeSpanTimer(decimal timeInt, decimal timeDefInt = 0, bool timeLeftPercentShown = false, string timeLeftPercentNumber = "", TimerMode timerMode = TimerMode.Elapsed) + private static string TimeSpanTimer(decimal timeInt, decimal timeDefInt = 0, bool timeLeftPercentShown = false, string timeLeftPercentNumber = "", TimerMode timerMode = TimerMode.Elapsed) { decimal time = timerMode == TimerMode.Elapsed && timeInt <= timeDefInt ? time = timeDefInt - timeInt : time = timeInt; decimal timeInSeconds = time / Numbers.FramesPerSecond; diff --git a/MHFZ_Overlay/ViewModels/Windows/BingoWindowViewModel.cs b/MHFZ_Overlay/ViewModels/Windows/BingoWindowViewModel.cs index c1d1aad0..c6b3bbba 100644 --- a/MHFZ_Overlay/ViewModels/Windows/BingoWindowViewModel.cs +++ b/MHFZ_Overlay/ViewModels/Windows/BingoWindowViewModel.cs @@ -38,18 +38,22 @@ namespace MHFZ_Overlay.ViewModels.Windows; using LiveChartsCore.Kernel.Sketches; using System.Windows.Markup; -public partial class BingoWindowViewModel : ObservableRecipient +public partial class BingoWindowViewModel : ObservableRecipient, IRecipient, IRecipient { - private ObservableCollection _observableValues { get; set; } + private ObservableCollection? _observableValues { get; set; } + + private static readonly NLog.Logger LoggerInstance = NLog.LogManager.GetCurrentClassLogger(); public BingoWindowViewModel(SnackbarPresenter snackbarPresenter) { - WeakReferenceMessenger.Default.Register(this, OnReceivedQuestID); - WeakReferenceMessenger.Default.Register(this, OnReceivedRunID); BingoWindowSnackbarPresenter = snackbarPresenter; SetGraphs(); } + public void Receive(QuestIDMessage message) => OnReceivedQuestID(message); + + public void Receive(RunIDMessage message) => OnReceivedRunID(message); + private void SetGraphs() { // Use ObservableCollections to let the chart listen for changes (or any INotifyCollectionChanged). @@ -116,7 +120,7 @@ public IEnumerable Difficulties [ObservableProperty] private BingoCell[,]? cells = new BingoCell[5, 5]; - public ObservableCollection Series { get; set; } + public ObservableCollection? Series { get; set; } // TODO private void UpdateBingoBoard(int questID) @@ -160,28 +164,22 @@ private void UpdateRunIDs(int runID) partial void OnReceivedRunIDChanged(int value) => UpdateRunIDs(value); - private void OnReceivedQuestID(object recipient, QuestIDMessage message) + private void OnReceivedQuestID(QuestIDMessage message) { - // Handle the message here, with r being the recipient and m being the - // input message. Using the recipient passed as input makes it so that - // the lambda expression doesn't capture "this", improving performance. - MessageBox.Show(nameof(recipient)); if (!IsBingoRunning) { + LoggerInstance.Info("Received Quest {0} but bingo is not running.", message); return; } ReceivedQuestID = message.Value; } - private void OnReceivedRunID(object recipient, RunIDMessage message) + private void OnReceivedRunID(RunIDMessage message) { - // Handle the message here, with r being the recipient and m being the - // input message. Using the recipient passed as input makes it so that - // the lambda expression doesn't capture "this", improving performance. - MessageBox.Show(nameof(recipient)); if (!IsBingoRunning) { + LoggerInstance.Info("Received Run {0} but bingo is not running.", message); return; }