Skip to content

Commit

Permalink
Update tests and lint (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
herulume authored Jul 25, 2024
1 parent e1f7595 commit 1e5648f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 73 deletions.
60 changes: 30 additions & 30 deletions OpenerCreator/Actions/GroupOfActions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Dalamud.Interface.Textures;
using OpenerCreator.Helpers;

namespace OpenerCreator.Actions;
Expand All @@ -26,46 +25,47 @@ 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<int> 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,
[
15999, // Emboite
16000, // Entrechat
16001, // Jete
16002, // Pirouette
16002 // Pirouette
]
),
new(
new GroupOfActions(
-2,
"Mudra",
Jobs.NIN,
Expand All @@ -75,37 +75,37 @@ public static List<int> 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,
Expand All @@ -114,8 +114,8 @@ public static List<int> GetFilteredGroups(string name, Jobs job, ActionTypes act
25792, // Starfall Dance
36983, // Last Dance
15992, // Fountainfall
15991, // Reverse Cascade
15991 // Reverse Cascade
]
),
)
];
}
34 changes: 17 additions & 17 deletions OpenerCreator/Actions/PvEActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,33 @@ 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)
{
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<int> ActionsIdList(ActionTypes actionType)
{
return actionsSheet
Expand Down
52 changes: 29 additions & 23 deletions OpenerCreator/Windows/OpenerCreatorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,29 @@ 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;
if (actionDragAndDrop != null)
{
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);
}

Expand All @@ -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)
Expand All @@ -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;

Expand All @@ -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))
Expand Down Expand Up @@ -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}");
Expand All @@ -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");

Expand Down Expand Up @@ -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));
Expand All @@ -467,31 +470,34 @@ 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)
{
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);
drawList.PrimWriteIdx((ushort)(vtx + 3));
drawList.PrimWriteIdx((ushort)(vtx + 2));
drawList.PrimWriteIdx(vtx);
}

drawList.PopClipRect();
}
else
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions OpenerCreatorTests/OpenerManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ public class ActionsMock : IActionManager

private readonly IEnumerable<int> 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);
}
Expand Down

0 comments on commit 1e5648f

Please sign in to comment.