Skip to content

Commit

Permalink
add services and wait fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaksuhn committed Jul 29, 2024
1 parent 4701a95 commit e21b873
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion SomethingNeedDoing/Grammar/Commands/CallbackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class CallbackCommand : MacroCommand
public static string Description => "Send arbitrary inputs to most addons in the game.";
public static string[] Examples => ["/callback AddonName UpdateState [AtkValues]", "/callback FashionCheck true -1"];

private static readonly Regex Regex = new($@"^/{string.Join("|", Commands)}\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 static readonly Regex Regex = new($@"^/{string.Join("|", Commands)}\s+(?<addon>\b\w+\b)\s+(?<updateState>true|false)\s+(?<values>(true|false|\b\w+\b|-?\d+|""[^""]+"")(\s+(true|false|\b\w+\b|-?\d+|""[^""]+""))*).*$", RegexOptions.Compiled);
private readonly unsafe string addon;
private readonly bool updateState;
private readonly List<object> valueArgs = [];
Expand Down
6 changes: 4 additions & 2 deletions SomethingNeedDoing/Grammar/Commands/ClickCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ private ClickCommand(string text, string addon, string method, string[] mParams,

public static unsafe ClickCommand Parse(string text)
{
_ = WaitModifier.TryParse(ref text, out var waitModifier);
var mods = Regex.Match(text, @"<[^>]*>");
var modsText = mods.Success ? mods.Value : string.Empty;
_ = WaitModifier.TryParse(ref modsText, out var waitModifier);

var match = Regex.Match(text);
var match = Regex.Match(text.Replace(modsText, string.Empty).Trim());
if (!match.Success)
throw new MacroSyntaxError(text);

Expand Down
1 change: 0 additions & 1 deletion SomethingNeedDoing/Grammar/Commands/MacroCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using FFXIVClientStructs.FFXIV.Client.Graphics.Kernel;
using SomethingNeedDoing.Grammar.Modifiers;
using SomethingNeedDoing.Misc;
using System;
Expand Down
1 change: 0 additions & 1 deletion SomethingNeedDoing/Grammar/Commands/SendCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Dalamud.Game.ClientState.Keys;
using ECommons.Automation;
using SomethingNeedDoing.Exceptions;
using SomethingNeedDoing.Grammar.Modifiers;
using SomethingNeedDoing.Misc;
Expand Down
17 changes: 7 additions & 10 deletions SomethingNeedDoing/Interface/HelpWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,26 +592,23 @@ private void DrawLua()
{
using var font = ImRaii.PushFont(UiBuilder.MonoFont);

var text = @"
var text = @$"
Lua scripts work by yielding commands back to the macro engine.
For example:
yield(""/ac Muscle memory <wait.3>"")
yield(""/ac Precise touch <wait.2>"")
yield(""/echo done!"")
...and so on.".Trim();
...and so on.
//Every script is able to access these global variables:
//Interface, IClientState, IGameGui, IDataManager, IBuddyList, IChatGui, ICommandManager, ICondition, IFateTable, IFlyTextGui, IFramework, IGameNetwork, IJobGauges, IKeyState, ILibcFunction, IObjectTable, IPartyFinderGui, IPartyList, ISigScanner, ITargetManager, IToastGui, IGameConfig, IGameLifecycle, IGamepadState, IDtrBar, IDutyState, IGameInteropProvider, ITextureProvider, IPluginLog, IAddonLifecycle, IAetheryteList, IAddonEventManager, ITextureSubstitution, ITitleScreenMenu,
Every script has access to these global variables:
{string.Join(", ", typeof(Svc).GetProperties().Select(p => p.Name))}
//ActionManager, AgentMap, EnvManager, EventFramework, FateManager, Framework, InventoryManager, LimitBreakController, PlayerState, QuestManager, RouletteController, UIState

//They are Dalamud services, whose code is available here
//https://github.com/goatcorp/Dalamud/tree/master/Dalamud/Plugin/Services.
They are Dalamud services, whose code is available here
https://github.com/goatcorp/Dalamud/tree/master/Dalamud/Plugin/Services".Trim();

//Many custom functions in SND are simple wrappers around these, but with the global variables
//you can get many properties and functions directly without them needing wrappers added to SND itself.
//ActionManager, AgentMap, EnvManager, EventFramework, FateManager, Framework, InventoryManager, LimitBreakController, PlayerState, QuestManager, RouletteController, UIState

ImGui.TextWrapped(text);
ImGui.Separator();
Expand Down
1 change: 0 additions & 1 deletion SomethingNeedDoing/Interface/MacroWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace SomethingNeedDoing.Interface;

Expand Down
3 changes: 0 additions & 3 deletions SomethingNeedDoing/Managers/CSharpManager.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using ECommons.Reflection;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Emit;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.Loader;

namespace SomethingNeedDoing.Managers;
public class CSharpManager
Expand Down
6 changes: 4 additions & 2 deletions SomethingNeedDoing/Misc/ActiveMacro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,11 @@ static void RegisterClassMethods(Lua lua, object obj)
lua.DoString(FStringSnippet);
lua.DoString(PackageSearchersSnippet);

foreach (string path in Service.Configuration.LuaRequirePaths) {
foreach (var p in typeof(Svc).GetProperties())
lua[p.Name] = p.GetValue(typeof(Svc));

foreach (var path in Service.Configuration.LuaRequirePaths)
lua.DoString($"table.insert(snd.require.paths, '{path}')");
}

var results = lua.DoString(script);

Expand Down
5 changes: 5 additions & 0 deletions SomethingNeedDoing/Misc/Changelog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ static void DisplayChangelog(string date, string changes, bool separator = true)
}
using var font = ImRaii.PushFont(UiBuilder.MonoFont);

DisplayChangelog(
"2024-07-29",
"- Added dalamud services to lua\n" +
"- Potentially fixed the /click and /callback commands to allow wait modifiers\n");

DisplayChangelog(
"2024-07-26",
"- Added lua options for requiring paths (thanks OhKannaDuh)\n");
Expand Down

0 comments on commit e21b873

Please sign in to comment.