forked from Nekojimi/JackIt
53 lines
1.3 KiB
GDScript3
53 lines
1.3 KiB
GDScript3
|
@tool
|
||
|
extends Control
|
||
|
class_name Card
|
||
|
|
||
|
var front_shown: bool = true
|
||
|
|
||
|
#@export_tool_button("Flip")
|
||
|
#var action_flip = flip
|
||
|
#@export_tool_button("Appear")
|
||
|
#var action_appear = appear
|
||
|
|
||
|
signal revealed()
|
||
|
|
||
|
func _ready() -> void:
|
||
|
appear()
|
||
|
|
||
|
func appear():
|
||
|
change_shown_face(false, true)
|
||
|
$AnimationPlayer.play("move_from_top")
|
||
|
await $AnimationPlayer.animation_finished
|
||
|
if $"RootMover/Card Front/PostIt".visible:
|
||
|
$AnimationPlayer.play("move_postit_aside")
|
||
|
await $AnimationPlayer.animation_finished
|
||
|
|
||
|
func disappear():
|
||
|
change_shown_face(false)
|
||
|
if $"RootMover/Card Front/PostIt".visible:
|
||
|
$AnimationPlayer.play_backwards("move_postit_aside")
|
||
|
await $AnimationPlayer.animation_finished
|
||
|
$AnimationPlayer.play("move_to_bottom")
|
||
|
await $AnimationPlayer.animation_finished
|
||
|
|
||
|
func show_postit(shown: bool) -> void:
|
||
|
$"RootMover/Card Front/PostIt".visible = shown
|
||
|
|
||
|
func flip():
|
||
|
change_shown_face(!front_shown)
|
||
|
|
||
|
func _gui_input(event: InputEvent) -> void:
|
||
|
if event is InputEventMouseButton:
|
||
|
change_shown_face(true)
|
||
|
|
||
|
func change_shown_face(to_front: bool, instant: bool = false):
|
||
|
if to_front != front_shown:
|
||
|
front_shown = to_front
|
||
|
if to_front:
|
||
|
$AnimationPlayer.play_backwards("flip_to_back")
|
||
|
revealed.emit()
|
||
|
else:
|
||
|
$AnimationPlayer.play("flip_to_back")
|
||
|
if instant:
|
||
|
$AnimationPlayer.advance(0.5)
|