Skip to content

Commit

Permalink
Fix bad sort order for Waymarks
Browse files Browse the repository at this point in the history
- Move building actions into subclasses of FixedCommandStrategy
- Add shim class for `Marker` for API compat.
- Add sortorder to Marker
  • Loading branch information
KazWolfe committed May 24, 2023
1 parent 24a9a5b commit 203abb5
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 33 deletions.
17 changes: 6 additions & 11 deletions FFXIVPlugin/ActionExecutor/FixedCommandStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ namespace XIVDeck.FFXIVPlugin.ActionExecutor;

public abstract class FixedCommandStrategy<T> : IActionStrategy where T : ExcelRow {
private readonly List<ExecutableAction> _actionCache = new();

protected abstract string GetNameForAction(T action);
protected abstract HotbarSlotType GetHotbarSlotType();

protected abstract int GetIconForAction(T action);
protected abstract string? GetCommandToCallAction(T action);
protected abstract ExecutableAction? BuildExecutableAction(T action);

protected virtual IEnumerable<uint> GetIllegalActionIDs() => Array.Empty<uint>();

Expand All @@ -43,15 +42,11 @@ public List<ExecutableAction> GetAllowedItems() {
if (row.RowId == 0) continue;
if (this.GetIllegalActionIDs().Contains(row.RowId)) continue;

var actionName = this.GetNameForAction(row);
if (string.IsNullOrEmpty(actionName)) continue;
var action = this.BuildExecutableAction(row);

if (action == null || string.IsNullOrEmpty(action.ActionName)) continue;

this._actionCache.Add(new ExecutableAction {
ActionId = (int) row.RowId,
ActionName = actionName,
IconId = this.GetIconForAction(row),
HotbarSlotType = this.GetHotbarSlotType()
});
this._actionCache.Add(action);
}

return this._actionCache;
Expand Down
23 changes: 11 additions & 12 deletions FFXIVPlugin/ActionExecutor/Strategies/ExtraCommandStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,8 @@ namespace XIVDeck.FFXIVPlugin.ActionExecutor.Strategies;

[ActionStrategy(HotbarSlotType.ExtraCommand)]
public class ExtraCommandStrategy : FixedCommandStrategy<ExtraCommand> {
protected override string GetNameForAction(ExtraCommand action) {
return action.Name.ToString();
}

protected override HotbarSlotType GetHotbarSlotType() {
return HotbarSlotType.FieldMarker;
}

protected override int GetIconForAction(ExtraCommand action) {
return action.Icon;
}

protected override int GetIconForAction(ExtraCommand action) => action.Icon;

protected override string GetCommandToCallAction(ExtraCommand action) {
// ToDo: there has to be some better way to get this command.
return action.RowId switch {
Expand All @@ -28,4 +18,13 @@ protected override string GetCommandToCallAction(ExtraCommand action) {
_ => throw new ArgumentException(string.Format(UIStrings.ExtraCommandStrategy_NoCommandError, action.Name))
};
}

protected override ExecutableAction BuildExecutableAction(ExtraCommand action) {
return new ExecutableAction {
ActionId = (int) action.RowId,
ActionName = action.Name.ToString(),
IconId = this.GetIconForAction(action),
HotbarSlotType = HotbarSlotType.ExtraCommand
};
}
}
19 changes: 14 additions & 5 deletions FFXIVPlugin/ActionExecutor/Strategies/MarkerStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
using System;
using Dalamud.Logging;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
using Lumina.Excel.GeneratedSheets;
using XIVDeck.FFXIVPlugin.Base;
using Lumina.Excel.GeneratedSheets;
using XIVDeck.FFXIVPlugin.Game.Managers;

using Marker = XIVDeck.FFXIVPlugin.Game.Data.Marker;

namespace XIVDeck.FFXIVPlugin.ActionExecutor.Strategies;

[ActionStrategy(HotbarSlotType.Marker)]
public class MarkerStrategy : FixedCommandStrategy<Marker> {
protected override string GetNameForAction(Marker action) => action.Name.ToString();

protected override HotbarSlotType GetHotbarSlotType() => HotbarSlotType.Marker;


protected override int GetIconForAction(Marker action) => action.Icon;

protected override string GetCommandToCallAction(Marker action) => throw new NotSupportedException();

protected override ExecutableAction? BuildExecutableAction(Marker action) {
return new ExecutableAction {
ActionId = (int) action.RowId,
ActionName = action.Name.ToString(),
IconId = this.GetIconForAction(action),
HotbarSlotType = HotbarSlotType.Marker,
SortOrder = action.SortOrder,
};
}

protected override void ExecuteInner(Marker action) {
PluginLog.Debug($"Executing {action} ({action.Name}) directly via hotbar");
Expand Down
14 changes: 9 additions & 5 deletions FFXIVPlugin/ActionExecutor/Strategies/WaymarkStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ namespace XIVDeck.FFXIVPlugin.ActionExecutor.Strategies;

[ActionStrategy(HotbarSlotType.FieldMarker)]
public class WaymarkStrategy : FixedCommandStrategy<FieldMarker> {
protected override string GetNameForAction(FieldMarker action) => action.Name.ToString();

protected override HotbarSlotType GetHotbarSlotType() => HotbarSlotType.FieldMarker;

protected override int GetIconForAction(FieldMarker action) => action.UiIcon;

protected override string GetCommandToCallAction(FieldMarker action) => throw new NotSupportedException();

protected override ExecutableAction BuildExecutableAction(FieldMarker action) {
return new ExecutableAction {
ActionId = (int) action.RowId,
ActionName = action.Name.ToString(),
IconId = this.GetIconForAction(action),
HotbarSlotType = HotbarSlotType.FieldMarker
};
}

protected override void ExecuteInner(FieldMarker action) {
PluginLog.Debug($"Executing {action} ({action.Name}) directly via hotbar");

Expand Down
15 changes: 15 additions & 0 deletions FFXIVPlugin/Game/Data/Marker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Lumina;
using Lumina.Data;
using Lumina.Excel;

namespace XIVDeck.FFXIVPlugin.Game.Data;

public class Marker : Lumina.Excel.GeneratedSheets.Marker {
public byte SortOrder { get; private set; }

public override void PopulateData(RowParser parser, GameData gameData, Language language) {
base.PopulateData(parser, gameData, language);

this.SortOrder = parser.ReadColumn<byte>(1);
}
}

0 comments on commit 203abb5

Please sign in to comment.