mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2026-02-22 07:27:44 +01:00
Add Revert-Design for automated designs.
This commit is contained in:
parent
c909510edc
commit
d70d6ff1b3
6 changed files with 98 additions and 66 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using Glamourer.Customization;
|
||||
using Glamourer.Designs;
|
||||
using Glamourer.Interop.Structs;
|
||||
using Glamourer.State;
|
||||
using Glamourer.Structs;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
|
|
@ -9,6 +10,8 @@ namespace Glamourer.Automation;
|
|||
|
||||
public class AutoDesign
|
||||
{
|
||||
public const string RevertName = "Revert";
|
||||
|
||||
[Flags]
|
||||
public enum Type : byte
|
||||
{
|
||||
|
|
@ -21,10 +24,19 @@ public class AutoDesign
|
|||
All = Armor | Accessories | Customizations | Weapons | Stains,
|
||||
}
|
||||
|
||||
public Design Design = null!;
|
||||
public Design? Design;
|
||||
public JobGroup Jobs;
|
||||
public Type ApplicationType;
|
||||
|
||||
public string Name(bool incognito)
|
||||
=> Revert ? RevertName : incognito ? Design!.Incognito : Design!.Name.Text;
|
||||
|
||||
public ref DesignData GetDesignData(ActorState state)
|
||||
=> ref Design == null ? ref state.BaseData : ref Design.DesignData;
|
||||
|
||||
public bool Revert
|
||||
=> Design == null;
|
||||
|
||||
public AutoDesign Clone()
|
||||
=> new()
|
||||
{
|
||||
|
|
@ -39,7 +51,7 @@ public class AutoDesign
|
|||
public JObject Serialize()
|
||||
=> new()
|
||||
{
|
||||
["Design"] = Design.Identifier.ToString(),
|
||||
["Design"] = Design?.Identifier.ToString(),
|
||||
["ApplicationType"] = (uint)ApplicationType,
|
||||
["Conditions"] = CreateConditionObject(),
|
||||
};
|
||||
|
|
@ -59,7 +71,12 @@ public class AutoDesign
|
|||
| (ApplicationType.HasFlag(Type.Accessories) ? AccessoryFlags : 0)
|
||||
| (ApplicationType.HasFlag(Type.Stains) ? StainFlags : 0);
|
||||
var customizeFlags = ApplicationType.HasFlag(Type.Customizations) ? CustomizeFlagExtensions.All : 0;
|
||||
return (equipFlags & Design.ApplyEquip, customizeFlags & Design.ApplyCustomize,
|
||||
|
||||
if (Revert)
|
||||
return (equipFlags, customizeFlags, ApplicationType.HasFlag(Type.Armor), ApplicationType.HasFlag(Type.Armor),
|
||||
ApplicationType.HasFlag(Type.Weapons), ApplicationType.HasFlag(Type.Customizations));
|
||||
|
||||
return (equipFlags & Design!.ApplyEquip, customizeFlags & Design.ApplyCustomize,
|
||||
ApplicationType.HasFlag(Type.Armor) && Design.DoApplyHatVisible(),
|
||||
ApplicationType.HasFlag(Type.Armor) && Design.DoApplyVisorToggle(),
|
||||
ApplicationType.HasFlag(Type.Weapons) && Design.DoApplyWeaponVisible(),
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ using Glamourer.Structs;
|
|||
using Glamourer.Unlocks;
|
||||
using Penumbra.GameData.Actors;
|
||||
using Penumbra.GameData.Enums;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace Glamourer.Automation;
|
||||
|
||||
|
|
@ -206,13 +205,16 @@ public class AutoDesignApplier : IDisposable
|
|||
if (design.ApplicationType is 0)
|
||||
continue;
|
||||
|
||||
if (actor.AsCharacter->CharacterData.ModelCharaId != design.Design.DesignData.ModelId)
|
||||
ref var data = ref design.GetDesignData(state);
|
||||
var source = design.Revert ? StateChanged.Source.Game : StateChanged.Source.Fixed;
|
||||
|
||||
if (actor.AsCharacter->CharacterData.ModelCharaId != data.ModelId)
|
||||
continue;
|
||||
|
||||
var (equipFlags, customizeFlags, applyHat, applyVisor, applyWeapon, applyWet) = design.ApplyWhat();
|
||||
Reduce(state, in design.Design.DesignData, applyHat, applyVisor, applyWeapon, applyWet, ref totalMetaFlags, respectManual);
|
||||
Reduce(state, in design.Design.DesignData, customizeFlags, ref totalCustomizeFlags, respectManual);
|
||||
Reduce(state, in design.Design.DesignData, equipFlags, ref totalEquipFlags, respectManual);
|
||||
Reduce(state, data, applyHat, applyVisor, applyWeapon, applyWet, ref totalMetaFlags, respectManual, source);
|
||||
Reduce(state, data, customizeFlags, ref totalCustomizeFlags, respectManual, source);
|
||||
Reduce(state, data, equipFlags, ref totalEquipFlags, respectManual, source);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -229,7 +231,7 @@ public class AutoDesignApplier : IDisposable
|
|||
return _manager.EnabledSets.TryGetValue(identifier, out set);
|
||||
}
|
||||
|
||||
private void Reduce(ActorState state, in DesignData design, EquipFlag equipFlags, ref EquipFlag totalEquipFlags, bool respectManual)
|
||||
private void Reduce(ActorState state, in DesignData design, EquipFlag equipFlags, ref EquipFlag totalEquipFlags, bool respectManual, StateChanged.Source source)
|
||||
{
|
||||
equipFlags &= ~totalEquipFlags;
|
||||
if (equipFlags == 0)
|
||||
|
|
@ -244,7 +246,7 @@ public class AutoDesignApplier : IDisposable
|
|||
if (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.ItemId, out _))
|
||||
{
|
||||
if (!respectManual || state[slot, false] is not StateChanged.Source.Manual)
|
||||
_state.ChangeItem(state, slot, item, StateChanged.Source.Fixed);
|
||||
_state.ChangeItem(state, slot, item, source);
|
||||
totalEquipFlags |= flag;
|
||||
}
|
||||
}
|
||||
|
|
@ -253,7 +255,7 @@ public class AutoDesignApplier : IDisposable
|
|||
if (equipFlags.HasFlag(stainFlag))
|
||||
{
|
||||
if (!respectManual || state[slot, true] is not StateChanged.Source.Manual)
|
||||
_state.ChangeStain(state, slot, design.Stain(slot), StateChanged.Source.Fixed);
|
||||
_state.ChangeStain(state, slot, design.Stain(slot), source);
|
||||
totalEquipFlags |= stainFlag;
|
||||
}
|
||||
}
|
||||
|
|
@ -265,7 +267,7 @@ public class AutoDesignApplier : IDisposable
|
|||
&& (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.ItemId, out _)))
|
||||
{
|
||||
if (!respectManual || state[EquipSlot.MainHand, false] is not StateChanged.Source.Manual)
|
||||
_state.ChangeItem(state, EquipSlot.MainHand, item, StateChanged.Source.Fixed);
|
||||
_state.ChangeItem(state, EquipSlot.MainHand, item, source);
|
||||
totalEquipFlags |= EquipFlag.Mainhand;
|
||||
}
|
||||
}
|
||||
|
|
@ -277,7 +279,7 @@ public class AutoDesignApplier : IDisposable
|
|||
&& (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.ItemId, out _)))
|
||||
{
|
||||
if (!respectManual || state[EquipSlot.OffHand, false] is not StateChanged.Source.Manual)
|
||||
_state.ChangeItem(state, EquipSlot.OffHand, item, StateChanged.Source.Fixed);
|
||||
_state.ChangeItem(state, EquipSlot.OffHand, item, source);
|
||||
totalEquipFlags |= EquipFlag.Offhand;
|
||||
}
|
||||
}
|
||||
|
|
@ -285,20 +287,20 @@ public class AutoDesignApplier : IDisposable
|
|||
if (equipFlags.HasFlag(EquipFlag.MainhandStain))
|
||||
{
|
||||
if (!respectManual || state[EquipSlot.MainHand, true] is not StateChanged.Source.Manual)
|
||||
_state.ChangeStain(state, EquipSlot.MainHand, design.Stain(EquipSlot.MainHand), StateChanged.Source.Fixed);
|
||||
_state.ChangeStain(state, EquipSlot.MainHand, design.Stain(EquipSlot.MainHand), source);
|
||||
totalEquipFlags |= EquipFlag.MainhandStain;
|
||||
}
|
||||
|
||||
if (equipFlags.HasFlag(EquipFlag.OffhandStain))
|
||||
{
|
||||
if (!respectManual || state[EquipSlot.OffHand, true] is not StateChanged.Source.Manual)
|
||||
_state.ChangeStain(state, EquipSlot.OffHand, design.Stain(EquipSlot.OffHand), StateChanged.Source.Fixed);
|
||||
_state.ChangeStain(state, EquipSlot.OffHand, design.Stain(EquipSlot.OffHand), source);
|
||||
totalEquipFlags |= EquipFlag.OffhandStain;
|
||||
}
|
||||
}
|
||||
|
||||
private void Reduce(ActorState state, in DesignData design, CustomizeFlag customizeFlags, ref CustomizeFlag totalCustomizeFlags,
|
||||
bool respectManual)
|
||||
bool respectManual, StateChanged.Source source)
|
||||
{
|
||||
customizeFlags &= ~totalCustomizeFlags;
|
||||
if (customizeFlags == 0)
|
||||
|
|
@ -328,12 +330,12 @@ public class AutoDesignApplier : IDisposable
|
|||
}
|
||||
|
||||
if (fixFlags != 0)
|
||||
_state.ChangeCustomize(state, customize, fixFlags, StateChanged.Source.Fixed);
|
||||
_state.ChangeCustomize(state, customize, fixFlags, source);
|
||||
|
||||
if (customizeFlags.HasFlag(CustomizeFlag.Face))
|
||||
{
|
||||
if (!respectManual || state[CustomizeIndex.Face] is not StateChanged.Source.Manual)
|
||||
_state.ChangeCustomize(state, CustomizeIndex.Face, design.Customize.Face, StateChanged.Source.Fixed);
|
||||
_state.ChangeCustomize(state, CustomizeIndex.Face, design.Customize.Face, source);
|
||||
customizeFlags &= ~CustomizeFlag.Face;
|
||||
totalCustomizeFlags |= CustomizeFlag.Face;
|
||||
}
|
||||
|
|
@ -351,40 +353,40 @@ public class AutoDesignApplier : IDisposable
|
|||
&& (!_config.UnlockedItemMode || _customizeUnlocks.IsUnlocked(data.Value, out _)))
|
||||
{
|
||||
if (!respectManual || state[index] is not StateChanged.Source.Manual)
|
||||
_state.ChangeCustomize(state, index, value, StateChanged.Source.Fixed);
|
||||
_state.ChangeCustomize(state, index, value, source);
|
||||
totalCustomizeFlags |= flag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Reduce(ActorState state, in DesignData design, bool applyHat, bool applyVisor, bool applyWeapon, bool applyWet,
|
||||
ref byte totalMetaFlags, bool respectManual)
|
||||
ref byte totalMetaFlags, bool respectManual, StateChanged.Source source)
|
||||
{
|
||||
if (applyHat && (totalMetaFlags & 0x01) == 0)
|
||||
{
|
||||
if (!respectManual || state[ActorState.MetaIndex.HatState] is not StateChanged.Source.Manual)
|
||||
_state.ChangeHatState(state, design.IsHatVisible(), StateChanged.Source.Fixed);
|
||||
_state.ChangeHatState(state, design.IsHatVisible(), source);
|
||||
totalMetaFlags |= 0x01;
|
||||
}
|
||||
|
||||
if (applyVisor && (totalMetaFlags & 0x02) == 0)
|
||||
{
|
||||
if (!respectManual || state[ActorState.MetaIndex.VisorState] is not StateChanged.Source.Manual)
|
||||
_state.ChangeVisorState(state, design.IsVisorToggled(), StateChanged.Source.Fixed);
|
||||
_state.ChangeVisorState(state, design.IsVisorToggled(), source);
|
||||
totalMetaFlags |= 0x02;
|
||||
}
|
||||
|
||||
if (applyWeapon && (totalMetaFlags & 0x04) == 0)
|
||||
{
|
||||
if (!respectManual || state[ActorState.MetaIndex.WeaponState] is not StateChanged.Source.Manual)
|
||||
_state.ChangeWeaponState(state, design.IsWeaponVisible(), StateChanged.Source.Fixed);
|
||||
_state.ChangeWeaponState(state, design.IsWeaponVisible(), source);
|
||||
totalMetaFlags |= 0x04;
|
||||
}
|
||||
|
||||
if (applyWet && (totalMetaFlags & 0x08) == 0)
|
||||
{
|
||||
if (!respectManual || state[ActorState.MetaIndex.Wetness] is not StateChanged.Source.Manual)
|
||||
_state.ChangeWetness(state, design.IsWet(), StateChanged.Source.Fixed);
|
||||
_state.ChangeWetness(state, design.IsWet(), source);
|
||||
totalMetaFlags |= 0x08;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using System.Linq;
|
|||
using System.Text.RegularExpressions;
|
||||
using Dalamud.Game.ClientState.Objects.Enums;
|
||||
using Dalamud.Interface.Internal.Notifications;
|
||||
using Dalamud.Utility;
|
||||
using Glamourer.Designs;
|
||||
using Glamourer.Events;
|
||||
using Glamourer.Interop;
|
||||
|
|
@ -185,7 +184,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
|||
return;
|
||||
|
||||
set.Enabled = value;
|
||||
AutoDesignSet? oldEnabled = null;
|
||||
AutoDesignSet? oldEnabled;
|
||||
if (value)
|
||||
{
|
||||
if (_enabled.Remove(set.Identifiers[0], out oldEnabled))
|
||||
|
|
@ -225,7 +224,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
|||
_event.Invoke(AutomationChanged.Type.ChangedBase, set, (old, newBase));
|
||||
}
|
||||
|
||||
public void AddDesign(AutoDesignSet set, Design design)
|
||||
public void AddDesign(AutoDesignSet set, Design? design)
|
||||
{
|
||||
var newDesign = new AutoDesign()
|
||||
{
|
||||
|
|
@ -235,7 +234,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
|||
};
|
||||
set.Designs.Add(newDesign);
|
||||
Save();
|
||||
Glamourer.Log.Debug($"Added new associated design {design.Identifier} as design {set.Designs.Count} to design set.");
|
||||
Glamourer.Log.Debug($"Added new associated design {design?.Identifier.ToString() ?? "Reverter"} as design {set.Designs.Count} to design set.");
|
||||
_event.Invoke(AutomationChanged.Type.AddedDesign, set, set.Designs.Count - 1);
|
||||
}
|
||||
|
||||
|
|
@ -260,20 +259,20 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
|||
_event.Invoke(AutomationChanged.Type.MovedDesign, set, (from, to));
|
||||
}
|
||||
|
||||
public void ChangeDesign(AutoDesignSet set, int which, Design newDesign)
|
||||
public void ChangeDesign(AutoDesignSet set, int which, Design? newDesign)
|
||||
{
|
||||
if (which >= set.Designs.Count || which < 0)
|
||||
return;
|
||||
|
||||
var design = set.Designs[which];
|
||||
if (design.Design.Identifier == newDesign.Identifier)
|
||||
if (design.Design?.Identifier == newDesign?.Identifier)
|
||||
return;
|
||||
|
||||
var old = design.Design;
|
||||
design.Design = newDesign;
|
||||
Save();
|
||||
Glamourer.Log.Debug(
|
||||
$"Changed linked design from {old.Identifier} to {newDesign.Identifier} for associated design {which + 1} in design set.");
|
||||
$"Changed linked design from {old?.Identifier.ToString() ?? "Reverter"} to {newDesign?.Identifier.ToString() ?? "Reverter"} for associated design {which + 1} in design set.");
|
||||
_event.Invoke(AutomationChanged.Type.ChangedDesign, set, (which, old, newDesign));
|
||||
}
|
||||
|
||||
|
|
@ -390,7 +389,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
|||
|
||||
var set = new AutoDesignSet(name, id)
|
||||
{
|
||||
Enabled = obj["Enabled"]?.ToObject<bool>() ?? false,
|
||||
Enabled = obj["Enabled"]?.ToObject<bool>() ?? false,
|
||||
BaseState = obj["BaseState"]?.ToObject<AutoDesignSet.Base>() ?? AutoDesignSet.Base.Current,
|
||||
};
|
||||
|
||||
|
|
@ -425,30 +424,33 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
|||
|
||||
private AutoDesign? ToDesignObject(JObject jObj)
|
||||
{
|
||||
var designIdentifier = jObj["Design"]?.ToObject<string>();
|
||||
if (designIdentifier.IsNullOrEmpty())
|
||||
var designIdentifier = jObj["Design"]?.ToObject<string?>();
|
||||
Design? design = null;
|
||||
// designIdentifier == null means Revert-Design.
|
||||
if (designIdentifier != null)
|
||||
{
|
||||
Glamourer.Chat.NotificationMessage("Error parsing automatically applied design: No design specified.");
|
||||
return null;
|
||||
if (designIdentifier.Length == 0)
|
||||
{
|
||||
Glamourer.Chat.NotificationMessage("Error parsing automatically applied design: No design specified.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(designIdentifier, out var guid))
|
||||
{
|
||||
Glamourer.Chat.NotificationMessage($"Error parsing automatically applied design: {designIdentifier} is not a valid GUID.");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
design = _designs.Designs.FirstOrDefault(d => d.Identifier == guid);
|
||||
if (design == null)
|
||||
{
|
||||
Glamourer.Chat.NotificationMessage($"Error parsing automatically applied design: The specified design {guid} does not exist.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(designIdentifier, out var guid))
|
||||
{
|
||||
Glamourer.Chat.NotificationMessage($"Error parsing automatically applied design: {designIdentifier} is not a valid GUID.");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
var design = _designs.Designs.FirstOrDefault(d => d.Identifier == guid);
|
||||
if (design == null)
|
||||
{
|
||||
Glamourer.Chat.NotificationMessage($"Error parsing automatically applied design: The specified design {guid} does not exist.");
|
||||
return null;
|
||||
}
|
||||
|
||||
var applicationType = (AutoDesign.Type)(jObj["ApplicationType"]?.ToObject<uint>() ?? 0);
|
||||
|
||||
|
||||
var ret = new AutoDesign()
|
||||
{
|
||||
Design = design,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue