Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: Added some comments, unwrapped last LINQ
Browse files Browse the repository at this point in the history
  • Loading branch information
RiotNOR committed May 16, 2023
1 parent a6145df commit 059efa8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
1 change: 0 additions & 1 deletion RotationSolver/Helpers/RotationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
44 changes: 34 additions & 10 deletions RotationSolver/Updaters/RotationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ internal static class RotationUpdater
internal static SortedList<string, string> AuthorHashes { get; private set; } = new SortedList<string, string>();
static CustomRotationGroup[] CustomRotations { get; set; } = Array.Empty<CustomRotationGroup>();

public static ICustomRotation RightNowRotation { get; private set; }
public static IAction[] RightRotationActions { get; private set; } = Array.Empty<IAction>();

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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -108,10 +115,25 @@ private static void LoadRotationsFromLocal(string relayFolder)
}

CustomRotations = LoadCustomRotationGroup(assemblies);
var customRotationsGroupedByJobRole = new Dictionary<JobRole, List<CustomRotationGroup>>();
foreach (var customRotationGroup in CustomRotations)
{
var jobRole = customRotationGroup.Rotations[0].Job.GetJobRole();
if (!customRotationsGroupedByJobRole.ContainsKey(jobRole))
{
customRotationsGroupedByJobRole[jobRole] = new List<CustomRotationGroup>();
}
customRotationsGroupedByJobRole[jobRole].Add(customRotationGroup);
}

CustomRotationsDict = new SortedList<JobRole, CustomRotationGroup[]>();
foreach (var jobRole in customRotationsGroupedByJobRole.Keys)
{
var customRotationGroups = customRotationsGroupedByJobRole[jobRole];
var sortedCustomRotationGroups = customRotationGroups.OrderBy(crg => crg.JobId).ToArray();
CustomRotationsDict[jobRole] = sortedCustomRotationGroups;
}

CustomRotationsDict = new SortedList<JobRole, CustomRotationGroup[]>
(CustomRotations.GroupBy(g => g.Rotations[0].Job.GetJobRole())
.ToDictionary(set => set.Key, set => set.OrderBy(i => i.JobId).ToArray()));
}

private static CustomRotationGroup[] LoadCustomRotationGroup(List<Assembly> assemblies)
Expand Down Expand Up @@ -156,8 +178,9 @@ private static CustomRotationGroup[] LoadCustomRotationGroup(List<Assembly> 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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -332,8 +360,6 @@ private static ICustomRotation[] CreateRotationSet(ICustomRotation[] combos)
return result.ToArray();
}

public static ICustomRotation RightNowRotation { get; private set; }

public static IEnumerable<IGrouping<string, IAction>> AllGroupedActions
=> RightNowRotation?.AllActions.GroupBy(a =>
{
Expand Down Expand Up @@ -377,8 +403,6 @@ public static IEnumerable<IGrouping<string, IAction>> AllGroupedActions

}).OrderBy(g => g.Key);

public static IAction[] RightRotationActions { get; private set; } = Array.Empty<IAction>();

public static void UpdateRotation()
{
var nowJob = (ClassJobID)Service.Player.ClassJob.Id;
Expand Down

0 comments on commit 059efa8

Please sign in to comment.