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 pk) { foreach (var sub in Subscribers) ResetView(sub, slot, type, pk); Previous = slot; PreviousType = type; PreviousEntity = pk; } private void ResetView(ISlotViewer sub, ISlotInfo slot, SlotTouchType type, PKM pk) { if (Previous != null) sub.NotifySlotOld(Previous); if (slot is not SlotInfoBox b || sub.ViewIndex == b.Box) sub.NotifySlotChanged(slot, type, pk); } public void ResetView(ISlotViewer sub) { if (Previous == null || PreviousEntity == null) return; ResetView(sub, Previous, PreviousType, PreviousEntity); } }