extends WindowDialog

onready var player = get_tree().get_nodes_in_group("player")[0]

func _unhandled_key_input(event):
	if event.is_action_pressed("open_debug"):
		if visible:
			hide()
		else:
			popup()

func _on_charge_pressed():
	player.modify_inventory("coins", 1)

func _on_charge_5_pressed():
	player.modify_inventory("coins", 5)

func _on_raw_yam_pressed():
	player.pick_up_item(preload("res://item_types/raw_yam.tres").spawn_node())

func _on_cooked_yam_pressed():
	player.pick_up_item(preload("res://item_types/cooked_yam.tres").spawn_node())

func _on_ore_pressed():
	player.pick_up_item(preload("res://item_types/ore.tres").spawn_node())

func _on_repair_kit_pressed():
	player.pick_up_item(preload("res://item_types/repair_kit.tres").spawn_node())

func _on_clear_pressed():
	if player.has_item():
		player.drop_item_in_hand()

func _on_random_damage_pressed():
	var damageable = get_tree().get_nodes_in_group("damageable")
	if damageable.empty():
		return
	damageable[randi() % damageable.size()].take_damage()


func _on_timer_2_s_pressed():
	var game_manager = get_tree().get_nodes_in_group("game_manager")[0]
	var day_timer = game_manager.get_node("day_timer")
	day_timer.start(2.0)
	day_timer.wait_time = game_manager.time_per_day
