@@ -640,12 +640,6 @@ API.functions["shop"] = function(args)
640640 end ,
641641 }
642642 elseif action == " buy_card" then
643-
644- -- TODO: Implement buy card.
645- -- Get card to buy from zero-based index
646- -- Execute buy_from_shop action in G.FUNCS
647- -- Defer sending response until the shop has updated
648-
649643 -- Validate index argument
650644 if args .index == nil then
651645 API .send_error_response (
@@ -680,8 +674,27 @@ API.functions["shop"] = function(args)
680674
681675 -- Get card buy button from zero based index
682676 local card = area .cards [card_pos ]
677+
678+ -- Click the card
679+ card :click ()
680+
681+ -- Wait for the shop to update
682+ love .timer .sleep (0.5 )
683+
684+ -- Get the buy button
683685 local buy_btn = card .children and card .children .buy_button
684686
687+ -- activate the buy button
688+ G .FUNCS [buy_btn .config .button ](buy_btn )
689+
690+
691+ sendDebugMessage (" Card: " .. tostring (card ))
692+ sendDebugMessage (" Card Label: " .. tostring (card .label ))
693+ sendDebugMessage (" Buy button: " .. tostring (buy_btn ))
694+
695+ -- Wait for the shop to update
696+ love .timer .sleep (0.5 )
697+
685698 if not buy_btn then
686699 API .send_error_response (
687700 " Card has no buy button" ,
@@ -691,18 +704,20 @@ API.functions["shop"] = function(args)
691704 return
692705 end
693706
694- -- Validate card is purchasable
695- if not buy_btn :can_buy () then
696- API .send_error_response (
697- " Card is not purchasable" ,
698- ERROR_CODES .INVALID_ACTION ,
699- { index = args .index }
700- )
701- return
702- end
707+ -- -- Validate card is purchasable
708+ -- This is wrong, and would be a redundant check anyways.
709+ -- Can_buy is used to create the buy button.
710+ -- if not G.FUNCS.can_buy(buy_btn) then
711+ -- API.send_error_response(
712+ -- "Card is not purchasable",
713+ -- ERROR_CODES.INVALID_ACTION,
714+ -- { index = args.index }
715+ -- )
716+ -- return
717+ -- end
703718
704719 -- Execute buy_from_shop action in G.FUNCS
705- G .FUNCS .buy_from_shop (buy_btn )
720+ -- G.FUNCS.buy_from_shop(buy_btn)
706721
707722 -- send response once shop is updated
708723 --- @type PendingRequest
0 commit comments