Skip to content

Commit

Permalink
call(back) me maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaksuhn committed Jul 3, 2024
1 parent 77cc2ff commit 223a33b
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 173 deletions.
2 changes: 1 addition & 1 deletion ECommons
Submodule ECommons updated 30 files
+1 −1 ECommons/ECommons.csproj
+10 −0 ECommons/ExcelServices/Job.cs
+2 −2 ECommons/EzCmd.cs
+2 −1 ECommons/GameFunctions/CharacterFunctions.cs
+30 −0 ECommons/GenericHelpers.cs
+1 −1 ECommons/Hooks/ActionEffect.cs
+3 −3 ECommons/UIHelpers/AddonFinder.cs
+20 −0 ECommons/UIHelpers/AddonMasterImplementations/!AddonMaster.cs
+58 −0 ECommons/UIHelpers/AddonMasterImplementations/!AddonMasterBase.cs
+0 −22 ECommons/UIHelpers/AddonMasterImplementations/AddonMasterBase.cs
+29 −0 ECommons/UIHelpers/AddonMasterImplementations/GrandCompanySupplyReward.cs
+31 −0 ECommons/UIHelpers/AddonMasterImplementations/MaterializeDialog.cs
+30 −0 ECommons/UIHelpers/AddonMasterImplementations/RecipeNote.cs
+30 −0 ECommons/UIHelpers/AddonMasterImplementations/Repair.cs
+53 −0 ECommons/UIHelpers/AddonMasterImplementations/Request.cs
+52 −0 ECommons/UIHelpers/AddonMasterImplementations/RetainerList.cs
+28 −0 ECommons/UIHelpers/AddonMasterImplementations/RetainerTaskAsk.cs
+30 −0 ECommons/UIHelpers/AddonMasterImplementations/RetainerTaskResult.cs
+76 −0 ECommons/UIHelpers/AddonMasterImplementations/SelectString.cs
+0 −53 ECommons/UIHelpers/AddonMasterImplementations/SelectStringMaster.cs
+42 −0 ECommons/UIHelpers/AddonMasterImplementations/SelectYesno.cs
+0 −41 ECommons/UIHelpers/AddonMasterImplementations/SelectYesnoMaster.cs
+32 −0 ECommons/UIHelpers/AddonMasterImplementations/Talk.cs
+44 −0 ECommons/UIHelpers/AddonMasterImplementations/TitleDCWorldMap.cs
+77 −0 ECommons/UIHelpers/AddonMasterImplementations/_CharaSelectListMenu.cs
+61 −0 ECommons/UIHelpers/AddonMasterImplementations/_CharaSelectWorldServer.cs
+37 −0 ECommons/UIHelpers/AddonMasterImplementations/_TitleMenu.cs
+30 −0 ECommons/UIHelpers/AtkEventDataBuilder.cs
+2 −0 ECommons/UIHelpers/AtkReader.cs
+1 −1 ECommons/UIHelpers/AtkReaderImplementations/ReaderRetainerList.cs
14 changes: 5 additions & 9 deletions SomethingNeedDoing/Exceptions/MacroSyntaxError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ namespace SomethingNeedDoing.Exceptions;
/// <summary>
/// Error thrown when the syntax of a macro does not parse correctly.
/// </summary>
internal class MacroSyntaxError : InvalidOperationException
/// <remarks>
/// Initializes a new instance of the <see cref="MacroSyntaxError"/> class.
/// </remarks>
/// <param name="command">The command that failed parsing.</param>
internal class MacroSyntaxError(string command, string guidance = "") : InvalidOperationException($"Syntax error: {command}{(guidance != string.Empty ? $"\n{guidance}" : string.Empty)}")
{
/// <summary>
/// Initializes a new instance of the <see cref="MacroSyntaxError"/> class.
/// </summary>
/// <param name="command">The command that failed parsing.</param>
public MacroSyntaxError(string command)
: base($"Syntax error: {command}")
{
}
}
176 changes: 91 additions & 85 deletions SomethingNeedDoing/Grammar/Commands/CallbackCommand.cs
Original file line number Diff line number Diff line change
@@ -1,96 +1,102 @@
//using System.Collections.Generic;
//using System.Text.RegularExpressions;
//using System.Threading;
//using System.Threading.Tasks;
//using ECommons.DalamudServices;
//using FFXIVClientStructs.FFXIV.Component.GUI;
//using SomethingNeedDoing.Grammar.Modifiers;
//using SomethingNeedDoing.Misc;
//using static ECommons.GenericHelpers;
//using ECommons.Automation;
using ECommons.Automation;
using FFXIVClientStructs.FFXIV.Component.GUI;
using SomethingNeedDoing.Exceptions;
using SomethingNeedDoing.Grammar.Modifiers;
using SomethingNeedDoing.Misc;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using static ECommons.GenericHelpers;

//namespace SomethingNeedDoing.Grammar.Commands;
namespace SomethingNeedDoing.Grammar.Commands;

