1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 23:54:23 +00:00

Cleanup and document Counter

This commit is contained in:
Steffo 2024-04-15 22:39:43 +02:00
parent 85d487a56c
commit 97b415fabd
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0

View file

@ -1,18 +1,17 @@
extends Node extends Node
class_name Counter class_name Counter
## Counts up or down from a starting value.
signal changed(old: int, new: int) signal changed(old: int, new: int)
@export var starting_value: int @export var starting_value: int
var value: int var value: int = 0
func _ready():
value = starting_value
func change(amount: int): func change(amount: int):
var old = value var old = value
value = amount value = amount
@ -27,3 +26,6 @@ func decrease(amount: int = 1):
if amount < 0: if amount < 0:
Log.w(self, "Decreasing a counter by a negative value.") Log.w(self, "Decreasing a counter by a negative value.")
change(value - amount) change(value - amount)
func _ready():
value = starting_value