extends Node2D

onready var global: Node = get_node("/root/Global")

onready var room_sprite = $Sprite
onready var shovel = $Shovel
onready var door_left_closed = $DoorLeftClosed
onready var door_left = $DoorLeft

func _ready():
	if global.game_vars.has("shovel_grabbed"):
		grabbed_shovel()
	if global.game_vars.has("key_used"):
		open_door()

func _on_Shovel_used() -> void:
	if global.inventory.add_item(global.inventory.Items.shovel):
		global.game_vars["shovel_grabbed"] = true
		global.play_sound("shovel_grab")
		grabbed_shovel()

func _on_DoorLeftClosed_item_used(item_id) -> void:
	var inv = global.inventory
	if item_id == inv.Items.key:
		if inv.remove_item(item_id):
			var anim: AnimationPlayer = global.player.animation_player
			anim.play("Victory")
			global.game_vars["key_used"] = true
			open_door()

func grabbed_shovel() -> void:
	room_sprite.frame = 1
	shovel.queue_free()

func open_door() -> void:
	door_left_closed.hide()
	door_left.show()



func _on_DoorLeft_used():
	if !global.game_vars.has("rec_cartridge_used"):
		global.change_music("small_house")
