Refactor synth helper checking

This commit is contained in:
Asriel Camora
2024-08-03 00:18:50 -07:00
parent 530285352d
commit ff7d7693ad
+22 -25
View File
@@ -22,7 +22,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using ActionType = Craftimizer.Simulator.Actions.ActionType; using ActionType = Craftimizer.Simulator.Actions.ActionType;
using Sim = Craftimizer.Simulator.Simulator; using Sim = Craftimizer.Simulator.Simulator;
using SimNoRandom = Craftimizer.Simulator.SimulatorNoRandom; using SimNoRandom = Craftimizer.Simulator.SimulatorNoRandom;
@@ -124,13 +123,13 @@ public sealed unsafe class SynthHelper : Window, IDisposable
if (WasCalculatable) if (WasCalculatable)
SolverTask?.Cancel(); SolverTask?.Cancel();
else if (Macro.Count == 0) else if (Macro.Count == 0)
CurrentState = GetCurrentState(); RefreshCurrentState();
} }
if (Macro.Count == 0 && ShouldOpen) if (Macro.Count == 0 && ShouldOpen)
{ {
if (ShouldOpen != WasOpen || IsCollapsed != WasCollapsed) if (ShouldOpen != WasOpen || IsCollapsed != WasCollapsed)
CurrentState = GetCurrentState(); RefreshCurrentState();
} }
if (!ShouldOpen) if (!ShouldOpen)
@@ -156,6 +155,24 @@ public sealed unsafe class SynthHelper : Window, IDisposable
if (!Service.Configuration.EnableSynthHelper) if (!Service.Configuration.EnableSynthHelper)
return false; return false;
var agent = AgentRecipeNote.Instance();
var recipeId = (ushort)agent->ActiveCraftRecipeId;
if (agent->ActiveCraftRecipeId == 0)
{
RecipeData = null;
return false;
}
Addon = (AddonSynthesis*)Service.GameGui.GetAddonByName("Synthesis");
if (Addon == null)
return false;
// Check if Synthesis addon is visible
if (Addon->AtkUnitBase.WindowNode == null)
return false;
if (Service.Configuration.DisableSynthHelperOnMacro) if (Service.Configuration.DisableSynthHelperOnMacro)
{ {
var module = RaptureShellModule.Instance(); var module = RaptureShellModule.Instance();
@@ -175,24 +192,6 @@ public sealed unsafe class SynthHelper : Window, IDisposable
} }
} }
Addon = (AddonSynthesis*)Service.GameGui.GetAddonByName("Synthesis");
if (Addon == null)
return false;
// Check if Synthesis addon is visible
if (Addon->AtkUnitBase.WindowNode == null)
return false;
var agent = AgentRecipeNote.Instance();
var recipeId = (ushort)agent->ActiveCraftRecipeId;
if (agent->ActiveCraftRecipeId == 0)
{
RecipeData = null;
return false;
}
if (RecipeData?.RecipeId != agent->ActiveCraftRecipeId) if (RecipeData?.RecipeId != agent->ActiveCraftRecipeId)
OnStartCrafting(recipeId); OnStartCrafting(recipeId);
@@ -203,7 +202,7 @@ public sealed unsafe class SynthHelper : Window, IDisposable
var isInCraftAction = Service.Condition[ConditionFlag.Crafting40]; var isInCraftAction = Service.Condition[ConditionFlag.Crafting40];
if (!isInCraftAction && wasInCraftAction) if (!isInCraftAction && wasInCraftAction)
OnFinishedUsingAction(); RefreshCurrentState();
wasInCraftAction = isInCraftAction; wasInCraftAction = isInCraftAction;
return true; return true;
@@ -518,10 +517,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable
CurrentActionStates = CurrentState.ActionStates; CurrentActionStates = CurrentState.ActionStates;
} }
private void OnFinishedUsingAction() private void RefreshCurrentState() =>
{
CurrentState = GetCurrentState(); CurrentState = GetCurrentState();
}
private SimulationState GetCurrentState() private SimulationState GetCurrentState()
{ {