This commit is contained in:
Soreepeong 2023-12-01 20:55:46 +09:00
parent 34e3adb3f2
commit 35f4ff5c94
9 changed files with 226 additions and 217 deletions

View file

@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Dalamud.Configuration.Internal;
using Dalamud.Game.Inventory.InventoryChangeArgsTypes;
@ -22,21 +24,20 @@ internal class GameInventory : IDisposable, IServiceType, IGameInventory
{
private static readonly ModuleLog Log = new("GameInventory");
private readonly List<InventoryEventArgs> allEvents = new();
private readonly List<InventoryItemAddedArgs> addedEvents = new();
private readonly List<InventoryItemRemovedArgs> removedEvents = new();
private readonly List<InventoryItemChangedArgs> changedEvents = new();
private readonly List<InventoryItemMovedArgs> movedEvents = new();
[ServiceManager.ServiceDependency]
private readonly Framework framework = Service<Framework>.Get();
[ServiceManager.ServiceDependency]
private readonly DalamudConfiguration dalamudConfiguration = Service<DalamudConfiguration>.Get();
private readonly GameInventoryType[] inventoryTypes;
private readonly GameInventoryItem[]?[] inventoryItems;
[ServiceManager.ServiceConstructor]
private GameInventory()
{
@ -59,10 +60,10 @@ internal class GameInventory : IDisposable, IServiceType, IGameInventory
public event IGameInventory.InventoryChangedDelegate? ItemRemoved;
/// <inheritdoc/>
public event IGameInventory.InventoryChangedDelegate? ItemMoved;
public event IGameInventory.InventoryChangedDelegate? ItemChanged;
/// <inheritdoc/>
public event IGameInventory.InventoryChangedDelegate? ItemChanged;
public event IGameInventory.InventoryChangedDelegate? ItemMoved;
/// <inheritdoc/>
public void Dispose()
@ -111,7 +112,7 @@ internal class GameInventory : IDisposable, IServiceType, IGameInventory
Log.Error(e, "Exception during {argType} callback", arg.Type);
}
}
private void OnFrameworkUpdate(IFramework framework1)
{
for (var i = 0; i < this.inventoryTypes.Length; i++)
@ -152,124 +153,135 @@ internal class GameInventory : IDisposable, IServiceType, IGameInventory
}
// Was there any change? If not, stop further processing.
// Note that...
// * this.movedEvents is not checked; it will be populated after this check.
// * this.allEvents is not checked; it is a temporary list to be used after this check.
// Note that this.movedEvents is not checked; it will be populated after this check.
if (this.addedEvents.Count == 0 && this.removedEvents.Count == 0 && this.changedEvents.Count == 0)
return;
try
// Broadcast InventoryChangedRaw.
InvokeSafely(
this.InventoryChangedRaw,
new DeferredReadOnlyCollection<InventoryEventArgs>(
this.addedEvents.Count +
this.removedEvents.Count +
this.changedEvents.Count,
() => Array.Empty<InventoryEventArgs>()
.Concat(this.addedEvents)
.Concat(this.removedEvents)
.Concat(this.changedEvents)));
// Resolve changelog for item moved, from 1 added + 1 removed event.
for (var iAdded = this.addedEvents.Count - 1; iAdded >= 0; --iAdded)
{
// Broadcast InventoryChangedRaw, if necessary.
if (this.InventoryChangedRaw is not null)
var added = this.addedEvents[iAdded];
for (var iRemoved = this.removedEvents.Count - 1; iRemoved >= 0; --iRemoved)
{
this.allEvents.Clear();
this.allEvents.EnsureCapacity(
this.addedEvents.Count
+ this.removedEvents.Count
+ this.changedEvents.Count);
this.allEvents.AddRange(this.addedEvents);
this.allEvents.AddRange(this.removedEvents);
this.allEvents.AddRange(this.changedEvents);
InvokeSafely(this.InventoryChangedRaw, this.allEvents);
}
var removed = this.removedEvents[iRemoved];
if (added.Item.ItemId != removed.Item.ItemId)
continue;
// Resolve changelog for item moved, from 1 added + 1 removed event.
for (var iAdded = this.addedEvents.Count - 1; iAdded >= 0; --iAdded)
this.movedEvents.Add(new(removed, added));
// Remove the reinterpreted entries.
this.addedEvents.RemoveAt(iAdded);
this.removedEvents.RemoveAt(iRemoved);
break;
}
}
// Resolve changelog for item moved, from 2 changed events.
for (var i = this.changedEvents.Count - 1; i >= 0; --i)
{
var e1 = this.changedEvents[i];
for (var j = i - 1; j >= 0; --j)
{
var added = this.addedEvents[iAdded];
for (var iRemoved = this.removedEvents.Count - 1; iRemoved >= 0; --iRemoved)
{
var removed = this.removedEvents[iRemoved];
if (added.Item.ItemId != removed.Item.ItemId)
continue;
var e2 = this.changedEvents[j];
if (e1.Item.ItemId != e2.Item.ItemId || e1.Item.ItemId != e2.Item.ItemId)
continue;
this.movedEvents.Add(new(removed, added));
// Remove the reinterpreted entries.
this.addedEvents.RemoveAt(iAdded);
this.removedEvents.RemoveAt(iRemoved);
break;
}
// move happened, and e2 has an item
if (!e2.Item.IsEmpty)
this.movedEvents.Add(new(e1, e2));
// move happened, and e1 has an item
if (!e1.Item.IsEmpty)
this.movedEvents.Add(new(e2, e1));
// Remove the reinterpreted entries. Note that i > j.
this.changedEvents.RemoveAt(i);
this.changedEvents.RemoveAt(j);
break;
}
}
// Resolve changelog for item moved, from 2 changed events.
for (var i = this.changedEvents.Count - 1; i >= 0; --i)
{
var e1 = this.changedEvents[i];
for (var j = i - 1; j >= 0; --j)
{
var e2 = this.changedEvents[j];
if (e1.Item.ItemId != e2.Item.ItemId || e1.Item.ItemId != e2.Item.ItemId)
continue;
// move happened, and e2 has an item
if (!e2.Item.IsEmpty)
this.movedEvents.Add(new(e1, e2));
// move happened, and e1 has an item
if (!e1.Item.IsEmpty)
this.movedEvents.Add(new(e2, e1));
// Remove the reinterpreted entries. Note that i > j.
this.changedEvents.RemoveAt(i);
this.changedEvents.RemoveAt(j);
break;
}
}
// Log only if it matters.
if (this.dalamudConfiguration.LogLevel >= LogEventLevel.Verbose)
{
foreach (var x in this.addedEvents)
Log.Verbose($"{x}");
foreach (var x in this.removedEvents)
Log.Verbose($"{x}");
foreach (var x in this.changedEvents)
Log.Verbose($"{x}");
foreach (var x in this.movedEvents)
Log.Verbose($"{x} (({x.SourceEvent}) + ({x.TargetEvent}))");
}
// Broadcast InventoryChanged, if necessary.
if (this.InventoryChanged is not null)
{
this.allEvents.Clear();
this.allEvents.EnsureCapacity(
this.addedEvents.Count
+ this.removedEvents.Count
+ this.changedEvents.Count
+ this.movedEvents.Count);
this.allEvents.AddRange(this.addedEvents);
this.allEvents.AddRange(this.removedEvents);
this.allEvents.AddRange(this.changedEvents);
this.allEvents.AddRange(this.movedEvents);
InvokeSafely(this.InventoryChanged, this.allEvents);
}
// Broadcast the rest.
// Log only if it matters.
if (this.dalamudConfiguration.LogLevel <= LogEventLevel.Verbose)
{
foreach (var x in this.addedEvents)
InvokeSafely(this.ItemAdded, x);
Log.Verbose($"{x}");
foreach (var x in this.removedEvents)
InvokeSafely(this.ItemRemoved, x);
Log.Verbose($"{x}");
foreach (var x in this.changedEvents)
InvokeSafely(this.ItemChanged, x);
Log.Verbose($"{x}");
foreach (var x in this.movedEvents)
InvokeSafely(this.ItemMoved, x);
Log.Verbose($"{x} (({x.SourceEvent}) + ({x.TargetEvent}))");
}
finally
// Broadcast the rest.
InvokeSafely(
this.InventoryChanged,
new DeferredReadOnlyCollection<InventoryEventArgs>(
this.addedEvents.Count +
this.removedEvents.Count +
this.changedEvents.Count +
this.movedEvents.Count,
() => Array.Empty<InventoryEventArgs>()
.Concat(this.addedEvents)
.Concat(this.removedEvents)
.Concat(this.changedEvents)
.Concat(this.movedEvents)));
foreach (var x in this.addedEvents)
InvokeSafely(this.ItemAdded, x);
foreach (var x in this.removedEvents)
InvokeSafely(this.ItemRemoved, x);
foreach (var x in this.changedEvents)
InvokeSafely(this.ItemChanged, x);
foreach (var x in this.movedEvents)
InvokeSafely(this.ItemMoved, x);
// We're done using the lists. Clean them up.
this.addedEvents.Clear();
this.removedEvents.Clear();
this.changedEvents.Clear();
this.movedEvents.Clear();
}
/// <summary>
/// A <see cref="IReadOnlyCollection{T}"/> view of <see cref="IEnumerable{T}"/>, so that the number of items
/// contained within can be known in advance, and it can be enumerated multiple times.
/// </summary>
/// <typeparam name="T">The type of elements being enumerated.</typeparam>
private class DeferredReadOnlyCollection<T> : IReadOnlyCollection<T>
{
private readonly Func<IEnumerable<T>> enumerableGenerator;
public DeferredReadOnlyCollection(int count, Func<IEnumerable<T>> enumerableGenerator)
{
this.addedEvents.Clear();
this.removedEvents.Clear();
this.changedEvents.Clear();
this.movedEvents.Clear();
this.enumerableGenerator = enumerableGenerator;
this.Count = count;
}
public int Count { get; }
public IEnumerator<T> GetEnumerator() => this.enumerableGenerator().GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => this.enumerableGenerator().GetEnumerator();
}
}
@ -313,10 +325,10 @@ internal class GameInventoryPluginScoped : IDisposable, IServiceType, IGameInven
public event IGameInventory.InventoryChangedDelegate? ItemRemoved;
/// <inheritdoc/>
public event IGameInventory.InventoryChangedDelegate? ItemMoved;
public event IGameInventory.InventoryChangedDelegate? ItemChanged;
/// <inheritdoc/>
public event IGameInventory.InventoryChangedDelegate? ItemChanged;
public event IGameInventory.InventoryChangedDelegate? ItemMoved;
/// <inheritdoc/>
public void Dispose()
@ -325,15 +337,15 @@ internal class GameInventoryPluginScoped : IDisposable, IServiceType, IGameInven
this.gameInventoryService.InventoryChangedRaw -= this.OnInventoryChangedRawForward;
this.gameInventoryService.ItemAdded -= this.OnInventoryItemAddedForward;
this.gameInventoryService.ItemRemoved -= this.OnInventoryItemRemovedForward;
this.gameInventoryService.ItemMoved -= this.OnInventoryItemMovedForward;
this.gameInventoryService.ItemChanged -= this.OnInventoryItemChangedForward;
this.gameInventoryService.ItemMoved -= this.OnInventoryItemMovedForward;
this.InventoryChanged = null;
this.InventoryChangedRaw = null;
this.ItemAdded = null;
this.ItemRemoved = null;
this.ItemMoved = null;
this.ItemChanged = null;
this.ItemMoved = null;
}
private void OnInventoryChangedForward(IReadOnlyCollection<InventoryEventArgs> events)
@ -341,16 +353,16 @@ internal class GameInventoryPluginScoped : IDisposable, IServiceType, IGameInven
private void OnInventoryChangedRawForward(IReadOnlyCollection<InventoryEventArgs> events)
=> this.InventoryChangedRaw?.Invoke(events);
private void OnInventoryItemAddedForward(GameInventoryEvent type, InventoryEventArgs data)
=> this.ItemAdded?.Invoke(type, data);
private void OnInventoryItemRemovedForward(GameInventoryEvent type, InventoryEventArgs data)
=> this.ItemRemoved?.Invoke(type, data);
private void OnInventoryItemMovedForward(GameInventoryEvent type, InventoryEventArgs data)
=> this.ItemMoved?.Invoke(type, data);
private void OnInventoryItemChangedForward(GameInventoryEvent type, InventoryEventArgs data)
=> this.ItemChanged?.Invoke(type, data);
private void OnInventoryItemMovedForward(GameInventoryEvent type, InventoryEventArgs data)
=> this.ItemMoved?.Invoke(type, data);
}

