Continue renames, some cleanup.

This commit is contained in:
Ottermandias 2025-01-24 17:50:58 +01:00
parent 7be283ca30
commit d9f9937d41
18 changed files with 175 additions and 134 deletions

View file

@ -17,7 +17,7 @@ public class StateEditor(
InternalStateEditor editor,
StateApplier applier,
StateChanged stateChanged,
StateUpdated stateUpdated,
StateFinalized stateFinalized,
JobChangeState jobChange,
Configuration config,
ItemManager items,
@ -25,12 +25,12 @@ public class StateEditor(
ModSettingApplier modApplier,
GPoseService gPose) : IDesignEditor
{
protected readonly InternalStateEditor Editor = editor;
protected readonly StateApplier Applier = applier;
protected readonly StateChanged StateChanged = stateChanged;
protected readonly StateUpdated StateUpdated = stateUpdated;
protected readonly Configuration Config = config;
protected readonly ItemManager Items = items;
protected readonly InternalStateEditor Editor = editor;
protected readonly StateApplier Applier = applier;
protected readonly StateChanged StateChanged = stateChanged;
protected readonly StateFinalized StateFinalized = stateFinalized;
protected readonly Configuration Config = config;
protected readonly ItemManager Items = items;
/// <summary> Turn an actor to. </summary>
public void ChangeModelId(ActorState state, uint modelId, CustomizeArray customize, nint equipData, StateSource source,
@ -43,7 +43,7 @@ public class StateEditor(
Glamourer.Log.Verbose(
$"Set model id in state {state.Identifier.Incognito(null)} from {old} to {modelId}. [Affecting {actors.ToLazyString("nothing")}.]");
StateChanged.Invoke(StateChangeType.Model, source, state, actors, null);
StateUpdated.Invoke(StateFinalizationType.ModelChange, actors);
StateFinalized.Invoke(StateFinalizationType.ModelChange, actors);
}
/// <inheritdoc/>
@ -383,7 +383,7 @@ public class StateEditor(
Editor.ChangeMetaState(state, meta, mergedDesign.Design.DesignData.GetMeta(meta), Source(meta), out _, settings.Key);
}
if (settings.ResetMaterials || (!settings.RespectManual && mergedDesign.ResetAdvancedDyes))
if (settings.ResetMaterials || !settings.RespectManual && mergedDesign.ResetAdvancedDyes)
state.Materials.Clear();
foreach (var (key, value) in mergedDesign.Design.Materials)
@ -420,8 +420,8 @@ public class StateEditor(
Glamourer.Log.Verbose(
$"Applied design to {state.Identifier.Incognito(null)}. [Affecting {actors.ToLazyString("nothing")}.]");
StateChanged.Invoke(StateChangeType.Design, state.Sources[MetaIndex.Wetness], state, actors, null); // FIXME: maybe later
if(settings.SendStateUpdate)
StateUpdated.Invoke(StateFinalizationType.DesignApplied, actors);
if (settings.IsFinal)
StateFinalized.Invoke(StateFinalizationType.DesignApplied, actors);
return;
@ -442,7 +442,8 @@ public class StateEditor(
if (!settings.MergeLinks || design is not Design d)
merged = new MergedDesign(design);
else
merged = merger.Merge(d.AllLinks(true), state.ModelData.IsHuman ? state.ModelData.Customize : CustomizeArray.Default, state.BaseData,
merged = merger.Merge(d.AllLinks(true), state.ModelData.IsHuman ? state.ModelData.Customize : CustomizeArray.Default,
state.BaseData,
false, Config.AlwaysApplyAssociatedMods);
ApplyDesign(data, merged, settings with
@ -460,7 +461,7 @@ public class StateEditor(
if (!Config.ChangeEntireItem || !settings.Source.IsManual())
return;
var mh = newMainhand ?? state.ModelData.Item(EquipSlot.MainHand);
var mh = newMainhand ?? state.ModelData.Item(EquipSlot.MainHand);
// Do not change Shields to nothing.
if (mh.Type is FullEquipType.Sword)
return;

View file

@ -41,7 +41,7 @@ public class StateListener : IDisposable
private readonly HeadGearVisibilityChanged _headGearVisibility;
private readonly VisorStateChanged _visorState;
private readonly WeaponVisibilityChanged _weaponVisibility;
private readonly StateUpdated _stateUpdated;
private readonly StateFinalized _stateFinalized;
private readonly AutoDesignApplier _autoDesignApplier;
private readonly FunModule _funModule;
private readonly HumanModelList _humans;
@ -63,7 +63,7 @@ public class StateListener : IDisposable
WeaponVisibilityChanged weaponVisibility, HeadGearVisibilityChanged headGearVisibility, AutoDesignApplier autoDesignApplier,
FunModule funModule, HumanModelList humans, StateApplier applier, MovedEquipment movedEquipment, ObjectManager objects,
GPoseService gPose, ChangeCustomizeService changeCustomizeService, CustomizeService customizations, ICondition condition,
CrestService crestService, BonusSlotUpdating bonusSlotUpdating, StateUpdated stateUpdated)
CrestService crestService, BonusSlotUpdating bonusSlotUpdating, StateFinalized stateFinalized)
{
_manager = manager;
_items = items;
@ -88,7 +88,7 @@ public class StateListener : IDisposable
_condition = condition;
_crestService = crestService;
_bonusSlotUpdating = bonusSlotUpdating;
_stateUpdated = stateUpdated;
_stateFinalized = stateFinalized;
Subscribe();
}
@ -281,7 +281,7 @@ public class StateListener : IDisposable
_objects.Update();
if (_objects.TryGetValue(identifier, out var actors) && actors.Valid)
_stateUpdated.Invoke(StateFinalizationType.Gearset, actors);
_stateFinalized.Invoke(StateFinalizationType.Gearset, actors);
}

View file

@ -18,20 +18,20 @@ using Penumbra.GameData.Interop;
namespace Glamourer.State;
public sealed class StateManager(
ActorManager _actors,
ActorManager actors,
ItemManager items,
StateChanged @event,
StateUpdated @event2,
StateChanged changeEvent,
StateFinalized finalizeEvent,
StateApplier applier,
InternalStateEditor editor,
HumanModelList _humans,
IClientState _clientState,
HumanModelList humans,
IClientState clientState,
Configuration config,
JobChangeState jobChange,
DesignMerger merger,
ModSettingApplier modApplier,
GPoseService gPose)
: StateEditor(editor, applier, @event, @event2, jobChange, config, items, merger, modApplier, gPose),
: StateEditor(editor, applier, changeEvent, finalizeEvent, jobChange, config, items, merger, modApplier, gPose),
IReadOnlyDictionary<ActorIdentifier, ActorState>
{
private readonly Dictionary<ActorIdentifier, ActorState> _states = [];
@ -62,7 +62,7 @@ public sealed class StateManager(
/// <inheritdoc cref="GetOrCreate(ActorIdentifier, Actor, out ActorState?)"/>
public bool GetOrCreate(Actor actor, [NotNullWhen(true)] out ActorState? state)
=> GetOrCreate(actor.GetIdentifier(_actors), actor, out state);
=> GetOrCreate(actor.GetIdentifier(actors), actor, out state);
/// <summary> Try to obtain or create a new state for an existing actor. Returns false if no state could be created. </summary>
public unsafe bool GetOrCreate(ActorIdentifier identifier, Actor actor, [NotNullWhen(true)] out ActorState? state)
@ -82,7 +82,7 @@ public sealed class StateManager(
ModelData = FromActor(actor, true, false),
BaseData = FromActor(actor, false, false),
LastJob = (byte)(actor.IsCharacter ? actor.AsCharacter->CharacterData.ClassJob : 0),
LastTerritory = _clientState.TerritoryType,
LastTerritory = clientState.TerritoryType,
};
// state.Identifier is owned.
_states.Add(state.Identifier, state);
@ -115,7 +115,7 @@ public sealed class StateManager(
// Model ID is only unambiguously contained in the game object.
// The draw object only has the object type.
// TODO reverse search model data to get model id from model.
if (!_humans.IsHuman((uint)actor.AsCharacter->ModelContainer.ModelCharaId))
if (!humans.IsHuman((uint)actor.AsCharacter->ModelContainer.ModelCharaId))
{
ret.LoadNonHuman((uint)actor.AsCharacter->ModelContainer.ModelCharaId, *(CustomizeArray*)&actor.AsCharacter->DrawData.CustomizeData,
(nint)Unsafe.AsPointer(ref actor.AsCharacter->DrawData.EquipmentModelIds[0]));
@ -236,7 +236,7 @@ public sealed class StateManager(
public void TurnHuman(ActorState state, StateSource source, uint key = 0)
=> ChangeModelId(state, 0, CustomizeArray.Default, nint.Zero, source, key);
public void ResetState(ActorState state, StateSource source, uint key = 0, bool stateUpdate = false)
public void ResetState(ActorState state, StateSource source, uint key = 0, bool isFinal = false)
{
if (!state.Unlock(key))
return;
@ -278,8 +278,8 @@ public sealed class StateManager(
$"Reset entire state of {state.Identifier.Incognito(null)} to game base. [Affecting {actors.ToLazyString("nothing")}.]");
StateChanged.Invoke(StateChangeType.Reset, source, state, actors, null);
// only invoke if we define this reset call as the final call in our state update.
if(stateUpdate)
StateUpdated.Invoke(StateFinalizationType.Revert, actors);
if(isFinal)
StateFinalized.Invoke(StateFinalizationType.Revert, actors);
}
public void ResetAdvancedState(ActorState state, StateSource source, uint key = 0)
@ -306,7 +306,7 @@ public sealed class StateManager(
$"Reset advanced customization and dye state of {state.Identifier.Incognito(null)} to game base. [Affecting {actors.ToLazyString("nothing")}.]");
StateChanged.Invoke(StateChangeType.Reset, source, state, actors, null);
// Update that we have completed a full operation. (We can do this directly as nothing else is linked)
StateUpdated.Invoke(StateFinalizationType.RevertAdvanced, actors);
StateFinalized.Invoke(StateFinalizationType.RevertAdvanced, actors);
}
public void ResetCustomize(ActorState state, StateSource source, uint key = 0)
@ -325,7 +325,7 @@ public sealed class StateManager(
Glamourer.Log.Verbose(
$"Reset customization state of {state.Identifier.Incognito(null)} to game base. [Affecting {actors.ToLazyString("nothing")}.]");
// Update that we have completed a full operation. (We can do this directly as nothing else is linked)
StateUpdated.Invoke(StateFinalizationType.RevertCustomize, actors);
StateFinalized.Invoke(StateFinalizationType.RevertCustomize, actors);
}
public void ResetEquip(ActorState state, StateSource source, uint key = 0)
@ -376,7 +376,7 @@ public sealed class StateManager(
Glamourer.Log.Verbose(
$"Reset equipment state of {state.Identifier.Incognito(null)} to game base. [Affecting {actors.ToLazyString("nothing")}.]");
// Update that we have completed a full operation. (We can do this directly as nothing else is linked)
StateUpdated.Invoke(StateFinalizationType.RevertEquipment, actors);
StateFinalized.Invoke(StateFinalizationType.RevertEquipment, actors);
}
public void ResetStateFixed(ActorState state, bool respectManualPalettes, uint key = 0)
@ -453,23 +453,23 @@ public sealed class StateManager(
}
}
public void ReapplyState(Actor actor, bool forceRedraw, StateSource source, bool stateUpdate = false)
public void ReapplyState(Actor actor, bool forceRedraw, StateSource source, bool isFinal = false)
{
if (!GetOrCreate(actor, out var state))
return;
ReapplyState(actor, state, forceRedraw, source, stateUpdate);
ReapplyState(actor, state, forceRedraw, source, isFinal);
}
public void ReapplyState(Actor actor, ActorState state, bool forceRedraw, StateSource source, bool stateUpdate)
public void ReapplyState(Actor actor, ActorState state, bool forceRedraw, StateSource source, bool isFinal)
{
var data = Applier.ApplyAll(state,
forceRedraw
|| !actor.Model.IsHuman
|| CustomizeArray.Compare(actor.Model.GetCustomize(), state.ModelData.Customize).RequiresRedraw(), false);
StateChanged.Invoke(StateChangeType.Reapply, source, state, data, null);
if(stateUpdate)
StateUpdated.Invoke(StateFinalizationType.Reapply, data);
if(isFinal)
StateFinalized.Invoke(StateFinalizationType.Reapply, data);
}
/// <summary> Automation variant for reapply, to fire the correct StateUpdateType once reapplied. </summary>
@ -490,7 +490,7 @@ public sealed class StateManager(
|| CustomizeArray.Compare(actor.Model.GetCustomize(), state.ModelData.Customize).RequiresRedraw(), false);
StateChanged.Invoke(StateChangeType.Reapply, source, state, data, null);
// invoke the automation update based on what reset is.
StateUpdated.Invoke(wasReset ? StateFinalizationType.RevertAutomation : StateFinalizationType.ReapplyAutomation, data);
StateFinalized.Invoke(wasReset ? StateFinalizationType.RevertAutomation : StateFinalizationType.ReapplyAutomation, data);
}
public void DeleteState(ActorIdentifier identifier)