Compare commits

...

1 Commits

Author SHA1 Message Date
bed1384dc7 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
2026-05-04 10:19:00 +02:00
13 changed files with 258 additions and 124 deletions

View File

@@ -130,6 +130,7 @@
<Folder Include="tests\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Chickensoft.Sync" Version="2.3.0" />
<PackageReference Include="RustyOptions" Version="0.10.1" />
</ItemGroup>
<ItemGroup>

View File

@@ -32,12 +32,21 @@ func _exit_tree() -> void:
func close() -> void:
menu_closing.emit()
hide()
queue_free()
func hide_menu() -> void:
_scene_tree.paused = _initial_pause_state
Input.set_mouse_mode(_initial_mouse_mode)
if is_instance_valid(_initial_focus_control) and _initial_focus_control.is_inside_tree():
_initial_focus_control.focus_mode = _initial_focus_mode
_initial_focus_control.grab_focus()
queue_free()
GUIDE.disable_mapping_context(menu_context)
for previous_context in previous_mapping_contexts:
GUIDE.enable_mapping_context(previous_context)
visible = false
func _handle_cancel_input() -> void:
close()
@@ -45,7 +54,7 @@ func _handle_cancel_input() -> void:
func _on_close_button_pressed() -> void:
close()
func _enter_tree() -> void:
func show_menu() -> void:
_scene_tree = get_tree()
_initial_pause_state = _scene_tree.paused
_initial_mouse_mode = Input.get_mouse_mode()
@@ -61,5 +70,11 @@ func _enter_tree() -> void:
for previous_context in previous_mapping_contexts:
GUIDE.disable_mapping_context(previous_context)
GUIDE.enable_mapping_context(menu_context)
visible = true
func _enter_tree() -> void:
print("enter_tree")
show_menu()
back_action.triggered.connect(_handle_cancel_input)

View File

@@ -12,6 +12,7 @@ public class ExplodingSwordBehavior(PackedScene explosion, float radius) : IAbil
{
if (context.Owner is not Node3D owner)
{
GD.Print("Owner isn't a Node3D");
context.InstanceHandle.End();
return;
}
@@ -30,7 +31,6 @@ public class ExplodingSwordBehavior(PackedScene explosion, float radius) : IAbil
}
explo.Radius = radius;
GD.Print("explosion");
owner.GetTree().GetRoot().CallDeferred(Node.MethodName.AddChild, explo);
explo.CallDeferred(Node3D.MethodName.SetGlobalPosition, owner.GlobalPosition);

View File

