82 lines
3.2 KiB
C#
82 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Chickensoft.AutoInject;
|
|
using Chickensoft.Introspection;
|
|
using Chickensoft.Sync.Primitives;
|
|
using Gamesmiths.Forge.Godot.Resources.Abilities;
|
|
using Godot;
|
|
using Movementtests.systems;
|
|
|
|
namespace Movementtests.managers;
|
|
|
|
public partial class WeaponEventAbilityData(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior ability)
|
|
: RefCounted
|
|
{
|
|
public WeaponSystem.WeaponEvent ForEvent { get; private set; } = forEvent;
|
|
public ForgeAbilityBehavior Ability { get; private set; } = ability;
|
|
}
|
|
|
|
[GlobalClass, Meta(typeof(IAutoNode))]
|
|
public partial class InventoryManager : Node, IDisposable
|
|
{
|
|
public override void _Notification(int what) => this.Notify(what);
|
|
|
|
#region Signals
|
|
|
|
[Signal]
|
|
public delegate void WeaponEventAbilityAddedEventHandler(WeaponEventAbilityData data);
|
|
[Signal]
|
|
public delegate void WeaponEventAbilityRemovedEventHandler(WeaponEventAbilityData data);
|
|
|
|
#endregion
|
|
|
|
private AutoSet<ForgeAbilityBehavior> _startedFlyingAbilities = new();
|
|
private AutoSet<ForgeAbilityBehavior> _flyingTickAbilities = new();
|
|
private AutoSet<ForgeAbilityBehavior> _stoppedFlyingAbilities = new();
|
|
|
|
public IAutoSet<ForgeAbilityBehavior> StartedFlyingAbilities => _startedFlyingAbilities;
|
|
public IAutoSet<ForgeAbilityBehavior> FlyingTickAbilities => _flyingTickAbilities;
|
|
public IAutoSet<ForgeAbilityBehavior> StoppedFlyingAbilities => _stoppedFlyingAbilities;
|
|
|
|
private readonly AutoMap<WeaponSystem.WeaponEvent, AutoSet<ForgeAbilityBehavior>> _weaponEventsInventory = new();
|
|
public IAutoMap<WeaponSystem.WeaponEvent, AutoSet<ForgeAbilityBehavior>> WeaponEventsInventory => _weaponEventsInventory;
|
|
|
|
public void OnReady()
|
|
{
|
|
_weaponEventsInventory[WeaponSystem.WeaponEvent.StartedFlying] = _startedFlyingAbilities;
|
|
_weaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick] = _flyingTickAbilities;
|
|
_weaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying] = _stoppedFlyingAbilities;
|
|
}
|
|
|
|
public void InitializeFromResource(WeaponInventory inventory)
|
|
{
|
|
_startedFlyingAbilities = new AutoSet<ForgeAbilityBehavior>(inventory.OnWeaponStartedFlyingAbilities);
|
|
_flyingTickAbilities = new AutoSet<ForgeAbilityBehavior>(inventory.OnWeaponFlyingTickAbilities);
|
|
_stoppedFlyingAbilities = new AutoSet<ForgeAbilityBehavior>(inventory.OnWeaponStoppedFlyingAbilities);
|
|
}
|
|
|
|
public new void Dispose()
|
|
{
|
|
GC.SuppressFinalize(this);
|
|
|
|
_startedFlyingAbilities.Dispose();
|
|
_flyingTickAbilities.Dispose();
|
|
_stoppedFlyingAbilities.Dispose();
|
|
_weaponEventsInventory.Dispose();
|
|
|
|
base.Dispose();
|
|
}
|
|
|
|
public void AddAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
|
|
{
|
|
var inventoryForEvent = _weaponEventsInventory[forEvent];
|
|
inventoryForEvent.Add(abilityBehavior);
|
|
}
|
|
|
|
public void RemoveAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
|
|
{
|
|
var inventoryForEvent = _weaponEventsInventory[forEvent];
|
|
inventoryForEvent.Remove(abilityBehavior);
|
|
}
|
|
}
|