VegeCard/Scripts/Card.gd

55 lines
1.2 KiB
GDScript3
Raw Normal View History

2025-03-18 15:47:09 +08:00
extends TextureButton
class_name Card
enum Category {
Onion,
Cabbage,
Carrot,
Bucket
}
@export var mouse_follow_speed: int = 50
@export var index : Vector2 = Global.invalid_cell_index
@export var category : Category = Category.Cabbage
@export var value : int = 0
@export var onion_texture : Texture2D
@export var cabbage_texture : Texture2D
@export var carrot_texture : Texture2D
@export var bucket_texture : Texture2D
var origin_pos : Vector2
var has_mouse : bool
var settled : bool
func setup_card(category: Category, value: int) -> void:
origin_pos = global_position
setup_sprite()
func setup_sprite() -> void:
$Value.text = str(value)
match category :
Category.Onion:
texture_normal = onion_texture
Category.Cabbage:
texture_normal = cabbage_texture
Category.Carrot:
texture_normal = carrot_texture
Category.Bucket:
texture_normal = bucket_texture
func _on_button_down() -> void:
if !settled:
has_mouse = true
get_node("/root/GameRoot").emit_signal("dragging_card", self)
func _on_button_up() -> void:
has_mouse = false
func _process(delta):
pass
#if has_mouse and !settled:
#global_position = global_position.lerp(get_global_mouse_position(), mouse_follow_speed*delta)