Make a reapply event.

This commit is contained in:
Ottermandias 2024-02-18 13:05:04 +01:00
parent 0bc9fc872e
commit 22a8ba3f35
9 changed files with 22 additions and 16 deletions

View file

@ -110,7 +110,7 @@ public partial class GlamourerIpc
foreach (var obj in data.Objects)
{
_autoDesignApplier.ReapplyAutomation(obj, state.Identifier, state);
_stateManager.ReapplyState(obj);
_stateManager.ReapplyState(obj, StateSource.IpcManual);
}
}
}

View file

@ -151,7 +151,7 @@ public sealed class AutoDesignApplier : IDisposable
{
Reduce(data.Objects[0], state, newSet, false, false);
foreach (var actor in data.Objects)
_state.ReapplyState(actor);
_state.ReapplyState(actor, StateSource.Fixed);
}
}
else if (_objects.TryGetValueAllWorld(id, out data) || _objects.TryGetValueNonOwned(id, out data))
@ -162,7 +162,7 @@ public sealed class AutoDesignApplier : IDisposable
if (_state.GetOrCreate(specificId, actor, out var state))
{
Reduce(actor, state, newSet, false, false);
_state.ReapplyState(actor);
_state.ReapplyState(actor, StateSource.Fixed);
}
}
}
@ -210,7 +210,7 @@ public sealed class AutoDesignApplier : IDisposable
var respectManual = state.LastJob == newJob.Id;
state.LastJob = actor.Job;
Reduce(actor, state, set, respectManual, true);
_state.ReapplyState(actor);
_state.ReapplyState(actor, StateSource.Fixed);
}
public void ReapplyAutomation(Actor actor, ActorIdentifier identifier, ActorState state)
@ -310,7 +310,7 @@ public sealed class AutoDesignApplier : IDisposable
Reduce(data.Objects[0], state, set, respectManual, job != state.LastJob);
NewGearsetId = -1;
foreach (var actor in data.Objects)
_state.ReapplyState(actor);
_state.ReapplyState(actor, StateSource.Fixed);
}
public static unsafe bool CheckGearset(short check)

View file

@ -53,6 +53,9 @@ namespace Glamourer.Events
/// <summary> A characters saved state had a meta toggle changed. Data is the old stain id, the new stain id and the slot [(StainId, StainId, EquipSlot)]. </summary>
Other,
/// <summary> A characters state was reapplied. Data is null. </summary>
Reapply,
}
public enum Priority

View file

@ -225,7 +225,7 @@ public sealed class DesignQuickBar : Window, IDisposable
foreach (var actor in data.Objects)
{
_autoDesignApplier.ReapplyAutomation(actor, id, state!);
_stateManager.ReapplyState(actor);
_stateManager.ReapplyState(actor, StateSource.Manual);
}
}

View file

@ -373,7 +373,7 @@ public class ActorPanel(
ImGui.SameLine();
if (ImGuiUtil.DrawDisabledButton("Reapply State", Vector2.Zero, "Try to reapply the configured state if something went wrong.",
_state!.IsLocked))
_stateManager.ReapplyState(_actor);
_stateManager.ReapplyState(_actor, StateSource.Manual);
ImGui.SameLine();
if (ImGuiUtil.DrawDisabledButton("Reapply Automation", Vector2.Zero,
@ -381,7 +381,7 @@ public class ActorPanel(
!_config.EnableAutoDesigns || _state!.IsLocked))
{
_autoDesignApplier.ReapplyAutomation(_actor, _identifier, _state!);
_stateManager.ReapplyState(_actor);
_stateManager.ReapplyState(_actor, StateSource.Manual);
}
}

View file

@ -1,4 +1,4 @@
using Glamourer.Designs;
using Glamourer.Designs;
using Glamourer.Services;
using Newtonsoft.Json.Linq;
using Penumbra.GameData.Enums;
@ -54,9 +54,10 @@ public sealed class CmaFile
{
foreach (var slot in EquipSlotExtensions.EqdpSlots)
{
var idx = slot.ToIndex();
var idx = slot.ToIndex();
if (idx * 4 + 3 >= byteData.Length)
continue;
var armor = ((CharacterArmor*)ptr)[idx];
var item = items.Identify(slot, armor.Set, armor.Variant);
data.SetItem(slot, item);

View file

@ -308,7 +308,7 @@ public class CommandService : IDisposable
if (_stateManager.GetOrCreate(identifier, actor, out var state))
{
_autoDesignApplier.ReapplyAutomation(actor, identifier, state);
_stateManager.ReapplyState(actor);
_stateManager.ReapplyState(actor, StateSource.Manual);
}
}
}
@ -357,7 +357,7 @@ public class CommandService : IDisposable
return true;
foreach (var actor in data.Objects)
_stateManager.ReapplyState(actor);
_stateManager.ReapplyState(actor, StateSource.Manual);
}

View file

@ -341,6 +341,8 @@ public class StateApplier(
ChangeMetaState(actors, MetaIndex.VisorState, state.ModelData.IsVisorToggled());
ChangeCrests(actors, state.ModelData.CrestVisibility);
ChangeParameters(actors, state.OnlyChangedParameters(), state.ModelData.Parameters, state.IsLocked);
foreach (var material in state.Materials.Values)
ChangeMaterialValue(actors, MaterialValueIndex.FromKey(material.Key), material.Value.Model, state.IsLocked);
}
return actors;

View file

@ -334,14 +334,14 @@ public sealed class StateManager(
}
}
public void ReapplyState(Actor actor)
public void ReapplyState(Actor actor, StateSource source)
{
if (!GetOrCreate(actor, out var state))
return;
Applier.ApplyAll(state,
!actor.Model.IsHuman || CustomizeArray.Compare(actor.Model.GetCustomize(), state.ModelData.Customize).RequiresRedraw(),
false);
var data = Applier.ApplyAll(state,
!actor.Model.IsHuman || CustomizeArray.Compare(actor.Model.GetCustomize(), state.ModelData.Customize).RequiresRedraw(), false);
StateChanged.Invoke(StateChanged.Type.Reapply, source, state, data, null);
}
public void DeleteState(ActorIdentifier identifier)