diff --git a/README.md b/README.md index 7d761dd..9aed7f3 100644 --- a/README.md +++ b/README.md @@ -258,8 +258,10 @@ And it's also a good idea to upload a demo build of YaGames to your game's draft | `lb.getLeaderboardPlayerEntry(leaderboardName)` | `yagames.leaderboards_get_player_entry(leaderboard_name, [options], callback)`
If the player doesn't have any score, you get the error `FetchError: Player is not present in leaderboard`.
The argument `options` is an optional Lua table `{ getAvatarSrc = "size", getAvatarSrcSet = "size" }`, where `size` (string) can be `small`, `medium`, `large`. | | `lb.getLeaderboardEntries(leaderboardName, options)` | `yagames.leaderboards_get_entries(leaderboard_name, [options], callback)`
The argument `options` is an optional Lua table `{ includeUser = boolean, quantityAround = number, quantityTop = number, getAvatarSrc = "size", getAvatarSrcSet = "size" }`, where `size` (string) can be `small`, `medium`, `large`. | | `lb.setLeaderboardScore(leaderboardName, score, extraData)` | `yagames.leaderboards_set_score(leaderboard_name, score, [extra_data], [callback])` | -| **Features** [(docs)](https://yandex.com/dev/games/doc/en/sdk/sdk-gameready) | | +| **Features** [(docs)](https://yandex.com/dev/games/doc/en/sdk/sdk-game-events) | | | `ysdk.features.LoadingAPI?.ready()` | `yagames.features_loadingapi_ready()` | +| `ysdk.features.GameplayAPI?.start()` | `yagames.features_gameplayapi_start()` | +| `ysdk.features.GameplayAPI?.stop()` | `yagames.features_gameplayapi_stop()` | | **Feedback** [(docs)](https://yandex.ru/dev/games/doc/en/sdk/sdk-review) | | | `ysdk.feedback.canReview()` | `yagames.feedback_can_review(callback)`
The callback result is a table `{ value = true/false, reason = "string" }` | | `ysdk.feedback.requestReview()` | `yagames.feedback_request_review(callback)`
The callback result is a table `{ feedbackSent = true/false }` | diff --git a/example/ysdkinit/init.gui_script b/example/ysdkinit/init.gui_script index a7308b4..446a9c1 100755 --- a/example/ysdkinit/init.gui_script +++ b/example/ysdkinit/init.gui_script @@ -3,8 +3,14 @@ local druid = require("druid.druid") local druid_style = require("example.ysdkdebug.druid_style") local sitelock = require("yagames.sitelock") local rxi_json = require("yagames.helpers.json") +local yagames = require("yagames.yagames") local function continue_handler(self) + -- In fact, you should call the “start” function from GameplayAPI when gameplay starts. + -- Here it is called just to check if it works. + yagames.features_gameplayapi_start() + + -- Show the next screen! app_scenemanager.load_scene("ysdkdebug") end diff --git a/game.project b/game.project index 81bef21..a548880 100755 --- a/game.project +++ b/game.project @@ -11,7 +11,7 @@ high_dpi = 1 [project] title = yagames -version = 0.12.0 +version = 0.13.0 developer = Indiesoft LLC bundle_resources = example/bundle/ dependencies#0 = https://github.com/subsoap/defos/archive/v2.5.0.zip diff --git a/yagames/helpers/mock.lua b/yagames/helpers/mock.lua index 21c53f4..281d36f 100755 --- a/yagames/helpers/mock.lua +++ b/yagames/helpers/mock.lua @@ -59,6 +59,8 @@ local available_methods = { "deviceInfo.isTV", -- Features "features.LoadingAPI.ready", + "features.GameplayAPI.start", + "features.GameplayAPI.stop", -- Feedback "feedback.canReview", -- "feedback.requestReview", @@ -185,12 +187,18 @@ function M.device_info_is_tv() end function M.environment() - return '{"app":{"id":"1"},"payload":"test","i18n":{"tld":"en","lang":"en"},"browser":{"lang":"en"},"data":{"secondDomain":"yandex","baseUrl":"/games"}}' + return '{"app":{"id":"1"},"payload":"test","i18n":{"tld":"com","lang":"en"},"browser":{"lang":"en"},"data":{"secondDomain":"yandex","baseUrl":"/games"},"isTelegram":"false"}' end function M.features_loadingapi_ready() end +function M.features_gameplayapi_start() +end + +function M.features_gameplayapi_stop() +end + function M.feedback_can_review(cb_id) M.send(cb_id, NO_ERR, rxi_json.encode({ value = false, diff --git a/yagames/lib/web/lib_yagames.js b/yagames/lib/web/lib_yagames.js index 13665d8..678b10f 100755 --- a/yagames/lib/web/lib_yagames.js +++ b/yagames/lib/web/lib_yagames.js @@ -260,7 +260,7 @@ var LibYaGamesPrivate = { YaGamesPrivate_DeviceInfo_Type: function () { var self = YaGamesPrivate; - var ctype = stringToNewUTF8(self._ysdk.deviceInfo.type); + var ctype = stringToNewUTF8(self._ysdk.deviceInfo.type || "null"); return ctype; }, @@ -296,6 +296,24 @@ var LibYaGamesPrivate = { } }, + YaGamesPrivate_Features_GameplayAPI_Start: function () { + var self = YaGamesPrivate; + try { + self._ysdk.features.GameplayAPI.start(); + } catch (err) { + console.warn(err); + } + }, + + YaGamesPrivate_Features_GameplayAPI_Stop: function () { + var self = YaGamesPrivate; + try { + self._ysdk.features.GameplayAPI.stop(); + } catch (err) { + console.warn(err); + } + }, + YaGamesPrivate_Feedback_CanReview: function (cb_id) { var self = YaGamesPrivate; try { diff --git a/yagames/src/main.cpp b/yagames/src/main.cpp index 7b3be2f..c6f80cd 100644 --- a/yagames/src/main.cpp +++ b/yagames/src/main.cpp @@ -34,6 +34,8 @@ extern "C" const bool YaGamesPrivate_DeviceInfo_IsTV(); const char* YaGamesPrivate_Environment(); void YaGamesPrivate_Features_LoadingAPI_Ready(); + void YaGamesPrivate_Features_GameplayAPI_Start(); + void YaGamesPrivate_Features_GameplayAPI_Stop(); void YaGamesPrivate_Feedback_CanReview(const int cb_id); void YaGamesPrivate_Feedback_RequestReview(const int cb_id); void YaGamesPrivate_GetLeaderboards(const int cb_id); @@ -480,6 +482,18 @@ static int Features_LoadingAPI_Ready(lua_State* L) return 0; } +static int Features_GameplayAPI_Start(lua_State* L) +{ + YaGamesPrivate_Features_GameplayAPI_Start(); + return 0; +} + +static int Features_GameplayAPI_Stop(lua_State* L) +{ + YaGamesPrivate_Features_GameplayAPI_Stop(); + return 0; +} + static int Feedback_CanReview(lua_State* L) { YaGamesPrivate_Feedback_CanReview(luaL_checkint(L, 1)); @@ -874,6 +888,8 @@ static const luaL_reg Module_methods[] = { { "environment", Environment }, // - Features { "features_loadingapi_ready", Features_LoadingAPI_Ready }, + { "features_gameplayapi_start", Features_GameplayAPI_Start }, + { "features_gameplayapi_stop", Features_GameplayAPI_Stop }, // - Feedback { "feedback_can_review", Feedback_CanReview }, { "feedback_request_review", Feedback_RequestReview }, diff --git a/yagames/yagames.lua b/yagames/yagames.lua index 9f5f8a2..2a661b4 100755 --- a/yagames/yagames.lua +++ b/yagames/yagames.lua @@ -213,6 +213,20 @@ function M.features_loadingapi_ready() yagames_private.features_loadingapi_ready() end +--- The method should be called when the player starts or resumes gameplay +function M.features_gameplayapi_start() + assert(M.ysdk_ready, "YaGames is not initialized.") + + yagames_private.features_gameplayapi_start() +end + +--- The method should be called when the player stops or pauses gameplay +function M.features_gameplayapi_stop() + assert(M.ysdk_ready, "YaGames is not initialized.") + + yagames_private.features_gameplayapi_stop() +end + --- Return a table with game environment variables. -- @treturn table function M.environment()