@@ -1,13 +1,20 @@
using Gamesmiths.Forge.Abilities;
using Gamesmiths.Forge.Effects;
using Gamesmiths.Forge.Godot.Resources;
using Gamesmiths.Forge.Godot.Resources.Abilities;
using Godot;
namespace Movementtests.forge.abilities;
public class InstantEndBehavior : IAbilityBehavior
public class InstantEndBehavior(ForgeEffectData? effectData) : IAbilityBehavior
{
public void OnStarted(AbilityBehaviorContext context)
{
if (effectData != null)
{
var effect = new Effect(effectData.GetEffectData(), new EffectOwnership(context.Owner, context.Owner));
context.Owner.EffectsManager.ApplyEffect(effect);
}
context.AbilityHandle.CommitAbility();
context.InstanceHandle.End();
}
@@ -19,5 +26,6 @@ public class InstantEndBehavior : IAbilityBehavior
[GlobalClass]
public partial class ForgeInstantEndBehavior : ForgeAbilityBehavior
{
public override IAbilityBehavior GetBehavior() => new InstantEndBehavior();
[Export] public ForgeEffectData? OptionalEffectData { get; set; }
public override IAbilityBehavior GetBehavior() => new InstantEndBehavior(OptionalEffectData);
}

View File

@@ -1,84 +1,21 @@
[gd_resource type="Resource" script_class="ForgeAbilityData" format=3 uid="uid://dccuj66egxfwh"]
[ext_resource type="Resource" uid="uid://c4ea6ktafqe0r" path="res://forge/resources/effect_datas/temp_invincibility.tres" id="1_ent4t"]
[ext_resource type="Script" uid="uid://c7s5v7ii4nujg" path="res://forge/abilities/ForgeInstantEndBehavior.cs" id="2_ent4t"]
[ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="2_prg0a"]
[ext_resource type="Script" uid="uid://dngf30hxy5go4" path="res://addons/forge/resources/components/ModifierTags.cs" id="3_k72m0"]
[ext_resource type="Script" uid="uid://cn3b4ya15fg7e" path="res://addons/forge/resources/magnitudes/ForgeScalableFloat.cs" id="4_5fdax"]
[ext_resource type="Script" uid="uid://2gm1hdhi8u08" path="res://addons/forge/resources/magnitudes/ForgeModifierMagnitude.cs" id="5_5qmmj"]
[ext_resource type="Script" uid="uid://1hgogislo1l6" path="res://addons/forge/resources/magnitudes/ForgeScalableInt.cs" id="6_yi0bg"]
[ext_resource type="Script" uid="uid://b83hf13nj37k3" path="res://addons/forge/resources/ForgeEffectData.cs" id="7_0rp6y"]
[ext_resource type="Script" uid="uid://cl5hudinl1rex" path="res://forge/abilities/ForgeEffectApplicationBehavior.cs" id="7_ent4t"]
[ext_resource type="Resource" uid="uid://dn7b8frkoxpxr" path="res://forge/resources/cues/player_mana_changed_cue.tres" id="8_0olwd"]
[ext_resource type="Resource" uid="uid://cw2ytd34jsxj" path="res://forge/resources/tag_containers/immune_damage.tres" id="8_ent4t"]
[ext_resource type="Script" uid="uid://bdfcavbjyhxxa" path="res://addons/forge/resources/ForgeModifier.cs" id="9_wluo0"]
[ext_resource type="Script" uid="uid://dhxfbxh54pyxp" path="res://addons/forge/resources/abilities/ForgeAbilityData.cs" id="10_2sq4o"]
[sub_resource type="Resource" id="Resource_xltxv"]
script = ExtResource("3_k72m0")
TagsToAdd = ExtResource("8_ent4t")
metadata/_custom_type_script = "uid://dngf30hxy5go4"
[sub_resource type="Resource" id="Resource_60xl1"]
script = ExtResource("4_5fdax")
BaseValue = 1.0
[sub_resource type="Resource" id="Resource_2rev5"]
script = ExtResource("4_5fdax")
[sub_resource type="Resource" id="Resource_kxytj"]
script = ExtResource("4_5fdax")
[sub_resource type="Resource" id="Resource_e5nje"]
script = ExtResource("4_5fdax")
BaseValue = 1.0
[sub_resource type="Resource" id="Resource_xc8ja"]
script = ExtResource("4_5fdax")
[sub_resource type="Resource" id="Resource_tan32"]
script = ExtResource("4_5fdax")
[sub_resource type="Resource" id="Resource_l52b0"]
script = ExtResource("4_5fdax")
BaseValue = 0.3
metadata/_custom_type_script = "uid://cn3b4ya15fg7e"
[sub_resource type="Resource" id="Resource_6jn6y"]
script = ExtResource("5_5qmmj")
ScalableFloat = SubResource("Resource_l52b0")
Coefficient = SubResource("Resource_e5nje")
PreMultiplyAdditiveValue = SubResource("Resource_tan32")
PostMultiplyAdditiveValue = SubResource("Resource_xc8ja")
CalculatorCoefficient = SubResource("Resource_60xl1")
CalculatorPreMultiplyAdditiveValue = SubResource("Resource_kxytj")
CalculatorPostMultiplyAdditiveValue = SubResource("Resource_2rev5")
metadata/_custom_type_script = "uid://2gm1hdhi8u08"
[sub_resource type="Resource" id="Resource_ev6w4"]
script = ExtResource("6_yi0bg")
BaseValue = 1
[sub_resource type="Resource" id="Resource_u8xa8"]
script = ExtResource("6_yi0bg")
BaseValue = 1
[sub_resource type="Resource" id="Resource_xsfte"]
script = ExtResource("7_0rp6y")
Name = "ApplyInvincibility"
Modifiers = []
Components = Array[Object]([SubResource("Resource_xltxv")])
Executions = null
DurationType = 2
Duration = SubResource("Resource_6jn6y")
StackLimit = SubResource("Resource_u8xa8")
InitialStack = SubResource("Resource_ev6w4")
Cues = null
metadata/_custom_type_script = "uid://b83hf13nj37k3"
[sub_resource type="Resource" id="Resource_xh53a"]
script = ExtResource("7_ent4t")
EffectData = SubResource("Resource_xsfte")
Name = "Apply invincibility"
metadata/_custom_type_script = "uid://cl5hudinl1rex"
script = ExtResource("2_ent4t")
OptionalEffectData = ExtResource("1_ent4t")
metadata/_custom_type_script = "uid://c7s5v7ii4nujg"
[sub_resource type="Resource" id="Resource_h116a"]
script = ExtResource("2_prg0a")
@@ -245,5 +182,5 @@ script = ExtResource("10_2sq4o")
Name = "Empowered Action"
CooldownEffects = [SubResource("Resource_egh2b")]
CostEffect = SubResource("Resource_mtef8")
AbilityBehavior = SubResource("Resource_xh53a")
AbilityBehavior = SubResource("Resource_xltxv")
metadata/_custom_type_script = "uid://dhxfbxh54pyxp"

View File

@@ -0,0 +1,70 @@
[gd_resource type="Resource" script_class="ForgeEffectData" format=3 uid="uid://c4ea6ktafqe0r"]
[ext_resource type="Resource" uid="uid://cw2ytd34jsxj" path="res://forge/resources/tag_containers/immune_damage.tres" id="1_suvh6"]
[ext_resource type="Script" uid="uid://dngf30hxy5go4" path="res://addons/forge/resources/components/ModifierTags.cs" id="2_7y7k0"]
[ext_resource type="Script" uid="uid://cn3b4ya15fg7e" path="res://addons/forge/resources/magnitudes/ForgeScalableFloat.cs" id="3_wdmyo"]
[ext_resource type="Script" uid="uid://2gm1hdhi8u08" path="res://addons/forge/resources/magnitudes/ForgeModifierMagnitude.cs" id="4_m2dme"]
[ext_resource type="Script" uid="uid://1hgogislo1l6" path="res://addons/forge/resources/magnitudes/ForgeScalableInt.cs" id="5_uck3v"]
[ext_resource type="Script" uid="uid://b83hf13nj37k3" path="res://addons/forge/resources/ForgeEffectData.cs" id="6_gt48y"]
[sub_resource type="Resource" id="Resource_xltxv"]
script = ExtResource("2_7y7k0")
TagsToAdd = ExtResource("1_suvh6")
metadata/_custom_type_script = "uid://dngf30hxy5go4"
[sub_resource type="Resource" id="Resource_60xl1"]
script = ExtResource("3_wdmyo")
BaseValue = 1.0
[sub_resource type="Resource" id="Resource_2rev5"]
script = ExtResource("3_wdmyo")
[sub_resource type="Resource" id="Resource_kxytj"]
script = ExtResource("3_wdmyo")
[sub_resource type="Resource" id="Resource_e5nje"]
script = ExtResource("3_wdmyo")
BaseValue = 1.0
[sub_resource type="Resource" id="Resource_xc8ja"]
script = ExtResource("3_wdmyo")
[sub_resource type="Resource" id="Resource_tan32"]
script = ExtResource("3_wdmyo")
[sub_resource type="Resource" id="Resource_l52b0"]
script = ExtResource("3_wdmyo")
BaseValue = 0.3
metadata/_custom_type_script = "uid://cn3b4ya15fg7e"
[sub_resource type="Resource" id="Resource_6jn6y"]
script = ExtResource("4_m2dme")
ScalableFloat = SubResource("Resource_l52b0")
Coefficient = SubResource("Resource_e5nje")
PreMultiplyAdditiveValue = SubResource("Resource_tan32")
PostMultiplyAdditiveValue = SubResource("Resource_xc8ja")
CalculatorCoefficient = SubResource("Resource_60xl1")
CalculatorPreMultiplyAdditiveValue = SubResource("Resource_kxytj")
CalculatorPostMultiplyAdditiveValue = SubResource("Resource_2rev5")
metadata/_custom_type_script = "uid://2gm1hdhi8u08"
[sub_resource type="Resource" id="Resource_ev6w4"]
script = ExtResource("5_uck3v")
BaseValue = 1
[sub_resource type="Resource" id="Resource_u8xa8"]
script = ExtResource("5_uck3v")
BaseValue = 1
[resource]
script = ExtResource("6_gt48y")
Name = "ApplyInvincibility"
Modifiers = []
Components = Array[Object]([SubResource("Resource_xltxv")])
Executions = []
DurationType = 2
Duration = SubResource("Resource_6jn6y")
StackLimit = SubResource("Resource_u8xa8")
InitialStack = SubResource("Resource_ev6w4")
Cues = []
metadata/_custom_type_script = "uid://b83hf13nj37k3"

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,9 +16,11 @@ 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
{
public override void _Notification(int what) => this.Notify(what);
#region Signals
[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);
}
}

