Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Gameplay API #27

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`<br>If the player doesn't have any score, you get the error `FetchError: Player is not present in leaderboard`.<br>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)`<br>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)`<br>The callback result is a table `{ value = true/false, reason = "string" }` |
| `ysdk.feedback.requestReview()` | `yagames.feedback_request_review(callback)`<br>The callback result is a table `{ feedbackSent = true/false }` |
Expand Down
6 changes: 6 additions & 0 deletions example/ysdkinit/init.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion game.project
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion yagames/helpers/mock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ local available_methods = {
"deviceInfo.isTV",
-- Features
"features.LoadingAPI.ready",
"features.GameplayAPI.start",
"features.GameplayAPI.stop",
-- Feedback
"feedback.canReview",
-- "feedback.requestReview",
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 19 additions & 1 deletion yagames/lib/web/lib_yagames.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions yagames/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 },
Expand Down
14 changes: 14 additions & 0 deletions yagames/yagames.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down