Skip to content

Commit b45bd54

Browse files
committed
buy card WIP
1 parent 5254cd1 commit b45bd54

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

src/lua/api.lua

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,6 @@ API.functions["shop"] = function(args)
556556
end,
557557
}
558558
elseif action == "buy_card" then
559-
560-
-- TODO: Implement buy card.
561-
-- Get card to buy from zero-based index
562-
-- Execute buy_from_shop action in G.FUNCS
563-
-- Defer sending response until the shop has updated
564-
565559
-- Validate index argument
566560
if args.index == nil then
567561
API.send_error_response(
@@ -596,8 +590,27 @@ API.functions["shop"] = function(args)
596590

597591
-- Get card buy button from zero based index
598592
local card = area.cards[card_pos]
593+
594+
-- Click the card
595+
card:click()
596+
597+
-- Wait for the shop to update
598+
love.timer.sleep(0.5)
599+
600+
-- Get the buy button
599601
local buy_btn = card.children and card.children.buy_button
600602

603+
-- activate the buy button
604+
G.FUNCS[buy_btn.config.button](buy_btn)
605+
606+
607+
sendDebugMessage("Card: " .. tostring(card))
608+
sendDebugMessage("Card Label: " .. tostring(card.label))
609+
sendDebugMessage("Buy button: " .. tostring(buy_btn))
610+
611+
-- Wait for the shop to update
612+
love.timer.sleep(0.5)
613+
601614
if not buy_btn then
602615
API.send_error_response(
603616
"Card has no buy button",
@@ -607,18 +620,20 @@ API.functions["shop"] = function(args)
607620
return
608621
end
609622

610-
-- Validate card is purchasable
611-
if not buy_btn:can_buy() then
612-
API.send_error_response(
613-
"Card is not purchasable",
614-
ERROR_CODES.INVALID_ACTION,
615-
{ index = args.index }
616-
)
617-
return
618-
end
623+
-- -- Validate card is purchasable
624+
-- This is wrong, and would be a redundant check anyways.
625+
-- Can_buy is used to create the buy button.
626+
-- if not G.FUNCS.can_buy(buy_btn) then
627+
-- API.send_error_response(
628+
-- "Card is not purchasable",
629+
-- ERROR_CODES.INVALID_ACTION,
630+
-- { index = args.index }
631+
-- )
632+
-- return
633+
-- end
619634

620635
-- Execute buy_from_shop action in G.FUNCS
621-
G.FUNCS.buy_from_shop(buy_btn)
636+
-- G.FUNCS.buy_from_shop(buy_btn)
622637

623638
-- send response once shop is updated
624639
---@type PendingRequest

0 commit comments

Comments
 (0)