Visualization for ammo

This commit is contained in:
Marco 2025-03-05 18:55:30 +01:00
commit 07ab64a0bf
12 changed files with 252 additions and 102 deletions

View file

@ -25,6 +25,12 @@ public partial class InventoryManager : Node2D
[Signal]
public delegate void ItemUsedEventHandler(LootItem itemKey, int totalCount);
[Signal]
public delegate void TotalAmmoChangedEventHandler(StringName ammoKey, int count);
[Signal]
public delegate void LoadedAmmoChangedEventHandler(StringName weaponKey, int count);
public override void _Ready()
{
@ -36,6 +42,11 @@ public partial class InventoryManager : Node2D
{
}
public bool TryGetItem(string key, out ItemContainer item)
{
return _itemsDict.TryGetValue(key, out item);
}
public bool HasItems(List<string> itemKeys)
{
return itemKeys.Aggregate(false, (current, item) => current || GetItemCount(item) > 0);
@ -59,8 +70,13 @@ public partial class InventoryManager : Node2D
_itemsDict.Remove(itemKey);
}
EmitSignal(nameof(ItemRemoved), itemKey, itm.Count);
EmitSignal(SignalName.ItemRemoved, itemKey, itm.Count);
if (itm.Item.Item is ItemTypes.Ammo)
{
EmitSignal(SignalName.TotalAmmoChanged, itemKey, itm.Count);
}
return removed;
}
@ -78,7 +94,7 @@ public partial class InventoryManager : Node2D
});
GD.Print($"Added new ({item.ItemKey}) {item.Item} x{item.Amount}");
EmitSignal(nameof(ItemAdded), item, item.Amount);
EmitSignal(SignalName.ItemAdded, item, item.Amount);
}
else
{
@ -97,7 +113,7 @@ public partial class InventoryManager : Node2D
return false;
}
}
EmitSignal(nameof(ItemAdded), item, itm.Count);
EmitSignal(SignalName.ItemAdded, item, itm.Count);
}
return true;
@ -141,6 +157,11 @@ public partial class InventoryManager : Node2D
return true;
}
public void NotifyLoadedAmmoChange(string weaponDataItemKey, int loadedAmmo)
{
EmitSignal(SignalName.LoadedAmmoChanged, weaponDataItemKey, loadedAmmo);
}
}
public class ItemContainer