More weapon events and abilities
This commit is contained in:
@@ -14,6 +14,11 @@ using Movementtests.systems;
|
||||
public partial class InventoryUi : Control, IDisposable
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
public record struct EventElements(
|
||||
AbilitySelection AbilitySelection,
|
||||
AutoSet<ForgeAbilityBehavior>.Binding Binding,
|
||||
IAutoSet<ForgeAbilityBehavior> Inventory);
|
||||
|
||||
#region Dependencies
|
||||
[Dependency]
|
||||
@@ -27,53 +32,67 @@ public partial class InventoryUi : Control, IDisposable
|
||||
public required AbilitySelection WhileFlying { get; set; }
|
||||
[Node]
|
||||
public required AbilitySelection StoppedFlying { get; set; }
|
||||
|
||||
[Node]
|
||||
public required AbilitySelection StartedPlanted { get; set; }
|
||||
[Node]
|
||||
public required AbilitySelection WhilePlanted { get; set; }
|
||||
[Node]
|
||||
public required AbilitySelection StoppedPlanted { get; set; }
|
||||
#endregion Nodes
|
||||
|
||||
public AutoSet<ForgeAbilityBehavior>.Binding StartedFlyingBinding { get; set; }
|
||||
public AutoSet<ForgeAbilityBehavior>.Binding FlyingTickBinding { get; set; }
|
||||
public AutoSet<ForgeAbilityBehavior>.Binding StoppedFlyingBinding { get; set; }
|
||||
public required AutoSet<ForgeAbilityBehavior>.Binding StartedFlyingBinding { get; set; }
|
||||
public required AutoSet<ForgeAbilityBehavior>.Binding FlyingTickBinding { get; set; }
|
||||
public required AutoSet<ForgeAbilityBehavior>.Binding StoppedFlyingBinding { get; set; }
|
||||
|
||||
public required AutoSet<ForgeAbilityBehavior>.Binding StartedPlantedBinding { get; set; }
|
||||
public required AutoSet<ForgeAbilityBehavior>.Binding PlantedTickBinding { get; set; }
|
||||
public required AutoSet<ForgeAbilityBehavior>.Binding StoppedPlantedBinding { get; set; }
|
||||
|
||||
public Dictionary<WeaponSystem.WeaponEvent, EventElements> EventElementsMap { get; private set; } = [];
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
StartedFlying.AbilityAdded += AddAbilityForEvent;
|
||||
WhileFlying.AbilityAdded += AddAbilityForEvent;
|
||||
StoppedFlying.AbilityAdded += AddAbilityForEvent;
|
||||
|
||||
StartedFlying.AbilityRemoved += RemoveAbilityForEvent;
|
||||
WhileFlying.AbilityRemoved += RemoveAbilityForEvent;
|
||||
StoppedFlying.AbilityRemoved += RemoveAbilityForEvent;
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
StartedFlying.Initialize(InventoryManager.WeaponEventsInventory[WeaponSystem.WeaponEvent.StartedFlying]);
|
||||
WhileFlying.Initialize(InventoryManager.WeaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick]);
|
||||
StoppedFlying.Initialize(InventoryManager.WeaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying]);
|
||||
EventElementsMap = new Dictionary<WeaponSystem.WeaponEvent, EventElements>
|
||||
{
|
||||
{ WeaponSystem.WeaponEvent.StartedFlying, new EventElements(StartedFlying, StartedFlyingBinding, InventoryManager.StartedFlyingAbilities) },
|
||||
{ WeaponSystem.WeaponEvent.StoppedFlying, new EventElements(StoppedFlying, StoppedFlyingBinding, InventoryManager.StoppedFlyingAbilities)},
|
||||
{ WeaponSystem.WeaponEvent.FlyingTick, new EventElements(WhileFlying, FlyingTickBinding, InventoryManager.FlyingTickAbilities) },
|
||||
|
||||
{ WeaponSystem.WeaponEvent.StartedPlanted, new EventElements(StartedPlanted, StartedPlantedBinding, InventoryManager.StartedPlantedAbilities) },
|
||||
{ WeaponSystem.WeaponEvent.StoppedPlanted, new EventElements(StoppedPlanted, StoppedPlantedBinding, InventoryManager.StoppedPlantedAbilities) },
|
||||
{ WeaponSystem.WeaponEvent.PlantedTick, new EventElements(WhilePlanted, PlantedTickBinding, InventoryManager.PlantedTickAbilities) },
|
||||
};
|
||||
|
||||
StartedFlyingBinding = InventoryManager.StartedFlyingAbilities.Bind();
|
||||
StartedFlyingBinding
|
||||
.OnAdd(behavior => OnWeaponEventInventoryAdded(WeaponSystem.WeaponEvent.StartedFlying, behavior))
|
||||
.OnRemove(behavior => OnWeaponEventInventoryRemoved(WeaponSystem.WeaponEvent.StartedFlying, behavior))
|
||||
.OnClear(() => OnWeaponEventInventoryCleared(WeaponSystem.WeaponEvent.StartedFlying));
|
||||
FlyingTickBinding = InventoryManager.FlyingTickAbilities.Bind();
|
||||
FlyingTickBinding
|
||||
.OnAdd(behavior => OnWeaponEventInventoryAdded(WeaponSystem.WeaponEvent.FlyingTick, behavior))
|
||||
.OnRemove(behavior => OnWeaponEventInventoryRemoved(WeaponSystem.WeaponEvent.FlyingTick, behavior))
|
||||
.OnClear(() => OnWeaponEventInventoryCleared(WeaponSystem.WeaponEvent.FlyingTick));
|
||||
StoppedFlyingBinding = InventoryManager.StoppedFlyingAbilities.Bind();
|
||||
StoppedFlyingBinding
|
||||
.OnAdd(behavior => OnWeaponEventInventoryAdded(WeaponSystem.WeaponEvent.StoppedFlying, behavior))
|
||||
.OnRemove(behavior => OnWeaponEventInventoryRemoved(WeaponSystem.WeaponEvent.StoppedFlying, behavior))
|
||||
.OnClear(() => OnWeaponEventInventoryCleared(WeaponSystem.WeaponEvent.StoppedFlying));
|
||||
foreach (var (forEvent, element) in EventElementsMap)
|
||||
{
|
||||
element.AbilitySelection.AbilityAdded += AddAbilityForEvent;
|
||||
element.AbilitySelection.AbilityRemoved += RemoveAbilityForEvent;
|
||||
|
||||
var elem = EventElementsMap[forEvent];
|
||||
elem.AbilitySelection.Initialize(InventoryManager.WeaponEventsInventory[forEvent]);
|
||||
elem.Binding = element.Inventory.Bind();
|
||||
elem.Binding
|
||||
.OnAdd(behavior => OnWeaponEventInventoryAdded(forEvent, behavior))
|
||||
.OnRemove(behavior => OnWeaponEventInventoryRemoved(forEvent, behavior))
|
||||
.OnClear(() => OnWeaponEventInventoryCleared(forEvent));
|
||||
}
|
||||
|
||||
foreach (var forEvent in EventElementsMap.Keys)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
StartedFlying.Dispose();
|
||||
WhileFlying.Dispose();
|
||||
StoppedFlying.Dispose();
|
||||
foreach (var element in EventElementsMap.Values)
|
||||
element.Binding.Dispose();
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
@@ -108,13 +127,6 @@ public partial class InventoryUi : Control, IDisposable
|
||||
|
||||
public AbilitySelection GetAbilitySelection(WeaponSystem.WeaponEvent forEvent)
|
||||
{
|
||||
var abilitiesSelectionsMap = new Dictionary<WeaponSystem.WeaponEvent, AbilitySelection>
|
||||
{
|
||||
{ WeaponSystem.WeaponEvent.StartedFlying, StartedFlying },
|
||||
{ WeaponSystem.WeaponEvent.StoppedFlying, StoppedFlying },
|
||||
{ WeaponSystem.WeaponEvent.FlyingTick, WhileFlying },
|
||||
};
|
||||
|
||||
return abilitiesSelectionsMap[forEvent];
|
||||
return EventElementsMap[forEvent].AbilitySelection;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user