Implement synthhelper settings

This commit is contained in:
Asriel Camora
2023-11-15 03:50:25 -08:00
parent a1cdbdf5fc
commit 976df3cbae
5 changed files with 24 additions and 28 deletions
+2 -1
View File
@@ -192,12 +192,13 @@ internal sealed class SimulatedMacro
state = Macro[i].Recalculate(sim, state);
}
public void Enqueue(ActionType action)
public int Enqueue(ActionType action)
{
lock (QueueLock)
{
var lastState = QueuedSteps.Count > 0 ? QueuedSteps[^1].State : State;
QueuedSteps.Add(new(action, CreateSim(), lastState, out _));
return QueuedSteps.Count + Macro.Count;
}
}
+1 -1
View File
@@ -1554,7 +1554,7 @@ public sealed class MacroEditor : Window, IDisposable
using (SolverObject = new Solver.Solver(config, state) { Token = token })
{
SolverObject.OnLog += Log.Debug;
SolverObject.OnNewAction += Macro.Enqueue;
SolverObject.OnNewAction += a => Macro.Enqueue(a);
SolverObject.Start();
_ = SolverObject.GetTask().GetAwaiter().GetResult();
}
+11 -18
View File
@@ -155,8 +155,8 @@ public sealed class Settings : Window, IDisposable
{
DrawTabGeneral();
DrawTabSimulator();
//if (Config.EnableSynthHelper)
// DrawTabSynthHelper();
if (Config.EnableSynthHelper)
DrawTabSynthHelper();
DrawTabAbout();
ImGui.EndTabBar();
@@ -173,22 +173,15 @@ public sealed class Settings : Window, IDisposable
var isDirty = false;
using (var g = ImRaii.Group())
{
using var d = ImRaii.Disabled();
DrawOption(
"Enable Synthesis Helper",
"Adds a helper next to your synthesis window to help solve for the best craft.\n" +
"Extremely useful for expert recipes, where the condition can greatly affect\n" +
"which actions you take.",
Config.EnableSynthHelper,
v => Config.EnableSynthHelper = v,
ref isDirty
);
}
if (ImGui.IsItemHovered())
ImGui.SetTooltip("Disabled temporarily for testing");
DrawOption(
"Enable Synthesis Helper",
"Adds a helper next to your synthesis window to help solve for the best craft.\n" +
"Extremely useful for expert recipes, where the condition can greatly affect\n" +
"which actions you take.",
Config.EnableSynthHelper,
v => Config.EnableSynthHelper = v,
ref isDirty
);
DrawOption(
"Show Only One Macro Stat in Crafting Log",
+9 -4
View File
@@ -153,7 +153,6 @@ public sealed unsafe class SynthHelper : Window, IDisposable
var pos = new Vector2(unit.X, unit.Y);
var size = new Vector2(unit.WindowNode->AtkResNode.Width, unit.WindowNode->AtkResNode.Height) * scale;
var node = unit.GetNodeById(46);
var offset = 5;
Position = ImGuiHelpers.MainViewport.Pos + pos + new Vector2(size.X, offset * scale);
@@ -206,7 +205,6 @@ public sealed unsafe class SynthHelper : Window, IDisposable
}
if (ImGui.ImageButton(action.GetIcon(RecipeData!.ClassJob).ImGuiHandle, new(imageSize), default, Vector2.One, 0, default, failedAction ? new(1, 1, 1, ImGui.GetStyle().DisabledAlpha) : Vector4.One))
{
Log.Debug($"Clicked {action.GetName(RecipeData.ClassJob)} [{i}]");
if (i == 0)
Chat.SendMessage($"/ac \"{action.GetName(RecipeData.ClassJob)}\"");
}
@@ -220,7 +218,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable
lastState = state;
}
for (var i = 0; i < 2; ++i)
var rows = (int)Math.Max(1, MathF.Ceiling(Service.Configuration.SynthHelperStepCount / itemsPerRow));
for (var i = 0; i < rows; ++i)
{
if (Macro.Count <= i * itemsPerRow)
ImGui.Dummy(new(0, imageSize));
@@ -524,7 +523,7 @@ public sealed unsafe class SynthHelper : Window, IDisposable
using (HelperTaskObject = new Solver.Solver(config, state) { Token = token })
{
HelperTaskObject.OnLog += Log.Debug;
HelperTaskObject.OnNewAction += Macro.Enqueue;
HelperTaskObject.OnNewAction += EnqueueAction;
HelperTaskObject.Start();
_ = HelperTaskObject.GetTask().GetAwaiter().GetResult();
}
@@ -532,6 +531,12 @@ public sealed unsafe class SynthHelper : Window, IDisposable
token.ThrowIfCancellationRequested();
}
private void EnqueueAction(ActionType action)
{
if (Macro.Enqueue(action) >= Service.Configuration.SynthHelperStepCount)
HelperTaskTokenSource?.Cancel();
}
private static Sim CreateSim(in SimulationState state) =>
Service.Configuration.ConditionRandomness ? new Sim() { State = state } : new SimNoRandom() { State = state };