1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2025-02-16 17:13:58 +00:00
hella-farm/behaviours/counter.gd

33 lines
597 B
GDScript3
Raw Normal View History

2024-04-15 23:45:42 +02:00
@icon("res://behaviours/counter.svg")
extends Node
class_name Counter
2024-04-15 22:39:43 +02:00
## Counts up or down from a starting value.
2024-04-24 04:43:27 +02:00
signal changed(new: int, old: int)
@export var starting_value: int
2024-04-15 22:39:43 +02:00
var value: int = 0
func change(amount: int):
var old = value
value = amount
2024-04-26 02:15:39 +02:00
changed.emit(value, old)
func increase(amount: int = 1):
if amount < 0:
Log.w(self, "Increasing a counter by a negative value.")
change(value + amount)
func decrease(amount: int = 1):
if amount < 0:
Log.w(self, "Decreasing a counter by a negative value.")
change(value - amount)
2024-04-15 22:39:43 +02:00
func _ready():
value = starting_value