mlpcardgame/Scenes/Components/Card.gd

41 lines
No EOL
1.1 KiB
GDScript

extends Spatial
signal card_selected()
signal card_unselected()
signal card_picked()
signal card_dropped()
var lifted := false
export var inHand := false
onready var animation := $Border/AnimationPlayer
func _mouse_hover():
if inHand:
animation.play("focus")
emit_signal("card_selected")
func _mouse_blur():
if inHand:
animation.play("blur")
emit_signal("card_unselected")
func _input_event(camera, event, click_position, click_normal, shape_idx):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
if event.pressed:
lifted = true
animation.play("lift")
emit_signal("card_picked")
else:
lifted = false
animation.play_backwards("lift")
emit_signal("card_dropped")
if lifted and event is InputEventMouseMotion:
var origin: Vector3 = camera.project_ray_origin(event.position)
var direction: Vector3 = camera.project_ray_normal(event.position)
if inHand:
transform.origin = Vector3.ZERO + Vector3.RIGHT * direction * 3.0
else:
var denom := Vector3.UP.dot(direction)
var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom;
transform.origin = origin + direction * t