From aef1b8ac2898e147e6200fe257e8fdd82ee7fdbc Mon Sep 17 00:00:00 2001 From: wartech0 Date: Sun, 29 Dec 2019 08:06:02 -0600 Subject: Added the new ChestItemChanged event. --- src/SMAPI/Events/ChestItemChangedEventArgs.cs | 47 +++++++++++++++++++++++++++ src/SMAPI/Events/IWorldEvents.cs | 3 ++ 2 files changed, 50 insertions(+) create mode 100644 src/SMAPI/Events/ChestItemChangedEventArgs.cs (limited to 'src/SMAPI/Events') diff --git a/src/SMAPI/Events/ChestItemChangedEventArgs.cs b/src/SMAPI/Events/ChestItemChangedEventArgs.cs new file mode 100644 index 00000000..6b06487c --- /dev/null +++ b/src/SMAPI/Events/ChestItemChangedEventArgs.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Xna.Framework; +using StardewValley; +using Item = StardewValley.Item; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class ChestItemChangedEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// The location which changed. + public GameLocation Location { get; } + + /// The objects added to the location. + public IEnumerable Added { get; } + + /// The objects removed from the location. + public IEnumerable Removed { get; } + + /// The location of the chest from where the item was added or removed + public Vector2 LocationOfChest { get; } + + /// Whether this is the location containing the local player. + public bool IsCurrentLocation => object.ReferenceEquals(this.Location, Game1.player?.currentLocation); + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The location which changed. + /// The objects added to the location. + /// The objects removed from the location. + internal ChestItemChangedEventArgs(GameLocation location, IEnumerable added, IEnumerable removed, Vector2 locationOfChest) + { + this.Location = location; + this.Added = added.ToArray(); + this.Removed = removed.ToArray(); + this.LocationOfChest = locationOfChest; + } + } +} diff --git a/src/SMAPI/Events/IWorldEvents.cs b/src/SMAPI/Events/IWorldEvents.cs index 0ceffcc1..6f9b71a7 100644 --- a/src/SMAPI/Events/IWorldEvents.cs +++ b/src/SMAPI/Events/IWorldEvents.cs @@ -23,6 +23,9 @@ namespace StardewModdingAPI.Events /// Raised after objects are added or removed in a location. event EventHandler ObjectListChanged; + /// Raised after items are added or removed from a chest in a location. + event EventHandler ChestItemChanged; + /// Raised after terrain features (like floors and trees) are added or removed in a location. event EventHandler TerrainFeatureListChanged; } -- cgit From 1286a90ec2fb0dcf26bd59feec714544844e4398 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 29 Dec 2019 13:29:25 -0500 Subject: minor refactoring This commit... - removes key fields added to non-keyed types like NetListWatcher and SnapshotListDiff; - fixes existing chests not being watched; - fixes diffs not correctly updated for added/removed chests; - performs minor cleanup, adds missing docs, etc. --- src/SMAPI/Events/ChestInventoryChangedEventArgs.cs | 47 ++++++++++++++++++++++ src/SMAPI/Events/ChestItemChangedEventArgs.cs | 47 ---------------------- src/SMAPI/Events/IWorldEvents.cs | 4 +- 3 files changed, 49 insertions(+), 49 deletions(-) create mode 100644 src/SMAPI/Events/ChestInventoryChangedEventArgs.cs delete mode 100644 src/SMAPI/Events/ChestItemChangedEventArgs.cs (limited to 'src/SMAPI/Events') diff --git a/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs b/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs new file mode 100644 index 00000000..0b54e909 --- /dev/null +++ b/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Xna.Framework; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class ChestInventoryChangedEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// The location containing the chest. + public GameLocation Location { get; } + + /// The tile position of the chest. + public Vector2 Tile { get; } + + /// The objects added to the location. + public IEnumerable Added { get; } + + /// The objects removed from the location. + public IEnumerable Removed { get; } + + /// Whether this is the location containing the local player. + public bool IsCurrentLocation => object.ReferenceEquals(this.Location, Game1.player?.currentLocation); + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The location containing the chest. + /// The tile position of the chest. + /// The objects added to the location. + /// The objects removed from the location. + internal ChestInventoryChangedEventArgs(GameLocation location, Vector2 tile, IEnumerable added, IEnumerable removed) + { + this.Location = location; + this.Tile = tile; + this.Added = added.ToArray(); + this.Removed = removed.ToArray(); + } + } +} diff --git a/src/SMAPI/Events/ChestItemChangedEventArgs.cs b/src/SMAPI/Events/ChestItemChangedEventArgs.cs deleted file mode 100644 index 6b06487c..00000000 --- a/src/SMAPI/Events/ChestItemChangedEventArgs.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Xna.Framework; -using StardewValley; -using Item = StardewValley.Item; - -namespace StardewModdingAPI.Events -{ - /// Event arguments for a event. - public class ChestItemChangedEventArgs : EventArgs - { - /********* - ** Accessors - *********/ - /// The location which changed. - public GameLocation Location { get; } - - /// The objects added to the location. - public IEnumerable Added { get; } - - /// The objects removed from the location. - public IEnumerable Removed { get; } - - /// The location of the chest from where the item was added or removed - public Vector2 LocationOfChest { get; } - - /// Whether this is the location containing the local player. - public bool IsCurrentLocation => object.ReferenceEquals(this.Location, Game1.player?.currentLocation); - - - /********* - ** Public methods - *********/ - /// Construct an instance. - /// The location which changed. - /// The objects added to the location. - /// The objects removed from the location. - internal ChestItemChangedEventArgs(GameLocation location, IEnumerable added, IEnumerable removed, Vector2 locationOfChest) - { - this.Location = location; - this.Added = added.ToArray(); - this.Removed = removed.ToArray(); - this.LocationOfChest = locationOfChest; - } - } -} diff --git a/src/SMAPI/Events/IWorldEvents.cs b/src/SMAPI/Events/IWorldEvents.cs index 6f9b71a7..9569a57b 100644 --- a/src/SMAPI/Events/IWorldEvents.cs +++ b/src/SMAPI/Events/IWorldEvents.cs @@ -23,8 +23,8 @@ namespace StardewModdingAPI.Events /// Raised after objects are added or removed in a location. event EventHandler ObjectListChanged; - /// Raised after items are added or removed from a chest in a location. - event EventHandler ChestItemChanged; + /// Raised after items are added or removed from a chest. + event EventHandler ChestInventoryChanged; /// Raised after terrain features (like floors and trees) are added or removed in a location. event EventHandler TerrainFeatureListChanged; -- cgit From 0411dcf3db277ed0d3c9f0201b7554a7d61ed1e8 Mon Sep 17 00:00:00 2001 From: wartech0 Date: Tue, 31 Dec 2019 04:20:36 -0600 Subject: Finished chest events --- src/SMAPI/Events/ChestInventoryChangedEventArgs.cs | 20 ++++++-------------- src/SMAPI/Events/ItemStackChange.cs | 7 ++++++- 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'src/SMAPI/Events') diff --git a/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs b/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs index 0b54e909..a0c63fdc 100644 --- a/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs +++ b/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs @@ -16,17 +16,10 @@ namespace StardewModdingAPI.Events public GameLocation Location { get; } /// The tile position of the chest. - public Vector2 Tile { get; } - - /// The objects added to the location. - public IEnumerable Added { get; } - - /// The objects removed from the location. - public IEnumerable Removed { get; } - - /// Whether this is the location containing the local player. - public bool IsCurrentLocation => object.ReferenceEquals(this.Location, Game1.player?.currentLocation); + public StardewValley.Objects.Chest Chest { get; } + /// The inventory changes added to the chest. + public ItemStackChange[] Changes { get; } /********* ** Public methods @@ -36,12 +29,11 @@ namespace StardewModdingAPI.Events /// The tile position of the chest. /// The objects added to the location. /// The objects removed from the location. - internal ChestInventoryChangedEventArgs(GameLocation location, Vector2 tile, IEnumerable added, IEnumerable removed) + internal ChestInventoryChangedEventArgs(GameLocation location, StardewValley.Objects.Chest chest, ItemStackChange[] changes) { this.Location = location; - this.Tile = tile; - this.Added = added.ToArray(); - this.Removed = removed.ToArray(); + this.Chest = chest; + this.Changes = changes; } } } diff --git a/src/SMAPI/Events/ItemStackChange.cs b/src/SMAPI/Events/ItemStackChange.cs index f9ae6df6..dbb529d6 100644 --- a/src/SMAPI/Events/ItemStackChange.cs +++ b/src/SMAPI/Events/ItemStackChange.cs @@ -16,5 +16,10 @@ namespace StardewModdingAPI.Events /// How the inventory slot changed. public ChangeType ChangeType { get; set; } + + public override string ToString() + { + return this.StackChange + " " + this.Item.Name + " " + this.ChangeType.ToString(); + } } -} \ No newline at end of file +} -- cgit From 6bf99f0f81582ab6d6212dc21e8c36686ceb5a35 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 31 Dec 2019 17:32:46 -0500 Subject: minor refactoring --- src/SMAPI/Events/ChestInventoryChangedEventArgs.cs | 20 +++++++++----------- src/SMAPI/Events/ItemStackChange.cs | 5 ----- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'src/SMAPI/Events') diff --git a/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs b/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs index a0c63fdc..7771cd7c 100644 --- a/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs +++ b/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Xna.Framework; using StardewValley; +using StardewValley.Objects; namespace StardewModdingAPI.Events { @@ -12,24 +10,24 @@ namespace StardewModdingAPI.Events /********* ** Accessors *********/ + /// The chest whose inventory changed. + public Chest Chest { get; } + /// The location containing the chest. public GameLocation Location { get; } - /// The tile position of the chest. - public StardewValley.Objects.Chest Chest { get; } - - /// The inventory changes added to the chest. + /// The inventory changes in the chest. public ItemStackChange[] Changes { get; } + /********* ** Public methods *********/ /// Construct an instance. + /// The chest whose inventory changed. /// The location containing the chest. - /// The tile position of the chest. - /// The objects added to the location. - /// The objects removed from the location. - internal ChestInventoryChangedEventArgs(GameLocation location, StardewValley.Objects.Chest chest, ItemStackChange[] changes) + /// The inventory changes in the chest. + internal ChestInventoryChangedEventArgs(Chest chest, GameLocation location, ItemStackChange[] changes) { this.Location = location; this.Chest = chest; diff --git a/src/SMAPI/Events/ItemStackChange.cs b/src/SMAPI/Events/ItemStackChange.cs index dbb529d6..cb5d2b88 100644 --- a/src/SMAPI/Events/ItemStackChange.cs +++ b/src/SMAPI/Events/ItemStackChange.cs @@ -16,10 +16,5 @@ namespace StardewModdingAPI.Events /// How the inventory slot changed. public ChangeType ChangeType { get; set; } - - public override string ToString() - { - return this.StackChange + " " + this.Item.Name + " " + this.ChangeType.ToString(); - } } } -- cgit From e64a1220e309e8fc83e20833b8849de1721ec469 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 1 Jan 2020 18:52:24 -0500 Subject: unify item diff logic for players & chests --- src/SMAPI/Events/ChestInventoryChangedEventArgs.cs | 21 +++++++++---- src/SMAPI/Events/InventoryChangedEventArgs.cs | 34 +++++++--------------- src/SMAPI/Events/ItemStackChange.cs | 20 ------------- 3 files changed, 26 insertions(+), 49 deletions(-) delete mode 100644 src/SMAPI/Events/ItemStackChange.cs (limited to 'src/SMAPI/Events') diff --git a/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs b/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs index 7771cd7c..4b4c4210 100644 --- a/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs +++ b/src/SMAPI/Events/ChestInventoryChangedEventArgs.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using StardewValley; using StardewValley.Objects; @@ -16,8 +17,14 @@ namespace StardewModdingAPI.Events /// The location containing the chest. public GameLocation Location { get; } - /// The inventory changes in the chest. - public ItemStackChange[] Changes { get; } + /// The added item stacks. + public IEnumerable Added { get; } + + /// The removed item stacks. + public IEnumerable Removed { get; } + + /// The item stacks whose size changed. + public IEnumerable QuantityChanged { get; } /********* @@ -26,12 +33,16 @@ namespace StardewModdingAPI.Events /// Construct an instance. /// The chest whose inventory changed. /// The location containing the chest. - /// The inventory changes in the chest. - internal ChestInventoryChangedEventArgs(Chest chest, GameLocation location, ItemStackChange[] changes) + /// The added item stacks. + /// The removed item stacks. + /// The item stacks whose size changed. + internal ChestInventoryChangedEventArgs(Chest chest, GameLocation location, Item[] added, Item[] removed, ItemStackSizeChange[] quantityChanged) { this.Location = location; this.Chest = chest; - this.Changes = changes; + this.Added = added; + this.Removed = removed; + this.QuantityChanged = quantityChanged; } } } diff --git a/src/SMAPI/Events/InventoryChangedEventArgs.cs b/src/SMAPI/Events/InventoryChangedEventArgs.cs index 874c2e48..40cd4128 100644 --- a/src/SMAPI/Events/InventoryChangedEventArgs.cs +++ b/src/SMAPI/Events/InventoryChangedEventArgs.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using StardewValley; namespace StardewModdingAPI.Events @@ -14,13 +13,13 @@ namespace StardewModdingAPI.Events /// The player whose inventory changed. public Farmer Player { get; } - /// The added items. + /// The added item stacks. public IEnumerable Added { get; } - /// The removed items. + /// The removed item stacks. public IEnumerable Removed { get; } - /// The items whose stack sizes changed, with the relative change. + /// The item stacks whose size changed. public IEnumerable QuantityChanged { get; } /// Whether the affected player is the local one. @@ -32,28 +31,15 @@ namespace StardewModdingAPI.Events *********/ /// Construct an instance. /// The player whose inventory changed. - /// The inventory changes. - internal InventoryChangedEventArgs(Farmer player, ItemStackChange[] changedItems) + /// The added item stacks. + /// The removed item stacks. + /// The item stacks whose size changed. + internal InventoryChangedEventArgs(Farmer player, Item[] added, Item[] removed, ItemStackSizeChange[] quantityChanged) { this.Player = player; - this.Added = changedItems - .Where(n => n.ChangeType == ChangeType.Added) - .Select(p => p.Item) - .ToArray(); - - this.Removed = changedItems - .Where(n => n.ChangeType == ChangeType.Removed) - .Select(p => p.Item) - .ToArray(); - - this.QuantityChanged = changedItems - .Where(n => n.ChangeType == ChangeType.StackChange) - .Select(change => new ItemStackSizeChange( - item: change.Item, - oldSize: change.Item.Stack - change.StackChange, - newSize: change.Item.Stack - )) - .ToArray(); + this.Added = added; + this.Removed = removed; + this.QuantityChanged = quantityChanged; } } } diff --git a/src/SMAPI/Events/ItemStackChange.cs b/src/SMAPI/Events/ItemStackChange.cs deleted file mode 100644 index cb5d2b88..00000000 --- a/src/SMAPI/Events/ItemStackChange.cs +++ /dev/null @@ -1,20 +0,0 @@ -using StardewValley; - -namespace StardewModdingAPI.Events -{ - /// Represents an inventory slot that changed. - public class ItemStackChange - { - /********* - ** Accessors - *********/ - /// The item in the slot. - public Item Item { get; set; } - - /// The amount by which the item's stack size changed. - public int StackChange { get; set; } - - /// How the inventory slot changed. - public ChangeType ChangeType { get; set; } - } -} -- cgit