fixed inventory + using Sync bindings
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

This commit is contained in:
2026-05-04 10:19:00 +02:00
parent 99f383be00
commit bed1384dc7
13 changed files with 258 additions and 124 deletions

View File

@@ -1,6 +1,8 @@
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;
@@ -14,11 +16,13 @@ public partial class WeaponEventAbilityData(WeaponSystem.WeaponEvent forEvent, F
public ForgeAbilityBehavior Ability { get; private set; } = ability;
}
[GlobalClass]
public partial class InventoryManager : Node
[GlobalClass, Meta(typeof(IAutoNode))]
public partial class InventoryManager : Node, IDisposable
{
#region Signals
public override void _Notification(int what) => this.Notify(what);
#region Signals
[Signal]
public delegate void WeaponEventAbilityAddedEventHandler(WeaponEventAbilityData data);
[Signal]
@@ -26,35 +30,52 @@ public partial class InventoryManager : Node
#endregion
public Dictionary<WeaponSystem.WeaponEvent, HashSet<ForgeAbilityBehavior>> WeaponEventsInventory { get; private set; }
= new() {
{ WeaponSystem.WeaponEvent.FlyingTick, [] },
{ WeaponSystem.WeaponEvent.StartedFlying, [] },
{ WeaponSystem.WeaponEvent.StoppedFlying, [] }
};
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)
{
WeaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick] = new HashSet<ForgeAbilityBehavior>(inventory.OnWeaponFlyingTickAbilities);
WeaponEventsInventory[WeaponSystem.WeaponEvent.StartedFlying] = new HashSet<ForgeAbilityBehavior>(inventory.OnWeaponStartedFlyingAbilities);
WeaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying] = new HashSet<ForgeAbilityBehavior>(inventory.OnWeaponStoppedFlyingAbilities);
_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];
var addedAbilityToInventory = inventoryForEvent.Add(abilityBehavior);
if (!addedAbilityToInventory) return;
EmitSignalWeaponEventAbilityAdded(new WeaponEventAbilityData(forEvent, abilityBehavior));
var inventoryForEvent = _weaponEventsInventory[forEvent];
inventoryForEvent.Add(abilityBehavior);
}
public void RemoveAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
{
var inventoryForEvent = WeaponEventsInventory[forEvent];
var removedFromInventory = inventoryForEvent.Remove(abilityBehavior);
if (!removedFromInventory) return;
EmitSignalWeaponEventAbilityRemoved(new WeaponEventAbilityData(forEvent, abilityBehavior));
var inventoryForEvent = _weaponEventsInventory[forEvent];
inventoryForEvent.Remove(abilityBehavior);
}
}