Skip to content

Commit

Permalink
Change fixed state handling for advanced dyes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Mar 2, 2024
1 parent bade38f commit 93ba44d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
10 changes: 9 additions & 1 deletion Glamourer/Automation/AutoDesignApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Glamourer.Designs.Links;
using Glamourer.Events;
using Glamourer.Interop;
using Glamourer.Interop.Material;
using Glamourer.Interop.Structs;
using Glamourer.State;
using Penumbra.GameData.Actors;
Expand Down Expand Up @@ -256,17 +257,24 @@ public bool Reduce(Actor actor, ActorIdentifier identifier, [NotNullWhen(true)]
private unsafe void Reduce(Actor actor, ActorState state, AutoDesignSet set, bool respectManual, bool fromJobChange)
{
if (set.BaseState is AutoDesignSet.Base.Game)
{
_state.ResetStateFixed(state, respectManual);
}
else if (!respectManual)
{
state.Sources.RemoveFixedDesignSources();
foreach(var (key, value) in state.Materials.Values)
if (value.Source is StateSource.Fixed)
state.Materials.UpdateValue(key, new MaterialValueState(value.Game, value.Model, value.DrawData, StateSource.Manual), out _);
}

if (!_humans.IsHuman((uint)actor.AsCharacter->CharacterData.ModelCharaId))
return;

var mergedDesign = _designMerger.Merge(
set.Designs.Where(d => d.IsActive(actor)).SelectMany(d => d.Design.AllLinks.Select(l => (l.Design, l.Flags & d.Type))),
state.ModelData.Customize, state.BaseData, true, _config.AlwaysApplyAssociatedMods);
_state.ApplyDesign(state, mergedDesign, new ApplySettings(0, StateSource.Fixed, respectManual, fromJobChange, false, false, set.BaseState is AutoDesignSet.Base.Game));
_state.ApplyDesign(state, mergedDesign, new ApplySettings(0, StateSource.Fixed, respectManual, fromJobChange, false, false, false));
}

/// <summary> Get world-specific first and all-world afterward. </summary>
Expand Down
22 changes: 17 additions & 5 deletions Glamourer/Interop/Material/MaterialValueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,17 @@ public MaterialValueManager<T> Clone()
}

public bool TryGetValue(MaterialValueIndex index, out T value)
=> TryGetValue(index.Key, out value);

public bool TryGetValue(uint key, out T value)
{
if (_values.Count == 0)
{
value = default!;
return false;
}

var idx = Search(index.Key);
var idx = Search(key);
if (idx >= 0)
{
value = _values[idx].Value;
Expand All @@ -247,8 +250,10 @@ public bool TryGetValue(MaterialValueIndex index, out T value)
}

public bool TryAddValue(MaterialValueIndex index, in T value)
=> TryAddValue(index.Key, value);

public bool TryAddValue(uint key, in T value)
{
var key = index.Key;
var idx = Search(key);
if (idx >= 0)
return false;
Expand All @@ -258,11 +263,14 @@ public bool TryAddValue(MaterialValueIndex index, in T value)
}

public bool RemoveValue(MaterialValueIndex index)
=> RemoveValue(index.Key);

public bool RemoveValue(uint key)
{
if (_values.Count == 0)
return false;

var idx = Search(index.Key);
var idx = Search(key);
if (idx < 0)
return false;

Expand All @@ -271,8 +279,10 @@ public bool RemoveValue(MaterialValueIndex index)
}

public void AddOrUpdateValue(MaterialValueIndex index, in T value)
=> AddOrUpdateValue(index.Key, value);

public void AddOrUpdateValue(uint key, in T value)
{
var key = index.Key;
var idx = Search(key);
if (idx < 0)
_values.Insert(~idx, (key, value));
Expand All @@ -281,14 +291,16 @@ public void AddOrUpdateValue(MaterialValueIndex index, in T value)
}

public bool UpdateValue(MaterialValueIndex index, in T value, out T oldValue)
=> UpdateValue(index.Key, value, out oldValue);

public bool UpdateValue(uint key, in T value, out T oldValue)
{
if (_values.Count == 0)
{
oldValue = default!;
return false;
}

var key = index.Key;
var idx = Search(key);
if (idx < 0)
{
Expand Down
16 changes: 15 additions & 1 deletion Glamourer/State/StateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,19 @@ public void ResetEquip(ActorState state, StateSource source, uint key = 0)
{
actors = Applier.ChangeArmor(state, EquipSlotExtensions.EqdpSlots[0], true);
foreach (var slot in EquipSlotExtensions.EqdpSlots.Skip(1))
{
Applier.ChangeArmor(actors, slot, state.ModelData.Armor(slot), !state.Sources[slot, false].IsIpc(),
state.ModelData.IsHatVisible());
}

var mainhandActors = state.ModelData.MainhandType != state.BaseData.MainhandType ? actors.OnlyGPose() : actors;
Applier.ChangeMainhand(mainhandActors, state.ModelData.Item(EquipSlot.MainHand), state.ModelData.Stain(EquipSlot.MainHand));
var offhandActors = state.ModelData.OffhandType != state.BaseData.OffhandType ? actors.OnlyGPose() : actors;
Applier.ChangeOffhand(offhandActors, state.ModelData.Item(EquipSlot.OffHand), state.ModelData.Stain(EquipSlot.OffHand));
}

Glamourer.Log.Verbose($"Reset equipment state of {state.Identifier.Incognito(null)} to game base. [Affecting {actors.ToLazyString("nothing")}.]");
Glamourer.Log.Verbose(
$"Reset equipment state of {state.Identifier.Incognito(null)} to game base. [Affecting {actors.ToLazyString("nothing")}.]");
}

public void ResetStateFixed(ActorState state, bool respectManualPalettes, uint key = 0)
Expand Down Expand Up @@ -386,6 +389,17 @@ public void ResetStateFixed(ActorState state, bool respectManualPalettes, uint k
state.Sources[meta] = StateSource.Game;
state.ModelData.SetMeta(meta, state.BaseData.GetMeta(meta));
}

foreach (var (index, value) in state.Materials.Values.ToList())
{
switch (value.Source)
{
case StateSource.Fixed:
case StateSource.Manual when !respectManualPalettes:
state.Materials.RemoveValue(index);
break;
}
}
}

public void ReapplyState(Actor actor, StateSource source)
Expand Down

0 comments on commit 93ba44d

Please sign in to comment.