extends Spatial

export var max_charge_capacity : int = 1
export var time_to_generate : float = 120

var current_holding : int = 0 setget set_current_holding
var current_timer : float = 0

func set_current_holding(new_value):
	current_holding = new_value
	$CointCount.text = "Charge Count: %d" % current_holding

func _ready():
	set_current_holding(current_holding)

func _process(delta):
	current_timer += delta
	if current_timer >= time_to_generate:
		generate_charge()
		current_timer = 0

func generate_charge():
	if current_holding >= max_charge_capacity:
		return
	self.current_holding += 1
	print("power station: charge generated")

func collect_charges_from_station():
	var charges_to_return : int = current_holding
	self.current_holding = 0
	return charges_to_return

func on_player_interact(player) -> bool:
	assert(player.has_method("modify_inventory"))
	var charges = collect_charges_from_station()
	if charges <= 0:
		$sounds/error.play()
		return false
	
	player.modify_inventory("coins", charges)
	$sounds/charge_get.play()
	return true
