Moved events inside the player

This commit is contained in:
Maddo 2025-02-28 18:50:42 +01:00
commit 7d9db8cfb6
7 changed files with 57 additions and 75 deletions

View file

@ -28,8 +28,6 @@ public partial class GameManager : Node2D
//[Export] public Marker2D PlayerSpawnMarker { get; set; }
[Export] public PackedScene WeaponTemplate { get; private set; }
[Export] public Array<LootItem> StartingEquipment { get; private set; } = new();
private InventoryManager _inventoryManager { get; set; }
@ -150,21 +148,6 @@ public partial class GameManager : Node2D
return;
}
if (_inventoryManager is not null)
{
_inventoryManager.ItemAdded += (LootItem item, int amount) =>
{
if (item.Item == ItemTypes.Weapon)
{
SpawnPlayerWeapon(item);
}
};
_inventoryManager.WeaponEquip += _player.EquipWeapon;
_inventoryManager.ItemUsed += _player.UseItem;
}
// Wait before the player is fully initialized before spawning weapons on it
CallDeferred(MethodName.SpawnWeapons);
}
@ -252,25 +235,6 @@ public partial class GameManager : Node2D
}
}
private void SpawnPlayerWeapon(LootItem startingItem)
{
if (WeaponTemplate == null)
{
GD.Print("Could not spawn weapon because template is null");
return;
}
var weapon = _player.CreateChild<Weapon>(WeaponTemplate);
weapon.WeaponData = startingItem.WeaponData;
_player.AddWeapon(weapon);
if (_player.EquippedWeapon == null)
{
_player.EquipWeapon(weapon);
}
}
private void SpawnBulletsContainer()
{
_bulletsContainer = new Node2D();