Skip to content

Commit 9ea95f6

Browse files
stirbyS1M0N38
authored andcommitted
added atomic update checks
1 parent 685f9b9 commit 9ea95f6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/lua/api.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,18 +728,23 @@ API.functions["shop"] = function(args)
728728
return
729729
end
730730

731+
732+
-- Used to ensure dollars and shop have been updated before responding, not inheritly atomic
733+
local dollars_before = G.GAME.dollars
734+
local expected_dollars = dollars_before - card.cost
735+
local shop_size_before = #G.shop_jokers.cards
736+
731737
-- activate the buy button using the UI element handler
732738
G.FUNCS.buy_from_shop(card_buy_button)
733739

734-
735740
-- send response once shop is updated
736741
---@type PendingRequest
737742
API.pending_requests["shop"] = {
738-
-- TODO: This sends the update before the dollars have been updated.
739743
condition = function()
740744
return G.STATE == G.STATES.SHOP
741-
and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD
742-
and G.STATE_COMPLETE
745+
and #G.shop_jokers.cards == shop_size_before - 1
746+
and G.GAME.dollars == expected_dollars
747+
and G.STATE_COMPLETE
743748
end,
744749
action = function()
745750
local game_state = utils.get_game_state()

0 commit comments

Comments
 (0)