From 7a91fa268bb52ba84e10022e56132dd731807df0 Mon Sep 17 00:00:00 2001 From: Eduardo Jorge Date: Thu, 25 Jul 2024 09:45:39 +0100 Subject: [PATCH] Update tests and lint --- OpenerCreator/Actions/GroupOfActions.cs | 60 ++++++++++---------- OpenerCreator/Actions/PvEActions.cs | 34 +++++------ OpenerCreator/Windows/OpenerCreatorWindow.cs | 52 +++++++++-------- OpenerCreatorTests/OpenerManagerTests.cs | 6 +- 4 files changed, 79 insertions(+), 73 deletions(-) diff --git a/OpenerCreator/Actions/GroupOfActions.cs b/OpenerCreator/Actions/GroupOfActions.cs index 37a3177..da72c3a 100644 --- a/OpenerCreator/Actions/GroupOfActions.cs +++ b/OpenerCreator/Actions/GroupOfActions.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Dalamud.Interface.Textures; using OpenerCreator.Helpers; namespace OpenerCreator.Actions; @@ -26,35 +25,36 @@ public bool HasId(int i) public static bool TryGetDefault(int id, out GroupOfActions value) { - foreach(var group in DefaultGroups) - if(group.Id == id) + foreach (var group in DefaultGroups) + if (group.Id == id) { value = group; return true; } - - value = new(0, "", Jobs.ANY, []); + + value = new GroupOfActions(0, "", Jobs.ANY, []); return false; } public static List GetFilteredGroups(string name, Jobs job, ActionTypes actionType) { return DefaultGroups - .AsParallel() - .Where(a => - (name.Length == 0 || a.Name.Contains(name, StringComparison.CurrentCultureIgnoreCase)) - && (job == a.Job || job == Jobs.ANY) - && ((actionType == ActionTypes.GCD && a.IsGCD) - || (actionType == ActionTypes.OGCD && !a.IsGCD) - || actionType == ActionTypes.ANY) - ) - .Select(a => a.Id) - .OrderBy(id => id) - .ToList(); + .AsParallel() + .Where(a => + (name.Length == 0 || a.Name.Contains(name, StringComparison.CurrentCultureIgnoreCase)) + && (job == a.Job || job == Jobs.ANY) + && ((actionType == ActionTypes.GCD && a.IsGCD) + || (actionType == ActionTypes.OGCD && !a.IsGCD) + || actionType == ActionTypes.ANY) + ) + .Select(a => a.Id) + .OrderBy(id => id) + .ToList(); } - public static readonly GroupOfActions[] DefaultGroups = [ - new( + public static readonly GroupOfActions[] DefaultGroups = + [ + new GroupOfActions( -1, "Dancer Step", Jobs.DNC, @@ -62,10 +62,10 @@ public static List GetFilteredGroups(string name, Jobs job, ActionTypes act 15999, // Emboite 16000, // Entrechat 16001, // Jete - 16002, // Pirouette + 16002 // Pirouette ] ), - new( + new GroupOfActions( -2, "Mudra", Jobs.NIN, @@ -75,37 +75,37 @@ public static List GetFilteredGroups(string name, Jobs job, ActionTypes act 2261, // Chi 18806, // Chi 2263, // Jin - 18807, // Jin + 18807 // Jin ] ), - new( + new GroupOfActions( -3, "Refulgent Arrow Proc", Jobs.BRD, [ 16495, // Burst Shot - 7409, // Refulgent Arrow + 7409 // Refulgent Arrow ] ), - new( + new GroupOfActions( -4, "Verthunder/Veraero", Jobs.RDM, [ 25855, // Verthunder III - 25856, // Veraero III + 25856 // Veraero III ] ), - new( + new GroupOfActions( -5, "Saber/Starfall Dance", Jobs.DNC, [ 16005, // Saber Dance - 25792, // Starfall Dance + 25792 // Starfall Dance ] ), - new( + new GroupOfActions( -6, "Dancer Priority GCD", Jobs.DNC, @@ -114,8 +114,8 @@ public static List GetFilteredGroups(string name, Jobs job, ActionTypes act 25792, // Starfall Dance 36983, // Last Dance 15992, // Fountainfall - 15991, // Reverse Cascade + 15991 // Reverse Cascade ] - ), + ) ]; } diff --git a/OpenerCreator/Actions/PvEActions.cs b/OpenerCreator/Actions/PvEActions.cs index 46082ac..3065dd4 100644 --- a/OpenerCreator/Actions/PvEActions.cs +++ b/OpenerCreator/Actions/PvEActions.cs @@ -41,26 +41,16 @@ public static PvEActions Instance } } - public bool IsActionOGCD(int id) - { - return id >= 0 - ? (id == IActionManager.CatchAllActionId - ? false - : actionsSheetDictionary.TryGetValue((uint)id, out var action) - && ActionTypesExtension.GetType(action) == ActionTypes.OGCD) - : GroupOfActions.TryGetDefault(id, out var group) - && !group.IsGCD; - } - public string GetActionName(int id) { return id >= 0 - ? (id == IActionManager.CatchAllActionId - ? IActionManager.CatchAllActionName - : actionsSheetDictionary.GetValueOrDefault((uint)id)?.Name.ToString() ?? IActionManager.OldActionName) - : (GroupOfActions.TryGetDefault(id, out var group) - ? group.Name - : IActionManager.OldActionName); + ? id == IActionManager.CatchAllActionId + ? IActionManager.CatchAllActionName + : actionsSheetDictionary.GetValueOrDefault((uint)id)?.Name.ToString() ?? + IActionManager.OldActionName + : GroupOfActions.TryGetDefault(id, out var group) + ? group.Name + : IActionManager.OldActionName; } public bool SameActionsByName(string name, int aId) @@ -68,6 +58,16 @@ public bool SameActionsByName(string name, int aId) return GetActionName(aId).Contains(name, StringComparison.CurrentCultureIgnoreCase); } + public bool IsActionOGCD(int id) + { + return id >= 0 + ? id != IActionManager.CatchAllActionId && actionsSheetDictionary.TryGetValue( + (uint)id, out var action) + && ActionTypesExtension.GetType(action) == ActionTypes.OGCD + : GroupOfActions.TryGetDefault(id, out var group) + && !group.IsGCD; + } + public List ActionsIdList(ActionTypes actionType) { return actionsSheet diff --git a/OpenerCreator/Windows/OpenerCreatorWindow.cs b/OpenerCreator/Windows/OpenerCreatorWindow.cs index 5afb37b..fdc1824 100644 --- a/OpenerCreator/Windows/OpenerCreatorWindow.cs +++ b/OpenerCreator/Windows/OpenerCreatorWindow.cs @@ -77,18 +77,21 @@ private void DrawActionsGui() var iconsPerLine = (int)Math.Floor((ImGui.GetContentRegionAvail().X - (padding.X * 2.0) + spacing.X) / (IconSize.X + spacing.X)); var lines = (float)Math.Max(Math.Ceiling(loadedActions.ActionsCount() / (float)iconsPerLine), 1); - + var frameW = ImGui.GetContentRegionAvail().X; ImGui.BeginChildFrame( 2426787, - new Vector2(frameW, (lines * (IconSize.Y * 1.7f + spacing.Y)) - spacing.Y + (padding.Y * 2)), + new Vector2(frameW, (lines * ((IconSize.Y * 1.7f) + spacing.Y)) - spacing.Y + (padding.Y * 2)), ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse); var drawList = ImGui.GetWindowDrawList(); for (var i = 0; i < lines; i++) { var pos = ImGui.GetCursorScreenPos(); - drawList.AddRectFilled(pos + new Vector2(0, IconSize.Y * 0.9f + i * (IconSize.Y * 1.7f + spacing.Y)), pos + new Vector2(frameW, IconSize.Y * 1.1f + i * (IconSize.Y * 1.7f + spacing.Y)), 0x64000000); + drawList.AddRectFilled(pos + new Vector2(0, (IconSize.Y * 0.9f) + (i * ((IconSize.Y * 1.7f) + spacing.Y))), + pos + new Vector2( + frameW, (IconSize.Y * 1.1f) + (i * ((IconSize.Y * 1.7f) + spacing.Y))), + 0x64000000); } int? dndTarget = null; @@ -96,7 +99,7 @@ private void DrawActionsGui() { var pos = ImGui.GetMousePos() - ImGui.GetCursorScreenPos(); var x = (int)Math.Floor(pos.X / (IconSize.X + spacing.X)); - var y = (int)Math.Floor(pos.Y / (IconSize.Y * 1.7f + spacing.Y)); + var y = (int)Math.Floor(pos.Y / ((IconSize.Y * 1.7f) + spacing.Y)); dndTarget = Math.Clamp((y * iconsPerLine) + x, 0, loadedActions.ActionsCount() - 1); } @@ -115,7 +118,7 @@ private void DrawActionsGui() { var actionAt = loadedActions.GetActionAt(actionDragAndDrop!.Value); if (!PvEActions.Instance.IsActionOGCD(actionAt)) - ImGui.SetCursorPosY(ImGui.GetCursorPosY() + IconSize.Y * 0.5f); + ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (IconSize.Y * 0.5f)); DrawIcon(actionAt, IconSize, 0x64FFFFFF); if (actionDragAndDrop != i) @@ -130,13 +133,13 @@ private void DrawActionsGui() { var actionAt = loadedActions.GetActionAt(i); var color = loadedActions.IsWrongActionAt(i) ? 0xFF6464FF : 0xFFFFFFFF; - - ImGui.BeginChild((uint)i, new(IconSize.X, IconSize.Y * 1.7f)); + + ImGui.BeginChild((uint)i, new Vector2(IconSize.X, IconSize.Y * 1.7f)); if (!PvEActions.Instance.IsActionOGCD(actionAt)) - ImGui.SetCursorPosY(ImGui.GetCursorPosY() + IconSize.Y * 0.5f); + ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (IconSize.Y * 0.5f)); DrawIcon(actionAt, IconSize, color); ImGui.EndChild(); - + if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) actionDragAndDrop = i; @@ -150,14 +153,13 @@ private void DrawActionsGui() ImGui.BeginTooltip(); ImGui.Text(group.Name); ImGui.Indent(); - foreach(var action in group.Actions) + foreach (var action in group.Actions) ImGui.Text(PvEActions.Instance.GetActionName((int)action)); ImGui.Unindent(); ImGui.EndTooltip(); } else ImGui.SetTooltip($"Invalid action id ({actionAt})"); - } if (ImGui.IsItemClicked(ImGuiMouseButton.Right)) @@ -297,7 +299,7 @@ private void DrawCreatorTab() loadedActions.AddAction(actionId); OpenerManager.Instance.Loaded = loadedActions.GetActionsByRef(); } - + ImGui.SameLine(); if (actionId >= 0) ImGui.Text($"{PvEActions.Instance.GetAction((uint)actionId).Name}"); @@ -306,7 +308,7 @@ private void DrawCreatorTab() else ImGui.Text($"Invalid action id ({actionId})"); } - + if (actionsIds.Count > 50) ImGui.Text("More than 50 results, limiting results shown"); @@ -452,10 +454,11 @@ void DrawJobCategoryToggle(string label, JobCategory jobCategory) } } - private static void DrawIcon(int id, Vector2 size, uint color = 0xFFFFFFFF, Vector2? pos = null) { + private static void DrawIcon(int id, Vector2 size, uint color = 0xFFFFFFFF, Vector2? pos = null) + { var realPos = pos ?? ImGui.GetCursorScreenPos(); var drawList = pos == null ? ImGui.GetWindowDrawList() : ImGui.GetForegroundDrawList(); - + if (id >= 0) { drawList.PushTextureID(GetIcon((uint)id)); @@ -467,7 +470,7 @@ private static void DrawIcon(int id, Vector2 size, uint color = 0xFFFFFFFF, Vect { // could do it the "proper" way of making an actual rectangle... or do this // will break if the group only contains a single action, but why use a group at that point?? - var center = realPos + size / 2; + var center = realPos + (size / 2); var actionCount = group.Actions.Count(); drawList.PushClipRect(realPos, realPos + size, true); for (var i = 0; i < actionCount; ++i) @@ -475,16 +478,18 @@ private static void DrawIcon(int id, Vector2 size, uint color = 0xFFFFFFFF, Vect var action = group.Actions.ElementAt(i); drawList.PushTextureID(GetIcon(action)); drawList.PrimReserve(6, 4); - + var vtx = (ushort)drawList._VtxCurrentIdx; - drawList.PrimWriteVtx(center, new(0.5f, 0.5f), color); - + drawList.PrimWriteVtx(center, new Vector2(0.5f, 0.5f), color); + for (var j = 0; j < 3; j++) { - (var s, var c) = MathF.SinCos((i - 1.0f + j * 0.5f) / actionCount * MathF.PI * 2.0f - MathF.PI / 4); - drawList.PrimWriteVtx(center + new Vector2(s * size.X, c * size.Y), new(0.5f + s, 0.5f + c), color); + var (s, c) = + MathF.SinCos(((i - 1.0f + (j * 0.5f)) / actionCount * MathF.PI * 2.0f) - (MathF.PI / 4)); + drawList.PrimWriteVtx(center + new Vector2(s * size.X, c * size.Y), new Vector2(0.5f + s, 0.5f + c), + color); } - + drawList.PrimWriteIdx((ushort)(vtx + 2)); drawList.PrimWriteIdx((ushort)(vtx + 1)); drawList.PrimWriteIdx(vtx); @@ -492,6 +497,7 @@ private static void DrawIcon(int id, Vector2 size, uint color = 0xFFFFFFFF, Vect drawList.PrimWriteIdx((ushort)(vtx + 2)); drawList.PrimWriteIdx(vtx); } + drawList.PopClipRect(); } else @@ -501,7 +507,7 @@ private static void DrawIcon(int id, Vector2 size, uint color = 0xFFFFFFFF, Vect drawList.PrimRectUV(realPos, realPos + size, Vector2.Zero, Vector2.One, color); drawList.PopTextureID(); } - + if (pos == null) ImGui.Dummy(size); } diff --git a/OpenerCreatorTests/OpenerManagerTests.cs b/OpenerCreatorTests/OpenerManagerTests.cs index b208e52..abd3251 100644 --- a/OpenerCreatorTests/OpenerManagerTests.cs +++ b/OpenerCreatorTests/OpenerManagerTests.cs @@ -10,13 +10,13 @@ public class ActionsMock : IActionManager private readonly IEnumerable oldActions = new[] { OldAction1 }; - public string GetActionName(uint action) + public string GetActionName(int action) { - return oldActions.Contains((int)action) ? IActionManager.OldActionName : action.ToString(); + return oldActions.Contains(action) ? IActionManager.OldActionName : action.ToString(); } - public bool SameActionsByName(string action1, uint action2) + public bool SameActionsByName(string action1, int action2) { return GetActionName(action2).Contains(action1, StringComparison.CurrentCultureIgnoreCase); }