Skip to content

Commit

Permalink
Disable synthhelper if a macro is running
Browse files Browse the repository at this point in the history
  • Loading branch information
WorkingRobot committed Nov 15, 2023
1 parent 976df3c commit bce114d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
1 change: 1 addition & 0 deletions Craftimizer/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class Configuration : IPluginConfiguration
[JsonConverter(typeof(PopulateConverter))]
public SolverConfig SynthHelperSolverConfig { get; set; } = SolverConfig.SynthHelperDefault;
public bool EnableSynthHelper { get; set; } = true;
public bool DisableSynthHelperOnMacro { get; set; } = true;
public bool ShowOptimalMacroStat { get; set; } = true;
public int SynthHelperStepCount { get; set; } = 5;

Expand Down
8 changes: 8 additions & 0 deletions Craftimizer/Windows/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,14 @@ private void DrawTabSynthHelper()

var isDirty = false;

DrawOption(
"Disable when running macro",
"Disables itself when an in-game macro is running.",
Config.DisableSynthHelperOnMacro,
v => Config.DisableSynthHelperOnMacro = v,
ref isDirty
);

DrawOption(
"Step Count",
"The number of future actions to solve for during an in-game craft.",
Expand Down
62 changes: 32 additions & 30 deletions Craftimizer/Windows/SynthHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using FFXIVClientStructs.FFXIV.Client.UI.Shell;
using ImGuiNET;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -85,34 +86,6 @@ public SynthHelper() : base("Craftimizer SynthHelper", WindowFlags)
Service.WindowSystem.AddWindow(this);
}

private bool wasInCraftAction;
public override void Update()
{
Addon = (AddonSynthesis*)Service.GameGui.GetAddonByName("Synthesis");

if (Addon != null)
{
var agent = AgentRecipeNote.Instance();
var recipeId = (ushort)agent->ActiveCraftRecipeId;

if (agent->ActiveCraftRecipeId == 0)
IsCrafting = false;
else if (!IsCrafting)
{
IsCrafting = true;
OnStartCrafting(recipeId);
}
}
else
IsCrafting = false;

Macro.FlushQueue();

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

private bool wasOpen;
public override bool DrawConditions()
Expand All @@ -121,28 +94,57 @@ public override bool DrawConditions()
if (isOpen != wasOpen)
{
if (wasOpen)
{
IsCrafting = false;
HelperTaskTokenSource?.Cancel();
}
}

wasOpen = isOpen;
return isOpen;
}

private bool wasInCraftAction;
private bool ShouldDraw()
{
if (Service.ClientState.LocalPlayer == null)
return false;

if (Addon == null)
if (!Service.Configuration.EnableSynthHelper)
return false;

if (!IsCrafting)
if (Service.Configuration.DisableSynthHelperOnMacro &&
RaptureShellModule.Instance()->MacroCurrentLine >= 0)
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;

var agent = AgentRecipeNote.Instance();
var recipeId = (ushort)agent->ActiveCraftRecipeId;

if (agent->ActiveCraftRecipeId == 0)
return false;

if (!IsCrafting)
{
IsCrafting = true;
OnStartCrafting(recipeId);
}

Macro.FlushQueue();

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

return true;
}

Expand Down

1 comment on commit bce114d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: bce114d Previous: a8c3f34 Ratio
Craftimizer.Benchmark.Bench.Solve(State: 14205961, Config: 021AF32A) 1725848660 ns (± 11100758.726501536)
Craftimizer.Benchmark.Bench.Solve(State: 14205961, Config: 021AF32A) 1388765926.6666667 ns (± 7097800.416775675)
Craftimizer.Benchmark.Bench.Solve(State: A1C31B93, Config: 021AF32A) 1727985842.857143 ns (± 2347280.72580045)
Craftimizer.Benchmark.Bench.Solve(State: A1C31B93, Config: 021AF32A) 1407302766.6666667 ns (± 5557874.673401524)

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.