92 lines
3.6 KiB
C#
92 lines
3.6 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;
|
|
|
|
|
|
[GlobalClass, Meta(typeof(IAutoNode))]
|
|
public partial class InventoryManager : Node, IDisposable
|
|
{
|
|
public override void _Notification(int what) => this.Notify(what);
|
|
|
|
private AutoSet<ForgeAbilityBehavior> _startedFlyingAbilities = new();
|
|
private AutoSet<ForgeAbilityBehavior> _flyingTickAbilities = new();
|
|
private AutoSet<ForgeAbilityBehavior> _stoppedFlyingAbilities = new();
|
|
|
|
private AutoSet<ForgeAbilityBehavior> _startedPlantedAbilities = new();
|
|
private AutoSet<ForgeAbilityBehavior> _plantedTickAbilities = new();
|
|
private AutoSet<ForgeAbilityBehavior> _stoppedPlantedAbilities = new();
|
|
|
|
public IAutoSet<ForgeAbilityBehavior> StartedFlyingAbilities => _startedFlyingAbilities;
|
|
public IAutoSet<ForgeAbilityBehavior> FlyingTickAbilities => _flyingTickAbilities;
|
|
public IAutoSet<ForgeAbilityBehavior> StoppedFlyingAbilities => _stoppedFlyingAbilities;
|
|
|
|
public IAutoSet<ForgeAbilityBehavior> StartedPlantedAbilities => _startedPlantedAbilities;
|
|
public IAutoSet<ForgeAbilityBehavior> PlantedTickAbilities => _plantedTickAbilities;
|
|
public IAutoSet<ForgeAbilityBehavior> StoppedPlantedAbilities => _stoppedPlantedAbilities;
|
|
|
|
private readonly AutoMap<WeaponSystem.WeaponEvent, AutoSet<ForgeAbilityBehavior>> _weaponEventsInventory = new();
|
|
public IAutoMap<WeaponSystem.WeaponEvent, AutoSet<ForgeAbilityBehavior>> WeaponEventsInventory => _weaponEventsInventory;
|
|
|
|
public Dictionary<WeaponSystem.WeaponEvent, AutoSet<ForgeAbilityBehavior>> GetEventElements()
|
|
{
|
|
return new Dictionary<WeaponSystem.WeaponEvent, AutoSet<ForgeAbilityBehavior>>
|
|
{
|
|
{ WeaponSystem.WeaponEvent.StartedFlying, _startedFlyingAbilities },
|
|
{ WeaponSystem.WeaponEvent.StoppedFlying, _stoppedFlyingAbilities},
|
|
{ WeaponSystem.WeaponEvent.FlyingTick, _flyingTickAbilities },
|
|
|
|
{ WeaponSystem.WeaponEvent.StartedPlanted, _startedPlantedAbilities },
|
|
{ WeaponSystem.WeaponEvent.StoppedPlanted, _stoppedPlantedAbilities },
|
|
{ WeaponSystem.WeaponEvent.PlantedTick, _plantedTickAbilities },
|
|
};
|
|
}
|
|
|
|
public void OnReady()
|
|
{
|
|
foreach (var (forEvent, behaviorSet) in GetEventElements())
|
|
{
|
|
_weaponEventsInventory[forEvent] = behaviorSet;
|
|
}
|
|
}
|
|
|
|
public void InitializeFromResource(WeaponInventory inventory)
|
|
{
|
|
var elements = GetEventElements();
|
|
foreach (var forEvent in elements.Keys)
|
|
{
|
|
elements[forEvent] = new AutoSet<ForgeAbilityBehavior>(inventory.EventMap[forEvent]);
|
|
}
|
|
}
|
|
|
|
public new void Dispose()
|
|
{
|
|
GC.SuppressFinalize(this);
|
|
|
|
foreach (var element in GetEventElements().Values)
|
|
element.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);
|
|
}
|
|
}
|