diff --git a/RotationSolver/Helpers/RotationHelper.cs b/RotationSolver/Helpers/RotationHelper.cs index a8f73de1b..a6a2e694a 100644 --- a/RotationSolver/Helpers/RotationHelper.cs +++ b/RotationSolver/Helpers/RotationHelper.cs @@ -90,7 +90,6 @@ public static Vector4 GetColor(this ICustomRotation rotation) { if (!rotation.IsValid) { - PluginLog.Log("This is not a valid rotation: " + rotation.RotationName); return ImGuiColors.DPSRed; } diff --git a/RotationSolver/Updaters/RotationUpdater.cs b/RotationSolver/Updaters/RotationUpdater.cs index 3a2546219..9fa052e0a 100644 --- a/RotationSolver/Updaters/RotationUpdater.cs +++ b/RotationSolver/Updaters/RotationUpdater.cs @@ -13,10 +13,15 @@ internal static class RotationUpdater internal static SortedList AuthorHashes { get; private set; } = new SortedList(); static CustomRotationGroup[] CustomRotations { get; set; } = Array.Empty(); + public static ICustomRotation RightNowRotation { get; private set; } + public static IAction[] RightRotationActions { get; private set; } = Array.Empty(); + private static DateTime LastRunTime; static bool _isLoading = false; + // Retrieves custom rotations from local and/or downloads + // them from remote server based on DownloadOption public static async Task GetAllCustomRotationsAsync(DownloadOption option) { if (_isLoading) return; @@ -58,6 +63,8 @@ public static async Task GetAllCustomRotationsAsync(DownloadOption option) } } + // This method loads custom rotation groups from local directories and assemblies, creates a sorted list of + // author hashes, and creates a sorted list of custom rotations grouped by job role. private static void LoadRotationsFromLocal(string relayFolder) { var directories = Service.Config.OtherLibs @@ -108,10 +115,25 @@ private static void LoadRotationsFromLocal(string relayFolder) } CustomRotations = LoadCustomRotationGroup(assemblies); + var customRotationsGroupedByJobRole = new Dictionary>(); + foreach (var customRotationGroup in CustomRotations) + { + var jobRole = customRotationGroup.Rotations[0].Job.GetJobRole(); + if (!customRotationsGroupedByJobRole.ContainsKey(jobRole)) + { + customRotationsGroupedByJobRole[jobRole] = new List(); + } + customRotationsGroupedByJobRole[jobRole].Add(customRotationGroup); + } + + CustomRotationsDict = new SortedList(); + foreach (var jobRole in customRotationsGroupedByJobRole.Keys) + { + var customRotationGroups = customRotationsGroupedByJobRole[jobRole]; + var sortedCustomRotationGroups = customRotationGroups.OrderBy(crg => crg.JobId).ToArray(); + CustomRotationsDict[jobRole] = sortedCustomRotationGroups; + } - CustomRotationsDict = new SortedList - (CustomRotations.GroupBy(g => g.Rotations[0].Job.GetJobRole()) - .ToDictionary(set => set.Key, set => set.OrderBy(i => i.JobId).ToArray())); } private static CustomRotationGroup[] LoadCustomRotationGroup(List assemblies) @@ -156,8 +178,9 @@ private static CustomRotationGroup[] LoadCustomRotationGroup(List asse return result.ToArray(); } - - + // Downloads rotation files from a remote server and saves them to a local folder. + // The download list is obtained from a JSON file on the remote server. + // If mustDownload is set to true, it will always download the files, otherwise it will only download if the file doesn't exist locally. private static async Task DownloadRotationsAsync(string relayFolder, bool mustDownload) { // Code to download rotations from remote server @@ -253,9 +276,14 @@ private static Assembly LoadOne(string filePath) return null; } + + // This method watches for changes in local rotation files by checking the + // last modified time of the files in the directories specified in the configuration. + // If there are new changes, it triggers a reload of the custom rotation. + // This method uses Parallel.ForEach to improve performance. + // It also has a check to ensure it's not running too frequently, to avoid hurting the FPS of the game. public static void LocalRotationWatcher() { - // This will cripple FPS is run on every frame. if (DateTime.Now < LastRunTime.AddSeconds(2)) { return; @@ -332,8 +360,6 @@ private static ICustomRotation[] CreateRotationSet(ICustomRotation[] combos) return result.ToArray(); } - public static ICustomRotation RightNowRotation { get; private set; } - public static IEnumerable> AllGroupedActions => RightNowRotation?.AllActions.GroupBy(a => { @@ -377,8 +403,6 @@ public static IEnumerable> AllGroupedActions }).OrderBy(g => g.Key); - public static IAction[] RightRotationActions { get; private set; } = Array.Empty(); - public static void UpdateRotation() { var nowJob = (ClassJobID)Service.Player.ClassJob.Id;