diff options
| author | alex <[email protected]> | 2026-11-23 12:00:20 +0100 |
|---|---|---|
| committer | alex <[email protected]> | 2026-11-23 12:00:20 +0100 |
| commit | 7f4bd1856869d7ae10fa8f07708fbd75c5bb7b1e (patch) | |
| tree | e1fa2d87a79bc8bae87da9e62b19521fe27643e5 /scripts/items/ItemPickup.cs | |
| parent | 45326f4f10ba2af92ff5d35f0f63e1dc35a4f8eb (diff) | |
| download | godot-testing-7f4bd1856869d7ae10fa8f07708fbd75c5bb7b1e.tar.xz godot-testing-7f4bd1856869d7ae10fa8f07708fbd75c5bb7b1e.zip | |
pesitems
Diffstat (limited to 'scripts/items/ItemPickup.cs')
| -rw-r--r-- | scripts/items/ItemPickup.cs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/scripts/items/ItemPickup.cs b/scripts/items/ItemPickup.cs new file mode 100644 index 0000000..df5d997 --- /dev/null +++ b/scripts/items/ItemPickup.cs @@ -0,0 +1,35 @@ +using Godot; + +public partial class ItemPickup : Area2D +{ + [Export] public ItemDefinition? Item { get; set; } + + public override void _Ready() + { + BodyEntered += OnBodyEntered; + } + + private void OnBodyEntered(Node2D body) + { + if (!body.IsInGroup("player") || Item == null) + { + return; + } + + PlayerBuildComponent? build = body.GetNodeOrNull<PlayerBuildComponent>("PlayerBuildComponent"); + if (build == null) + { + GD.PrintErr("[ItemPickup] PlayerBuildComponent missing on player."); + return; + } + + bool applied = Item.Type == ItemDefinition.ItemType.Passive + ? build.AddPassiveItem(Item) + : build.EquipWeaponItem(Item); + + if (applied) + { + QueueFree(); + } + } +} |
