Update slot items to simplified slotting logic + reveal renderers

This commit is contained in:
Michal Pikulski
2025-12-16 11:08:29 +01:00
parent 2807292cd7
commit ef709f5725
4 changed files with 232 additions and 1829 deletions

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using UnityEngine;
using Interactions;
using Core.Lifecycle;
using Core.SaveLoad;
namespace Core
{
@@ -31,18 +30,10 @@ namespace Core
// Broadcasts when any registered ItemSlot reports a correct item slotted
// Args: slot's itemData (the slot definition), then the slotted item data
public event Action<PickupItemData, PickupItemData> OnCorrectItemSlotted;
// Broadcasts when any registered ItemSlot reports an incorrect item slotted
// Args: slot's itemData (the slot definition), then the slotted item data
public event Action<PickupItemData, PickupItemData> OnIncorrectItemSlotted;
// Broadcasts when any registered ItemSlot reports a forbidden item slotted
// Args: slot's itemData (the slot definition), then the slotted item data
public event Action<PickupItemData, PickupItemData> OnForbiddenItemSlotted;
// Broadcasts when any registered ItemSlot is cleared (item removed)
// Args: the item data that was removed
public event Action<PickupItemData> OnItemSlotCleared;
// Broadcasts when a wrong item is attempted (not slotted, just attempted)
// Args: slot's itemData (the slot definition), then the attempted item data
public event Action<PickupItemData, PickupItemData> OnWrongItemAttempted;
// Broadcasts when any two items are successfully combined
// Args: first item data, second item data, result item data
@@ -82,17 +73,11 @@ namespace Core
{
OnCorrectItemSlotted?.Invoke(slotData, slottedItem);
}
// Handler that forwards incorrect-slot events
private void ItemSlot_OnIncorrectItemSlotted(PickupItemData slotData, PickupItemData slottedItem)
// Handler that forwards wrong-item-attempted events
private void ItemSlot_OnWrongItemAttempted(PickupItemData slotData, PickupItemData attemptedItem)
{
OnIncorrectItemSlotted?.Invoke(slotData, slottedItem);
}
// Handler that forwards forbidden-slot events
private void ItemSlot_OnForbiddenItemSlotted(PickupItemData slotData, PickupItemData slottedItem)
{
OnForbiddenItemSlotted?.Invoke(slotData, slottedItem);
OnWrongItemAttempted?.Invoke(slotData, attemptedItem);
}
// Handler that forwards item combination events
@@ -107,12 +92,6 @@ namespace Core
OnItemsCombined?.Invoke(itemA, itemB, resultItem);
}
// Handler that forwards slot-removed events
private void ItemSlot_OnItemSlotRemoved(PickupItemData removedItem)
{
OnItemSlotCleared?.Invoke(removedItem);
}
/// <summary>
/// Unsubscribe all pickup/slot event handlers and clear registries and manager events.
/// </summary>
@@ -137,8 +116,7 @@ namespace Core
if (s != null)
{
s.OnCorrectItemSlotted -= ItemSlot_OnCorrectItemSlotted;
s.OnIncorrectItemSlotted -= ItemSlot_OnIncorrectItemSlotted;
s.OnItemSlotRemoved -= ItemSlot_OnItemSlotRemoved;
s.OnWrongItemAttempted -= ItemSlot_OnWrongItemAttempted;
}
}
_itemSlots.Clear();
@@ -149,9 +127,7 @@ namespace Core
// Clear manager-level event subscribers
OnItemPickedUp = null;
OnCorrectItemSlotted = null;
OnIncorrectItemSlotted = null;
OnForbiddenItemSlotted = null;
OnItemSlotCleared = null;
OnWrongItemAttempted = null;
OnItemsCombined = null;
}
@@ -181,10 +157,9 @@ namespace Core
if (slot == null) return;
if (_itemSlots.Add(slot))
{
// Subscribe to all slot events
// Subscribe to active slot events only
slot.OnCorrectItemSlotted += ItemSlot_OnCorrectItemSlotted;
slot.OnIncorrectItemSlotted += ItemSlot_OnIncorrectItemSlotted;
slot.OnItemSlotRemoved += ItemSlot_OnItemSlotRemoved;
slot.OnWrongItemAttempted += ItemSlot_OnWrongItemAttempted;
}
}
@@ -193,10 +168,9 @@ namespace Core
if (slot == null) return;
if (_itemSlots.Remove(slot))
{
// Unsubscribe from all slot events
// Unsubscribe from active slot events
slot.OnCorrectItemSlotted -= ItemSlot_OnCorrectItemSlotted;
slot.OnIncorrectItemSlotted -= ItemSlot_OnIncorrectItemSlotted;
slot.OnItemSlotRemoved -= ItemSlot_OnItemSlotRemoved;
slot.OnWrongItemAttempted -= ItemSlot_OnWrongItemAttempted;
}
}