adds tapping/untapping

This commit is contained in:
Nathan Singer 2025-04-27 12:55:09 -04:00
parent dd73e1b477
commit 1beb89ea84
2 changed files with 61 additions and 13 deletions

66
card.gd
View File

@ -5,8 +5,14 @@ extends TextureRect
## 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.
# TODO: Implement card utilities such as mana cost, land value, etc using api data.
const ManaCosts = preload("res://data/mana.gd")
enum pivot {
ROTATE_0,
ROTATE_90,
ROTATE_180,
ROTATE_270
}
var current_pivot = pivot.ROTATE_0
var card_id: String
var card_name: String
@ -14,29 +20,61 @@ var card_type: String
var oracle_text: String
var is_dragging = false
var is_pivot = false
var delay = 5.0 # TODO find the best value for this
var mouse_offset: Vector2
func _pivot() -> int:
var deg: int
match current_pivot:
pivot.ROTATE_0:
deg = 0
pivot.ROTATE_90:
deg = 90
pivot.ROTATE_180:
deg = 180
pivot.ROTATE_270:
deg = 270
is_pivot = false
return deg
func _physics_process(delta: float) -> void:
if is_dragging == true:
var tween = get_tree().create_tween()
tween.tween_property(self, "position", get_global_mouse_position() - mouse_offset, delay * delta)
if is_pivot == true:
var tween = get_tree().create_tween()
tween.tween_property(self, "rotation_degrees", _pivot(), delta * delay)
func _gui_input(event: InputEvent) -> void:
if event is not InputEventMouseButton:
return
match event.button_index:
MOUSE_BUTTON_LEFT:
if event.pressed:
is_dragging = true
mouse_offset = get_global_mouse_position() - global_position
else:
is_dragging = false
MOUSE_BUTTON_RIGHT:
pass
if event is InputEventMouseButton:
match event.button_index:
MOUSE_BUTTON_LEFT:
if event.pressed:
print("down")
is_dragging = true
mouse_offset = get_global_mouse_position() - global_position
else:
is_dragging = false
MOUSE_BUTTON_RIGHT:
pass
func _unhandled_key_input(event: InputEvent) -> void:
if event.is_action_pressed("default_action"):
print("space pressed!")
if current_pivot == pivot.ROTATE_0:
current_pivot = pivot.ROTATE_90
is_pivot = true
else:
current_pivot = pivot.ROTATE_0
is_pivot = true
func _card_error(error_type: String) -> String:
return "ERROR::CARD::%s::%s::%s::\n" % [card_id, card_name, error_type]
@ -52,6 +90,8 @@ func _ready() -> void:
# if the card is not cached, perhaps a placeholder blank card can be used instead?
# Setting that up can be put here later...
push_error("Failed to load card.")
set_pivot_offset(size / 2)
func _load_card() -> Error:

View File

@ -24,3 +24,11 @@ window/size/mode=3
[editor_plugins]
enabled=PackedStringArray()
[input]
default_action={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
]
}