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

Commit

Permalink
Tidy up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Taurenkey committed Jul 23, 2024
1 parent 576a225 commit 5a14682
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 143 deletions.
4 changes: 2 additions & 2 deletions XIVSlothCombo/Attributes/CustomComboInfoAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ 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<ClassJob>().HasRow(jobID))
return Svc.Data.GetExcelSheet<ClassJob>().GetRow(jobID).Role;

return 0;
}

private uint JobIDToClassJobCategory(byte jobID)
private static uint JobIDToClassJobCategory(byte jobID)
{
if (Svc.Data.GetExcelSheet<ClassJob>().HasRow(jobID))
return Svc.Data.GetExcelSheet<ClassJob>().GetRow(jobID).ClassJobCategory.Row;
Expand Down
25 changes: 3 additions & 22 deletions XIVSlothCombo/Data/CustomComboCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint, CooldownData> cooldownCache = new();
private readonly ConcurrentDictionary<uint, CooldownData?> cooldownCache = new();

// Do not invalidate these
private readonly ConcurrentDictionary<uint, byte> cooldownGroupCache = new();
private readonly ConcurrentDictionary<Type, JobGaugeBase> jobGaugeCache = new();
private readonly ConcurrentDictionary<(uint ActionID, uint ClassJobID, byte Level), (ushort CurrentMax, ushort Max)> chargesCache = new();

/// <summary> Initializes a new instance of the <see cref="CustomComboCache"/> class. </summary>
public CustomComboCache() => Service.Framework.Update += Framework_Update;
Expand Down Expand Up @@ -74,12 +72,8 @@ internal T GetJobGauge<T>() where T : JobGaugeBase
/// <returns> Cooldown data. </returns>
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()
{
Expand Down Expand Up @@ -108,19 +102,6 @@ internal static unsafe int GetResourceCost(uint actionID)
return cost;
}

/// <summary> Get the cooldown group of an action. </summary>
/// <param name="actionID"> Action ID to check. </param>
private byte GetCooldownGroup(uint actionID)
{
if (cooldownGroupCache.TryGetValue(actionID, out byte cooldownGroup))
return cooldownGroup;

var sheet = Service.DataManager.GetExcelSheet<Lumina.Excel.GeneratedSheets.Action>()!;
var row = sheet.GetRow(actionID);

return cooldownGroupCache[actionID] = row!.CooldownGroup;
}

/// <summary> Triggers when the game framework updates. Clears cooldown and status caches. </summary>
private unsafe void Framework_Update(IFramework framework)
{
Expand Down
142 changes: 68 additions & 74 deletions XIVSlothCombo/Window/ConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}


Expand Down
4 changes: 2 additions & 2 deletions XIVSlothCombo/Window/Tabs/AboutUs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ internal class AboutUs : ConfigWindow
{
public Version version = null!;

private Dictionary<string, IDalamudTextureWrap> Images = new Dictionary<string, IDalamudTextureWrap>();
private readonly Dictionary<string, IDalamudTextureWrap> Images = [];

public AboutUs()
{
LoadAllImages();
}

internal void Draw()
public override void Draw()
{
try
{
Expand Down
59 changes: 16 additions & 43 deletions XIVSlothCombo/XIVSlothCombo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint> DisabledJobsPVE = new List<uint>()
{
public static readonly List<uint> DisabledJobsPVE =
[
//ADV.JobID,
//AST.JobID,
BLM.JobID,
Expand All @@ -71,35 +71,9 @@ public sealed partial class XIVSlothCombo : IDalamudPlugin
//VPR.JobID,
//WAR.JobID,
//WHM.JobID
};
];

public static readonly List<uint> DisabledJobsPVP = new List<uint>()
{
//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<uint> DisabledJobsPVP = [];

public static uint? JobID
{
Expand Down Expand Up @@ -258,6 +232,7 @@ private void PrintMotD()
}

/// <inheritdoc/>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Used for non-static only window initialization")]
public string Name => "XIVSlothCombo";

/// <inheritdoc/>
Expand Down Expand Up @@ -314,7 +289,7 @@ private void OnCommand(string command, string arguments)
string? targetPreset = argumentsParts[1].ToLowerInvariant();
foreach (CustomComboPreset preset in Enum.GetValues<CustomComboPreset>())
{
if (preset.ToString().ToLowerInvariant() != targetPreset)
if (!preset.ToString().Equals(targetPreset, StringComparison.InvariantCultureIgnoreCase))
continue;

Service.Configuration.EnabledActions.Add(preset);
Expand All @@ -339,19 +314,17 @@ private void OnCommand(string command, string arguments)
string? targetPreset = argumentsParts[1].ToLowerInvariant();
foreach (CustomComboPreset preset in Enum.GetValues<CustomComboPreset>())
{
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");
}
}

Expand All @@ -373,7 +346,7 @@ private void OnCommand(string command, string arguments)
string? targetPreset = argumentsParts[1].ToLowerInvariant();
foreach (CustomComboPreset preset in Enum.GetValues<CustomComboPreset>())
{
if (preset.ToString().ToLowerInvariant() != targetPreset)
if (!preset.ToString().Equals(targetPreset, StringComparison.InvariantCultureIgnoreCase))
continue;

Service.Configuration.EnabledActions.Remove(preset);
Expand Down Expand Up @@ -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}");
}
}
Expand Down

0 comments on commit 5a14682

Please sign in to comment.