mirror of
https://github.com/defold/extension-iap
synced 2025-06-27 10:27:46 +02:00
58 lines
1.4 KiB
Plaintext
58 lines
1.4 KiB
Plaintext
local dirtylarry = require "dirtylarry/dirtylarry"
|
|
|
|
local items = {
|
|
"consumable",
|
|
"nonconsumable"
|
|
}
|
|
|
|
local product_items = {}
|
|
|
|
local function list_callback(self, products, error)
|
|
if error == nil then
|
|
for k,p in pairs(products) do
|
|
product_items[p.ident] = p
|
|
local name = p.ident.."/larrylabel"
|
|
gui.set_color(gui.get_node(name), vmath.vector4(1,1,1,1))
|
|
end
|
|
else
|
|
print(error.error)
|
|
end
|
|
end
|
|
|
|
local function buy_listener(self, transaction, error)
|
|
if not error and transaction.ident == "nonconsumable" then
|
|
local name = "reset/larrylabel"
|
|
gui.set_color(gui.get_node(name), vmath.vector4(1,1,1,1))
|
|
product_items["reset"] = transaction
|
|
elseif not error then
|
|
iap.finish(transaction)
|
|
end
|
|
end
|
|
|
|
function init(self)
|
|
msg.post(".", "acquire_input_focus")
|
|
iap.list(items, list_callback)
|
|
iap.set_listener(buy_listener)
|
|
end
|
|
|
|
function on_input(self, action_id, action)
|
|
if product_items["consumable"] then
|
|
dirtylarry:button("consumable", action_id, action, function()
|
|
iap.buy("consumable")
|
|
end)
|
|
end
|
|
|
|
if product_items["nonconsumable"] then
|
|
dirtylarry:button("nonconsumable", action_id, action, function()
|
|
iap.buy("nonconsumable")
|
|
end)
|
|
end
|
|
|
|
if product_items["reset"] then
|
|
dirtylarry:button("reset", action_id, action, function()
|
|
iap.finish(product_items["reset"])
|
|
product_items["reset"] = nil
|
|
gui.set_color(gui.get_node("reset/larrylabel"), vmath.vector4(1,0,0,1))
|
|
end)
|
|
end
|
|
end |