mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 20:24:16 +01:00
Cleanup
This commit is contained in:
parent
6dd34ebda4
commit
1039c1eb8a
5 changed files with 48 additions and 24 deletions
|
|
@ -9,8 +9,6 @@ using Dalamud.IoC.Internal;
|
||||||
using Dalamud.Logging.Internal;
|
using Dalamud.Logging.Internal;
|
||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
|
|
||||||
using FFXIVClientStructs.FFXIV.Client.Game;
|
|
||||||
|
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
|
||||||
namespace Dalamud.Game.Inventory;
|
namespace Dalamud.Game.Inventory;
|
||||||
|
|
@ -94,22 +92,6 @@ internal class GameInventory : IDisposable, IServiceType, IGameInventory
|
||||||
this.framework.Update -= this.OnFrameworkUpdate;
|
this.framework.Update -= this.OnFrameworkUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a <see cref="Span{T}"/> view of <see cref="InventoryItem"/>s, wrapped as <see cref="GameInventoryItem"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="type">The inventory type.</param>
|
|
||||||
/// <returns>The span.</returns>
|
|
||||||
private static unsafe ReadOnlySpan<GameInventoryItem> GetItemsForInventory(GameInventoryType type)
|
|
||||||
{
|
|
||||||
var inventoryManager = InventoryManager.Instance();
|
|
||||||
if (inventoryManager is null) return default;
|
|
||||||
|
|
||||||
var inventory = inventoryManager->GetInventoryContainer((InventoryType)type);
|
|
||||||
if (inventory is null) return default;
|
|
||||||
|
|
||||||
return new ReadOnlySpan<GameInventoryItem>(inventory->Items, (int)inventory->Size);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void InvokeSafely(
|
private static void InvokeSafely(
|
||||||
IGameInventory.InventoryChangelogDelegate? cb,
|
IGameInventory.InventoryChangelogDelegate? cb,
|
||||||
IReadOnlyCollection<InventoryEventArgs> data)
|
IReadOnlyCollection<InventoryEventArgs> data)
|
||||||
|
|
@ -140,7 +122,7 @@ internal class GameInventory : IDisposable, IServiceType, IGameInventory
|
||||||
{
|
{
|
||||||
for (var i = 0; i < this.inventoryTypes.Length; i++)
|
for (var i = 0; i < this.inventoryTypes.Length; i++)
|
||||||
{
|
{
|
||||||
var newItems = GetItemsForInventory(this.inventoryTypes[i]);
|
var newItems = GameInventoryItem.GetReadOnlySpanOfInventory(this.inventoryTypes[i]);
|
||||||
if (newItems.IsEmpty)
|
if (newItems.IsEmpty)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,28 @@ public unsafe struct GameInventoryItem : IEquatable<GameInventoryItem>
|
||||||
public ReadOnlySpan<ushort> MateriaGrade =>
|
public ReadOnlySpan<ushort> MateriaGrade =>
|
||||||
new(Unsafe.AsPointer(ref Unsafe.AsRef(in this.InternalItem.MateriaGrade[0])), 5);
|
new(Unsafe.AsPointer(ref Unsafe.AsRef(in this.InternalItem.MateriaGrade[0])), 5);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the address of native inventory item in the game.<br />
|
||||||
|
/// Can be 0 if this instance of <see cref="GameInventoryItem"/> does not point to a valid set of container type and slot.
|
||||||
|
/// </summary>
|
||||||
|
public nint NativeAddress
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var s = GetReadOnlySpanOfInventory(this.ContainerType);
|
||||||
|
if (s.IsEmpty)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
foreach (ref readonly var i in s)
|
||||||
|
{
|
||||||
|
if (i.InventorySlot == this.InventorySlot)
|
||||||
|
return (nint)Unsafe.AsPointer(ref Unsafe.AsRef(in i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the color used for this item.
|
/// Gets the color used for this item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -160,4 +182,20 @@ public unsafe struct GameInventoryItem : IEquatable<GameInventoryItem>
|
||||||
this.IsEmpty
|
this.IsEmpty
|
||||||
? "empty"
|
? "empty"
|
||||||
: $"item({this.ItemId}@{this.ContainerType}#{this.InventorySlot})";
|
: $"item({this.ItemId}@{this.ContainerType}#{this.InventorySlot})";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a <see cref="Span{T}"/> view of <see cref="InventoryItem"/>s, wrapped as <see cref="GameInventoryItem"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">The inventory type.</param>
|
||||||
|
/// <returns>The span.</returns>
|
||||||
|
internal static ReadOnlySpan<GameInventoryItem> GetReadOnlySpanOfInventory(GameInventoryType type)
|
||||||
|
{
|
||||||
|
var inventoryManager = InventoryManager.Instance();
|
||||||
|
if (inventoryManager is null) return default;
|
||||||
|
|
||||||
|
var inventory = inventoryManager->GetInventoryContainer((InventoryType)type);
|
||||||
|
if (inventory is null) return default;
|
||||||
|
|
||||||
|
return new ReadOnlySpan<GameInventoryItem>(inventory->Items, (int)inventory->Size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,6 @@ public sealed class InventoryItemMovedArgs : InventoryComplexEventArgs
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// <inheritdoc/>
|
|
||||||
// public override string ToString() => $"{this.Type}({this.SourceEvent}, {this.TargetEvent})";
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override string ToString() =>
|
public override string ToString() =>
|
||||||
$"{this.Type}(item({this.Item.ItemId}) from {this.SourceInventory}#{this.SourceSlot} to {this.TargetInventory}#{this.TargetSlot})";
|
$"{this.Type}(item({this.Item.ItemId}) from {this.SourceInventory}#{this.SourceSlot} to {this.TargetInventory}#{this.TargetSlot})";
|
||||||
|
|
|
||||||
|
|
@ -679,6 +679,9 @@ internal class ConsoleWindow : Window, IDisposable
|
||||||
|
|
||||||
private bool IsFilterApplicable(LogEntry entry)
|
private bool IsFilterApplicable(LogEntry entry)
|
||||||
{
|
{
|
||||||
|
if (this.regexError)
|
||||||
|
return false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// If this entry is below a newly set minimum level, fail it
|
// If this entry is below a newly set minimum level, fail it
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,11 @@ public interface IGameInventory
|
||||||
public delegate void InventoryChangedDelegate(GameInventoryEvent type, InventoryEventArgs data);
|
public delegate void InventoryChangedDelegate(GameInventoryEvent type, InventoryEventArgs data);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event that is fired when the inventory has been changed.
|
/// Event that is fired when the inventory has been changed.<br />
|
||||||
|
/// Note that some events, such as <see cref="ItemAdded"/>, <see cref="ItemRemoved"/>, and <see cref="ItemChanged"/>
|
||||||
|
/// currently is subject to reinterpretation as <see cref="ItemMoved"/>, <see cref="ItemMerged"/>, and
|
||||||
|
/// <see cref="ItemSplit"/>.<br />
|
||||||
|
/// Use <see cref="InventoryChangedRaw"/> if you do not want such reinterpretation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event InventoryChangelogDelegate InventoryChanged;
|
public event InventoryChangelogDelegate InventoryChanged;
|
||||||
|
|
||||||
|
|
@ -34,7 +38,7 @@ public interface IGameInventory
|
||||||
/// Event that is fired when the inventory has been changed, without trying to interpret two inventory slot changes
|
/// 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 />
|
/// as a move event as appropriate.<br />
|
||||||
/// In other words, <see cref="GameInventoryEvent.Moved"/>, <see cref="GameInventoryEvent.Merged"/>, and
|
/// In other words, <see cref="GameInventoryEvent.Moved"/>, <see cref="GameInventoryEvent.Merged"/>, and
|
||||||
/// <see cref="GameInventoryEvent.Split"/> do not fire in this event.
|
/// <see cref="GameInventoryEvent.Split"/> currently do not fire in this event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event InventoryChangelogDelegate InventoryChangedRaw;
|
public event InventoryChangelogDelegate InventoryChangedRaw;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue