Rework game over logic and game initialization

This commit is contained in:
2025-10-27 15:04:01 -07:00
parent 720696aed0
commit 7e6dca1c29
46 changed files with 653 additions and 610 deletions

View File

@@ -2,6 +2,7 @@
using Chickensoft.Introspection;
using Chickensoft.Serialization;
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
using Zennysoft.Game.Abstractions;
@@ -17,6 +18,8 @@ public partial class Inventory : Node, IInventory
// TODO: Constants class with export
private const int _maxInventorySize = 20;
public event Action<string> BroadcastMessage;
public Inventory()
{
Items = [];
@@ -25,6 +28,20 @@ public partial class Inventory : Node, IInventory
[Save("inventory_items")]
public List<InventoryItem> Items { get; private set; }
public bool PickUpItem(InventoryItem item)
{
var isAdded = TryAdd(item);
if (isAdded)
{
BroadcastMessage?.Invoke($"{item.ItemName} picked up.");
item.QueueFree();
}
else
BroadcastMessage?.Invoke($"Could not pick up {item.ItemName}.");
return isAdded;
}
public bool TryAdd(InventoryItem inventoryItem)
{
if (Items.Count >= _maxInventorySize)