using System.Collections.Generic;
namespace PKHeX.Core
{
///
/// Pushes slot update notifications out to all subscribers.
///
public sealed class SlotPublisher
{
///
/// All instances that provide a view on individual content.
///
public List Subscribers { get; } = new List();
private SlotChange Previous;
private SlotTouchType PreviousType = SlotTouchType.None;
///
/// Notifies all with the latest slot change details.
///
/// Last interacted slot
/// Last interacted slot interaction type
public void NotifySlotChanged(SlotChange slot, SlotTouchType type)
{
foreach (var sub in Subscribers)
ResetView(sub, slot, type);
Previous = slot;
PreviousType = type;
}
private void ResetView(ISlotViewer sub, SlotChange slot, SlotTouchType type)
{
if (Previous != null)
sub.NotifySlotOld(Previous);
int index = sub.ViewIndex;
if (index == slot.Box)
sub.NotifySlotChanged(slot, type);
}
public void ResetView(ISlotViewer sub) => ResetView(sub, Previous, PreviousType);
}
}