View file

@ -3,7 +3,6 @@
/// <summary>
/// Class representing a item's changelog state.
/// </summary>
[Flags]
public enum GameInventoryEvent
{
/// <summary>
@ -11,24 +10,24 @@ public enum GameInventoryEvent
/// You should not see this value, unless you explicitly used it yourself, or APIs using this enum say otherwise.
/// </summary>
Empty = 0,
/// <summary>
/// Item was added to an inventory.
/// </summary>
Added = 1 << 0,
Added = 1,
/// <summary>
/// Item was removed from an inventory.
/// </summary>
Removed = 1 << 1,
Removed = 2,
/// <summary>
/// Properties are changed for an item in an inventory.
/// </summary>
Changed = 1 << 2,
Changed = 3,
/// <summary>
/// Item has been moved, possibly across different inventories.
/// </summary>
Moved = 1 << 3,
Moved = 4,
}

View file

@ -12,11 +12,6 @@ namespace Dalamud.Game.Inventory;
[StructLayout(LayoutKind.Explicit, Size = StructSizeInBytes)]
public unsafe struct GameInventoryItem : IEquatable<GameInventoryItem>
{
/// <summary>
/// An empty instance of <see cref="GameInventoryItem"/>.
/// </summary>
internal static readonly GameInventoryItem Empty = default;
/// <summary>
/// The actual data.
/// </summary>
@ -104,7 +99,7 @@ public unsafe struct GameInventoryItem : IEquatable<GameInventoryItem>
/// Gets the array of materia types.
/// </summary>
public ReadOnlySpan<ushort> Materia => new(Unsafe.AsPointer(ref Unsafe.AsRef(in this.InternalItem.Materia[0])), 5);
/// <summary>
/// Gets the array of materia grades.
/// </summary>
@ -119,8 +114,8 @@ public unsafe struct GameInventoryItem : IEquatable<GameInventoryItem>
/// <summary>
/// Gets the glamour id for this item.
/// </summary>
public uint GlmaourId => this.InternalItem.GlamourID;
public uint GlamourId => this.InternalItem.GlamourID;
/// <summary>
/// Gets the items crafter's content id.
/// NOTE: I'm not sure if this is a good idea to include or not in the dalamud api. Marked internal for now.
@ -163,6 +158,6 @@ public unsafe struct GameInventoryItem : IEquatable<GameInventoryItem>
/// <inheritdoc cref="object.ToString"/>
public override string ToString() =>
this.IsEmpty
? "<Empty>"
: $"Item #{this.ItemId} at slot {this.InventorySlot} in {this.ContainerType}";
? "no item"
: $"item #{this.ItemId} at slot {this.InventorySlot} in {this.ContainerType}";
}

