mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-01 05:13:40 +01:00
Proposed API Surface
This commit is contained in:
parent
40575e1a88
commit
7c6f98dc9f
10 changed files with 311 additions and 93 deletions
|
|
@ -1,4 +1,4 @@
|
|||
using Dalamud.Game.Inventory;
|
||||
using Dalamud.Game.GameInventory;
|
||||
|
||||
namespace Dalamud.Plugin.Services;
|
||||
|
||||
|
|
@ -9,82 +9,41 @@ public interface IGameInventory
|
|||
{
|
||||
/// <summary>
|
||||
/// Delegate function to be called when inventories have been changed.
|
||||
/// This delegate sends the entire set of changes recorded.
|
||||
/// </summary>
|
||||
/// <param name="events">The events.</param>
|
||||
public delegate void InventoryChangeDelegate(ReadOnlySpan<GameInventoryEventArgs> events);
|
||||
public delegate void InventoryChangelogDelegate(ReadOnlySpan<InventoryEventArgs> events);
|
||||
|
||||
/// <summary>
|
||||
/// Delegate function to be called for each change to inventories.
|
||||
/// This delegate sends individual events for changes.
|
||||
/// </summary>
|
||||
/// <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 InventoryChangeDelegate InventoryChanged;
|
||||
|
||||
public event InventoryChangelogDelegate InventoryChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Argument for <see cref="InventoryChangeDelegate"/>.
|
||||
/// Event that is fired when an item is added to an inventory.
|
||||
/// </summary>
|
||||
public readonly struct GameInventoryEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of the event.
|
||||
/// </summary>
|
||||
public readonly GameInventoryEvent Type;
|
||||
public event InventoryChangedDelegate ItemAdded;
|
||||
|
||||
/// <summary>
|
||||
/// The content of the item in the source inventory.<br />
|
||||
/// Relevant if <see cref="Type"/> is <see cref="GameInventoryEvent.Moved"/>, <see cref="GameInventoryEvent.Changed"/>, or <see cref="GameInventoryEvent.Removed"/>.
|
||||
/// </summary>
|
||||
public readonly GameInventoryItem Source;
|
||||
|
||||
/// <summary>
|
||||
/// The content of the item in the target inventory<br />
|
||||
/// Relevant if <see cref="Type"/> is <see cref="GameInventoryEvent.Moved"/>, <see cref="GameInventoryEvent.Changed"/>, or <see cref="GameInventoryEvent.Added"/>.
|
||||
/// </summary>
|
||||
public readonly GameInventoryItem Target;
|
||||
/// <summary>
|
||||
/// Event that is fired when an item is removed from an inventory.
|
||||
/// </summary>
|
||||
public event InventoryChangedDelegate ItemRemoved;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GameInventoryEventArgs"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of the event.</param>
|
||||
/// <param name="source">The source inventory item.</param>
|
||||
/// <param name="target">The target inventory item.</param>
|
||||
public GameInventoryEventArgs(GameInventoryEvent type, GameInventoryItem source, GameInventoryItem target)
|
||||
{
|
||||
this.Type = type;
|
||||
this.Source = source;
|
||||
this.Target = target;
|
||||
}
|
||||
/// <summary>
|
||||
/// Event that is fired when an item is moved from one inventory into another.
|
||||
/// </summary>
|
||||
public event InventoryChangedDelegate ItemMoved;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this instance of <see cref="GameInventoryEventArgs"/> contains no information.
|
||||
/// </summary>
|
||||
public bool IsEmpty => this.Type == GameInventoryEvent.Empty;
|
||||
|
||||
// TODO: are the following two aliases useful?
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the source inventory.<br />
|
||||
/// Relevant for <see cref="GameInventoryEvent.Moved"/> and <see cref="GameInventoryEvent.Removed"/>.
|
||||
/// </summary>
|
||||
public GameInventoryType SourceType => this.Source.ContainerType;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the target inventory.<br />
|
||||
/// Relevant for <see cref="GameInventoryEvent.Moved"/>, <see cref="GameInventoryEvent.Changed"/>, and
|
||||
/// <see cref="GameInventoryEvent.Added"/>.
|
||||
/// </summary>
|
||||
public GameInventoryType TargetType => this.Target.ContainerType;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString() => this.Type switch
|
||||
{
|
||||
GameInventoryEvent.Empty =>
|
||||
$"<{this.Type}>",
|
||||
GameInventoryEvent.Added =>
|
||||
$"<{this.Type}> ({this.Target})",
|
||||
GameInventoryEvent.Removed =>
|
||||
$"<{this.Type}> ({this.Source})",
|
||||
GameInventoryEvent.Changed or GameInventoryEvent.Moved =>
|
||||
$"<{this.Type}> ({this.Source}) to ({this.Target})",
|
||||
_ => $"<Type={this.Type}> {this.Source} => {this.Target}",
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// Event that is fired when an items properties are changed.
|
||||
/// </summary>
|
||||
public event InventoryChangedDelegate ItemChanged;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue