extends "res://entities/GridBasedMovable.gd"

enum PLAYERTOOLS {CLEANING_TOOL, PUSH_TOOL, PULL_TOOL, GRINDING_TOOL}
@export var tool_type: PLAYERTOOLS = PLAYERTOOLS.CLEANING_TOOL

var taken_or_destroyed = false

signal tool_taken


func take_tool():
	if taken_or_destroyed:
		return
	
	emit_signal("tool_taken")
	enable_movement = false
	taken_or_destroyed = true

func _physics_process(delta):
	
	_handle_movement(delta)
	
	if ray_top.is_colliding():
		var topObject = ray_top.get_collider()
		if topObject != null:
			enable_movement = false
			taken_or_destroyed = true

	if taken_or_destroyed and timer.time_left < 0.05:
		call_deferred("queue_free")

func _ready() -> void:
	super._ready()
	enable_movement = false
	invincible = true
	await get_tree().create_timer(0.2).timeout
	invincible = false
	enable_movement = true

func _on_Health_no_health() -> void:
	hit()

func hit():
	call_deferred("queue_free")