View File

@@ -90,4 +90,12 @@ public partial class AbilitySelection : Control
return;
}
}
public void ClearAbilities()
{
foreach (var child in SelectedAbilities.GetChildren())
{
SelectedAbilities.RemoveChild(child);
}
}
}

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.Effects;
using Gamesmiths.Forge.Godot.Resources.Abilities;
using Godot;
@@ -9,7 +11,7 @@ using Movementtests.systems;
[Tool, GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_crate.png"), Meta(typeof(IAutoNode))]
public partial class InventoryUi : Control
public partial class InventoryUi : Control, IDisposable
{
public override void _Notification(int what) => this.Notify(what);
@@ -27,6 +29,10 @@ public partial class InventoryUi : Control
public required AbilitySelection StoppedFlying { 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 void OnReady()
{
StartedFlying.AbilityAdded += AddAbilityForEvent;
@@ -44,14 +50,32 @@ public partial class InventoryUi : Control
WhileFlying.Initialize(InventoryManager.WeaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick]);
StoppedFlying.Initialize(InventoryManager.WeaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying]);
InventoryManager.WeaponEventAbilityAdded += OnWeaponEventInventoryAdded;
InventoryManager.WeaponEventAbilityRemoved += OnWeaponEventInventoryRemoved;
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));
}
public void OnExitTree()
public new void Dispose()
{
InventoryManager.WeaponEventAbilityAdded -= OnWeaponEventInventoryAdded;
InventoryManager.WeaponEventAbilityRemoved -= OnWeaponEventInventoryRemoved;
GC.SuppressFinalize(this);
StartedFlying.Dispose();
WhileFlying.Dispose();
StoppedFlying.Dispose();
base.Dispose();
}
public void AddAbilityForEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
@@ -64,16 +88,22 @@ public partial class InventoryUi : Control
InventoryManager.RemoveAbilityForWeaponEvent(forEvent, abilityBehavior);
}
public void OnWeaponEventInventoryAdded(WeaponEventAbilityData data)
public void OnWeaponEventInventoryAdded(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
{
var selection = GetAbilitySelection(data.ForEvent);
selection.AddSelectedAbility(data.Ability);
var selection = GetAbilitySelection(forEvent);
selection.AddSelectedAbility(abilityBehavior);
}
public void OnWeaponEventInventoryRemoved(WeaponEventAbilityData data)
public void OnWeaponEventInventoryRemoved(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
{
var selection = GetAbilitySelection(data.ForEvent);
selection.RemoveSelectedAbility(data.Ability);
var selection = GetAbilitySelection(forEvent);
selection.RemoveSelectedAbility(abilityBehavior);
}
public void OnWeaponEventInventoryCleared(WeaponSystem.WeaponEvent forEvent)
{
var selection = GetAbilitySelection(forEvent);
selection.ClearAbilities();
}
public AbilitySelection GetAbilitySelection(WeaponSystem.WeaponEvent forEvent)

View File

@@ -8,5 +8,8 @@ extends OverlaidMenu
func _ready() -> void:
if Engine.is_editor_hint(): return
func _handle_cancel_input() -> void:
hide_menu()
func _on_close_button_pressed() -> void:
close()
hide_menu()

View File

@@ -342,6 +342,12 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
public void RemoveAllEventAbilities()
{
foreach (var weaponEvent in Enum.GetValues<WeaponEvent>())
{
RemoveAbilitiesForEvent(weaponEvent);
}
}
public void RemoveAbilitiesForEvent(WeaponEvent weaponEvent)
{
var abilities = GetGrantedAbilities(weaponEvent);
foreach (var ability in abilities.Values)
@@ -350,7 +356,6 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
}
abilities.Clear();
}
}
public Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> GetGrantedAbilities(WeaponEvent forEvent)
{

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Chickensoft.Sync.Primitives;
using Gamesmiths.Forge.Abilities;
using Gamesmiths.Forge.Attributes;
using Gamesmiths.Forge.Core;
@@ -34,7 +35,7 @@ public record struct EmpoweredActionPayload;
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_character.png"), Meta(typeof(IAutoNode))]
public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandler
public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandler, IDisposable
{
public override void _Notification(int what) => this.Notify(what);
@@ -743,14 +744,45 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
}
// Inventory changes signal binding
InventoryManager.WeaponEventAbilityAdded += OnWeaponEventAbilityAdded;
InventoryManager.WeaponEventAbilityRemoved += OnWeaponEventAbilityRemoved;
StartedFlyingBinding = InventoryManager.StartedFlyingAbilities.Bind();
StartedFlyingBinding
.OnAdd(behavior => WeaponSystem.GrantNewAbilityForEvent(WeaponSystem.WeaponEvent.StartedFlying, behavior))
.OnRemove(behavior => WeaponSystem.RemoveAbilityForEvent(WeaponSystem.WeaponEvent.StartedFlying, behavior))
.OnClear(() => WeaponSystem.RemoveAbilitiesForEvent(WeaponSystem.WeaponEvent.StartedFlying));
FlyingTickBinding = InventoryManager.FlyingTickAbilities.Bind();
FlyingTickBinding
.OnAdd(behavior => WeaponSystem.GrantNewAbilityForEvent(WeaponSystem.WeaponEvent.FlyingTick, behavior))
.OnRemove(behavior => WeaponSystem.RemoveAbilityForEvent(WeaponSystem.WeaponEvent.FlyingTick, behavior))
.OnClear(() => WeaponSystem.RemoveAbilitiesForEvent(WeaponSystem.WeaponEvent.FlyingTick));
StoppedFlyingBinding = InventoryManager.StoppedFlyingAbilities.Bind();
StoppedFlyingBinding
.OnAdd(behavior => WeaponSystem.GrantNewAbilityForEvent(WeaponSystem.WeaponEvent.StoppedFlying, behavior))
.OnRemove(behavior => WeaponSystem.RemoveAbilityForEvent(WeaponSystem.WeaponEvent.StoppedFlying, behavior))
.OnClear(() => WeaponSystem.RemoveAbilitiesForEvent(WeaponSystem.WeaponEvent.StoppedFlying));
// InventoryManager.WeaponEventAbilityAdded += OnWeaponEventAbilityAdded;
// InventoryManager.WeaponEventAbilityRemoved += OnWeaponEventAbilityRemoved;
}
public AutoSet<ForgeAbilityBehavior>.Binding StartedFlyingBinding { get; set; }
public AutoSet<ForgeAbilityBehavior>.Binding FlyingTickBinding { get; set; }
public AutoSet<ForgeAbilityBehavior>.Binding StoppedFlyingBinding { get; set; }
public new void Dispose()
{
GC.SuppressFinalize(this);
StartedFlyingBinding.Dispose();
FlyingTickBinding.Dispose();
StoppedFlyingBinding.Dispose();
base.Dispose();
}
public void OnExitTree()
{
InventoryManager.WeaponEventAbilityAdded -= OnWeaponEventAbilityAdded;
InventoryManager.WeaponEventAbilityRemoved -= OnWeaponEventAbilityRemoved;
// InventoryManager.WeaponEventAbilityAdded -= OnWeaponEventAbilityAdded;
// InventoryManager.WeaponEventAbilityRemoved -= OnWeaponEventAbilityRemoved;
}
#endregion

View File

@@ -21,6 +21,8 @@ extends Node
@onready var inventory_layer: CanvasLayer = $"../InventoryLayer"
@onready var player: PlayerController = $"../Player"
var inventory: OverlaidMenu = null
func _ready() -> void:
toolbox_action.triggered.connect(open_toolbox)
inventory_action.triggered.connect(open_inventory)
@@ -37,9 +39,11 @@ func open_toolbox() -> void:
debug_layer.call_deferred("add_child", toolbox)
func open_inventory() -> void:
var inventory: Control = open_overlaid_menu(inventory_scene)
# inventory.player = player
if inventory == null:
inventory = open_overlaid_menu(inventory_scene)
inventory_layer.call_deferred("add_child", inventory)
return
inventory.show_menu()
func on_player_died() -> void:
var lost_menu: LevelLostMenu = open_overlaid_menu(lost_menu_scene)