diff --git a/XIVSlothCombo/Attributes/CustomComboInfoAttribute.cs b/XIVSlothCombo/Attributes/CustomComboInfoAttribute.cs index 89a4bd97e..97ca55650 100644 --- a/XIVSlothCombo/Attributes/CustomComboInfoAttribute.cs +++ b/XIVSlothCombo/Attributes/CustomComboInfoAttribute.cs @@ -51,7 +51,7 @@ internal CustomComboInfoAttribute(string fancyName, string description, byte job public uint ClassJobCategory => JobIDToClassJobCategory(JobID); - private int JobIDToRole(byte jobID) + private static int JobIDToRole(byte jobID) { if (Svc.Data.GetExcelSheet().HasRow(jobID)) return Svc.Data.GetExcelSheet().GetRow(jobID).Role; @@ -59,7 +59,7 @@ private int JobIDToRole(byte jobID) return 0; } - private uint JobIDToClassJobCategory(byte jobID) + private static uint JobIDToClassJobCategory(byte jobID) { if (Svc.Data.GetExcelSheet().HasRow(jobID)) return Svc.Data.GetExcelSheet().GetRow(jobID).ClassJobCategory.Row; diff --git a/XIVSlothCombo/Data/CustomComboCache.cs b/XIVSlothCombo/Data/CustomComboCache.cs index 33fdbdef0..820117afa 100644 --- a/XIVSlothCombo/Data/CustomComboCache.cs +++ b/XIVSlothCombo/Data/CustomComboCache.cs @@ -17,12 +17,10 @@ internal partial class CustomComboCache : IDisposable // Invalidate these private readonly ConcurrentDictionary<(uint StatusID, ulong? TargetID, ulong? SourceID), DalamudStatus.Status?> statusCache = new(); - private readonly ConcurrentDictionary cooldownCache = new(); + private readonly ConcurrentDictionary cooldownCache = new(); // Do not invalidate these - private readonly ConcurrentDictionary cooldownGroupCache = new(); private readonly ConcurrentDictionary jobGaugeCache = new(); - private readonly ConcurrentDictionary<(uint ActionID, uint ClassJobID, byte Level), (ushort CurrentMax, ushort Max)> chargesCache = new(); /// Initializes a new instance of the class. public CustomComboCache() => Service.Framework.Update += Framework_Update; @@ -74,12 +72,8 @@ internal T GetJobGauge() where T : JobGaugeBase /// Cooldown data. internal unsafe CooldownData GetCooldown(uint actionID) { - if (cooldownCache.TryGetValue(actionID, out CooldownData found)) - return found; - - ActionManager* actionManager = ActionManager.Instance(); - if (actionManager == null) - return cooldownCache[actionID] = default; + if (cooldownCache.TryGetValue(actionID, out CooldownData? found)) + return found!; CooldownData data = new() { @@ -108,19 +102,6 @@ internal static unsafe int GetResourceCost(uint actionID) return cost; } - /// Get the cooldown group of an action. - /// Action ID to check. - private byte GetCooldownGroup(uint actionID) - { - if (cooldownGroupCache.TryGetValue(actionID, out byte cooldownGroup)) - return cooldownGroup; - - var sheet = Service.DataManager.GetExcelSheet()!; - var row = sheet.GetRow(actionID); - - return cooldownGroupCache[actionID] = row!.CooldownGroup; - } - /// Triggers when the game framework updates. Clears cooldown and status caches. private unsafe void Framework_Update(IFramework framework) { diff --git a/XIVSlothCombo/Window/ConfigWindow.cs b/XIVSlothCombo/Window/ConfigWindow.cs index 68d1d17f5..cfead9dfd 100644 --- a/XIVSlothCombo/Window/ConfigWindow.cs +++ b/XIVSlothCombo/Window/ConfigWindow.cs @@ -101,92 +101,86 @@ public override void Draw() var topLeftSideHeight = region.Y; - using (var style = ImRaii.PushStyle(ImGuiStyleVar.CellPadding, new Vector2(4, 0))) - { - using (var table = ImRaii.Table("###MainTable", 2, ImGuiTableFlags.Resizable)) - { - if (!table) - return; + using var style = ImRaii.PushStyle(ImGuiStyleVar.CellPadding, new Vector2(4, 0)); + using var table = ImRaii.Table("###MainTable", 2, ImGuiTableFlags.Resizable); + if (!table) + return; - ImGui.TableSetupColumn("##LeftColumn", ImGuiTableColumnFlags.WidthFixed, ImGui.GetWindowWidth() / 3); + ImGui.TableSetupColumn("##LeftColumn", ImGuiTableColumnFlags.WidthFixed, ImGui.GetWindowWidth() / 3); - ImGui.TableNextColumn(); + ImGui.TableNextColumn(); - var regionSize = ImGui.GetContentRegionAvail(); + var regionSize = ImGui.GetContentRegionAvail(); - ImGui.PushStyleVar(ImGuiStyleVar.SelectableTextAlign, new Vector2(0.5f, 0.5f)); + ImGui.PushStyleVar(ImGuiStyleVar.SelectableTextAlign, new Vector2(0.5f, 0.5f)); - using (var leftChild = ImRaii.Child($"###SlothLeftSide", regionSize with { Y = topLeftSideHeight }, false, ImGuiWindowFlags.NoDecoration)) + using (var leftChild = ImRaii.Child($"###SlothLeftSide", regionSize with { Y = topLeftSideHeight }, false, ImGuiWindowFlags.NoDecoration)) + { + if (ThreadLoadImageHandler.TryGetTextureWrap(@"https://github.com/Taurenkey/XIVSlothCombo/blob/main/res/plugin/xivslothcombo.png?raw=true", out var logo)) + { + ImGuiEx.LineCentered("###SlothLogo", () => { - if (ThreadLoadImageHandler.TryGetTextureWrap(@"https://github.com/Taurenkey/XIVSlothCombo/blob/main/res/plugin/xivslothcombo.png?raw=true", out var logo)) - { - ImGuiEx.LineCentered("###SlothLogo", () => - { - ImGui.Image(logo.ImGuiHandle, new(125f.Scale(), 125f.Scale())); - }); - - } - ImGui.Spacing(); - ImGui.Separator(); - - if (ImGui.Selectable("PvE Features", OpenWindow == OpenWindow.PvE)) - { - OpenWindow = OpenWindow.PvE; - } - if (ImGui.Selectable("PvP Features", OpenWindow == OpenWindow.PvP)) - { - OpenWindow = OpenWindow.PvP; - } - ImGui.Spacing(); - if (ImGui.Selectable("Misc. Settings", OpenWindow == OpenWindow.Settings)) - { - OpenWindow = OpenWindow.Settings; - } - ImGui.Spacing(); - if (ImGui.Selectable("About", OpenWindow == OpenWindow.About)) - { - OpenWindow = OpenWindow.About; - } + ImGui.Image(logo.ImGuiHandle, new(125f.Scale(), 125f.Scale())); + }); -#if DEBUG - ImGui.Spacing(); - if (ImGui.Selectable("DEBUG", OpenWindow == OpenWindow.Debug)) - { - OpenWindow = OpenWindow.Debug; - } - ImGui.Spacing(); -#endif + } + ImGui.Spacing(); + ImGui.Separator(); - } + if (ImGui.Selectable("PvE Features", OpenWindow == OpenWindow.PvE)) + { + OpenWindow = OpenWindow.PvE; + } + if (ImGui.Selectable("PvP Features", OpenWindow == OpenWindow.PvP)) + { + OpenWindow = OpenWindow.PvP; + } + ImGui.Spacing(); + if (ImGui.Selectable("Misc. Settings", OpenWindow == OpenWindow.Settings)) + { + OpenWindow = OpenWindow.Settings; + } + ImGui.Spacing(); + if (ImGui.Selectable("About", OpenWindow == OpenWindow.About)) + { + OpenWindow = OpenWindow.About; + } - ImGui.PopStyleVar(); - ImGui.TableNextColumn(); - using (var rightChild = ImRaii.Child($"###SlothRightSide", Vector2.Zero, false)) - { - switch (OpenWindow) - { - case OpenWindow.PvE: - PvEFeatures.Draw(); - break; - case OpenWindow.PvP: - PvPFeatures.Draw(); - break; - case OpenWindow.Settings: - Settings.Draw(); - break; - case OpenWindow.About: - P.AboutUs.Draw(); - break; - case OpenWindow.Debug: - Debug.Draw(); - break; - default: - break; - }; - } +#if DEBUG + ImGui.Spacing(); + if (ImGui.Selectable("DEBUG", OpenWindow == OpenWindow.Debug)) + { + OpenWindow = OpenWindow.Debug; } + ImGui.Spacing(); +#endif + } + + ImGui.PopStyleVar(); + ImGui.TableNextColumn(); + using var rightChild = ImRaii.Child($"###SlothRightSide", Vector2.Zero, false); + switch (OpenWindow) + { + case OpenWindow.PvE: + PvEFeatures.Draw(); + break; + case OpenWindow.PvP: + PvPFeatures.Draw(); + break; + case OpenWindow.Settings: + Settings.Draw(); + break; + case OpenWindow.About: + P.AboutUs.Draw(); + break; + case OpenWindow.Debug: + Debug.Draw(); + break; + default: + break; + }; } diff --git a/XIVSlothCombo/Window/Tabs/AboutUs.cs b/XIVSlothCombo/Window/Tabs/AboutUs.cs index 140b1eb10..d15e3d0aa 100644 --- a/XIVSlothCombo/Window/Tabs/AboutUs.cs +++ b/XIVSlothCombo/Window/Tabs/AboutUs.cs @@ -17,14 +17,14 @@ internal class AboutUs : ConfigWindow { public Version version = null!; - private Dictionary Images = new Dictionary(); + private readonly Dictionary Images = []; public AboutUs() { LoadAllImages(); } - internal void Draw() + public override void Draw() { try { diff --git a/XIVSlothCombo/XIVSlothCombo.cs b/XIVSlothCombo/XIVSlothCombo.cs index 6f352a342..92e4d0f4d 100644 --- a/XIVSlothCombo/XIVSlothCombo.cs +++ b/XIVSlothCombo/XIVSlothCombo.cs @@ -38,15 +38,15 @@ public sealed partial class XIVSlothCombo : IDalamudPlugin private readonly ConfigWindow ConfigWindow; private readonly TargetHelper TargetHelper; internal readonly AboutUs AboutUs; - internal static XIVSlothCombo P = null!; + internal static XIVSlothCombo? P = null!; internal WindowSystem ws; private readonly HttpClient httpClient = new(); private readonly TextPayload starterMotd = new("[Sloth Message of the Day] "); private static uint? jobID; - public static readonly List DisabledJobsPVE = new List() - { + public static readonly List DisabledJobsPVE = + [ //ADV.JobID, //AST.JobID, BLM.JobID, @@ -71,35 +71,9 @@ public sealed partial class XIVSlothCombo : IDalamudPlugin //VPR.JobID, //WAR.JobID, //WHM.JobID - }; + ]; - public static readonly List DisabledJobsPVP = new List() - { - //ADV.JobID, - //AST.JobID, - //BLM.JobID, - //BLU.JobID, - //BRD.JobID, - //DNC.JobID, - //DOL.JobID, - //DRG.JobID, - //DRK.JobID, - //GNB.JobID, - //MCH.JobID, - //MNK.JobID, - //NIN.JobID, - //PCT.JobID, - //PLD.JobID, - //RDM.JobID, - //RPR.JobID, - //SAM.JobID, - //SCH.JobID, - //SGE.JobID, - //SMN.JobID, - //VPR.JobID, - //WAR.JobID, - //WHM.JobID - }; + public static readonly List DisabledJobsPVP = []; public static uint? JobID { @@ -258,6 +232,7 @@ private void PrintMotD() } /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Used for non-static only window initialization")] public string Name => "XIVSlothCombo"; /// @@ -314,7 +289,7 @@ private void OnCommand(string command, string arguments) string? targetPreset = argumentsParts[1].ToLowerInvariant(); foreach (CustomComboPreset preset in Enum.GetValues()) { - if (preset.ToString().ToLowerInvariant() != targetPreset) + if (!preset.ToString().Equals(targetPreset, StringComparison.InvariantCultureIgnoreCase)) continue; Service.Configuration.EnabledActions.Add(preset); @@ -339,19 +314,17 @@ private void OnCommand(string command, string arguments) string? targetPreset = argumentsParts[1].ToLowerInvariant(); foreach (CustomComboPreset preset in Enum.GetValues()) { - if (preset.ToString().ToLowerInvariant() != targetPreset) + if (!preset.ToString().Equals(targetPreset, StringComparison.InvariantCultureIgnoreCase)) continue; - if (Service.Configuration.EnabledActions.Contains(preset)) + if (!Service.Configuration.EnabledActions.Remove(preset)) { - Service.Configuration.EnabledActions.Remove(preset); - Service.ChatGui.Print($"{preset} UNSET"); + Service.Configuration.EnabledActions.Add(preset); + Service.ChatGui.Print($"{preset} SET"); } - else { - Service.Configuration.EnabledActions.Add(preset); - Service.ChatGui.Print($"{preset} SET"); + Service.ChatGui.Print($"{preset} UNSET"); } } @@ -373,7 +346,7 @@ private void OnCommand(string command, string arguments) string? targetPreset = argumentsParts[1].ToLowerInvariant(); foreach (CustomComboPreset preset in Enum.GetValues()) { - if (preset.ToString().ToLowerInvariant() != targetPreset) + if (!preset.ToString().Equals(targetPreset, StringComparison.InvariantCultureIgnoreCase)) continue; Service.Configuration.EnabledActions.Remove(preset); @@ -487,9 +460,9 @@ private void OnCommand(string command, string arguments) { if (int.TryParse(preset.ToString(), out _)) { i++; continue; } - if (preset.ToString()[..3].ToLower() == specificJob || // Job identifier - preset.ToString()[..3].ToLower() == "all" || // Adds in Globals - preset.ToString()[..3].ToLower() == "pvp") // Adds in PvP Globals + if (preset.ToString()[..3].Equals(specificJob, StringComparison.CurrentCultureIgnoreCase) || // Job identifier + preset.ToString()[..3].Equals("all", StringComparison.CurrentCultureIgnoreCase) || // Adds in Globals + preset.ToString()[..3].Equals("pvp", StringComparison.CurrentCultureIgnoreCase)) // Adds in PvP Globals file.WriteLine($"{(int)preset} - {preset}"); } }