State management bug fixes

This commit is contained in:
Asriel Camora
2024-07-31 10:27:01 -07:00
parent 10bb95d9d8
commit 7c32ff74b1
4 changed files with 30 additions and 24 deletions
+2
View File
@@ -5,6 +5,7 @@ using Dalamud.Interface.Windowing;
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using Dalamud.Storage.Assets;
namespace Craftimizer.Plugin;
@@ -19,6 +20,7 @@ public sealed class Service
[PluginService] public static IClientState ClientState { get; private set; }
[PluginService] public static IDataManager DataManager { get; private set; }
[PluginService] public static ITextureProvider TextureProvider { get; private set; }
[PluginService] public static IDalamudAssetManager DalamudAssetManager { get; private set; }
[PluginService] public static ITargetManager TargetManager { get; private set; }
[PluginService] public static ICondition Condition { get; private set; }
[PluginService] public static IFramework Framework { get; private set; }
+5 -2
View File
@@ -66,7 +66,10 @@ public sealed unsafe class Hooks : IDisposable
if (!Service.Configuration.SynthHelperAbilityAnts)
return ret;
if (!Service.Plugin.SynthHelperWindow.ShouldDrawAnts)
if (Service.Plugin.SynthHelperWindow is not { } window)
return ret;
if (!window.ShouldDrawAnts)
return ret;
if (actionType is not (CSActionType.CraftAction or CSActionType.Action))
@@ -84,7 +87,7 @@ public sealed unsafe class Hooks : IDisposable
if (simActionType == null)
return ret;
if (Service.Plugin.SynthHelperWindow.NextAction != simActionType)
if (window.NextAction != simActionType)
return 0;
}
catch (Exception ex)
+1 -4
View File
@@ -28,9 +28,6 @@ public sealed class IconManager : IDisposable
{
private sealed class LoadedIcon : ILoadedTextureIcon
{
// 10: DXGI_FORMAT_R16G16B16A16_FLOAT
public static IDalamudTextureWrap EmptyTexture { get; } = Service.TextureProvider.CreateEmpty(new(4, 4, 10), false, false);
public ISharedImmediateTexture Source { get; }
public Vector2? Dimensions => GetWrap()?.Size;
@@ -54,7 +51,7 @@ public sealed class IconManager : IDisposable
return null;
}
public IDalamudTextureWrap GetWrapOrEmpty() => GetWrap() ?? EmptyTexture;
public IDalamudTextureWrap GetWrapOrEmpty() => GetWrap() ?? Service.DalamudAssetManager.Empty4X4;
public void Dispose()
{
+21 -17
View File
@@ -46,9 +46,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable
public CharacterStats? CharacterStats { get; private set; }
public SimulationInput? SimulationInput { get; private set; }
public ActionType? NextAction => (ShouldOpen && Macro.Count > 0) ? Macro[0].Action : null;
public bool ShouldDrawAnts => ShouldOpen;
public bool ShouldDrawAnts => ShouldOpen && !IsCollapsed;
public bool IsCrafting { get; private set; }
private int CurrentActionCount { get; set; }
private ActionStates CurrentActionStates { get; set; }
private SimulationState CurrentState
@@ -112,6 +111,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable
private bool ShouldCalculate => !IsCollapsed && ShouldOpen;
private bool WasCalculatable { get; set; }
private bool IsRecalculateQueued { get; set; }
public override void Update()
{
base.Update();
@@ -121,14 +122,15 @@ public sealed unsafe class SynthHelper : Window, IDisposable
if (ShouldCalculate != WasCalculatable)
{
if (WasCalculatable)
{
IsCrafting = false;
SolverTask?.Cancel();
}
else if (Macro.Count == 0)
{
OnStateUpdated();
}
if (Macro.Count == 0)
{
if (ShouldOpen != WasOpen || IsCollapsed != WasCollapsed)
OnStateUpdated();
}
if (!ShouldOpen)
@@ -188,11 +190,11 @@ public sealed unsafe class SynthHelper : Window, IDisposable
if (agent->ActiveCraftRecipeId == 0)
return false;
if (!IsCrafting)
{
IsCrafting = true;
if (RecipeData?.RecipeId != agent->ActiveCraftRecipeId)
OnStartCrafting(recipeId);
}
if (IsRecalculateQueued)
OnStateUpdated();
Macro.FlushQueue();
@@ -474,6 +476,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable
private void OnStartCrafting(ushort recipeId)
{
Log.Debug("On Start craftgin begin!");
var shouldUpdateInput = false;
if (recipeId != RecipeData?.RecipeId)
{
@@ -504,13 +508,12 @@ public sealed unsafe class SynthHelper : Window, IDisposable
CurrentActionCount = 0;
CurrentActionStates = new();
CurrentState = GetCurrentState();
Log.Debug("On Start craftgin end!");
}
private void OnUseAction(ActionType action)
{
if (!IsCrafting || !ShouldOpen || IsCollapsed)
return;
(_, CurrentState) = new SimNoRandom().Execute(GetCurrentState(), action);
CurrentActionCount = CurrentState.ActionCount;
CurrentActionStates = CurrentState.ActionStates;
@@ -518,9 +521,6 @@ public sealed unsafe class SynthHelper : Window, IDisposable
private void OnFinishedUsingAction()
{
if (!IsCrafting || !ShouldOpen || IsCollapsed)
return;
CurrentState = GetCurrentState();
}
@@ -575,9 +575,13 @@ public sealed unsafe class SynthHelper : Window, IDisposable
private void OnStateUpdated()
{
if (!IsCrafting || !ShouldOpen || IsCollapsed)
if (!ShouldOpen || IsCollapsed)
{
IsRecalculateQueued = true;
return;
}
IsRecalculateQueued = false;
Macro.Clear();
Macro.InitialState = CurrentState;
CalculateBestMacro();