tool
extends ESCItem
class_name ESCItemWithTooltip, "res://addons/escoria-core/design/esc_item.svg"

# Action 1 Label text
export(String) var action1_text = ""

# Action 2 Label text
export(String) var action2_text = ""

# Action 3 tooltip text if item in inventory
export(String) var action3_text = ""

# Action 4 tooltip text if item in inventory
export(String) var action4_text = ""

export(Dictionary) var tooltips = {}

# Action 3 tooltip texts if item is target. Dictionary with tool's global id as key.
export(Dictionary) var action3_target_texts = {}

# Action 4 tooltip texts if item is target. Dictionary with tool's global id as key
export(Dictionary) var action4_target_texts = {}

# If action used by player is in this list, this is a valid target (second item in combination)
export(Array) var target_when_selected_action_is_in = []

# If item is countable (E.g. money) marks the quantity
export(int) var count = 0

# ESCItemComponents children of this node
var components: Dictionary = {}

var custom_data: Dictionary = {}

# If item is countable (E.g. money) marks which texture to use depending of count value.
# Each element is a Dictionary with start and texture keys:
# [
#   { "start": 0, "texture": "res://gymkhana/items/inventory/assets/no_money.png"},
#   { "start": 1, "texture": "res://gymkhana/items/inventory/assets/one_coin.png"},
#   { "start": 2, "texture": "res://gymkhana/items/inventory/assets/two_coins.png"},
#   { "start": 3, "texture": "res://gymkhana/items/inventory/assets/coins.png"},
#   { "start": 10, "texture": "res://gymkhana/items/inventory/assets/bills.png"},
# ]
export(Array) var count_textures = []


func _ready():
	register_components()

func set_tooltip(action: String, text: String):
	tooltips[action] =  text

func has_component(key: String)->bool:
	return components.has(key)
			
func get_component(key: String):
	if(has_component(key)):
		return components[key]
	return null
			
func register_components():
	autoload_components()
	for child in get_children():
		if(child is ESCItemComponent):
			child = child as ESCItemComponent
			components[child.get_component_type()] = child
			child.register(custom_data)

func autoload_components():
	add_child(ESCItemComponentOutline.new())
	add_child(ESCItemComponentInventoryChecker.new())
