mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-24 17:14:23 +00:00
32 lines
597 B
GDScript
32 lines
597 B
GDScript
@icon("res://behaviours/counter.svg")
|
|
extends Node
|
|
class_name Counter
|
|
|
|
## Counts up or down from a starting value.
|
|
|
|
|
|
signal changed(new: int, old: int)
|
|
|
|
|
|
@export var starting_value: int
|
|
|
|
var value: int = 0
|
|
|
|
|
|
func change(amount: int):
|
|
var old = value
|
|
value = amount
|
|
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)
|
|
|
|
func _ready():
|
|
value = starting_value
|