Skip to content

Commit 4f04d3f

Browse files
committed
refactor: completion conditions to be table[name][action]
1 parent 53ff2d5 commit 4f04d3f

File tree

1 file changed

+94
-58
lines changed

1 file changed

+94
-58
lines changed

src/lua/utils.lua

Lines changed: 94 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -636,71 +636,107 @@ local EVENT_QUEUE_THRESHOLD = 3
636636

637637
---Completion conditions for different game actions to determine when action execution is complete
638638
---These are shared between API and LOG systems to ensure consistent timing
639-
---@type table<string, function>
639+
---@type table<string, table>
640640
utils.COMPLETION_CONDITIONS = {
641-
get_game_state = function()
642-
return #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD
643-
end,
644-
645-
go_to_menu = function()
646-
return G.STATE == G.STATES.MENU and G.MAIN_MENU_UI
647-
end,
648-
649-
start_run = function()
650-
return G.STATE == G.STATES.BLIND_SELECT
651-
and G.GAME.blind_on_deck
652-
and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD
653-
end,
654-
655-
skip_or_select_blind = function()
656-
-- Check if we're selecting a blind (facing_blind is set)
657-
if G.GAME and G.GAME.facing_blind and G.STATE == G.STATES.SELECTING_HAND then
641+
get_game_state = {
642+
[""] = function()
658643
return #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD
659-
end
660-
-- Check if we skipped a blind (any blind is marked as "Skipped")
661-
if G.prev_small_state == "Skipped" or G.prev_large_state == "Skipped" or G.prev_boss_state == "Skipped" then
662-
return #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD
663-
end
664-
return false
665-
end,
666-
667-
play_hand_or_discard = function()
668-
if #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE then
669-
-- round still going
670-
if G.buttons and G.STATE == G.STATES.SELECTING_HAND then
671-
return true
672-
-- round won and entering cash out state (ROUND_EVAL state)
673-
elseif G.STATE == G.STATES.ROUND_EVAL then
674-
return true
675-
-- game over state
676-
elseif G.STATE == G.STATES.GAME_OVER then
677-
return true
678-
end
679-
end
680-
return false
681-
end,
644+
end,
645+
},
682646

683-
rearrange_hand = function()
684-
return G.STATE == G.STATES.SELECTING_HAND and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE
685-
end,
647+
go_to_menu = {
648+
[""] = function()
649+
return G.STATE == G.STATES.MENU and G.MAIN_MENU_UI
650+
end,
651+
},
686652

687-
rearrange_jokers = function()
688-
return #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE
689-
end,
653+
start_run = {
654+
[""] = function()
655+
return G.STATE == G.STATES.BLIND_SELECT
656+
and G.GAME.blind_on_deck
657+
and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD
658+
end,
659+
},
690660

691-
cash_out = function()
692-
return G.STATE == G.STATES.SHOP and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE
693-
end,
661+
skip_or_select_blind = {
662+
["select"] = function()
663+
if G.GAME and G.GAME.facing_blind and G.STATE == G.STATES.SELECTING_HAND then
664+
return #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD
665+
end
666+
end,
667+
["skip"] = function()
668+
if G.prev_small_state == "Skipped" or G.prev_large_state == "Skipped" or G.prev_boss_state == "Skipped" then
669+
return #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD
670+
end
671+
return false
672+
end,
673+
},
674+
675+
play_hand_or_discard = {
676+
-- TODO: refine condition for be specific about the action
677+
["play_hand"] = function()
678+
if #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE then
679+
-- round still going
680+
if G.buttons and G.STATE == G.STATES.SELECTING_HAND then
681+
return true
682+
-- round won and entering cash out state (ROUND_EVAL state)
683+
elseif G.STATE == G.STATES.ROUND_EVAL then
684+
return true
685+
-- game over state
686+
elseif G.STATE == G.STATES.GAME_OVER then
687+
return true
688+
end
689+
end
690+
return false
691+
end,
692+
["discard"] = function()
693+
if #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE then
694+
-- round still going
695+
if G.buttons and G.STATE == G.STATES.SELECTING_HAND then
696+
return true
697+
-- round won and entering cash out state (ROUND_EVAL state)
698+
elseif G.STATE == G.STATES.ROUND_EVAL then
699+
return true
700+
-- game over state
701+
elseif G.STATE == G.STATES.GAME_OVER then
702+
return true
703+
end
704+
end
705+
return false
706+
end,
707+
},
694708

695-
-- Actions that keep the player in the shop (e.g. buy_card, reroll, buy_and_use_card).
696-
-- Semantically identical to cash_out but named for clarity.
697-
shop_idle = function()
698-
return G.STATE == G.STATES.SHOP and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE
699-
end,
709+
rearrange_hand = {
710+
[""] = function()
711+
return G.STATE == G.STATES.SELECTING_HAND
712+
and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD
713+
and G.STATE_COMPLETE
714+
end,
715+
},
700716

701-
shop = function()
702-
return G.STATE == G.STATES.BLIND_SELECT and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE
703-
end,
717+
rearrange_jokers = {
718+
[""] = function()
719+
return #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE
720+
end,
721+
},
722+
723+
cash_out = {
724+
[""] = function()
725+
return G.STATE == G.STATES.SHOP and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE
726+
end,
727+
},
728+
729+
shop = {
730+
buy_card = function()
731+
return G.STATE == G.STATES.SHOP and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE
732+
end,
733+
next_round = function()
734+
return G.STATE == G.STATES.BLIND_SELECT and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE
735+
end,
736+
reroll = function()
737+
return G.STATE == G.STATES.SHOP and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE
738+
end,
739+
},
704740
}
705741

706742
return utils

0 commit comments

Comments
 (0)