Skip to content

Commit

Permalink
Refactor synth helper checking
Browse files Browse the repository at this point in the history
  • Loading branch information
WorkingRobot committed Aug 3, 2024
1 parent 5302853 commit ff7d769
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions Craftimizer/Windows/SynthHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using System.Linq;
using System.Numerics;
using System.Threading;
using System.Threading.Tasks;
using ActionType = Craftimizer.Simulator.Actions.ActionType;
using Sim = Craftimizer.Simulator.Simulator;
using SimNoRandom = Craftimizer.Simulator.SimulatorNoRandom;
Expand Down Expand Up @@ -124,13 +123,13 @@ public override void Update()
if (WasCalculatable)
SolverTask?.Cancel();
else if (Macro.Count == 0)
CurrentState = GetCurrentState();
RefreshCurrentState();
}

if (Macro.Count == 0 && ShouldOpen)
{
if (ShouldOpen != WasOpen || IsCollapsed != WasCollapsed)
CurrentState = GetCurrentState();
RefreshCurrentState();
}

if (!ShouldOpen)
Expand All @@ -156,6 +155,24 @@ private bool CalculateShouldOpen()
if (!Service.Configuration.EnableSynthHelper)
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)
{
var module = RaptureShellModule.Instance();
Expand All @@ -175,24 +192,6 @@ private bool CalculateShouldOpen()
}
}

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)
OnStartCrafting(recipeId);

Expand All @@ -203,7 +202,7 @@ private bool CalculateShouldOpen()

var isInCraftAction = Service.Condition[ConditionFlag.Crafting40];
if (!isInCraftAction && wasInCraftAction)
OnFinishedUsingAction();
RefreshCurrentState();
wasInCraftAction = isInCraftAction;

return true;
Expand Down Expand Up @@ -518,10 +517,8 @@ private void OnUseAction(ActionType action)
CurrentActionStates = CurrentState.ActionStates;
}

private void OnFinishedUsingAction()
{
private void RefreshCurrentState() =>
CurrentState = GetCurrentState();
}

private SimulationState GetCurrentState()
{
Expand Down

0 comments on commit ff7d769

Please sign in to comment.