Skip to content

Commit 0f6cd93

Browse files
authored
Implement ysdk.isAvailableMethod (#25)
1 parent d23dc02 commit 0f6cd93

File tree

8 files changed

+404
-18
lines changed

8 files changed

+404
-18
lines changed

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@ YaGames is the Yandex.Games SDK native extension for the [Defold](https://www.de
1212

1313
[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.
1414

15-
You can check [here](https://radar.yandex.ru/yandex) the size of Yandex.Games audience. The platform is constantly growing.
16-
1715
## Installation
1816

19-
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).**
20-
21-
**Note:** Use [version 0.8.1](https://github.com/indiesoftby/defold-yagames/releases/tag/0.8.1) for Defold <=1.3.7.
17+
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).**
2218

2319
## Getting Started
2420

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

3329
1. [Sign up as a developer](https://yandex.ru/dev/games/doc/dg/concepts/about.html?lang=en).
34-
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).
30+
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).
3531
3. Prepare assets for the catalogue:
3632
- Icon 512 x 512 px.
3733
- Cover 800 x 470 px.
3834
- Screenshots.
3935
- *(Optional)* Videos and GIF.
4036
4. Add [the extension](https://github.com/indiesoftby/defold-yagames/archive/master.zip) as a Defold library dependency to your project.
4137
5. Enable monetization and earn revenue from placing ad blocks in your game. Ad blocks are available in the following formats:
42-
- **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.*
43-
- **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.*
44-
- **Sticky banners**: the same as RTB but they're much easier to setup.
38+
- **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!*
39+
- **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!*
40+
- **Sticky banners**: banner ads, super easy to setup.
4541
- **In-game purchases**: earn revenue by providing paid services to your users.
4642
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).
4743

@@ -173,6 +169,9 @@ end
173169

174170
### Misc
175171

172+
> [!TIP]
173+
> 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.
174+
176175
#### Native Cache How-To
177176

178177
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.
@@ -183,7 +182,7 @@ Yandex's [Native Cache](https://yandex.ru/dev/games/doc/dg/concepts/native-cache
183182

184183
#### Service Worker How-To
185184

186-
Yandex allows to integrate Service Worker into your game to be able to run both offline and online.
185+
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.
187186

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

216215
### Lua <-> JS
217216

218-
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:
217+
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.
218+
219+
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.
219220

220221
| Yandex.Games JS SDK | YaGames Lua API |
221222
| ------------------- | --------------- |
222223
| `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. |
224+
| `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) |
223225
| **Advertisement** [(docs)](https://yandex.ru/dev/games/doc/en/sdk/sdk-adv) | |
224226
| `ysdk.adv.showFullscreenAdv({callbacks:{}})` | `yagames.adv_show_fullscreen_adv(callbacks)` [<kbd>Example</kbd>](#2-interstitial-ad) |
225227
| `ysdk.adv.showRewardedVideo({callbacks:{}})` | `yagames.adv_show_rewarded_video(callbacks)` [<kbd>Example</kbd>](#3-rewarded-videos) |
@@ -296,7 +298,7 @@ The best way to integrate SDK into your game is to read [the official documentat
296298

297299
## Sitelock
298300

299-
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.
301+
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.
300302

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

example/ysdkdebug/pg_methods.lua

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
local druid_style = require("example.ysdkdebug.druid_style")
2+
3+
local yagames = require("yagames.yagames")
4+
5+
local log_print = require("example.ysdkdebug.log_print")
6+
local print = log_print.print
7+
8+
local M = {}
9+
10+
function M.not_available_methods_handler(self)
11+
local methods = {
12+
"isAvailableMethod",
13+
-- Advertisement
14+
"adv.showFullscreenAdv",
15+
"adv.showRewardedVideo",
16+
"adv.getBannerAdvStatus",
17+
"adv.showBannerAdv",
18+
"adv.hideBannerAdv",
19+
-- Auth
20+
"auth.openAuthDialog",
21+
-- Clipboard
22+
"clipboard.writeText",
23+
-- Device Info
24+
"deviceInfo.isDesktop",
25+
"deviceInfo.isMobile",
26+
"deviceInfo.isTablet",
27+
"deviceInfo.isTV",
28+
-- Features
29+
"features.LoadingAPI.ready",
30+
-- Feedback
31+
"feedback.canReview",
32+
"feedback.requestReview",
33+
-- Leaderboards
34+
"getLeaderboards",
35+
"leaderboards.getLeaderboardDescription",
36+
"leaderboards.getLeaderboardPlayerEntry",
37+
"leaderboards.getLeaderboardEntries",
38+
"leaderboards.setLeaderboardScore",
39+
-- Payments
40+
"getPayments",
41+
"payments.purchase",
42+
"payments.getPurchases",
43+
"payments.getCatalog",
44+
"payments.consumePurchase",
45+
-- Player
46+
"getPlayer",
47+
"player.getID",
48+
"player.getIDsPerGame",
49+
"player.getMode",
50+
"player.getName",
51+
"player.getPhoto",
52+
"player.getUniqueID",
53+
"player.setData",
54+
"player.getData",
55+
"player.setStats",
56+
"player.incrementStats",
57+
"player.getStats",
58+
-- Fullscreen
59+
"screen.fullscreen.exit",
60+
"screen.fullscreen.request",
61+
-- Shortcut
62+
"shortcut.canShowPrompt",
63+
"shortcut.showPrompt",
64+
-- Safe Storage
65+
"getStorage",
66+
-- Events
67+
"dispatchEvent",
68+
"onEvent",
69+
-- Flags
70+
"getFlags",
71+
}
72+
73+
for _, name in ipairs(methods) do
74+
yagames.is_available_method(name, function(self, err, result)
75+
-- Show only not available methods:
76+
if not result then
77+
print("yagames.is_available_method('" .. name .. "'):", err or tostring(result))
78+
end
79+
end)
80+
end
81+
end
82+
83+
function M.init(self)
84+
druid_style.make_button(self, "button_not_available_methods", M.not_available_methods_handler)
85+
end
86+
87+
return M

example/ysdkdebug/playground.gui

Lines changed: 174 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,175 @@ nodes {
20752075
visible: true
20762076
material: ""
20772077
}
2078+
nodes {
2079+
position {
2080+
x: 805.72217
2081+
y: -21.0
2082+
z: 0.0
2083+
w: 1.0
2084+
}
2085+
rotation {
2086+
x: 0.0
2087+
y: 0.0
2088+
z: 0.0
2089+
w: 1.0
2090+
}
2091+
scale {
2092+
x: 0.7
2093+
y: 0.7
2094+
z: 0.7
2095+
w: 1.0
2096+
}
2097+
size {
2098+
x: 200.0
2099+
y: 100.0
2100+
z: 0.0
2101+
w: 1.0
2102+
}
2103+
color {
2104+
x: 1.0
2105+
y: 1.0
2106+
z: 1.0
2107+
w: 1.0
2108+
}
2109+
type: TYPE_TEMPLATE
2110+
id: "button_not_available_methods"
2111+
parent: "group_debug_log"
2112+
layer: ""
2113+
inherit_alpha: true
2114+
alpha: 1.0
2115+
template: "/example/ysdkdebug/button.gui"
2116+
template_node_child: false
2117+
custom_type: 0
2118+
enabled: true
2119+
}
2120+
nodes {
2121+
position {
2122+
x: 0.0
2123+
y: 0.0
2124+
z: 0.0
2125+
w: 1.0
2126+
}
2127+
rotation {
2128+
x: 0.0
2129+
y: 0.0
2130+
z: 0.0
2131+
w: 1.0
2132+
}
2133+
scale {
2134+
x: 1.0
2135+
y: 1.0
2136+
z: 1.0
2137+
w: 1.0
2138+
}
2139+
size {
2140+
x: 320.0
2141+
y: 70.0
2142+
z: 0.0
2143+
w: 1.0
2144+
}
2145+
color {
2146+
x: 1.0
2147+
y: 1.0
2148+
z: 1.0
2149+
w: 1.0
2150+
}
2151+
type: TYPE_BOX
2152+
blend_mode: BLEND_MODE_ALPHA
2153+
texture: "common/button"
2154+
id: "button_not_available_methods/body"
2155+
xanchor: XANCHOR_NONE
2156+
yanchor: YANCHOR_NONE
2157+
pivot: PIVOT_CENTER
2158+
adjust_mode: ADJUST_MODE_FIT
2159+
parent: "button_not_available_methods"
2160+
layer: "common"
2161+
inherit_alpha: true
2162+
slice9 {
2163+
x: 24.0
2164+
y: 24.0
2165+
z: 24.0
2166+
w: 24.0
2167+
}
2168+
clipping_mode: CLIPPING_MODE_NONE
2169+
clipping_visible: true
2170+
clipping_inverted: false
2171+
alpha: 1.0
2172+
template_node_child: true
2173+
size_mode: SIZE_MODE_MANUAL
2174+
custom_type: 0
2175+
enabled: true
2176+
visible: true
2177+
material: ""
2178+
}
2179+
nodes {
2180+
position {
2181+
x: 0.0
2182+
y: 0.0
2183+
z: 0.0
2184+
w: 1.0
2185+
}
2186+
rotation {
2187+
x: 0.0
2188+
y: 0.0
2189+
z: 0.0
2190+
w: 1.0
2191+
}
2192+
scale {
2193+
x: 0.8
2194+
y: 0.8
2195+
z: 1.0
2196+
w: 1.0
2197+
}
2198+
size {
2199+
x: 375.0
2200+
y: 87.5
2201+
z: 0.0
2202+
w: 1.0
2203+
}
2204+
color {
2205+
x: 1.0
2206+
y: 1.0
2207+
z: 1.0
2208+
w: 1.0
2209+
}
2210+
type: TYPE_TEXT
2211+
blend_mode: BLEND_MODE_ALPHA
2212+
text: "List Not Available Methods"
2213+
font: "font2"
2214+
id: "button_not_available_methods/text"
2215+
xanchor: XANCHOR_NONE
2216+
yanchor: YANCHOR_NONE
2217+
pivot: PIVOT_CENTER
2218+
outline {
2219+
x: 0.0
2220+
y: 0.0
2221+
z: 0.0
2222+
w: 1.0
2223+
}
2224+
shadow {
2225+
x: 0.0
2226+
y: 0.0
2227+
z: 0.0
2228+
w: 1.0
2229+
}
2230+
adjust_mode: ADJUST_MODE_FIT
2231+
line_break: false
2232+
parent: "button_not_available_methods/body"
2233+
layer: "font2"
2234+
inherit_alpha: true
2235+
alpha: 1.0
2236+
outline_alpha: 1.0
2237+
shadow_alpha: 1.0
2238+
overridden_fields: 8
2239+
template_node_child: true
2240+
text_leading: 1.0
2241+
text_tracking: 0.0
2242+
custom_type: 0
2243+
enabled: true
2244+
visible: true
2245+
material: ""
2246+
}
20782247
nodes {
20792248
position {
20802249
x: 20.0
@@ -5378,7 +5547,7 @@ nodes {
53785547
nodes {
53795548
position {
53805549
x: 550.0
5381-
y: 938.0
5550+
y: 1086.7816
53825551
z: 0.0
53835552
w: 1.0
53845553
}
@@ -7023,7 +7192,7 @@ nodes {
70237192
nodes {
70247193
position {
70257194
x: 550.0
7026-
y: 1093.0
7195+
y: 1241.7816
70277196
z: 0.0
70287197
w: 1.0
70297198
}
@@ -7486,7 +7655,7 @@ nodes {
74867655
nodes {
74877656
position {
74887657
x: 1080.0
7489-
y: 938.0
7658+
y: 1086.7816
74907659
z: 0.0
74917660
w: 1.0
74927661
}
@@ -8118,7 +8287,7 @@ nodes {
81188287
nodes {
81198288
position {
81208289
x: 1080.0
8121-
y: 798.501
8290+
y: 947.28253
81228291
z: 0.0
81238292
w: 1.0
81248293
}
@@ -8749,7 +8918,7 @@ nodes {
87498918
nodes {
87508919
position {
87518920
x: 1249.8689
8752-
y: 1093.0
8921+
y: 1241.7816
87538922
z: 0.0
87548923
w: 1.0
87558924
}

0 commit comments

Comments
 (0)