Skip to content

Commit 0bd1640

Browse files
committed
make a new config cause I cbf
1 parent a999056 commit 0bd1640

File tree

3 files changed

+76
-57
lines changed

3 files changed

+76
-57
lines changed

YesAlready/Configuration.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using System.Collections.Generic;
2-
using System.IO;
3-
using System.Linq;
4-
51
using Dalamud.Configuration;
62
using Dalamud.Game.ClientState.Keys;
73
using Dalamud.Game.Text;
84
using Newtonsoft.Json;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Linq;
98

109
namespace YesAlready;
1110

@@ -69,13 +68,13 @@ public partial class Configuration() : IPluginConfiguration
6968
public bool MiragePrismRemoveDispel { get; set; } = false;
7069
public bool MiragePrismExecuteCast { get; set; } = false;
7170

72-
public List<CustomBother> CustomBothers { get; set; } = [];
71+
public List<CustomBother> CustomCallbacks { get; set; } = [];
7372

7473
public class CustomBother
7574
{
7675
public string Addon { get; set; }
7776
public bool UpdateState { get; set; } = true;
78-
public object[] CallbackParams { get; set; }
77+
public string CallbackParams { get; set; }
7978
}
8079

8180
public enum TradeMultipleMode

YesAlready/Features/CustomAddonCallbacks.cs

+63-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using Dalamud.Game.Addon.Lifecycle;
22
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
33
using ECommons.Automation;
4+
using System.Collections.Generic;
45
using System.Linq;
6+
using System.Text;
57
using YesAlready.BaseFeatures;
68

79
namespace YesAlready.Features;
@@ -10,7 +12,7 @@ public class CustomAddonCallbacks : BaseFeature
1012
public override void Enable()
1113
{
1214
base.Enable();
13-
foreach (var addon in P.Config.CustomBothers)
15+
foreach (var addon in P.Config.CustomCallbacks)
1416
Svc.AddonLifecycle.RegisterListener(AddonEvent.PostSetup, addon.Addon, AddonSetup);
1517
}
1618

@@ -25,7 +27,66 @@ protected static unsafe void AddonSetup(AddonEvent eventType, AddonArgs addonInf
2527
if (!P.Active) return;
2628

2729
var addon = addonInfo.Base();
28-
var callbacks = P.Config.CustomBothers.First(x => x.Addon == addonInfo.AddonName).CallbackParams;
30+
var callbacks = P.Config.CustomCallbacks.First(x => x.Addon == addonInfo.AddonName).CallbackParams;
2931
Callback.Fire(addon, true, callbacks);
3032
}
33+
34+
public static string CallbackToString(object[] args)
35+
{
36+
var sb = new StringBuilder();
37+
foreach (var obj in args)
38+
{
39+
if (obj is uint)
40+
sb.Append('u');
41+
else if (obj is string str && str.Contains(' '))
42+
sb.Append($"\"{str}\"");
43+
else
44+
sb.Append(obj.ToString());
45+
sb.Append(' ');
46+
}
47+
if (sb.Length >= 2)
48+
sb.Length -= 2;
49+
return sb.ToString();
50+
}
51+
52+
public static object[] CallbackToArray(string args)
53+
{
54+
var rawValues = args.Split(' ');
55+
var valueArgs = new List<object>();
56+
57+
var current = "";
58+
var inQuotes = false;
59+
60+
for (var i = 0; i < rawValues.Length; i++)
61+
{
62+
if (!inQuotes)
63+
{
64+
if (rawValues[i].StartsWith('\"'))
65+
{
66+
inQuotes = true;
67+
current = rawValues[i].TrimStart('"');
68+
}
69+
else
70+
{
71+
if (int.TryParse(rawValues[i], out var iValue)) valueArgs.Add(iValue);
72+
else if (uint.TryParse(rawValues[i].TrimEnd('U', 'u'), out var uValue)) valueArgs.Add(uValue);
73+
else if (bool.TryParse(rawValues[i], out var bValue)) valueArgs.Add(bValue);
74+
else valueArgs.Add(rawValues[i]);
75+
}
76+
}
77+
else
78+
{
79+
if (rawValues[i].EndsWith('\"'))
80+
{
81+
inQuotes = false;
82+
current += " " + rawValues[i].TrimEnd('"');
83+
valueArgs.Add(current);
84+
current = "";
85+
}
86+
else
87+
current += " " + rawValues[i];
88+
}
89+
}
90+
return [.. valueArgs];
91+
}
3192
}

