fixing up issues with internal state handling and animation referencing

This commit is contained in:
betalars 2023-07-18 14:48:28 +02:00
parent bc38a177d5
commit f507b9b890
2 changed files with 23 additions and 17 deletions

View File

@ -4,6 +4,7 @@ extends CenterContainer
enum { enum {
INI, INI,
CARDS, CARDS,
CARDS_SELECTED,
TRANSITION, TRANSITION,
POSTS, POSTS,
DONE DONE
@ -24,9 +25,11 @@ var has_stage = false:
self.hide() self.hide()
has_stage = focus has_stage = focus
var _input_locked = true
var selection_state = INI var selection_state = INI:
var input_locked = true set(state):
selection_state = state
_input_locked = !(state == CARDS or state == POSTS)
var anim_players:Array var anim_players:Array
var curr_selection_id: int = -1: var curr_selection_id: int = -1:
@ -51,20 +54,21 @@ signal cards_picked(Array)
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
if get_parent() == get_tree().root: selection_state = CARDS
var card_controls = $cards.get_children() var card_controls = $cards.get_children()
for control in card_controls: for control in card_controls:
options.append(control.get_child(1)) options.append(control.get_child(1))
anim_players.append(control.get_child(0)) anim_players.append(control.get_child(0))
fill_card_slots(0) fill_card_slots(0)
input_locked = false
func fill_card_slots(id: int): func fill_card_slots(id: int):
for i in range($cards.get_child_count()): for i in range($cards.get_child_count()):
var card:Card = $cards.get_child(i).get_child(1) var card:Card = $cards.get_child(i).get_child(1)
card.replace_with(debug_board.get_child(id).get_child(i) as Card) card.replace_with(debug_board.get_child(id).get_child(i) as Card)
card.connect("mouse_entered", Callable(self, "get_highlight")) card.connect("mouse_entered", Callable(self, "get_highlight"))
card.owner = self
func fill_post_slots(): func fill_post_slots():
var post_its: Array[PostIt] = [] var post_its: Array[PostIt] = []
@ -74,9 +78,10 @@ func fill_post_slots():
for i in range(post_its.size()): for i in range(post_its.size()):
options[i].replace_with(post_its[i]) options[i].replace_with(post_its[i])
options[i].owner = self
func _unhandled_input(event): func _unhandled_input(event):
if has_stage and not input_locked: if has_stage and not _input_locked:
if event.is_action_pressed("ui_up") or event.is_action_pressed("ui_left") or event.is_action_pressed("ui_focus_next"): 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 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"): elif event.is_action_pressed("ui_down") or event.is_action_pressed("ui_right") or event.is_action_pressed("ui_focus_prev"):
@ -91,7 +96,10 @@ func pick(id: int):
curr_selection_id = 0 curr_selection_id = 0
return return
input_locked = true if selection_state == CARDS:
selection_state = CARDS_SELECTED
elif selection_state == POSTS:
selection_state = DONE
anim_players[id].play("pick") anim_players[id].play("pick")
var yield_to = anim_players[id].animation_finished var yield_to = anim_players[id].animation_finished
@ -123,7 +131,7 @@ func pick(id: int):
await yield_to await yield_to
if selection_state == CARDS: if selection_state == CARDS_SELECTED:
selection_state = TRANSITION selection_state = TRANSITION
options = [] options = []
anim_players = [] anim_players = []
@ -137,8 +145,7 @@ func pick(id: int):
await anim_players[0].animation_finished await anim_players[0].animation_finished
selection_state = POSTS selection_state = POSTS
input_locked = false elif selection_state == DONE:
else:
var out_str:Array[String] = [] var out_str:Array[String] = []
for card in output: for card in output:
out_str.append(card.name) out_str.append(card.name)
@ -146,15 +153,14 @@ func pick(id: int):
State.leave_stage(self) State.leave_stage(self)
func handle_hover(new_highlight): func handle_hover(new_highlight):
if not input_locked: if not _input_locked:
curr_selection_id = options.find(new_highlight) curr_selection_id = options.find(new_highlight)
func handle_mouse_button(new_selection: Node, button_event: InputEventMouseButton): func handle_mouse_button(new_selection: Node, button_event: InputEventMouseButton):
if not input_locked: if not _input_locked:
if button_event.button_index == MOUSE_BUTTON_LEFT and button_event.pressed: if button_event.button_index == MOUSE_BUTTON_LEFT and button_event.pressed:
pick(options.find(new_selection)) pick(options.find(new_selection))
func scene_finished(id: int): func scene_finished(id: int):
fill_card_slots(id) fill_card_slots(id)
State.transition_stage_to(self) State.transition_stage_to(self)

View File

@ -1531,7 +1531,7 @@ offset_top = -150.0
offset_bottom = -150.0 offset_bottom = -150.0
[node name="AnimationPlayer" type="AnimationPlayer" parent="postIts/postIt_1"] [node name="AnimationPlayer" type="AnimationPlayer" parent="postIts/postIt_1"]
root_node = NodePath("../post-it") root_node = NodePath(".")
autoplay = "ini" autoplay = "ini"
libraries = { libraries = {
"": SubResource("AnimationLibrary_ga4dm") "": SubResource("AnimationLibrary_ga4dm")
@ -1547,7 +1547,7 @@ offset_top = -50.0
offset_bottom = -50.0 offset_bottom = -50.0
[node name="AnimationPlayer" type="AnimationPlayer" parent="postIts/postIt_2"] [node name="AnimationPlayer" type="AnimationPlayer" parent="postIts/postIt_2"]
root_node = NodePath("../post-it") root_node = NodePath(".")
autoplay = "ini" autoplay = "ini"
libraries = { libraries = {
"": SubResource("AnimationLibrary_sxnmi") "": SubResource("AnimationLibrary_sxnmi")
@ -1563,7 +1563,7 @@ offset_top = 50.0
offset_bottom = 50.0 offset_bottom = 50.0
[node name="AnimationPlayer" type="AnimationPlayer" parent="postIts/postIt_3"] [node name="AnimationPlayer" type="AnimationPlayer" parent="postIts/postIt_3"]
root_node = NodePath("../post-it") root_node = NodePath(".")
autoplay = "ini" autoplay = "ini"
libraries = { libraries = {
"": SubResource("AnimationLibrary_xs06v") "": SubResource("AnimationLibrary_xs06v")
@ -1579,7 +1579,7 @@ offset_top = 150.0
offset_bottom = 150.0 offset_bottom = 150.0
[node name="AnimationPlayer" type="AnimationPlayer" parent="postIts/postIt_4"] [node name="AnimationPlayer" type="AnimationPlayer" parent="postIts/postIt_4"]
root_node = NodePath("../post-it") root_node = NodePath(".")
autoplay = "ini" autoplay = "ini"
libraries = { libraries = {
"": SubResource("AnimationLibrary_tdl1s") "": SubResource("AnimationLibrary_tdl1s")