2025-07-08 11:32:52 +02:00
|
|
|
class_name PlayingCard
|
2025-07-08 15:58:46 +02:00
|
|
|
extends Area3D
|
2025-07-08 11:32:52 +02:00
|
|
|
|
|
|
|
|
@export var card_mesh: MeshInstance3D
|
|
|
|
|
@export var front_texture: Texture
|
2025-07-08 15:58:46 +02:00
|
|
|
@export var move_duration: float = 0.2
|
|
|
|
|
|
2025-07-08 11:32:52 +02:00
|
|
|
var card_details: Card
|
|
|
|
|
|
2025-07-08 15:58:46 +02:00
|
|
|
signal card_clicked(playing_card: PlayingCard)
|
|
|
|
|
|
2025-07-08 11:32:52 +02:00
|
|
|
func _ready() -> void:
|
2025-07-08 15:58:46 +02:00
|
|
|
if card_details:
|
|
|
|
|
set_front_texture(CardManager.get_card_texture(card_details.card_id))
|
|
|
|
|
else:
|
|
|
|
|
set_front_texture(CardManager.get_card_texture(-1))
|
|
|
|
|
|
|
|
|
|
func move_to(new_x_position: float) -> void:
|
|
|
|
|
#self.position.x = new_x_position
|
2025-07-08 16:48:41 +02:00
|
|
|
_get_new_tween().tween_property(self, "position:x", new_x_position, move_duration)
|
|
|
|
|
|
|
|
|
|
func select() -> void:
|
|
|
|
|
_get_new_tween().tween_property(self, "position:y", 0.36, move_duration)
|
|
|
|
|
|
|
|
|
|
func unselect() -> void:
|
|
|
|
|
_get_new_tween().tween_property(self, "position:y", 0.0, move_duration)
|
2025-07-08 11:32:52 +02:00
|
|
|
|
|
|
|
|
func set_front_texture(texture: Texture) -> void:
|
|
|
|
|
card_mesh.get_surface_override_material(0).albedo_texture = front_texture
|
2025-07-08 15:58:46 +02:00
|
|
|
|
2025-07-08 16:48:41 +02:00
|
|
|
func _get_new_tween() -> Tween:
|
|
|
|
|
var tween = create_tween()
|
|
|
|
|
tween.set_trans(Tween.TRANS_BACK)
|
|
|
|
|
tween.set_ease(Tween.EASE_OUT)
|
|
|
|
|
return tween
|
|
|
|
|
|
2025-07-08 15:58:46 +02:00
|
|
|
func _on_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void:
|
2025-07-08 16:48:41 +02:00
|
|
|
if event.is_action_released("left_mouse_button"):
|
2025-07-08 15:58:46 +02:00
|
|
|
card_clicked.emit(self)
|