summaryrefslogtreecommitdiff
path: root/scripts/items/ItemPickup.cs
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/items/ItemPickup.cs')
-rw-r--r--scripts/items/ItemPickup.cs35
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();
+ }
+ }
+}