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(); public ISlotInfo? Previous { get; private set; } public SlotTouchType PreviousType { get; private set; } = SlotTouchType.None; public PKM? PreviousEntity { get; private set; } /// /// Notifies all with the latest slot change details. /// /// Last interacted slot /// Last interacted slot interaction type /// Last interacted slot interaction data public void NotifySlotChanged(ISlotInfo slot, SlotTouchType type, PKM pkm) { foreach (var sub in Subscribers) ResetView(sub, slot, type, pkm); Previous = slot; PreviousType = type; PreviousEntity = pkm; } private void ResetView(ISlotViewer sub, ISlotInfo slot, SlotTouchType type, PKM pkm) { if (Previous != null) sub.NotifySlotOld(Previous); if (slot is not SlotInfoBox b || sub.ViewIndex == b.Box) sub.NotifySlotChanged(slot, type, pkm); } public void ResetView(ISlotViewer sub) { if (Previous == null || PreviousEntity == null) return; ResetView(sub, Previous, PreviousType, PreviousEntity); } } }