1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-22 15:44:21 +00:00
swear-jar/value/evaluator.gd

31 lines
850 B
GDScript3
Raw Normal View History

extends Area2D
class_name Evaluator
## aggiunge al totale i valori dei Valuable che ci body_enterano e sottrae quelli che ci body_exitano
## The current amount of value evaluated.
2023-10-01 23:36:23 +00:00
var total: int = 0
2023-10-01 12:43:52 +00:00
## The evaluator has added the value of an object to the total.
2023-10-01 23:36:23 +00:00
signal added(what: Valuable, total: int)
2023-10-01 12:43:52 +00:00
## The evaluator has removed the value of an object to the total.
2023-10-01 23:36:23 +00:00
signal removed(what: Valuable, total: int)
## The total value of the evaluated items has changed.
signal changed(total: int)
2023-10-01 23:36:23 +00:00
func _on_body_entered(body: PhysicsBody2D):
var valuable: Valuable = body.get_node("Valuable")
total += valuable.value
added.emit(valuable, total)
changed.emit(total)
2023-10-01 12:43:52 +00:00
2023-10-01 23:36:23 +00:00
func _on_body_exited(body: PhysicsBody2D):
var valuable: Valuable = body.get_node("Valuable")
total -= valuable.value
removed.emit(valuable, total)
changed.emit(total)