tool
extends StaticBody2D

class_name Door

# 钥匙类型
export(String,"yellow_key,blue_key","red_key","none") var need_key_type : String = "yellow_key"

# 是否启用
export var enabled : bool = true

onready var anim_sprite : AnimatedSprite = $Sprite

func _ready():
	anim_sprite.connect("animation_finished",self,"on_animation_finished")

# 玩家触碰回调
func on_player_touched(player):
	if not enabled:
		return
	if need_key_type != "none":
		if player[need_key_type] <= 0:
			return
		player[need_key_type] -= 1
	anim_sprite.playing = true

# 动画结束回调
func on_animation_finished():
	queue_free()

# 强制开启	
func open():
	if need_key_type == "none":
		anim_sprite.playing = true