//internal class CallbackCommand : MacroCommand
//{
// private static readonly Regex Regex = new(@"^/callback\s+(?<name>.*?)\s*$", RegexOptions.Compiled);
// private readonly unsafe AtkUnitBase* addon;
// private readonly bool updateState;
// private readonly List<object> valueArgs = [];
internal class CallbackCommand : MacroCommand
{
private static readonly Regex Regex = new(@"^/callback\s+(?<addon>\b\w+\b)\s+(?<updateState>true|false)\s+(?<values>(true|false|\b\w+\b|-?\d+|""[^""]+"")(\s+(true|false|\b\w+\b|-?\d+|""[^""]+""))*)\s*$", RegexOptions.Compiled);
private readonly unsafe AtkUnitBase* addon;
private readonly bool updateState;
private readonly List<object> valueArgs = [];

// private unsafe CallbackCommand(AtkUnitBase* addon, bool updateState, List<object> valueArgs, WaitModifier wait) : base("", wait)
// {
// this.addon = addon;
// this.updateState = updateState;
// this.valueArgs = valueArgs;
// }
private unsafe CallbackCommand(AtkUnitBase* addon, bool updateState, List<object> valueArgs, WaitModifier wait) : base("", wait)
{
this.addon = addon;
this.updateState = updateState;
this.valueArgs = valueArgs;
}

// public unsafe static CallbackCommand Parse(List<string> args)
// {
// var text = string.Join(" ", args);
// _ = WaitModifier.TryParse(ref text, out var waitModifier);
public unsafe static CallbackCommand Parse(string text)
{
_ = WaitModifier.TryParse(ref text, out var waitModifier);

// if (!TryGetAddonByName<AtkUnitBase>(args[0], out var addonArg))
// {
// Svc.Log.Info($"Invalid addon {args[0]}. Please follow \"callback <addon> <bool> <atkValues>\"");
// }
// if (!bool.TryParse(args[1], out var boolArg))
// {
// Svc.Log.Info($"Invalid bool. Please follow \"callback <addon> <bool> <atkValues>\"");
// }
var match = Regex.Match(text);
if (!match.Success)
throw new MacroSyntaxError(text);

// var valueArgs = new List<object>();
var addonGroup = match.Groups["addon"];
var boolGroup = match.Groups["updateState"];
var valueGroup = match.Groups["values"];

// var current = "";
// var inQuotes = false;
if (!addonGroup.Success)
throw new MacroSyntaxError(text, "Invalid addon {addonGroup.Value}. Please follow \"/callback <addon> <bool> <atkValues>\"");
if (!boolGroup.Success)
throw new MacroSyntaxError(text, "Invalid bool. Please follow \"/callback <addon> <bool> <atkValues>\"");
if (!valueGroup.Success)
throw new MacroSyntaxError(text, "Invalid values. Please follow \"/callback <addon> <bool> <atkValues>\"");

// for (var i = 0; i < args.Count; i++)
// {
// if (!inQuotes)
// {
// if (args[i].StartsWith("\""))
// {
// inQuotes = true;
// current = args[i].TrimStart('"');
// }
// else
// {
// if (int.TryParse(args[i], out var iValue)) valueArgs.Add(iValue);
// else if (uint.TryParse(args[i].TrimEnd('U', 'u'), out var uValue)) valueArgs.Add(uValue);
// else if (bool.TryParse(args[i], out var bValue)) valueArgs.Add(bValue);
// else valueArgs.Add(args[i]);
// }
// }
// else
// {
// if (args[i].EndsWith("\""))
// {
// inQuotes = false;
// current += " " + args[i].TrimEnd('"');
// valueArgs.Add(current);
// current = "";
// }
// else
// {
// current += " " + args[i];
// }
// }
// }
var rawValues = valueGroup.Value.Split(' ');
var valueArgs = new List<object>();

// if (!string.IsNullOrEmpty(current))
// {
// Svc.Log.Error("Error: Unclosed quotes.");
// }
var current = "";
var inQuotes = false;

// return new CallbackCommand(addonArg, boolArg, valueArgs, waitModifier);
// }
for (var i = 0; i < rawValues.Length; i++)
{
if (!inQuotes)
{
if (rawValues[i].StartsWith('\"'))
{
inQuotes = true;
current = rawValues[i].TrimStart('"');
}
else
{
if (int.TryParse(rawValues[i], out var iValue)) valueArgs.Add(iValue);
else if (uint.TryParse(rawValues[i].TrimEnd('U', 'u'), out var uValue)) valueArgs.Add(uValue);
else if (bool.TryParse(rawValues[i], out var bValue)) valueArgs.Add(bValue);
else valueArgs.Add(rawValues[i]);
}
}
else
{
if (rawValues[i].EndsWith("\""))
{
inQuotes = false;
current += " " + rawValues[i].TrimEnd('"');
valueArgs.Add(current);
current = "";
}
else
{
current += " " + rawValues[i];
}
}
}

// public async override Task Execute(ActiveMacro macro, CancellationToken token)
// {
// unsafe
// {
// Callback.Fire(addon, updateState, valueArgs.ToArray());
// }
// await this.PerformWait(token);
// }
//}
if (!string.IsNullOrEmpty(current))
throw new MacroSyntaxError(text, "Unclosed quotes.");
if (TryGetAddonByName<AtkUnitBase>(addonGroup.Value, out var addonArg))
return new CallbackCommand(addonArg, bool.Parse(boolGroup.Value), valueArgs, waitModifier);
else
throw new MacroSyntaxError(text, "Invalid addon.");
}

public async override Task Execute(ActiveMacro macro, CancellationToken token)
{
unsafe
{
Callback.Fire(addon, updateState, valueArgs.ToArray());
}
await this.PerformWait(token);
}
}
1 change: 1 addition & 0 deletions SomethingNeedDoing/Grammar/MacroParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static MacroCommand ParseLine(string line)
"/action" => ActionCommand.Parse(line),
"/click" => ClickCommand.Parse(line),
"/craft" => GateCommand.Parse(line),
"/callback" => CallbackCommand.Parse(line),
"/equipitem" => EquipItemCommand.Parse(line),
"/gate" => GateCommand.Parse(line),
"/interact" => InteractCommand.Parse(line),
Expand Down
Loading

0 comments on commit 223a33b

Please sign in to comment.