Files
MovementTests/managers/InventoryManager.cs
Minimata 26f6a619cb
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 28s
Create tag and build when new code gets to main / Export (push) Successful in 6m50s
dependency injection test
2026-04-25 10:18:41 +02:00

56 lines
2.2 KiB
C#

using System.Collections.Generic;
using Gamesmiths.Forge.Godot.Resources.Abilities;
using Godot;
using Movementtests.systems;
namespace Movementtests.managers;
public partial class WeaponEventAbilityData(WeaponSystem.WeaponEvent forEvent, Resource ability)
: RefCounted
{
public WeaponSystem.WeaponEvent ForEvent { get; private set; } = forEvent;
public Resource Ability { get; private set; } = ability;
}
public partial class InventoryManager : Node
{
[Signal]
public delegate void InventoryChangedEventHandler();
[Signal]
public delegate void WeaponEventInventoryChangedEventHandler();
[Signal]
public delegate void WeaponEventAbilityAddedEventHandler(WeaponEventAbilityData data);
[Signal]
public delegate void WeaponEventAbilityRemovedEventHandler(WeaponEventAbilityData data);
public Dictionary<WeaponSystem.WeaponEvent, HashSet<Resource>> WeaponEventsInventory { get; } = [];
public override void _Ready()
{
WeaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick] = new HashSet<Resource>();
WeaponEventsInventory[WeaponSystem.WeaponEvent.StartedFlying] = new HashSet<Resource>();
WeaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying] = new HashSet<Resource>();
}
public void AddAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
{
var inventoryForEvent = WeaponEventsInventory[forEvent];
var addedAbilityToInventory = inventoryForEvent.Add(abilityBehavior);
if (!addedAbilityToInventory) return;
EmitSignalWeaponEventInventoryChanged();
EmitSignalWeaponEventAbilityAdded(new WeaponEventAbilityData(forEvent, abilityBehavior));
}
public void RemoveAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
{
var inventoryForEvent = WeaponEventsInventory[forEvent];
var removedFromInventory = inventoryForEvent.Remove(abilityBehavior);
if (!removedFromInventory) return;
EmitSignalWeaponEventInventoryChanged();
EmitSignalWeaponEventAbilityRemoved(new WeaponEventAbilityData(forEvent, abilityBehavior));
}
}