2023-06-07 00:13:37 +10:00
|
|
|
class_name Deck
|
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
signal clicked
|
|
|
|
signal mouse_entered
|
|
|
|
signal mouse_exited
|
|
|
|
|
|
|
|
enum Type {WORKER, CLIENT}
|
|
|
|
|
|
|
|
@export var type: Type
|
|
|
|
var cards: Array[Card] = []
|
|
|
|
|
|
|
|
@onready var _w_pos = $Worker.global_position
|
|
|
|
@onready var _c_pos = $Client.global_position
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
match type:
|
|
|
|
Type.WORKER:
|
|
|
|
$Area2D/WorkerShape.disabled = false
|
|
|
|
$Area2D/ClientSprite.visible = false
|
|
|
|
Type.CLIENT:
|
|
|
|
$Area2D/ClientShape.disabled = false
|
|
|
|
$Area2D/WorkerSprite.visible = false
|
|
|
|
|
|
|
|
|
|
|
|
func _on_area_2d_input_event(_viewport, event, _shape_idx) -> void:
|
|
|
|
if event is InputEventMouseButton and event.pressed:
|
|
|
|
clicked.emit()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_area_2d_mouse_entered() -> void:
|
|
|
|
mouse_entered.emit()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_area_2d_mouse_exited() -> void:
|
|
|
|
mouse_exited.emit()
|
|
|
|
|
|
|
|
|
2023-06-08 15:44:43 +10:00
|
|
|
func draw_card() -> Card:
|
2023-06-11 02:08:09 +10:00
|
|
|
if cards.size() == 0:
|
|
|
|
return null
|
2023-06-07 00:13:37 +10:00
|
|
|
return cards.pop_back()
|
|
|
|
|
|
|
|
|
|
|
|
func place(card: Card) -> void:
|
|
|
|
cards.append(card)
|
|
|
|
match type:
|
|
|
|
Type.WORKER:
|
|
|
|
card.slide_to_position(_w_pos.x, _w_pos.y, 0.0, 0.2)
|
|
|
|
Type.CLIENT:
|
|
|
|
card.slide_to_position(_c_pos.x, _c_pos.y, 0.0, 0.2)
|
|
|
|
|
|
|
|
|
|
|
|
func shuffle() -> void:
|
|
|
|
cards.shuffle()
|
2023-06-08 15:44:43 +10:00
|
|
|
|
|
|
|
|
|
|
|
func order(node_paths) -> void:
|
|
|
|
cards = []
|
|
|
|
for path in node_paths:
|
|
|
|
cards.append(get_node(path))
|