2023-05-25 08:39:39 +00:00
|
|
|
extends CenterContainer
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
INI,
|
|
|
|
|
CARDS,
|
|
|
|
|
TRANSITION,
|
|
|
|
|
POSTS,
|
|
|
|
|
DONE
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-28 13:25:26 +00:00
|
|
|
@onready var debug_board:Control = $"board of devs"
|
|
|
|
|
|
2023-06-25 21:45:52 +00:00
|
|
|
var has_focus = false:
|
|
|
|
|
set(focus):
|
|
|
|
|
if not focus == has_focus:
|
|
|
|
|
if focus:
|
|
|
|
|
for player in anim_players: player.play("reveal")
|
|
|
|
|
selection_state = CARDS # fixme
|
|
|
|
|
self.show()
|
|
|
|
|
has_focus = focus
|
|
|
|
|
|
2023-05-25 08:39:39 +00:00
|
|
|
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():
|
2023-05-28 13:25:26 +00:00
|
|
|
var card_controls = $cards.get_children()
|
|
|
|
|
for control in card_controls:
|
|
|
|
|
options.append(control.get_child(1))
|
|
|
|
|
anim_players.append(control.get_child(0))
|
2023-06-25 21:45:52 +00:00
|
|
|
selection_state = INI
|
2023-05-28 13:25:26 +00:00
|
|
|
|
|
|
|
|
fill_card_slots()
|
2023-05-25 08:39:39 +00:00
|
|
|
|
2023-05-28 13:25:26 +00:00
|
|
|
func fill_card_slots():
|
|
|
|
|
for i in range($cards.get_child_count()):
|
|
|
|
|
var card:Card = $cards.get_child(i).get_child(1)
|
2023-06-25 21:45:52 +00:00
|
|
|
card.replace_with(debug_board.get_child(0).get_child(i) as Card)
|
2023-05-28 13:25:26 +00:00
|
|
|
|
|
|
|
|
func fill_post_slots():
|
|
|
|
|
var post_its: Array[PostIt] = []
|
|
|
|
|
for card in output:
|
|
|
|
|
post_its.append_array(card.own_postits)
|
|
|
|
|
print(card.own_postits)
|
|
|
|
|
|
|
|
|
|
for i in range(post_its.size()):
|
|
|
|
|
options[i].replace_with(post_its[i])
|
|
|
|
|
|
2023-05-25 08:39:39 +00:00
|
|
|
func _unhandled_input(event):
|
2023-06-25 21:45:52 +00:00
|
|
|
if has_focus:
|
|
|
|
|
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)
|
2023-05-25 08:39:39 +00:00
|
|
|
|
|
|
|
|
func pick(id: int):
|
|
|
|
|
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])
|
|
|
|
|
|
2023-05-28 13:25:26 +00:00
|
|
|
var sibling_id = -1
|
|
|
|
|
if selection_state == POSTS:
|
|
|
|
|
|
|
|
|
|
sibling_id = options.find(options[id].sibling)
|
|
|
|
|
|
|
|
|
|
print("yeet sibling ", sibling_id)
|
|
|
|
|
|
2023-05-25 08:39:39 +00:00
|
|
|
options.remove_at(id)
|
|
|
|
|
anim_players.remove_at(id)
|
|
|
|
|
|
2023-05-28 13:25:26 +00:00
|
|
|
randomize()
|
2023-05-25 08:39:39 +00:00
|
|
|
var winning_id = randi() % options.size()
|
|
|
|
|
|
2023-05-28 13:25:26 +00:00
|
|
|
print("Winning ID ", id)
|
|
|
|
|
|
|
|
|
|
if winning_id == sibling_id:
|
|
|
|
|
winning_id = (winning_id + 1) % options.size()
|
|
|
|
|
|
2023-05-25 08:39:39 +00:00
|
|
|
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
|
2023-05-28 13:25:26 +00:00
|
|
|
options = []
|
2023-05-25 08:39:39 +00:00
|
|
|
anim_players = []
|
2023-05-28 13:25:26 +00:00
|
|
|
for control in $postIts.get_children():
|
|
|
|
|
options.append(control.get_child(1))
|
|
|
|
|
anim_players.append(control.get_child(0))
|
|
|
|
|
control.get_child(0).play("post")
|
2023-05-25 08:39:39 +00:00
|
|
|
curr_selection_id = -1
|
2023-05-28 13:25:26 +00:00
|
|
|
|
|
|
|
|
fill_post_slots()
|
|
|
|
|
|
2023-05-25 08:39:39 +00:00
|
|
|
await anim_players[0].animation_finished
|
2023-05-25 17:23:25 +00:00
|
|
|
selection_state = POSTS
|