organizes card scene, exports tween functionality to its own node and script
This commit is contained in:
parent
ce0bc104ff
commit
3c02ae63f9
4
field.gd
4
field.gd
@ -3,7 +3,7 @@ extends TextureRect
|
|||||||
var _screen_size: Vector2
|
var _screen_size: Vector2
|
||||||
var _colors: Array[Color]
|
var _colors: Array[Color]
|
||||||
|
|
||||||
var _card_scene = preload("res://card.tscn")
|
var _card_class = preload("res://scenes/card/card.tscn")
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
@ -11,7 +11,7 @@ func _ready() -> void:
|
|||||||
# TODO: Calculate this field's scale and position based on which no# field this is.
|
# TODO: Calculate this field's scale and position based on which no# field this is.
|
||||||
_screen_size = get_viewport_rect().size
|
_screen_size = get_viewport_rect().size
|
||||||
|
|
||||||
var card = _card_scene.instantiate()
|
var card = _card_class.instantiate()
|
||||||
|
|
||||||
# TODO: Currently working with an already-cached card with a known ID to load this.
|
# TODO: Currently working with an already-cached card with a known ID to load this.
|
||||||
# Later on, the cards should be pulling the IDs directly from the library's list of IDs.
|
# Later on, the cards should be pulling the IDs directly from the library's list of IDs.
|
||||||
|
2
hand.gd
2
hand.gd
@ -2,7 +2,7 @@ extends StaticBody2D
|
|||||||
|
|
||||||
var cards: Array[Node] = []
|
var cards: Array[Node] = []
|
||||||
|
|
||||||
var _card_class = preload("res://card.tscn")
|
var _card_class = preload("res://scenes/card/card.tscn")
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
var _card_class = preload("res://card.tscn")
|
var _card_class = preload("res://scenes/card/card.tscn")
|
||||||
|
|
||||||
var field_scene = preload("res://field.tscn")
|
var field_scene = preload("res://field.tscn")
|
||||||
var fields: Array[Node] = []
|
var fields: Array[Node] = []
|
||||||
|
@ -4,10 +4,6 @@ extends Node2D
|
|||||||
## Represents an instance of a card to be displayed on the tabletop.
|
## 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.
|
## Contains helper text for the text, the cards ID, and the image path.
|
||||||
|
|
||||||
enum pivot { ROTATE_0 = 0, ROTATE_90 = 90, ROTATE_180 = 180, ROTATE_270 = 270 }
|
|
||||||
|
|
||||||
var current_pivot = pivot.ROTATE_0
|
|
||||||
|
|
||||||
# Card information.
|
# Card information.
|
||||||
var card_id: String
|
var card_id: String
|
||||||
var card_name: String
|
var card_name: String
|
||||||
@ -15,50 +11,24 @@ var card_type: String
|
|||||||
var oracle_text: String
|
var oracle_text: String
|
||||||
|
|
||||||
# Card properties.
|
# Card properties.
|
||||||
var tapped = false
|
var tapped: bool
|
||||||
|
|
||||||
# Card input state.
|
# Card input state.
|
||||||
var is_focused = false # Is the card a focus?
|
var is_focused: bool # Is the card a focus?
|
||||||
var is_dragging = false # Is the card currently being dragged?
|
var is_dragging: bool # Is the card currently being dragged?
|
||||||
|
|
||||||
var delay = 5.0
|
|
||||||
var mouse_offset: Vector2
|
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
|
|
||||||
return deg
|
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
|
if is_focused:
|
||||||
# TODO: Export handling keypresses to its own area.
|
# TODO: Export handling keypresses to its own area.
|
||||||
if is_focused and Input.is_action_just_pressed("MAIN"):
|
if Input.is_action_just_pressed("MAIN"):
|
||||||
tapped = not tapped
|
tapped = not tapped
|
||||||
current_pivot = pivot.ROTATE_90 if tapped else pivot.ROTATE_0
|
$TweenController.tap(tapped, delta)
|
||||||
var tween = create_tween()
|
|
||||||
tween.tween_property(self, "rotation_degrees", current_pivot, delta * delay)
|
|
||||||
|
|
||||||
_tweening(delta)
|
|
||||||
|
|
||||||
|
|
||||||
func _tweening(delta: float) -> void:
|
|
||||||
# NOTE: Constant tweens include:
|
|
||||||
# - When dragging, new tween is created each physics_process frame to move the card to the new mouse location.
|
|
||||||
|
|
||||||
if is_dragging:
|
if is_dragging:
|
||||||
var tween = create_tween()
|
$TweenController.move_to(get_global_mouse_position() - mouse_offset, delta)
|
||||||
tween.tween_property(
|
|
||||||
self, "position", get_global_mouse_position() - mouse_offset, delay * delta
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
||||||
@ -86,11 +56,7 @@ func _on_mouse_entered() -> void:
|
|||||||
return
|
return
|
||||||
|
|
||||||
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
|
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
|
||||||
|
$TweenController.scale(1.05)
|
||||||
var tween = create_tween()
|
|
||||||
var focus_scale = Vector2(1.05, 1.05)
|
|
||||||
tween.tween_property(self, "scale", focus_scale, 0.1)
|
|
||||||
|
|
||||||
is_focused = true
|
is_focused = true
|
||||||
|
|
||||||
|
|
||||||
@ -100,24 +66,11 @@ func _on_mouse_exited() -> void:
|
|||||||
return
|
return
|
||||||
|
|
||||||
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
|
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
|
||||||
var tween = create_tween()
|
$TweenController.scale(1.0)
|
||||||
tween.tween_property(self, "scale", Vector2.ONE, 0.1)
|
|
||||||
|
|
||||||
is_focused = false
|
is_focused = false
|
||||||
|
|
||||||
|
|
||||||
func travel_to(position: Vector2) -> Error:
|
|
||||||
# TODO: Check whether position to travel to is within the confines of where this card can go.
|
|
||||||
return OK
|
|
||||||
|
|
||||||
|
|
||||||
# func _unhandled_key_input(event: InputEvent) -> void:
|
|
||||||
# if not event.is_action_pressed("default_action"):
|
|
||||||
# return
|
|
||||||
|
|
||||||
# set_pivot_offset(size / 2)
|
|
||||||
|
|
||||||
|
|
||||||
func _card_error(error_type: String) -> String:
|
func _card_error(error_type: String) -> String:
|
||||||
return "ERROR::CARD::%s::%s::%s::\n" % [card_id, card_name, error_type]
|
return "ERROR::CARD::%s::%s::%s::\n" % [card_id, card_name, error_type]
|
||||||
|
|
||||||
@ -134,8 +87,6 @@ func _ready() -> void:
|
|||||||
# Setting that up can be put here later...
|
# Setting that up can be put here later...
|
||||||
push_error("Failed to load card.")
|
push_error("Failed to load card.")
|
||||||
|
|
||||||
# set_pivot_offset(size / 2)
|
|
||||||
|
|
||||||
|
|
||||||
func _load_card() -> Error:
|
func _load_card() -> Error:
|
||||||
if _load_data() != OK:
|
if _load_data() != OK:
|
@ -1,6 +1,7 @@
|
|||||||
[gd_scene load_steps=3 format=3 uid="uid://cah3mvdnom1xg"]
|
[gd_scene load_steps=4 format=3 uid="uid://cah3mvdnom1xg"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://b3yqd1qu7dyq" path="res://card.gd" id="1_kikvd"]
|
[ext_resource type="Script" uid="uid://b3yqd1qu7dyq" path="res://scenes/card/card.gd" id="1_kikvd"]
|
||||||
|
[ext_resource type="Script" uid="uid://bkk0pyypi1id7" path="res://scenes/card/tween.gd" id="2_imta7"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_kikvd"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_kikvd"]
|
||||||
size = Vector2(125, 175)
|
size = Vector2(125, 175)
|
||||||
@ -15,6 +16,9 @@ script = ExtResource("1_kikvd")
|
|||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||||
shape = SubResource("RectangleShape2D_kikvd")
|
shape = SubResource("RectangleShape2D_kikvd")
|
||||||
|
|
||||||
|
[node name="TweenController" type="Node2D" parent="."]
|
||||||
|
script = ExtResource("2_imta7")
|
||||||
|
|
||||||
[connection signal="input_event" from="Area2D" to="." method="_on_input_event"]
|
[connection signal="input_event" from="Area2D" to="." method="_on_input_event"]
|
||||||
[connection signal="mouse_entered" from="Area2D" to="." method="_on_mouse_entered"]
|
[connection signal="mouse_entered" from="Area2D" to="." method="_on_mouse_entered"]
|
||||||
[connection signal="mouse_exited" from="Area2D" to="." method="_on_mouse_exited"]
|
[connection signal="mouse_exited" from="Area2D" to="." method="_on_mouse_exited"]
|
0
scenes/card/input.gd
Normal file
0
scenes/card/input.gd
Normal file
1
scenes/card/input.gd.uid
Normal file
1
scenes/card/input.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://dhgk6fhw8oua0
|
22
scenes/card/tween.gd
Normal file
22
scenes/card/tween.gd
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
@export var move_speed = 1.0
|
||||||
|
@export var tap_speed = 5.0
|
||||||
|
@export var scale_speed = 0.1
|
||||||
|
|
||||||
|
|
||||||
|
func move_to(location: Vector2, delta: float) -> void:
|
||||||
|
var tween = create_tween()
|
||||||
|
tween.tween_property(get_parent(), "position", location, delta * move_speed)
|
||||||
|
|
||||||
|
|
||||||
|
func tap(tapped: bool, delta: float) -> void:
|
||||||
|
var tween = create_tween()
|
||||||
|
var rotation = 90 if tapped else 0
|
||||||
|
tween.tween_property(get_parent(), "rotation_degrees", rotation, delta * tap_speed)
|
||||||
|
|
||||||
|
|
||||||
|
func scale(scalar: float) -> void:
|
||||||
|
var tween = create_tween()
|
||||||
|
var new_scale = Vector2.ONE * scalar
|
||||||
|
tween.tween_property(get_parent(), "scale", new_scale, scale_speed)
|
1
scenes/card/tween.gd.uid
Normal file
1
scenes/card/tween.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://bkk0pyypi1id7
|
Loading…
x
Reference in New Issue
Block a user