forked from daemitus/SomethingNeedDoing
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
174 additions
and
173 deletions.
There are no files selected for viewing
Submodule AutoRetainerAPI
updated
2 files
+19 −0 | AutoRetainerAPI/Configuration/FCData.cs | |
+1 −2 | AutoRetainerAPI/Configuration/OfflineCharacterData.cs |
Submodule ECommons
updated
30 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.