Skip to content

d954mas/defold-playdeck

Repository files navigation

GitHub release (latest by date) GitHub Workflow Status

PlayDeck for Defold

PlayDeck is a Telegram-native gaming marketplace that empowers game developers to showcase their games on one of the fastest-growing social platforms. With PlayDeck toolkit solutions, you can launch Web2 and Web3 games on Telegram and use all the benefits of social and referral mechanics to boost traffic and revenue.

More info

Official Integration Guide(JS)


Setup

Dependency

You can use the playdeck extension in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add:

https://github.com/d954mas/defold-playdeck/archive/refs/tags/1.0.1.zip


How to use

  1. Look at official integration guide Official Integration Guide(JS)

  2. Loding message will be send automatically.

// We auto-report progress based on the engine loading, if your game needs additional time to load assets,
// you can comment this out and report progress manually so the game does not start before it's ready.
Progress.addListener(val => {
    window.parent.window.postMessage({ playdeck: { method: "loading", value: val } }, "*");
});
  1. When your game is loaded register callback
playdeck.register_callback(function(self, data)
    pprint(data) -- log received data

    if data.method == "loaded" then
		
    elseif data.method == "getData" then
		
    elseif data.method == "play" then
	
    elseif (data.method == "rewardedAd") then
		
    elseif (data.method == "errAd") then
		
    elseif (data.method == "skipAd") then
		
    elseif (data.method == "notFoundAd") then
	
    elseif (data.method == "startAd") then
		
    ...
end)

API

For details look in Official Integration Guide(JS)

  1. Register Callback
playdeck.register_callback(function(self, data)
    pprint(data) -- log received data
    ...
  1. Loaiding

Loading is send autocaticaly. If you need you can remove Progress.addListener from playdeck\manifests\web\engine_template.html and send progress manualy

playdeck.loading(progress)
  1. GetUserProfile
playdeck.get_user_profile()
--callback
if data.method == "getUserProfile" then
    print(data.value)
end
  1. GetData/SetData
playdeck.get_data("storage")
playdeck.set_data("storage", json.encode(lua_table)) --string
playdeck.set_data("score", 100) --number
playdeck.set_data("is_happy", true) --boolean
--callback
if data.method == "getData" then
    if data.value.data then
        local lua_table = JSON.decode(data.value.data)
    else
        print("no data")
    end
end
  1. CustomShare.
playdeck.custom_share(lua_table)
  1. GetShareLink.
playdeck.get_share_link(lua_table)
--callback
if data.method == "getShareLink" then
    print(data.value)
end
  1. OpenTelegramLink.
playdeck.open_telegram_link(url)
  1. GetPlaydeckState.
playdeck.get_playdeck_state()
--callback
if data.method == "getPlaydeckState" then
    local isPlayDeckOpened = playdeck.value
end
  1. GameEnd.
playdeck.game_end()
  1. SendGameProgress.
playdeck.send_game_progress(lua_table)
  1. SendAnalyticNewSession.
playdeck.send_analytic_new_session()
  1. SendAnalytics.
playdeck.send_analytics(lua_table)
  1. RequestPayment.
playdeck.request_payment(lua_table)
--callback
if data.method == "requestPayment" then
    pprint(data.value) -- { url: 'https://t.me/$XIVLvBpfOEsBBwAARs....' } // payment link
    --How to open links is described in the chapter Sharing and opening links.
    playdeck.open_telegram_link(data.value.url)
elseif (data.method == 'invoiceClosed') {
    pprint(playdeck.value) -- { status: 'paid' | 'cancelled' | 'failed' | 'pending' }
end
  1. GetPaymentInfo.
playdeck.get_payment_info(lua_table)
--callback
if data.method == "getPaymentInfo" then
    pprint(data.value) -- { status: 'paid' | 'cancelled' | 'failed' | 'pending' }
end
  1. GetToken.
playdeck.get_token()
--callback
if data.method == "getToken" then
    pprint(data.value) -- token { token: '123456789...' }
end
  1. ShowAd.
playdeck.show_ad()
--callback
if data.method == "startAd" then
    pprint(data.value) --user has been started watching ad
elseif data.method == "rewardedAd" then
    pprint(data.value) --user has been watched ad
elseif data.method == "errAd" then
    pprint(data.value) --something went wrong at advert provider
elseif data.method == "skipAd" then
    pprint(data.value) --user has been skip ad
elseif data.method == "notFoundAd" then
    pprint(data.value) --advert provider doesn't return any ad
end