Files
MovementTests/managers/InventoryManager.cs
Minimata bed1384dc7
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 57s
Create tag and build when new code gets to main / Export (push) Successful in 5m13s
fixed inventory + using Sync bindings
2026-05-04 10:19:00 +02:00

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);
}
}