frame-of-mind/src/logic-scenes/card_picker/card_picker.gd

84 lines
2.3 KiB
GDScript3
Raw Normal View History

extends CenterContainer
enum {
INI,
CARDS,
TRANSITION,
POSTS,
DONE
}
var selection_state
var anim_players:Array
var curr_selection_id: int = -1:
set(new_id):
if selection_state == CARDS or selection_state == POSTS:
if not curr_selection_id == -1: anim_players[curr_selection_id].play("deselect")
if new_id > options.size() -1: curr_selection_id = 0
elif new_id < 0: curr_selection_id = options.size() - 1
else: curr_selection_id = new_id
anim_players[curr_selection_id].play("select")
else:
curr_selection_id = new_id
print(curr_selection_id)
var output:Array
var options:Array
# Called when the node enters the scene tree for the first time.
func _ready():
options = $cards.get_children()
for card in options:
anim_players.append(card.get_child(1))
selection_state = CARDS
func _unhandled_input(event):
if event.is_action_pressed("ui_up") or event.is_action_pressed("ui_left") or event.is_action_pressed("ui_focus_next"):
curr_selection_id -= 1
elif event.is_action_pressed("ui_down") or event.is_action_pressed("ui_right") or event.is_action_pressed("ui_focus_prev"):
curr_selection_id += 1
if event.is_action_pressed("ui_accept"):
pick(curr_selection_id)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func pick(id: int):
print("meep")
if id == -1:
curr_selection_id = 0
return
anim_players[id].play("pick")
var yield_to = anim_players[id].animation_finished
output.append(options[id])
options.remove_at(id)
anim_players.remove_at(id)
var winning_id = randi() % options.size()
output.append(options.pop_at(winning_id))
anim_players.pop_at(winning_id).play("shuffle")
for anim in anim_players:
anim.play("unshuffle")
await yield_to
if selection_state == CARDS:
selection_state = TRANSITION
options = $postIts.get_children()
anim_players = []
for post in options:
anim_players.append(post.get_child(1))
post.get_child(1).play("post")
curr_selection_id = -1
await anim_players[0].animation_finished
selection_state == POSTS