Inventory management of granted abilities

This commit is contained in:
2026-04-21 11:38:04 +02:00
parent 667d6b2588
commit b0fe2549ea
18 changed files with 322 additions and 92 deletions

View File

@@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using Gamesmiths.Forge.Godot.Resources.Abilities;
using Godot;
using Movementtests.systems;
namespace Movementtests.managers;
public partial class WeaponEventInventoryChangedData(WeaponSystem.WeaponEvent forEvent, string abilityName)
public partial class WeaponEventAbilityData(WeaponSystem.WeaponEvent forEvent, Resource ability)
: RefCounted
{
public WeaponSystem.WeaponEvent ForEvent { get; private set; } = forEvent;
public string Ability { get; private set; } = abilityName;
public Resource Ability { get; private set; } = ability;
}
public partial class InventoryManager : Node
@@ -18,19 +18,41 @@ public partial class InventoryManager : Node
public delegate void InventoryChangedEventHandler();
[Signal]
public delegate void WeaponEventInventoryChangedEventHandler(WeaponEventInventoryChangedData data);
public delegate void WeaponEventInventoryChangedEventHandler();
[Signal]
public delegate void WeaponEventAbilityAddedEventHandler(WeaponEventAbilityData data);
[Signal]
public delegate void WeaponEventAbilityRemovedEventHandler(WeaponEventAbilityData data);
public Dictionary<string, Resource> Inventory { get; } = new();
public Dictionary<WeaponSystem.WeaponEvent, HashSet<Resource>> WeaponEventsInventory { get; } = [];
public static InventoryManager Instance { get; private set; }
public override void _Ready()
{
Instance = this;
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, string abilityName)
public void AddAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
{
EmitSignalWeaponEventInventoryChanged(new WeaponEventInventoryChangedData(forEvent, abilityName));
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));
}
}