View file

@ -9,17 +9,17 @@ public enum GameInventoryType : ushort
/// First panel of main player inventory.
/// </summary>
Inventory1 = 0,
/// <summary>
/// Second panel of main player inventory.
/// </summary>
Inventory2 = 1,
/// <summary>
/// Third panel of main player inventory.
/// </summary>
Inventory3 = 2,
/// <summary>
/// Fourth panel of main player inventory.
/// </summary>
@ -40,32 +40,32 @@ public enum GameInventoryType : ushort
/// Crystal container.
/// </summary>
Crystals = 2001,
/// <summary>
/// Mail container.
/// </summary>
Mail = 2003,
/// <summary>
/// Key item container.
/// </summary>
KeyItems = 2004,
/// <summary>
/// Quest item hand-in inventory.
/// </summary>
HandIn = 2005,
/// <summary>
/// DamagedGear container.
/// </summary>
DamagedGear = 2007,
/// <summary>
/// Examine window container.
/// </summary>
Examine = 2009,
/// <summary>
/// Doman Enclave Reconstruction Reclamation Box.
/// </summary>
@ -75,22 +75,22 @@ public enum GameInventoryType : ushort
/// Armory off-hand weapon container.
/// </summary>
ArmoryOffHand = 3200,
/// <summary>
/// Armory head container.
/// </summary>
ArmoryHead = 3201,
/// <summary>
/// Armory body container.
/// </summary>
ArmoryBody = 3202,
/// <summary>
/// Armory hand/gloves container.
/// </summary>
ArmoryHands = 3203,
/// <summary>
/// Armory waist container.
/// <remarks>
@ -98,42 +98,42 @@ public enum GameInventoryType : ushort
/// </remarks>
/// </summary>
ArmoryWaist = 3204,
/// <summary>
/// Armory legs/pants/skirt container.
/// </summary>
ArmoryLegs = 3205,
/// <summary>
/// Armory feet/boots/shoes container.
/// </summary>
ArmoryFeets = 3206,
/// <summary>
/// Armory earring container.
/// </summary>
ArmoryEar = 3207,
/// <summary>
/// Armory necklace container.
/// </summary>
ArmoryNeck = 3208,
/// <summary>
/// Armory bracelet container.
/// </summary>
ArmoryWrist = 3209,
/// <summary>
/// Armory ring container.
/// </summary>
ArmoryRings = 3300,
/// <summary>
/// Armory soul crystal container.
/// </summary>
ArmorySoulCrystal = 3400,
/// <summary>
/// Armory main-hand weapon container.
/// </summary>
@ -143,17 +143,17 @@ public enum GameInventoryType : ushort
/// First panel of saddelbag inventory.
/// </summary>
SaddleBag1 = 4000,
/// <summary>
/// Second panel of Saddlebag inventory.
/// </summary>
SaddleBag2 = 4001,
/// <summary>
/// First panel of premium saddlebag inventory.
/// </summary>
PremiumSaddleBag1 = 4100,
/// <summary>
/// Second panel of premium saddlebag inventory.
/// </summary>
@ -163,52 +163,52 @@ public enum GameInventoryType : ushort
/// First panel of retainer inventory.
/// </summary>
RetainerPage1 = 10000,
/// <summary>
/// Second panel of retainer inventory.
/// </summary>
RetainerPage2 = 10001,
/// <summary>
/// Third panel of retainer inventory.
/// </summary>
RetainerPage3 = 10002,
/// <summary>
/// Fourth panel of retainer inventory.
/// </summary>
RetainerPage4 = 10003,
/// <summary>
/// Fifth panel of retainer inventory.
/// </summary>
RetainerPage5 = 10004,
/// <summary>
/// Sixth panel of retainer inventory.
/// </summary>
RetainerPage6 = 10005,
/// <summary>
/// Seventh panel of retainer inventory.
/// </summary>
RetainerPage7 = 10006,
/// <summary>
/// Retainer equipment container.
/// </summary>
RetainerEquippedItems = 11000,
/// <summary>
/// Retainer currency container.
/// </summary>
RetainerGil = 12000,
/// <summary>
/// Retainer crystal container.
/// </summary>
RetainerCrystals = 12001,
/// <summary>
/// Retainer market item container.
/// </summary>
@ -218,32 +218,32 @@ public enum GameInventoryType : ushort
/// First panel of Free Company inventory.
/// </summary>
FreeCompanyPage1 = 20000,
/// <summary>
/// Second panel of Free Company inventory.
/// </summary>
FreeCompanyPage2 = 20001,
/// <summary>
/// Third panel of Free Company inventory.
/// </summary>
FreeCompanyPage3 = 20002,
/// <summary>
/// Fourth panel of Free Company inventory.
/// </summary>
FreeCompanyPage4 = 20003,
/// <summary>
/// Fifth panel of Free Company inventory.
/// </summary>
FreeCompanyPage5 = 20004,
/// <summary>
/// Free Company currency container.
/// </summary>
FreeCompanyGil = 22000,
/// <summary>
/// Free Company crystal container.
/// </summary>
@ -253,102 +253,102 @@ public enum GameInventoryType : ushort
/// Housing exterior appearance container.
/// </summary>
HousingExteriorAppearance = 25000,
/// <summary>
/// Housing exterior placed items container.
/// </summary>
HousingExteriorPlacedItems = 25001,
/// <summary>
/// Housing interior appearance container.
/// </summary>
HousingInteriorAppearance = 25002,
/// <summary>
/// First panel of housing interior inventory.
/// </summary>
HousingInteriorPlacedItems1 = 25003,
/// <summary>
/// Second panel of housing interior inventory.
/// </summary>
HousingInteriorPlacedItems2 = 25004,
/// <summary>
/// Third panel of housing interior inventory.
/// </summary>
HousingInteriorPlacedItems3 = 25005,
/// <summary>
/// Fourth panel of housing interior inventory.
/// </summary>
HousingInteriorPlacedItems4 = 25006,
/// <summary>
/// Fifth panel of housing interior inventory.
/// </summary>
HousingInteriorPlacedItems5 = 25007,
/// <summary>
/// Sixth panel of housing interior inventory.
/// </summary>
HousingInteriorPlacedItems6 = 25008,
/// <summary>
/// Seventh panel of housing interior inventory.
/// </summary>
HousingInteriorPlacedItems7 = 25009,
/// <summary>
/// Eighth panel of housing interior inventory.
/// </summary>
HousingInteriorPlacedItems8 = 25010,
/// <summary>
/// Housing exterior storeroom inventory.
/// </summary>
HousingExteriorStoreroom = 27000,
/// <summary>
/// First panel of housing interior storeroom inventory.
/// </summary>
HousingInteriorStoreroom1 = 27001,
/// <summary>
/// Second panel of housing interior storeroom inventory.
/// </summary>
HousingInteriorStoreroom2 = 27002,
/// <summary>
/// Third panel of housing interior storeroom inventory.
/// </summary>
HousingInteriorStoreroom3 = 27003,
/// <summary>
/// Fourth panel of housing interior storeroom inventory.
/// </summary>
HousingInteriorStoreroom4 = 27004,
/// <summary>
/// Fifth panel of housing interior storeroom inventory.
/// </summary>
HousingInteriorStoreroom5 = 27005,
/// <summary>
/// Sixth panel of housing interior storeroom inventory.
/// </summary>
HousingInteriorStoreroom6 = 27006,
/// <summary>
/// Seventh panel of housing interior storeroom inventory.
/// </summary>
HousingInteriorStoreroom7 = 27007,
/// <summary>
/// Eighth panel of housing interior storeroom inventory.
/// </summary>
HousingInteriorStoreroom8 = 27008,
/// <summary>
/// An invalid value.
/// </summary>

