Skip to content
This repository has been archived by the owner on Jul 23, 2023. It is now read-only.

Commit

Permalink
feat(trigger-class): add tree selection
Browse files Browse the repository at this point in the history
docs: update readme
  • Loading branch information
bendobos committed Sep 3, 2022
1 parent 6d06f11 commit c6ce912
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
2 changes: 0 additions & 2 deletions LoupeXIVDeck/Commands/FFXIVActionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ protected override async void RunCommand(String actionParameter)
*/
private FFXIVAction ActionParameterToFFXIVAction(String actionParameter)
{
System.Diagnostics.Debug.WriteLine(actionParameter);

var paramArray = actionParameter.Split(':');

return new FFXIVAction(paramArray[0], Int32.Parse(paramArray[1]));
Expand Down
39 changes: 37 additions & 2 deletions LoupeXIVDeck/Commands/FFXIVClassCommand.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
namespace Loupedeck.LoupeXIVDeckPlugin.commands
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using static Loupedeck.LoupeXIVDeckPlugin.FFXIVGameTypes;

internal class FFXIVClassCommand : PluginDynamicCommand
{
private IFFXIVPluginLink _pluginLink;
private IFFXIVApi _api;
private IDisposable isApplicationReadySubscription;
public Boolean isApplicationReady;
private Boolean isApplicationReady;

public FFXIVClassCommand() : base("Trigger Class", "Trigger Class", "FFXIV Commands")
{
this.MakeProfileAction("text;Class ID");
this.MakeProfileAction("tree");
}

protected override Boolean OnLoad()
Expand All @@ -28,6 +31,37 @@ protected override Boolean OnLoad()
return true;
}

protected override PluginProfileActionData GetProfileActionData() {
var classes = Task.Run(async () => await this._api.GetClasses()).Result;
var tree = new PluginProfileActionTree("Select Class:");

tree.AddLevel("Category");
tree.AddLevel("Name");

var classesDict = new Dictionary<String, List<FFXIVClass>>();
foreach (var clazz in classes)
{
if (!classesDict.ContainsKey(clazz.categoryName))
{
classesDict.Add(clazz.categoryName, new List<FFXIVClass>());
}

classesDict[clazz.categoryName].Add(clazz);
}

foreach (var classCategory in classesDict)
{
var node = tree.Root.AddNode(classCategory.Key);

foreach (var clazz in classCategory.Value)
{
node.AddItem($"{clazz.id}", $"{clazz.name}{(clazz.hasGearset ? " (Has Gearset)" : "")}");
}
}

return tree;
}

protected override BitmapImage GetCommandImage(String actionParameter, PluginImageSize imageSize)
{
if (actionParameter != null && Int32.Parse(actionParameter) <= 40 && this.isApplicationReady)
Expand All @@ -46,6 +80,7 @@ protected override async void RunCommand(String actionParameter)
{
if (this.isApplicationReady)
{
await this._api.GetClasses();
await this._api.TriggerClass(Int32.Parse(actionParameter));
}
}
Expand Down
7 changes: 2 additions & 5 deletions LoupeXIVDeck/FFXIVLink/FFXIVApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,12 @@ async public Task<Boolean> ExecuteAction(String type, Int32 id)
return response.IsSuccessStatusCode;
}

async public Task<String> GetClasses(Boolean unlocked = false)
async public Task<List<FFXIVClass>> GetClasses(Boolean unlocked = false)
{
var response = await this.client.GetAsync($"{this.baseUrl}/classes{(unlocked ? "/available" : "")}");
var responseString = await response.Content.ReadAsStringAsync();


System.Diagnostics.Debug.WriteLine(responseString);

return await response.Content.ReadAsStringAsync();
return JsonHelpers.DeserializeObject<List<FFXIVClass>>(responseString);
}

async public Task<FFXIVClass> GetClass(Int32 classId)
Expand Down
3 changes: 2 additions & 1 deletion LoupeXIVDeck/FFXIVLink/Models/FFXIVGameTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public FFXIVAction(String type, Int32 id)

public class FFXIVClass
{
public Int32 number;
public Int32? id;
public Int32? number;
public String name;

public String categoryName;
Expand Down
1 change: 1 addition & 0 deletions LoupeXIVDeck/FFXIVLink/Models/IFFXIVApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public interface IFFXIVApi
Task<System.Boolean> ExecuteAction(System.String type, System.Int32 id);
Task<FFXIVGameTypes.FFXIVAction> GetAction(System.String type, System.Int32 id);
Task<System.Collections.Generic.Dictionary<System.String, System.Collections.Generic.List<FFXIVGameTypes.FFXIVAction>>> GetActions();
Task<System.Collections.Generic.List<FFXIVGameTypes.FFXIVClass>> GetClasses(System.Boolean unlocked = false);
Task<FFXIVGameTypes.FFXIVClass> GetClass(System.Int32 classId);
Task<HttpResponseMessage> GetHotbarSlot(System.Int32 hotbarId, System.Int32 slotId);
Task<System.Byte[]> GetIcon(System.Int32 iconId, System.Boolean hq = false);
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ LoupeXIVDeck supports the same commands as the Stream Deck plugin by @KazWolfe,
## TODO / Known Issues

* Add proper error and exception handling. For example, the plugin might currently crash if IDs for actions are given that are out of bounds.
* Improve usability for Action and Class commands by using `GetClasses` and `GetActions`.
* Changing the WebSocket port is currently not supported, so make sure you use the XIVDeck default port.
* Add some pictures and examples to this repo.

Expand Down

0 comments on commit c6ce912

Please sign in to comment.