Simple interactable rework

This commit is contained in:
Michal Pikulski
2025-10-31 13:50:08 +01:00
parent 095f21908b
commit 917230e10a
15 changed files with 1897 additions and 103 deletions

View File

@@ -19,7 +19,6 @@ namespace Interactions
/// <summary>
/// Interaction requirement that allows slotting, swapping, or picking up items in a slot.
/// </summary>
[RequireComponent(typeof(Interactable))]
public class ItemSlot : Pickup
{
// Tracks the current state of the slotted item
@@ -53,7 +52,7 @@ namespace Interactions
private PickupItemData _currentlySlottedItemData;
public SpriteRenderer slottedItemRenderer;
private GameObject _currentlySlottedItemObject = null;
private GameObject _currentlySlottedItemObject;
public GameObject GetSlottedObject()
{
@@ -69,7 +68,7 @@ namespace Interactions
}
}
public override void Awake()
protected override void Awake()
{
base.Awake();
@@ -82,8 +81,8 @@ namespace Interactions
{
Logging.Debug("[ItemSlot] OnCharacterArrived");
var heldItemData = FollowerController.CurrentlyHeldItemData;
var heldItemObj = FollowerController.GetHeldPickupObject();
var heldItemData = _followerController.CurrentlyHeldItemData;
var heldItemObj = _followerController.GetHeldPickupObject();
var config = _interactionSettings?.GetSlotItemConfig(itemData);
var forbidden = config?.forbiddenItems ?? new List<PickupItemData>();
@@ -97,7 +96,7 @@ namespace Interactions
onForbiddenItemSlotted?.Invoke();
OnForbiddenItemSlotted?.Invoke(itemData, heldItemData);
_currentState = ItemSlotState.Forbidden;
Interactable.BroadcastInteractionComplete(false);
CompleteInteraction(false);
return;
}
@@ -115,7 +114,7 @@ namespace Interactions
var slottedPickup = _currentlySlottedItemObject?.GetComponent<Pickup>();
if (slottedPickup != null)
{
var comboResult = FollowerController.TryCombineItems(slottedPickup, out var combinationResultItem);
var comboResult = _followerController.TryCombineItems(slottedPickup, out var combinationResultItem);
if (combinationResultItem != null && comboResult == FollowerController.CombinationResult.Successful)
{
// Combination succeeded: fire slot-removed events and clear internals (don't call SlotItem to avoid duplicate events)
@@ -128,14 +127,14 @@ namespace Interactions
_currentlySlottedItemData = null;
UpdateSlottedSprite();
Interactable.BroadcastInteractionComplete(false);
CompleteInteraction(false);
return;
}
}
}
// No combination (or not applicable) -> perform normal swap/pickup behavior
FollowerController.TryPickupItem(_currentlySlottedItemObject, _currentlySlottedItemData, false);
_followerController.TryPickupItem(_currentlySlottedItemObject, _currentlySlottedItemData, false);
onItemSlotRemoved?.Invoke();
OnItemSlotRemoved?.Invoke(_currentlySlottedItemData);
_currentState = ItemSlotState.None;
@@ -163,7 +162,6 @@ namespace Interactions
float desiredHeight = _playerFollowerSettings?.HeldIconDisplayHeight ?? 2.0f;
var sprite = _currentlySlottedItemData.mapSprite;
float spriteHeight = sprite.bounds.size.y;
float spriteWidth = sprite.bounds.size.x;
Vector3 parentScale = slottedItemRenderer.transform.parent != null
? slottedItemRenderer.transform.parent.localScale
: Vector3.one;
@@ -209,7 +207,7 @@ namespace Interactions
if (clearFollowerHeldItem)
{
FollowerController.ClearHeldItem();
_followerController.ClearHeldItem();
}
UpdateSlottedSprite();
@@ -227,7 +225,7 @@ namespace Interactions
_currentState = ItemSlotState.Correct;
}
Interactable.BroadcastInteractionComplete(true);
CompleteInteraction(true);
}
else
{
@@ -238,18 +236,23 @@ namespace Interactions
OnIncorrectItemSlotted?.Invoke(itemData, _currentlySlottedItemData);
_currentState = ItemSlotState.Incorrect;
}
Interactable.BroadcastInteractionComplete(false);
CompleteInteraction(false);
}
}
// Register with ItemManager when enabled
void Start()
{
// Note: Base Pickup class also calls RegisterPickup in its Start
// This additionally registers as ItemSlot
ItemManager.Instance?.RegisterPickup(this);
ItemManager.Instance?.RegisterItemSlot(this);
}
void OnDestroy()
{
// Unregister from both pickup and slot managers
ItemManager.Instance?.UnregisterPickup(this);
ItemManager.Instance?.UnregisterItemSlot(this);
}
}