extends Node2D

signal clicked

export (bool) var random_change_on_click = true
export (bool) var add_jock = false setget set_add_jock
var values = ["ace", "jack", "king", "queen"]
var famillies = ["clubs", "diamonds", "hearts", "spades"]
var joker = load("res://assets/joker.png")
var cards = []

onready var default_texture = $CardFace.texture

func reinit():
	$CardFace.set_texture(default_texture)

func set_add_jock(joke):
	if joke:
		cards.append(joker)
	else:
		cards.remove(cards.rfind(joker))

func _ready():
	randomize()
	for i in range(2, 11):
		values.append(str(i))
	for value in values:
		for familly in famillies:
			cards.append(load("res://assets/" + value + "_of_" + familly + ".png"))
	if add_jock:
		cards.append(joker)

func _on_Card_input_event(viewport, event, shape_idx):
	if event is InputEventMouseButton \
	and event.button_index == BUTTON_LEFT \
	and event.pressed:
		emit_signal("clicked")

func switch_card():
	$CardFace.set_texture(cards[randi()%len(cards)])

func _on_Card_clicked():
	if random_change_on_click:
		switch_card()