View file

@ -1,13 +1,12 @@
using System.Diagnostics.CodeAnalysis;
namespace Dalamud.Game.Inventory.InventoryChangeArgsTypes;
namespace Dalamud.Game.Inventory.InventoryChangeArgsTypes;
/// <summary>
/// Abstract base class representing inventory changed events.
/// </summary>
[SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1206:Declaration keywords should follow order", Justification = "It literally says <access modifiers>, <static>, and then <all other keywords>. required is not an access modifier.")]
public abstract class InventoryEventArgs
{
private readonly GameInventoryItem item;
/// <summary>
/// Initializes a new instance of the <see cref="InventoryEventArgs"/> class.
/// </summary>
@ -16,7 +15,7 @@ public abstract class InventoryEventArgs
protected InventoryEventArgs(GameInventoryEvent type, in GameInventoryItem item)
{
this.Type = type;
this.Item = item;
this.item = item;
}
/// <summary>
@ -28,8 +27,11 @@ public abstract class InventoryEventArgs
/// Gets the item associated with this event.
/// <remarks><em>This is a copy of the item data.</em></remarks>
/// </summary>
public GameInventoryItem Item { get; }
// impl note: we return a ref readonly view, to avoid making copies every time this property is accessed.
// see: https://devblogs.microsoft.com/premier-developer/avoiding-struct-and-readonly-reference-performance-pitfalls-with-errorprone-net/
// "Consider using ref readonly locals and ref return for library code"
public ref readonly GameInventoryItem Item => ref this.item;
/// <inheritdoc/>
public override string ToString() => $"<{this.Type}> ({this.Item})";
}

View file

@ -6,6 +6,8 @@
/// </summary>
public class InventoryItemChangedArgs : InventoryEventArgs
{
private readonly GameInventoryItem oldItemState;
/// <summary>
/// Initializes a new instance of the <see cref="InventoryItemChangedArgs"/> class.
/// </summary>
@ -14,7 +16,7 @@ public class InventoryItemChangedArgs : InventoryEventArgs
internal InventoryItemChangedArgs(in GameInventoryItem oldItem, in GameInventoryItem newItem)
: base(GameInventoryEvent.Changed, newItem)
{
this.OldItemState = oldItem;
this.oldItemState = oldItem;
}
/// <summary>
@ -29,6 +31,8 @@ public class InventoryItemChangedArgs : InventoryEventArgs
/// <summary>
/// Gets the state of the item from before it was changed.
/// <remarks><em>This is a copy of the item data.</em></remarks>
/// </summary>
public GameInventoryItem OldItemState { get; init; }
// impl note: see InventoryEventArgs.Item.
public ref readonly GameInventoryItem OldItemState => ref this.oldItemState;
}

View file

@ -1,11 +1,8 @@
using System.Diagnostics.CodeAnalysis;
namespace Dalamud.Game.Inventory.InventoryChangeArgsTypes;
namespace Dalamud.Game.Inventory.InventoryChangeArgsTypes;
/// <summary>
/// Represents the data associated with an item being moved from one inventory and added to another.
/// </summary>
[SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1206:Declaration keywords should follow order", Justification = "It literally says <access modifiers>, <static>, and then <all other keywords>. required is not an access modifier.")]
public class InventoryItemMovedArgs : InventoryEventArgs
{
/// <summary>
@ -29,7 +26,7 @@ public class InventoryItemMovedArgs : InventoryEventArgs
/// Gets the inventory this item was moved to.
/// </summary>
public GameInventoryType TargetInventory => this.Item.ContainerType;
/// <summary>
/// Gets the slot this item was moved from.
/// </summary>
@ -49,7 +46,7 @@ public class InventoryItemMovedArgs : InventoryEventArgs
/// Gets the associated target event.
/// </summary>
internal InventoryEventArgs TargetEvent { get; }
/// <inheritdoc/>
public override string ToString() =>
$"<{this.Type}> (Item #{this.Item.ItemId}) from (slot {this.SourceSlot} in {this.SourceInventory}) to (slot {this.TargetSlot} in {this.TargetInventory})";

View file

@ -13,12 +13,12 @@ public class InventoryItemRemovedArgs : InventoryEventArgs
: base(GameInventoryEvent.Removed, item)
{
}
/// <summary>
/// Gets the inventory this item was removed from.
/// </summary>
public GameInventoryType Inventory => this.Item.ContainerType;
/// <summary>
/// Gets the slot this item was removed from.
/// </summary>

View file

@ -24,12 +24,12 @@ public interface IGameInventory
/// <param name="type">The event try that triggered this message.</param>
/// <param name="data">Data for the triggered event.</param>
public delegate void InventoryChangedDelegate(GameInventoryEvent type, InventoryEventArgs data);
/// <summary>
/// Event that is fired when the inventory has been changed.
/// </summary>
public event InventoryChangelogDelegate InventoryChanged;
/// <summary>
/// Event that is fired when the inventory has been changed, without trying to interpret two inventory slot changes
/// as a move event as appropriate.<br />