YesAlready/UI/Tabs/Custom.cs

+8-49
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public static void Draw()
2323

2424
DrawButtons();
2525

26-
foreach (var bother in P.Config.CustomBothers.ToList())
26+
foreach (var bother in P.Config.CustomCallbacks.ToList())
2727
{
28-
using var id = ImRaii.PushId(P.Config.CustomBothers.IndexOf(bother));
28+
using var id = ImRaii.PushId(P.Config.CustomCallbacks.IndexOf(bother));
2929
var name = bother.Addon;
3030
if (ImGui.InputText("Addon Name", ref name, 50, ImGuiInputTextFlags.EnterReturnsTrue))
3131
{
@@ -34,18 +34,18 @@ public static void Draw()
3434
ToggleCustomBothers();
3535
}
3636

37-
var args = string.Join(" ", bother.CallbackParams);
37+
var args = bother.CallbackParams;
3838
if (ImGui.InputText("Parameters", ref args, 150, ImGuiInputTextFlags.EnterReturnsTrue))
3939
{
40-
bother.CallbackParams = ParseArgs(args);
40+
bother.CallbackParams = args;
4141
P.Config.Save();
4242
ToggleCustomBothers();
4343
}
4444

4545
ImGui.SameLine();
46-
if (ImGuiEx.IconButton(FontAwesomeIcon.Trash, "Remove Entry", id: $"Delete##{P.Config.CustomBothers.IndexOf(bother)}"))
46+
if (ImGuiEx.IconButton(FontAwesomeIcon.Trash, "Remove Entry", id: $"Delete##{P.Config.CustomCallbacks.IndexOf(bother)}"))
4747
{
48-
P.Config.CustomBothers.Remove(bother);
48+
P.Config.CustomCallbacks.Remove(bother);
4949
P.Config.Save();
5050
ToggleCustomBothers();
5151
}
@@ -60,10 +60,10 @@ public static void DrawButtons()
6060

6161
if (ImGuiEx.IconButton(FontAwesomeIcon.Plus, "Add new entry"))
6262
{
63-
P.Config.CustomBothers.Add(new CustomBother
63+
P.Config.CustomCallbacks.Add(new CustomBother
6464
{
6565
Addon = "AddonName",
66-
CallbackParams = [-1]
66+
CallbackParams = "-1"
6767
});
6868
P.Config.Save();
6969
}
@@ -101,45 +101,4 @@ private static void ToggleCustomBothers()
101101
}
102102
}
103103
}
104-
105-
private static object[] ParseArgs(string args)
106-
{
107-
var rawValues = args.Split(' ');
108-
var valueArgs = new List<object>();
109-
110-
var current = "";
111-
var inQuotes = false;
112-
113-
for (var i = 0; i < rawValues.Length; i++)
114-
{
115-
if (!inQuotes)
116-
{
117-
if (rawValues[i].StartsWith('\"'))
118-
{
119-
inQuotes = true;
120-
current = rawValues[i].TrimStart('"');
121-
}
122-
else
123-
{
124-
if (int.TryParse(rawValues[i], out var iValue)) valueArgs.Add(iValue);
125-
else if (uint.TryParse(rawValues[i].TrimEnd('U', 'u'), out var uValue)) valueArgs.Add(uValue);
126-
else if (bool.TryParse(rawValues[i], out var bValue)) valueArgs.Add(bValue);
127-
else valueArgs.Add(rawValues[i]);
128-
}
129-
}
130-
else
131-
{
132-
if (rawValues[i].EndsWith('\"'))
133-
{
134-
inQuotes = false;
135-
current += " " + rawValues[i].TrimEnd('"');
136-
valueArgs.Add(current);
137-
current = "";
138-
}
139-
else
140-
current += " " + rawValues[i];
141-
}
142-
}
143-
return [.. valueArgs];
144-
}
145104
}

0 commit comments

Comments
 (0)