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

35 lines
966 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-02 00:53:12 +00:00
func _on_body_entered(body: Node2D):
if body is PhysicsBody2D:
var valuable: Valuable = body.find_child("Valuable", false, false)
if valuable:
total += valuable.value
added.emit(valuable, total)
changed.emit(total)
2023-10-01 12:43:52 +00:00
2023-10-02 00:53:12 +00:00
func _on_body_exited(body: Node2D):
if body is PhysicsBody2D:
var valuable: Valuable = body.find_child("Valuable", false, false)
if valuable:
total -= valuable.value
removed.emit(valuable, total)
changed.emit(total)