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

42 lines
1.3 KiB
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.
var total_value: int = 0
## The types of [Collectible]s to value.
##
## The strings will match only if exactly the same.
2023-10-01 12:43:52 +00:00
#@export var collecting_types: Array[StringName]
## The collision mask to check colliding body against.
@export_flags_2d_physics var collecting_collision_mask: int
2023-10-01 12:43:52 +00:00
## The evaluator has added the value of an object to the total.
signal added(what: PhysicsBody2D)
2023-10-01 12:43:52 +00:00
## The evaluator has removed the value of an object to the total.
signal removed(what: PhysicsBody2D)
2023-10-01 12:43:52 +00:00
func _on_body_entered(body):
if body is PhysicsBody2D:
if body.collision_layer & collecting_collision_mask:
var evaluable: Valuable = body.get_node("Valuable")
print("sommato")
total_value += evaluable.value
evaluable.evaluate()
added.emit(body)
print("totale= "+str(total_value))
func _on_body_exited(body):
if body is PhysicsBody2D:
if body.collision_layer & collecting_collision_mask:
var evaluable: Valuable = body.get_node("Valuable")
print("sottratto")
total_value -= evaluable.value
evaluable.evaluate()
added.emit(body)
print("totale= "+str(total_value))