using System.Collections; using AceFieldNewHorizon.Scripts.Entities; using Godot; namespace AceFieldNewHorizon.Scripts.System; public partial class ItemPickup : Area2D { [Signal] public delegate void StackMergedEventHandler(string itemId, int totalQuantity); public const string PickupGroupName = "ItemPickupTarget"; [Export] public string ItemId { get; set; } = ""; [Export] public int Quantity { get; set; } = 1; [Export] public bool Infinite { get; set; } = false; [Export] public float MagnetRange { get; set; } = 64f; public int GetItemQuantity(string itemId) { if (itemId == ItemId) return Quantity; return 0; } public void SetItemQuantity(string itemId, int newQuantity) { if (itemId == ItemId) { Quantity = newQuantity; // Update the quantity label if it exists if (_quantityLabel != null) { if (Quantity > 1) _quantityLabel.Text = Quantity.ToString(); else _quantityLabel.Text = string.Empty; } } } public bool HasItem(string itemId) { return itemId == ItemId; } public void AddItem(string itemId, int amount) { if (itemId == ItemId) { Quantity += amount; // Update the quantity label if it exists if (_quantityLabel != null) { if (Quantity > 1) _quantityLabel.Text = Quantity.ToString(); else _quantityLabel.Text = string.Empty; } } } private Sprite2D _sprite; private Label _quantityLabel; private Sprite2D _shadowSprite; private Node2D _playerTarget; // Called when the node enters the scene tree public override void _Ready() { BodyEntered += OnEntered; AreaEntered += OnEntered; _sprite = GetNode("Sprite2D"); UpdateTexture(); // Get the Label node for quantity if (HasNode("Label")) { _quantityLabel = GetNode