Skip to content

Commit

Permalink
Implement ysdk.isAvailableMethod (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
aglitchman authored Jun 21, 2024
1 parent d23dc02 commit 0f6cd93
Show file tree
Hide file tree
Showing 8 changed files with 404 additions and 18 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ YaGames is the Yandex.Games SDK native extension for the [Defold](https://www.de

[Yandex.Games](https://yandex.com/games/) is a collection of browser HTML5 games for smartphones, computers, tablets, and TVs. The games are available in Yandex Browser and the Yandex app. Games from the catalog are displayed in Yandex recommendation systems, which have a total audience of more than 50 million users per month.

You can check [here](https://radar.yandex.ru/yandex) the size of Yandex.Games audience. The platform is constantly growing.

## Installation

You can use it in your own project by adding this project as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open your `game.project` file and in the dependencies field add **a link to the ZIP file of a [specific release](https://github.com/indiesoftby/defold-yagames/tags).**

**Note:** Use [version 0.8.1](https://github.com/indiesoftby/defold-yagames/releases/tag/0.8.1) for Defold <=1.3.7.
You can use it in your own project by adding this project as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open your `game.project` file and in the dependencies field add **a link to the ZIP file of a [specific release](https://github.com/indiesoftby/defold-yagames/releases).**

## Getting Started

Expand All @@ -31,17 +27,17 @@ You can use it in your own project by adding this project as a [Defold library d
### Checklist For Releasing Game

1. [Sign up as a developer](https://yandex.ru/dev/games/doc/dg/concepts/about.html?lang=en).
2. Translate your game to the Russian language (*tip:* It's a great idea to translate your game title into Russian too.). English and Turkish are optional [(more info)](https://yandex.ru/dev/games/doc/dg/concepts/languages-and-domains.html?lang=en).
2. Translate your game to the Russian language (*tip:* translate your game title into Russian too!). English and Turkish are optional [(more info)](https://yandex.ru/dev/games/doc/dg/concepts/languages-and-domains.html?lang=en).
3. Prepare assets for the catalogue:
- Icon 512 x 512 px.
- Cover 800 x 470 px.
- Screenshots.
- *(Optional)* Videos and GIF.
4. Add [the extension](https://github.com/indiesoftby/defold-yagames/archive/master.zip) as a Defold library dependency to your project.
5. Enable monetization and earn revenue from placing ad blocks in your game. Ad blocks are available in the following formats:
- **Interstitial blocks**: ad blocks that completely cover the app background and show up at certain points (for example, when accessing the next game level). *Important: Mute sounds before showing the ad.*
- **Rewarded videos**: blocks with video ads that the user can choose to view and earn a reward or in-game currency. *Important: Mute sounds before showing the ad.*
- **Sticky banners**: the same as RTB but they're much easier to setup.
- **Interstitial blocks**: ad blocks that completely cover the app background and show up at certain points (for example, when accessing the next game level). *Important: Mute sounds before showing the ad!*
- **Rewarded videos**: blocks with video ads that the user can choose to view and earn a reward or in-game currency. *Important: Mute sounds before showing the ad!*
- **Sticky banners**: banner ads, super easy to setup.
- **In-game purchases**: earn revenue by providing paid services to your users.
5. You can [publish your game on Yandex.Games](https://games.yandex.ru/console/) from this moment. It fully meets [the requirements](https://yandex.ru/dev/games/doc/dg/concepts/requirements.html?lang=en).

Expand Down Expand Up @@ -173,6 +169,9 @@ end

### Misc

> [!TIP]
> We don't use thes features in our games as we don't see any improvements in our games metrics, and the complexity of its integration and support is quite high.
#### Native Cache How-To

Yandex's [Native Cache](https://yandex.ru/dev/games/doc/dg/concepts/native-cache-settings.html?lang=en) lets users use games offline. Currently, it's available only in Yandex Browser or the Yandex app on smartphones.
Expand All @@ -183,7 +182,7 @@ Yandex's [Native Cache](https://yandex.ru/dev/games/doc/dg/concepts/native-cache

#### Service Worker How-To

Yandex allows to integrate Service Worker into your game to be able to run both offline and online.
Yandex dropped the Service Worker description page in their docs, but it still allows to integrate Service Worker into your game to be able to run both offline and online.

1. Set the path to the file `sw.js` in the `game.project` settings.
2. Copy the `yagames/manifests/web/sw.js` file to the root directory of your release build.
Expand Down Expand Up @@ -215,11 +214,14 @@ Yandex.Games JavaScript SDK uses ES6 Promise for asynchronous operations. For Lu

### Lua <-> JS

The best way to integrate SDK into your game is to read [the official documentation](https://yandex.ru/dev/games/doc/dg/concepts/about.html?lang=en) and to use corresponding Lua API functions. The table below helps to do that:
The best way to integrate SDK into your game is to read [the official documentation](https://yandex.ru/dev/games/doc/dg/concepts/about.html?lang=en) and to use corresponding Lua API functions.

And it's also a good idea to upload a demo build of YaGames to your game's draft and click on the buttons to understand what the arguments are and what each function returns.

| Yandex.Games JS SDK | YaGames Lua API |
| ------------------- | --------------- |
| `YaGames.init(options)` | `yagames.init(callback)`<br>The `options` is a JavaScript object `{}`, and it can be set in the `yagames.sdk_init_options` setting. |
| `ysdk.isAvailableMethod(name)` | `yagames.is_available_method(name, callback)` [<kbd>Example</kbd>](https://github.com/indiesoftby/defold-yagames/blob/master/example/ysdkdebug/pg_methods.lua) |
| **Advertisement** [(docs)](https://yandex.ru/dev/games/doc/en/sdk/sdk-adv) | |
| `ysdk.adv.showFullscreenAdv({callbacks:{}})` | `yagames.adv_show_fullscreen_adv(callbacks)` [<kbd>Example</kbd>](#2-interstitial-ad) |
| `ysdk.adv.showRewardedVideo({callbacks:{}})` | `yagames.adv_show_rewarded_video(callbacks)` [<kbd>Example</kbd>](#3-rewarded-videos) |
Expand Down Expand Up @@ -296,7 +298,7 @@ The best way to integrate SDK into your game is to read [the official documentat

## Sitelock

It's a good idea to protect your HTML5 game from simple copy-pasting to another website. YaGames has Sitelock API for that purpose. It's simple, but it's better than nothing.
It's a good idea to protect your HTML5 game from simple copy-pasting to another website. The YaGames extension has Sitelock API for that purpose. It's simple, but it's better than nothing.

By default, it checks hostnames `yandex.net` (CDN of the Yandex.Games) and `localhost` (for local debugging).

Expand Down
87 changes: 87 additions & 0 deletions example/ysdkdebug/pg_methods.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
local druid_style = require("example.ysdkdebug.druid_style")

local yagames = require("yagames.yagames")

local log_print = require("example.ysdkdebug.log_print")
local print = log_print.print

local M = {}

function M.not_available_methods_handler(self)
local methods = {
"isAvailableMethod",
-- Advertisement
"adv.showFullscreenAdv",
"adv.showRewardedVideo",
"adv.getBannerAdvStatus",
"adv.showBannerAdv",
"adv.hideBannerAdv",
-- Auth
"auth.openAuthDialog",
-- Clipboard
"clipboard.writeText",
-- Device Info
"deviceInfo.isDesktop",
"deviceInfo.isMobile",
"deviceInfo.isTablet",
"deviceInfo.isTV",
-- Features
"features.LoadingAPI.ready",
-- Feedback
"feedback.canReview",
"feedback.requestReview",
-- Leaderboards
"getLeaderboards",
"leaderboards.getLeaderboardDescription",
"leaderboards.getLeaderboardPlayerEntry",
"leaderboards.getLeaderboardEntries",
"leaderboards.setLeaderboardScore",
-- Payments
"getPayments",
"payments.purchase",
"payments.getPurchases",
"payments.getCatalog",
"payments.consumePurchase",
-- Player
"getPlayer",
"player.getID",
"player.getIDsPerGame",
"player.getMode",
"player.getName",
"player.getPhoto",
"player.getUniqueID",
"player.setData",
"player.getData",
"player.setStats",
"player.incrementStats",
"player.getStats",
-- Fullscreen
"screen.fullscreen.exit",
"screen.fullscreen.request",
-- Shortcut
"shortcut.canShowPrompt",
"shortcut.showPrompt",
-- Safe Storage
"getStorage",
-- Events
"dispatchEvent",
"onEvent",
-- Flags
"getFlags",
}

for _, name in ipairs(methods) do
yagames.is_available_method(name, function(self, err, result)
-- Show only not available methods:
if not result then
print("yagames.is_available_method('" .. name .. "'):", err or tostring(result))
end
end)
end
end

function M.init(self)
druid_style.make_button(self, "button_not_available_methods", M.not_available_methods_handler)
end

return M
179 changes: 174 additions & 5 deletions example/ysdkdebug/playground.gui
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,175 @@ nodes {
visible: true
material: ""
}
nodes {
position {
x: 805.72217
y: -21.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 0.7
y: 0.7
z: 0.7
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEMPLATE
id: "button_not_available_methods"
parent: "group_debug_log"
layer: ""
inherit_alpha: true
alpha: 1.0
template: "/example/ysdkdebug/button.gui"
template_node_child: false
custom_type: 0
enabled: true
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 320.0
y: 70.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "common/button"
id: "button_not_available_methods/body"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
parent: "button_not_available_methods"
layer: "common"
inherit_alpha: true
slice9 {
x: 24.0
y: 24.0
z: 24.0
w: 24.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 0.8
y: 0.8
z: 1.0
w: 1.0
}
size {
x: 375.0
y: 87.5
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "List Not Available Methods"
font: "font2"
id: "button_not_available_methods/text"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
shadow {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
parent: "button_not_available_methods/body"
layer: "font2"
inherit_alpha: true
alpha: 1.0
outline_alpha: 1.0
shadow_alpha: 1.0
overridden_fields: 8
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
x: 20.0
Expand Down Expand Up @@ -5378,7 +5547,7 @@ nodes {
nodes {
position {
x: 550.0
y: 938.0
y: 1086.7816
z: 0.0
w: 1.0
}
Expand Down Expand Up @@ -7023,7 +7192,7 @@ nodes {
nodes {
position {
x: 550.0
y: 1093.0
y: 1241.7816
z: 0.0
w: 1.0
}
Expand Down Expand Up @@ -7486,7 +7655,7 @@ nodes {
nodes {
position {
x: 1080.0
y: 938.0
y: 1086.7816
z: 0.0
w: 1.0
}
Expand Down Expand Up @@ -8118,7 +8287,7 @@ nodes {
nodes {
position {
x: 1080.0
y: 798.501
y: 947.28253
z: 0.0
w: 1.0
}
Expand Down Expand Up @@ -8749,7 +8918,7 @@ nodes {
nodes {
position {
x: 1249.8689
y: 1093.0
y: 1241.7816
z: 0.0
w: 1.0
}
Expand Down
Loading

0 comments on commit 0f6cd93

Please sign in to comment.