extends Node2D

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

onready var sprite = $Sprite
onready var cheese = $Cheese

func _ready():
	if global.game_vars.has("cheese_grabbed"):
		cheese_grabbed()

func _on_Drawer_pressed():
	if sprite.frame == 0:
		sprite.frame = 1
		global.play_sound("drawer_open")
		if cheese != null:
			cheese.show()
	else:
		if cheese != null:
			if global.inventory.add_item(global.inventory.Items.cheese):
				global.game_vars["cheese_grabbed"] = true
				global.play_sound("cheese_grab")
				cheese_grabbed()
		else:
			sprite.frame = 0
			global.play_sound("drawer_close")

func cheese_grabbed() -> void:
	cheese.queue_free()
	cheese = null
