69 lines
1.6 KiB
GDScript
69 lines
1.6 KiB
GDScript
extends Node2D
|
|
## The card class
|
|
##
|
|
## Represents an instance of a card to be displayed on the tabletop.
|
|
## Contains helper text for the text, the cards ID, and the image path.
|
|
|
|
# Card information.
|
|
var card_info: Dictionary
|
|
|
|
# Card properties.
|
|
var tapped: bool
|
|
|
|
# Card input state.
|
|
var hovered: bool # Is the mouse currently on this card?
|
|
var dragging: bool # Is the card currently being dragged?
|
|
var focused: bool # Is this card currently a focus?
|
|
|
|
var mouse_offset: Vector2
|
|
|
|
|
|
func init(id: String) -> void:
|
|
card_info["id"] = id
|
|
|
|
|
|
# This is called when we want to apply the behaviour of the mouse being
|
|
# inside/outside the card when we can't trigger the enter/exit triggers.
|
|
func check_hover() -> void:
|
|
if hovered:
|
|
_on_mouse_entered()
|
|
else:
|
|
_on_mouse_exited()
|
|
|
|
|
|
func error(error_type: String) -> String:
|
|
return "ERROR::CARD::%s::%s::%s::\n" % [card_info["id"], card_info["name"], error_type]
|
|
|
|
|
|
func colission_size() -> Vector2:
|
|
return $Area2D/CollisionShape2D.shape.size
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
focused = hovered or dragging
|
|
|
|
$InputHandler.handle_inputs(delta)
|
|
$TweenController.handle_constant_tweens(delta)
|
|
|
|
|
|
func _on_mouse_entered() -> void:
|
|
hovered = true
|
|
|
|
# Do not apply any more effects if we're dragging the card.
|
|
if dragging:
|
|
return
|
|
|
|
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
|
|
$TweenController.scale(1.05)
|
|
|
|
|
|
func _on_mouse_exited() -> void:
|
|
hovered = false
|
|
|
|
# Do not apply any more effects if we're dragging the card.
|
|
if dragging:
|
|
return
|
|
|
|
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
|
|
$TweenController.scale(1.0)
|