/// <summary> /// Gets the <see cref="InventoryChangeInfo"/>s for the changes that have been made. /// </summary> /// <returns>The <see cref="InventoryChangeInfo"/>s for the changes that have been made.</returns> public IEnumerable <InventoryChangeInfo> GetChanges() { // Iterate through every slot for (var i = 0; i < _buffer.Length; i++) { var invItem = _inventory[new InventorySlot(i)]; var tracker = _buffer[i]; // If the values are already equal, skip it if (ItemValueTracker.AreValuesEqual(invItem, tracker)) { continue; } // Yield return the changed item results yield return(new InventoryChangeInfo(invItem, tracker, new InventorySlot(i))); // Update the item with the new values, creating the tracker if needed if (tracker == null) { _buffer[i] = new ItemValueTracker(); } _buffer[i].SetValues(invItem); } }
public static bool AreValuesEqual(ItemEntity item, ItemValueTracker tracker) { // Treat a null ItemValueTracker just like if it was a tracker with IsNull set if (tracker == null) { // If both are null, they are considered equal return(item == null); } // Do a normal call to IsEqualTo since the tracker isn't null return(tracker.IsEqualTo(item)); }
public static bool AreValuesEqual(ItemEntity item, ItemValueTracker tracker) { // Treat a null ItemValueTracker just like if it was a tracker with IsNull set if (tracker == null) { // If both are null, they are considered equal return item == null; } // Do a normal call to IsEqualTo since the tracker isn't null return tracker.IsEqualTo(item); }
public InventoryChangeInfo(ItemEntity item, ItemValueTracker oldValues, InventorySlot slot) { _slot = slot; _item = item; if (oldValues == null || oldValues.IsNull) _oldValues = null; else _oldValues = oldValues; Debug.Assert(_item != null || _oldValues != null, "item and oldValues can not both be null. " + "This would imply that the item changed from null to null."); }
public InventoryChangeInfo(ItemEntity item, ItemValueTracker oldValues, InventorySlot slot) { _slot = slot; _item = item; if (oldValues == null || oldValues.IsNull) { _oldValues = null; } else { _oldValues = oldValues; } Debug.Assert(_item != null || _oldValues != null, "item and oldValues can not both be null. " + "This would imply that the item changed from null to null."); }
/// <summary> /// Gets the <see cref="InventoryChangeInfo"/>s for the changes that have been made. /// </summary> /// <returns>The <see cref="InventoryChangeInfo"/>s for the changes that have been made.</returns> public IEnumerable<InventoryChangeInfo> GetChanges() { // Iterate through every slot for (var i = 0; i < _buffer.Length; i++) { var invItem = _inventory[new InventorySlot(i)]; var tracker = _buffer[i]; // If the values are already equal, skip it if (ItemValueTracker.AreValuesEqual(invItem, tracker)) continue; // Yield return the changed item results yield return new InventoryChangeInfo(invItem, tracker, new InventorySlot(i)); // Update the item with the new values, creating the tracker if needed if (tracker == null) _buffer[i] = new ItemValueTracker(); _buffer[i].SetValues(invItem); } }