From 8012c84292405e25ed2ae0e5edf3cb49264d3ba9 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 15 Apr 2024 22:43:26 +0200 Subject: [PATCH] Refactor `Eater` and `Edible` --- behaviours/eater.gd | 6 ++++-- behaviours/edible.gd | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/behaviours/eater.gd b/behaviours/eater.gd index 2ff657c..472fbe8 100644 --- a/behaviours/eater.gd +++ b/behaviours/eater.gd @@ -1,18 +1,20 @@ extends Area2D class_name Eater +## Emits [signal eaten] whenever an [Edible] body with an acceptable [field Edible.diet] enters the given [CollisionShape2D]. + signal eaten(edible: Edible) -@export var tag: StringName +@export var acceptable_diets: Array[StringName] = [] func _on_body_entered(body: Node2D) -> void: var edibles: Array = body.find_children("Edible", "Edible", false, false) for edible in edibles: - if edible.tag == tag: + if edible.diet in acceptable_diets: eaten.emit(edible) edible.eat() diff --git a/behaviours/edible.gd b/behaviours/edible.gd index ee8847a..c18b046 100644 --- a/behaviours/edible.gd +++ b/behaviours/edible.gd @@ -1,13 +1,15 @@ extends Node class_name Edible +## Emits [signal eaten] when eaten by an [Eater] whose acceptable diets contain this node's [field diet]. +## +## To add multiple possible [Edible] diets to an entity, add multiple [Edible] nodes to it. signal eaten +@export var diet: StringName = &"" + + func eat(): eaten.emit() - get_parent().queue_free() - - -@export var tag: StringName