32 lines
990 B
GDScript
32 lines
990 B
GDScript
class_name PlayingCard
|
|
extends Area3D
|
|
|
|
@export var card_mesh: MeshInstance3D
|
|
@export var front_texture: Texture
|
|
@export var move_duration: float = 0.2
|
|
|
|
var card_details: Card
|
|
|
|
signal card_clicked(playing_card: PlayingCard)
|
|
|
|
func _ready() -> void:
|
|
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
|
|
var tween = create_tween()
|
|
tween.set_trans(Tween.TRANS_BACK)
|
|
tween.set_ease(Tween.EASE_OUT)
|
|
tween.tween_property(self, "position:x", new_x_position, move_duration)
|
|
|
|
func set_front_texture(texture: Texture) -> void:
|
|
card_mesh.get_surface_override_material(0).albedo_texture = front_texture
|
|
|
|
func _on_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void:
|
|
if event.is_action_pressed("left_mouse_button"):
|
|
print("yahaha!")
|
|
card_clicked.emit(self)
|