Fix /crafteditor command
This commit is contained in:
+38
-1
@@ -11,6 +11,7 @@ using Dalamud.IoC;
|
||||
using Dalamud.Plugin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Craftimizer.Plugin;
|
||||
@@ -69,12 +70,48 @@ public sealed class Plugin : IDalamudPlugin
|
||||
{
|
||||
HelpMessage = "Open the crafting macros window.",
|
||||
});
|
||||
Service.CommandManager.AddHandler("/crafteditor", new CommandInfo((_, _) => OpenSettingsWindow())
|
||||
Service.CommandManager.AddHandler("/crafteditor", new CommandInfo((_, _) => OpenEmptyMacroEditor())
|
||||
{
|
||||
HelpMessage = "Open the crafting macro editor.",
|
||||
});
|
||||
}
|
||||
|
||||
public (CharacterStats? Character, RecipeData? Recipe, MacroEditor.CrafterBuffs? Buffs) GetOpenedStats()
|
||||
{
|
||||
var editorWindow = (EditorWindow?.IsOpen ?? false) ? EditorWindow : null;
|
||||
var recipeData = editorWindow?.RecipeData ?? Service.Plugin.RecipeNoteWindow.RecipeData;
|
||||
var characterStats = editorWindow?.CharacterStats ?? Service.Plugin.RecipeNoteWindow.CharacterStats;
|
||||
var buffs = editorWindow?.Buffs ?? (RecipeNoteWindow.CharacterStats != null ? new(Service.ClientState.LocalPlayer?.StatusList) : null);
|
||||
|
||||
return (characterStats, recipeData, buffs);
|
||||
}
|
||||
|
||||
public (CharacterStats Character, RecipeData Recipe, MacroEditor.CrafterBuffs Buffs) GetDefaultStats()
|
||||
{
|
||||
var stats = GetOpenedStats();
|
||||
return (
|
||||
stats.Character ?? new()
|
||||
{
|
||||
Craftsmanship = 100,
|
||||
Control = 100,
|
||||
CP = 200,
|
||||
Level = 10,
|
||||
CanUseManipulation = false,
|
||||
HasSplendorousBuff = false,
|
||||
IsSpecialist = false,
|
||||
CLvl = 10,
|
||||
},
|
||||
stats.Recipe ?? new(1023),
|
||||
stats.Buffs ?? new(null)
|
||||
);
|
||||
}
|
||||
|
||||
public void OpenEmptyMacroEditor()
|
||||
{
|
||||
var stats = GetDefaultStats();
|
||||
OpenMacroEditor(stats.Character, stats.Recipe, stats.Buffs, Enumerable.Empty<ActionType>(), null);
|
||||
}
|
||||
|
||||
public void OpenMacroEditor(CharacterStats characterStats, RecipeData recipeData, MacroEditor.CrafterBuffs buffs, IEnumerable<ActionType> actions, Action<IEnumerable<ActionType>>? setter)
|
||||
{
|
||||
EditorWindow?.Dispose();
|
||||
|
||||
@@ -21,7 +21,6 @@ public sealed class MacroList : Window, IDisposable
|
||||
|
||||
public CharacterStats? CharacterStats { get; private set; }
|
||||
public RecipeData? RecipeData { get; private set; }
|
||||
private MacroEditor? EditorWindow { get; set; }
|
||||
|
||||
private IReadOnlyList<Macro> Macros => Service.Configuration.Macros;
|
||||
private Dictionary<Macro, SimulationState> MacroStateCache { get; } = new();
|
||||
@@ -51,10 +50,7 @@ public sealed class MacroList : Window, IDisposable
|
||||
var oldCharacterStats = CharacterStats;
|
||||
var oldRecipeData = RecipeData;
|
||||
|
||||
EditorWindow = Service.Plugin.EditorWindow;
|
||||
EditorWindow = (EditorWindow?.IsOpen ?? false) ? EditorWindow : null;
|
||||
RecipeData = EditorWindow?.RecipeData ?? Service.Plugin.RecipeNoteWindow.RecipeData;
|
||||
CharacterStats = EditorWindow?.CharacterStats ?? Service.Plugin.RecipeNoteWindow.CharacterStats;
|
||||
(CharacterStats, RecipeData, _) = Service.Plugin.GetOpenedStats();
|
||||
|
||||
if (oldCharacterStats != CharacterStats || oldRecipeData != RecipeData)
|
||||
RecalculateStats();
|
||||
@@ -310,21 +306,8 @@ public sealed class MacroList : Window, IDisposable
|
||||
|
||||
private void OpenEditor(Macro? macro)
|
||||
{
|
||||
var character = CharacterStats ?? new()
|
||||
{
|
||||
Craftsmanship = 100,
|
||||
Control = 100,
|
||||
CP = 200,
|
||||
Level = 10,
|
||||
CanUseManipulation = false,
|
||||
HasSplendorousBuff = false,
|
||||
IsSpecialist = false,
|
||||
CLvl = 10,
|
||||
};
|
||||
var recipe = RecipeData ?? new(1023);
|
||||
|
||||
var buffs = EditorWindow?.Buffs ?? new(Service.Plugin.RecipeNoteWindow.CharacterStats != null ? Service.ClientState.LocalPlayer?.StatusList : null);
|
||||
Service.Plugin.OpenMacroEditor(character, recipe, buffs, macro?.Actions ?? Enumerable.Empty<ActionType>(), macro != null ? (actions => { macro.ActionEnumerable = actions; Service.Configuration.Save(); }) : null);
|
||||
var stats = Service.Plugin.GetDefaultStats();
|
||||
Service.Plugin.OpenMacroEditor(stats.Character, stats.Recipe, stats.Buffs, macro?.Actions ?? Enumerable.Empty<ActionType>(), macro != null ? (actions => { macro.ActionEnumerable = actions; Service.Configuration.Save(); }) : null);
|
||||
}
|
||||
|
||||
private void OnMacroChanged(Macro macro)
|
||||
|
||||
Reference in New Issue
Block a user