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 GamesAPI methods #31

Merged
merged 3 commits into from
Oct 7, 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
18 changes: 18 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
It's a native extension for the Defold game engine. The Defold engine is a 2D game engine, but it can also be used to make 3D games. It uses Lua 5.1 as its scripting language with "bit" module for bitwise operations. Developers write Lua code in the files with ".lua", ".script", ".gui_script", ".render_script", ".editor_script" extensions. Source code is formatted with 4 spaces for indentation. "snake_case" is used for variable, function, file, folder names. It uses LDoc for documentation.

The example of LDoc is:

```lua
--- Summary ends with a period.
-- Some description, can be over several lines.
-- @tparam string p1 first parameter
-- @tparam[opt] string p2 second parameter (optional)
-- @treturn number a number value
-- @see second_fun
function mod1.first_fun(p1,p2)
end
```

The structure of the project is the following:
- folder "yagames" contains the Lua and C/C++ part of the extension. C/C++ code is compiled to WebAssembly via Emscripten or to the native code for other platforms.
- folder "example" contains the example project written in Lua for the extension.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ And it's also a good idea to upload a demo build of YaGames to your game's draft
| `ysdk.features.LoadingAPI?.ready()` | `yagames.features_loadingapi_ready()` |
| `ysdk.features.GameplayAPI?.start()` | `yagames.features_gameplayapi_start()` |
| `ysdk.features.GameplayAPI?.stop()` | `yagames.features_gameplayapi_stop()` |
| `ysdk.features.GamesAPI?.getAllGames()` | `yagames.features_gamesapi_get_all_games(callback)`<br>The callback result is a table `{ games = { ... }, developerURL = "string" }` |
| `ysdk.features.GamesAPI?.getGameByID(appID)` | `yagames.features_gamesapi_get_game_by_id(app_id, callback)`<br>The callback result is a table `{ isAvailable = true/false, game = { appID = "string", title = "string", url = "string", coverURL = "string", iconURL = "string" } }` |
| **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
35 changes: 35 additions & 0 deletions example/ysdkdebug/pg_games_api.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
local druid = require("druid.druid")
local druid_style = require("example.ysdkdebug.druid_style")
local table_util = require("example.ysdkdebug.table_util")

local yagames = require("yagames.yagames")

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

local M = {}

local game_id = 0

function M.get_all_games_handler(self)
yagames.features_gamesapi_get_all_games(function(self, err, result)
print("yagames.features_gamesapi_get_all_games:", err or table_util.tostring(result))
for _, game in ipairs(result.games) do
game_id = tonumber(game.appID)
break
end
end)
end

function M.get_game_by_id_handler(self)
yagames.features_gamesapi_get_game_by_id(game_id,function(self, err, result)
print("yagames.features_gamesapi_get_game_by_id(" .. tostring(game_id) .. "):", err or table_util.tostring(result))
end)
end

function M.init(self)
druid_style.make_button(self, "button_games_api_get_all_games", M.get_all_games_handler)
druid_style.make_button(self, "button_games_api_get_game_by_id", M.get_game_by_id_handler)
end

return M
Loading