├── bridge ├── ext.manifest ├── include │ ├── bridge_device.h │ ├── bridge_game.h │ ├── bridge_remote_config.h │ ├── bridge_leaderboards.h │ ├── bridge_player.h │ ├── bridge_achievements.h │ ├── bridge_payments.h │ ├── bridge_storage.h │ ├── bridge_advertisement.h │ ├── bridge_platform.h │ ├── bridge_social.h │ ├── bridge_helper.h │ └── bridge.h ├── bridge_device.lua ├── lib │ └── web │ │ ├── bridge_device.js │ │ ├── bridge_game.js │ │ ├── bridge_remote_config.js │ │ ├── bridge_player.js │ │ ├── bridge_leaderboards.js │ │ ├── bridge_achievements.js │ │ ├── bridge_payments.js │ │ ├── bridge_storage.js │ │ ├── bridge_advertisement.js │ │ ├── bridge_platform.js │ │ └── bridge_social.js ├── bridge_game.lua ├── src │ ├── bridge_device.cpp │ ├── bridge_game.cpp │ ├── bridge_remote_config.cpp │ ├── bridge_leaderboards.cpp │ ├── bridge_payments.cpp │ ├── bridge_storage.cpp │ ├── bridge_achievements.cpp │ ├── bridge_player.cpp │ ├── bridge_platform.cpp │ ├── bridge_social.cpp │ ├── bridge_advertisement.cpp │ ├── bridge_helper.cpp │ └── bridge.cpp ├── bridge_remote_config.lua ├── res │ └── web │ │ └── cpp_helper.js ├── bridge_leaderboards.lua ├── bridge_player.lua ├── bridge_payments.lua ├── bridge_achievements.lua ├── bridge_platfrom.lua ├── bridge_storage.lua ├── bridge_social.lua ├── bridge.lua ├── bridge_advertisement.lua ├── engine_template.html └── api │ └── bridge.script_api ├── input └── game.input_binding ├── main └── main.collection ├── .gitignore ├── game.project ├── res └── web │ └── playgama-bridge-config.json ├── LICENSE ├── README.md └── .clang-format /bridge/ext.manifest: -------------------------------------------------------------------------------- 1 | name: Bridge -------------------------------------------------------------------------------- /input/game.input_binding: -------------------------------------------------------------------------------- 1 | mouse_trigger { 2 | input: MOUSE_BUTTON_1 3 | action: "touch" 4 | } 5 | -------------------------------------------------------------------------------- /main/main.collection: -------------------------------------------------------------------------------- 1 | name: "main" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "go" 5 | data: "" 6 | } 7 | -------------------------------------------------------------------------------- /bridge/include/bridge_device.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(DM_PLATFORM_HTML5) 4 | 5 | extern "C" { 6 | char* js_bridge_device_type(); 7 | } 8 | 9 | #endif -------------------------------------------------------------------------------- /bridge/bridge_device.lua: -------------------------------------------------------------------------------- 1 | local device = {} 2 | 3 | -- Local variables 4 | local sysinfo = sys.get_sys_info() 5 | 6 | function device.type() 7 | return "desktop" 8 | end 9 | 10 | return device -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.internal 2 | /build 3 | .externalToolBuilders 4 | .DS_Store 5 | Thumbs.db 6 | .lock-wscript 7 | *.pyc 8 | .project 9 | .cproject 10 | builtins 11 | /.editor_settings 12 | *.der 13 | .vscode -------------------------------------------------------------------------------- /bridge/lib/web/bridge_device.js: -------------------------------------------------------------------------------- 1 | let js_bridge_device = { 2 | js_bridge_device_type: function () { 3 | return CStrOrNull(bridge.device.type); 4 | } 5 | } 6 | 7 | mergeInto(LibraryManager.library, js_bridge_device); -------------------------------------------------------------------------------- /bridge/bridge_game.lua: -------------------------------------------------------------------------------- 1 | local game = {} 2 | 3 | -- Local variables 4 | local visibility_state = "visible" 5 | 6 | function game.visibility_state() 7 | return visibility_state 8 | end 9 | 10 | function game.on(event_name, callback) 11 | end 12 | 13 | return game -------------------------------------------------------------------------------- /bridge/src/bridge_device.cpp: -------------------------------------------------------------------------------- 1 | #if defined(DM_PLATFORM_HTML5) 2 | #include "bridge_device.h" 3 | #include "bridge.h" 4 | #include "bridge_helper.h" 5 | 6 | int bridge::device::type(lua_State* L) { 7 | return getString(L, js_bridge_device_type); 8 | } 9 | 10 | #endif -------------------------------------------------------------------------------- /bridge/bridge_remote_config.lua: -------------------------------------------------------------------------------- 1 | local remote_config = {} 2 | 3 | function remote_config.is_supported() 4 | return false 5 | end 6 | 7 | function remote_config.get(options, on_success, on_failure) 8 | if on_failure then 9 | on_failure() 10 | end 11 | end 12 | 13 | return remote_config -------------------------------------------------------------------------------- /bridge/src/bridge_game.cpp: -------------------------------------------------------------------------------- 1 | #if defined(DM_PLATFORM_HTML5) 2 | #include "bridge_game.h" 3 | #include "bridge.h" 4 | 5 | int bridge::game::on(lua_State* L) { 6 | return makeOnCallback(L, js_bridge_game_on); 7 | } 8 | 9 | int bridge::game::visibilityState(lua_State* L) { 10 | return getString(L, js_bridge_game_visibilityState); 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /bridge/include/bridge_game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(DM_PLATFORM_HTML5) 4 | #include "bridge_helper.h" 5 | #include 6 | 7 | extern "C" { 8 | void js_bridge_game_on(OnHandler handler, 9 | const char* eventName, 10 | dmScript::LuaCallbackInfo* callback); 11 | 12 | char* js_bridge_game_visibilityState(); 13 | } 14 | 15 | #endif -------------------------------------------------------------------------------- /bridge/src/bridge_remote_config.cpp: -------------------------------------------------------------------------------- 1 | #if defined(DM_PLATFORM_HTML5) 2 | #include "bridge_remote_config.h" 3 | #include "bridge.h" 4 | 5 | int bridge::remoteConfig::isSupported(lua_State* L) { 6 | return getBoolean(L, js_bridge_remoteConfig_isSupported); 7 | } 8 | 9 | int bridge::remoteConfig::get(lua_State* L) { 10 | return makeCallbackWithJson(L, js_bridge_remoteConfig_get, true); 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /bridge/res/web/cpp_helper.js: -------------------------------------------------------------------------------- 1 | const Type = { 2 | Zero: 0, 3 | Json: 1, 4 | String: 2, 5 | Integer: 3, 6 | Number: 4, // float 7 | }; 8 | 9 | function packToJson(data) { 10 | if (data) { 11 | let obj = { data: data }; 12 | return stringToNewUTF8(JSON.stringify(obj)); 13 | } 14 | return 0; 15 | } 16 | 17 | function CStrOrNull(string) { 18 | if (string) { 19 | return stringToNewUTF8(string); 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /game.project: -------------------------------------------------------------------------------- 1 | [bootstrap] 2 | main_collection = /main/main.collectionc 3 | 4 | [script] 5 | shared_state = 1 6 | 7 | [display] 8 | width = 960 9 | height = 640 10 | high_dpi = 1 11 | 12 | [android] 13 | input_method = HiddenInputField 14 | 15 | [html5] 16 | scale_mode = stretch 17 | htmlfile = /bridge/engine_template.html 18 | 19 | [project] 20 | title = Bridge-defold 21 | dependencies = 22 | bundle_resources = /res 23 | 24 | [library] 25 | include_dirs = bridge 26 | 27 | -------------------------------------------------------------------------------- /res/web/playgama-bridge-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://bridge.playgama.com/v1.27.0/schema.json", 3 | "advertisement": { 4 | "interstitial": { 5 | "preloadOnStart": true 6 | }, 7 | "rewarded": { 8 | "preloadOnStart": true 9 | }, 10 | "useBuiltInErrorPopup": true, 11 | "backfillId": "" 12 | }, 13 | "payments": [], 14 | "leaderboards": [], 15 | "sendAnalyticsEvents": true 16 | } 17 | -------------------------------------------------------------------------------- /bridge/lib/web/bridge_game.js: -------------------------------------------------------------------------------- 1 | let js_bridge_game = { 2 | js_bridge_game_on: function (handler, event_name, callback) { 3 | bridge.game.on(UTF8ToString(event_name), state => { 4 | {{{ makeDynCall('vii', 'handler') }}} (callback, packToJson(state)); 5 | }); 6 | }, 7 | 8 | js_bridge_game_visibilityState: function () { 9 | return CStrOrNull(bridge.game.visibilityState); 10 | } 11 | } 12 | 13 | mergeInto(LibraryManager.library, js_bridge_game); -------------------------------------------------------------------------------- /bridge/include/bridge_remote_config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(DM_PLATFORM_HTML5) 4 | #include "bridge_helper.h" 5 | #include 6 | 7 | extern "C" { 8 | bool js_bridge_remoteConfig_isSupported(); 9 | 10 | void js_bridge_remoteConfig_get(UniversalHandler handler, 11 | const char* json, 12 | dmScript::LuaCallbackInfo* onSuccess, 13 | dmScript::LuaCallbackInfo* onFailure); 14 | } 15 | 16 | #endif -------------------------------------------------------------------------------- /bridge/bridge_leaderboards.lua: -------------------------------------------------------------------------------- 1 | local leaderboards = {} 2 | 3 | function leaderboards.type() 4 | return "not_available" 5 | end 6 | 7 | function leaderboards.set_score(id, score, on_success, on_failure) 8 | if on_failure then 9 | on_failure() 10 | end 11 | end 12 | 13 | function leaderboards.get_entries(id, on_success, on_failure) 14 | if on_failure then 15 | on_failure() 16 | end 17 | end 18 | 19 | function leaderboards.show_native_popup(id, on_success, on_failure) 20 | if on_failure then 21 | on_failure() 22 | end 23 | end 24 | 25 | return leaderboards -------------------------------------------------------------------------------- /bridge/bridge_player.lua: -------------------------------------------------------------------------------- 1 | local player = {} 2 | 3 | function player.is_authorization_supported() 4 | return false 5 | end 6 | 7 | function player.is_authorized() 8 | return false 9 | end 10 | 11 | function player.id() 12 | return nil 13 | end 14 | 15 | function player.name() 16 | return nil 17 | end 18 | 19 | function player.extra() 20 | return {} 21 | end 22 | 23 | function player.photos() 24 | return {} 25 | end 26 | 27 | function player.authorize(options, on_success, on_failure) 28 | if on_failure then 29 | on_failure() 30 | end 31 | end 32 | 33 | return player -------------------------------------------------------------------------------- /bridge/bridge_payments.lua: -------------------------------------------------------------------------------- 1 | local payments = {} 2 | 3 | function payments.is_supported() 4 | return false 5 | end 6 | 7 | function payments.purchase(id, options, on_success, on_failure) 8 | if on_failure then 9 | on_failure() 10 | end 11 | end 12 | 13 | function payments.consume_purchase(id, on_success, on_failure) 14 | if on_failure then 15 | on_failure() 16 | end 17 | end 18 | 19 | function payments.get_catalog(on_success, on_failure) 20 | if on_failure then 21 | on_failure() 22 | end 23 | end 24 | 25 | function payments.get_purchases(on_success, on_failure) 26 | if on_failure then 27 | on_failure() 28 | end 29 | end 30 | 31 | return payments -------------------------------------------------------------------------------- /bridge/src/bridge_leaderboards.cpp: -------------------------------------------------------------------------------- 1 | #if defined(DM_PLATFORM_HTML5) 2 | #include "bridge_leaderboards.h" 3 | #include "bridge.h" 4 | 5 | int bridge::leaderboards::type(lua_State* L) { 6 | return getString(L, js_bridge_leaderboards_type); 7 | } 8 | 9 | int bridge::leaderboards::setScore(lua_State* L) { 10 | return makeCallbackLeaderboardsSetScore(L, js_bridge_leaderboards_setScore, false); 11 | } 12 | 13 | int bridge::leaderboards::getEntries(lua_State* L) { 14 | return makeCallbackWithString(L, js_bridge_leaderboards_getEntries, true); 15 | } 16 | 17 | int bridge::leaderboards::showNativePopup(lua_State* L) { 18 | return makeCallbackWithString(L, js_bridge_leaderboards_showNativePopup, true); 19 | } 20 | 21 | #endif -------------------------------------------------------------------------------- /bridge/bridge_achievements.lua: -------------------------------------------------------------------------------- 1 | local achievements = {} 2 | 3 | function achievements.is_supported() 4 | return false 5 | end 6 | 7 | function achievements.is_get_list_supported() 8 | return false 9 | end 10 | 11 | function achievements.is_native_popup_supported() 12 | return false 13 | end 14 | 15 | function achievements.unlock(options, on_success, on_failure) 16 | if on_failure then 17 | on_failure() 18 | end 19 | end 20 | 21 | function achievements.get_list(options, on_success, on_failure) 22 | if on_failure then 23 | on_failure() 24 | end 25 | end 26 | 27 | function achievements.show_native_popup(options, on_success, on_failure) 28 | if on_failure then 29 | on_failure() 30 | end 31 | end 32 | 33 | return achievements -------------------------------------------------------------------------------- /bridge/include/bridge_leaderboards.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(DM_PLATFORM_HTML5) 4 | #include "bridge_helper.h" 5 | #include 6 | 7 | extern "C" { 8 | char* js_bridge_leaderboards_type(); 9 | 10 | void js_bridge_leaderboards_setScore(UniversalHandler handler, const char* id, int score, dmScript::LuaCallbackInfo* onSuccess, dmScript::LuaCallbackInfo* onFailure); 11 | void js_bridge_leaderboards_getEntries(UniversalHandler handler, const char* id, dmScript::LuaCallbackInfo* onSuccess, dmScript::LuaCallbackInfo* onFailure); 12 | void js_bridge_leaderboards_showNativePopup(UniversalHandler handler, const char* id, dmScript::LuaCallbackInfo* onSuccess, dmScript::LuaCallbackInfo* onFailure); 13 | } 14 | 15 | #endif -------------------------------------------------------------------------------- /bridge/include/bridge_player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(DM_PLATFORM_HTML5) 4 | #include "bridge_helper.h" 5 | #include 6 | 7 | extern "C" { 8 | bool js_bridge_player_isAuthorizationSupported(); 9 | 10 | bool js_bridge_player_isAuthorized(); 11 | 12 | char* js_bridge_player_id(); 13 | 14 | char* js_bridge_player_name(); 15 | 16 | char* js_bridge_player_extra(); 17 | 18 | char* js_bridge_player_photos(); 19 | 20 | void js_bridge_player_authorize(UniversalHandler handler, 21 | const char* json, 22 | dmScript::LuaCallbackInfo* onSuccess, 23 | dmScript::LuaCallbackInfo* onFailure); 24 | } 25 | 26 | #endif -------------------------------------------------------------------------------- /bridge/lib/web/bridge_remote_config.js: -------------------------------------------------------------------------------- 1 | let js_bridge_remoteConfig = { 2 | js_bridge_remoteConfig_isSupported: function () { 3 | return bridge.remoteConfig.isSupported; 4 | }, 5 | 6 | js_bridge_remoteConfig_get: function (handler, options, onSuccess, onFailure) { 7 | var jsOptions = JSON.parse(UTF8ToString(options)); 8 | bridge.remoteConfig.get(jsOptions) 9 | .then(data => { 10 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson(data)); 11 | }) 12 | .catch(error => { 13 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 14 | }) 15 | }, 16 | } 17 | 18 | mergeInto(LibraryManager.library, js_bridge_remoteConfig); -------------------------------------------------------------------------------- /bridge/src/bridge_payments.cpp: -------------------------------------------------------------------------------- 1 | #if defined(DM_PLATFORM_HTML5) 2 | #include "bridge_payments.h" 3 | #include "bridge.h" 4 | 5 | int bridge::payments::isSupported(lua_State* L) { 6 | return getBoolean(L, js_bridge_payments_isSupported); 7 | } 8 | 9 | int bridge::payments::purchase(lua_State* L) { 10 | return makeCallbackWithStringAndJson(L, js_bridge_payments_purchase, true); 11 | } 12 | 13 | int bridge::payments::consumePurchase(lua_State* L) { 14 | return makeCallbackWithString(L, js_bridge_payments_consumePurchase, true); 15 | } 16 | 17 | int bridge::payments::getCatalog(lua_State* L) { 18 | return makeCallback(L, js_bridge_payments_getCatalog, true); 19 | } 20 | 21 | int bridge::payments::getPurchases(lua_State* L) { 22 | return makeCallback(L, js_bridge_payments_getPurchases, true); 23 | } 24 | 25 | #endif -------------------------------------------------------------------------------- /bridge/src/bridge_storage.cpp: -------------------------------------------------------------------------------- 1 | #if defined(DM_PLATFORM_HTML5) 2 | #include "bridge_storage.h" 3 | #include "bridge.h" 4 | 5 | int bridge::storage::isSupported(lua_State* L) { return getBooleanWithString(L, js_bridge_storage_isSupported); } 6 | 7 | int bridge::storage::isAvailable(lua_State* L) { return getBooleanWithString(L, js_bridge_storage_isAvailable); } 8 | 9 | int bridge::storage::defaultType(lua_State* L) { return getString(L, js_bridge_storage_defaultType); } 10 | 11 | int bridge::storage::get(lua_State* L) { 12 | return makeCallbackStorage(L, js_bridge_storage_get, true); 13 | } 14 | 15 | int bridge::storage::set(lua_State* L) { 16 | return makeCallbackStorage(L, js_bridge_storage_set, false); 17 | } 18 | 19 | int bridge::storage::deleteData(lua_State* L) { 20 | return makeCallbackStorage(L, js_bridge_storage_delete, false); 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /bridge/src/bridge_achievements.cpp: -------------------------------------------------------------------------------- 1 | #if defined(DM_PLATFORM_HTML5) 2 | #include "bridge_achievements.h" 3 | #include "bridge.h" 4 | #include "bridge_helper.h" 5 | 6 | int bridge::achievements::isSupported(lua_State* L) { 7 | return getBoolean(L, js_bridge_achievements_isSupported); 8 | } 9 | 10 | int bridge::achievements::isGetListSupported(lua_State* L) { 11 | return getBoolean(L, js_bridge_achievements_isGetListSupported); 12 | } 13 | 14 | int bridge::achievements::isNativePopupSupported(lua_State* L) { 15 | return getBoolean(L, js_bridge_achievements_isNativePopupSupported); 16 | } 17 | 18 | int bridge::achievements::unlock(lua_State* L) { 19 | return makeCallbackWithJson(L, js_bridge_achievements_unlock, true); 20 | } 21 | 22 | int bridge::achievements::getList(lua_State* L) { 23 | return makeCallbackWithJson(L, js_bridge_achievements_getList, true); 24 | } 25 | 26 | int bridge::achievements::showNativePopup(lua_State* L) { 27 | return makeCallbackWithJson(L, js_bridge_achievements_showNativePopup, true); 28 | } 29 | 30 | #endif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2024, LeadToChanges L.L.C-FZ 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /bridge/bridge_platfrom.lua: -------------------------------------------------------------------------------- 1 | local platform = {} 2 | 3 | -- Local variables 4 | local sysinfo = sys.get_sys_info() 5 | 6 | function platform.on(event_name, callback) 7 | 8 | end 9 | 10 | function platform.language() 11 | return sysinfo.device_language 12 | end 13 | 14 | function platform.id() 15 | return "mock" 16 | end 17 | 18 | function platform.payload() 19 | return nil 20 | end 21 | 22 | function platform.tld() 23 | return nil 24 | end 25 | 26 | function platform.send_message(message, on_success, on_failure) 27 | if on_success then 28 | on_success() 29 | end 30 | end 31 | 32 | function platform.get_server_time(on_success, on_failure) 33 | on_success(nil, os.time()) 34 | end 35 | 36 | function platform.is_audio_enabled() 37 | return true 38 | end 39 | 40 | function platform.is_get_all_games_supported() 41 | return false 42 | end 43 | 44 | function platform.get_all_games(on_success, on_failure) 45 | if on_failure then 46 | on_failure() 47 | end 48 | end 49 | 50 | function platform.is_get_game_by_id_supported() 51 | return false 52 | end 53 | 54 | function platform.get_game_by_id(options, on_success, on_failure) 55 | if on_failure then 56 | on_failure() 57 | end 58 | end 59 | 60 | return platform -------------------------------------------------------------------------------- /bridge/src/bridge_player.cpp: -------------------------------------------------------------------------------- 1 | #if defined(DM_PLATFORM_HTML5) 2 | #include "bridge_player.h" 3 | #include "bridge.h" 4 | 5 | int bridge::player::isAuthorizationSupported(lua_State* L) { 6 | return getBoolean(L, js_bridge_player_isAuthorizationSupported); 7 | } 8 | 9 | int bridge::player::isAuthorized(lua_State* L) { 10 | return getBoolean(L, js_bridge_player_isAuthorized); 11 | } 12 | 13 | int bridge::player::id(lua_State* L) { 14 | return getString(L, js_bridge_player_id); 15 | } 16 | 17 | int bridge::player::name(lua_State* L) { 18 | return getString(L, js_bridge_player_name); 19 | } 20 | 21 | int bridge::player::extra(lua_State* L) { 22 | DM_LUA_STACK_CHECK(L, 1); 23 | char* extraJson = js_bridge_player_extra(); 24 | dmScript::JsonToLua(L, extraJson, strlen(extraJson)); 25 | free(extraJson); 26 | return 1; 27 | } 28 | 29 | int bridge::player::photos(lua_State* L) { 30 | DM_LUA_STACK_CHECK(L, 1); 31 | char* photosJson = js_bridge_player_photos(); 32 | dmScript::JsonToLua(L, photosJson, strlen(photosJson)); 33 | free(photosJson); 34 | return 1; 35 | } 36 | 37 | int bridge::player::authorize(lua_State* L) { 38 | return makeCallbackWithJson(L, js_bridge_player_authorize, false); 39 | } 40 | #endif -------------------------------------------------------------------------------- /bridge/include/bridge_achievements.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(DM_PLATFORM_HTML5) 4 | #include "bridge_helper.h" 5 | #include 6 | 7 | extern "C" { 8 | bool js_bridge_achievements_isSupported(); 9 | 10 | bool js_bridge_achievements_isGetListSupported(); 11 | 12 | bool js_bridge_achievements_isNativePopupSupported(); 13 | 14 | void js_bridge_achievements_unlock(UniversalHandler handler, 15 | const char* options, 16 | dmScript::LuaCallbackInfo* onSuccess, 17 | dmScript::LuaCallbackInfo* onFailure); 18 | 19 | void js_bridge_achievements_getList(UniversalHandler handler, 20 | const char* options, 21 | dmScript::LuaCallbackInfo* onSuccess, 22 | dmScript::LuaCallbackInfo* onFailure); 23 | 24 | void js_bridge_achievements_showNativePopup(UniversalHandler handler, 25 | const char* options, 26 | dmScript::LuaCallbackInfo* onSuccess, 27 | dmScript::LuaCallbackInfo* onFailure); 28 | } 29 | 30 | #endif -------------------------------------------------------------------------------- /bridge/lib/web/bridge_player.js: -------------------------------------------------------------------------------- 1 | let js_bridge_player = { 2 | js_bridge_player_isAuthorizationSupported: function () { 3 | return bridge.player.isAuthorizationSupported; 4 | }, 5 | 6 | js_bridge_player_isAuthorized: function () { 7 | return bridge.player.isAuthorized; 8 | }, 9 | 10 | js_bridge_player_id: function () { 11 | return CStrOrNull(bridge.player.id); 12 | }, 13 | 14 | js_bridge_player_name: function () { 15 | return CStrOrNull(bridge.player.name); 16 | }, 17 | 18 | js_bridge_player_extra: function () { 19 | return packToJson(bridge.player.extra); 20 | }, 21 | 22 | js_bridge_player_photos: function () { 23 | return packToJson(bridge.player.photos); 24 | }, 25 | 26 | js_bridge_player_authorize: function (handler, options, onSuccess, onFailure) { 27 | var jsOptions = JSON.parse(UTF8ToString(options)); 28 | bridge.player.authorize(jsOptions) 29 | .then(() => { 30 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 31 | }) 32 | .catch(error => { 33 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 34 | }) 35 | } 36 | } 37 | 38 | mergeInto(LibraryManager.library, js_bridge_player); -------------------------------------------------------------------------------- /bridge/include/bridge_payments.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(DM_PLATFORM_HTML5) 4 | #include "bridge_helper.h" 5 | #include 6 | 7 | extern "C" { 8 | bool js_bridge_payments_isSupported(); 9 | 10 | void js_bridge_payments_purchase(UniversalHandler handler, 11 | const char* id, 12 | const char* json, 13 | dmScript::LuaCallbackInfo* onSuccess, 14 | dmScript::LuaCallbackInfo* onFailure); 15 | 16 | void js_bridge_payments_consumePurchase(UniversalHandler handler, 17 | const char* id, 18 | dmScript::LuaCallbackInfo* onSuccess, 19 | dmScript::LuaCallbackInfo* onFailure); 20 | 21 | void js_bridge_payments_getCatalog(UniversalHandler handler, 22 | dmScript::LuaCallbackInfo* onSuccess, 23 | dmScript::LuaCallbackInfo* onFailure); 24 | 25 | void js_bridge_payments_getPurchases(UniversalHandler handler, 26 | dmScript::LuaCallbackInfo* onSuccess, 27 | dmScript::LuaCallbackInfo* onFailure); 28 | } 29 | 30 | #endif -------------------------------------------------------------------------------- /bridge/include/bridge_storage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(DM_PLATFORM_HTML5) 4 | 5 | #include 6 | #include 7 | 8 | extern "C" { 9 | char* js_bridge_storage_defaultType(); 10 | 11 | bool js_bridge_storage_isAvailable(const char* storageType); 12 | 13 | bool js_bridge_storage_isSupported(const char* storageType); 14 | 15 | void js_bridge_storage_get(UniversalHandler handler, 16 | const char* json, 17 | dmScript::LuaCallbackInfo* onSuccess, 18 | dmScript::LuaCallbackInfo* onFailure, 19 | const char* storageType); 20 | 21 | void js_bridge_storage_set(UniversalHandler handler, 22 | const char* json, 23 | dmScript::LuaCallbackInfo* onSuccess, 24 | dmScript::LuaCallbackInfo* onFailure, 25 | const char* storageType); 26 | 27 | void js_bridge_storage_delete(UniversalHandler handler, 28 | const char* json, 29 | dmScript::LuaCallbackInfo* onSuccess, 30 | dmScript::LuaCallbackInfo* onFailure, 31 | const char* storageType); 32 | } 33 | 34 | #endif -------------------------------------------------------------------------------- /bridge/lib/web/bridge_leaderboards.js: -------------------------------------------------------------------------------- 1 | let js_bridge_leaderboards = { 2 | js_bridge_leaderboards_type: function () { 3 | return CStrOrNull(bridge.leaderboards.type); 4 | }, 5 | 6 | js_bridge_leaderboards_setScore: function (handler, id, score, onSuccess, onFailure) { 7 | bridge.leaderboards.setScore(UTF8ToString(id), parseInt(score)) 8 | .then(() => { 9 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 10 | }) 11 | .catch(error => { 12 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 13 | }) 14 | }, 15 | 16 | js_bridge_leaderboards_getEntries: function (handler, id, onSuccess, onFailure) { 17 | bridge.leaderboards.getEntries(UTF8ToString(id)) 18 | .then(entries => { 19 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson(entries)); 20 | }) 21 | .catch(error => { 22 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 23 | }) 24 | }, 25 | 26 | js_bridge_leaderboards_showNativePopup: function (handler, id, onSuccess, onFailure) { 27 | bridge.leaderboards.showNativePopup(UTF8ToString(id)) 28 | .then(() => { 29 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 30 | }) 31 | .catch(error => { 32 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 33 | }) 34 | }, 35 | } 36 | 37 | mergeInto(LibraryManager.library, js_bridge_leaderboards); -------------------------------------------------------------------------------- /bridge/src/bridge_platform.cpp: -------------------------------------------------------------------------------- 1 | #if defined(DM_PLATFORM_HTML5) 2 | #include "bridge_platform.h" 3 | #include "bridge.h" 4 | #include "bridge_helper.h" 5 | 6 | int bridge::platform::on(lua_State* L) { 7 | return makeOnCallback(L, js_bridge_platform_on); 8 | } 9 | 10 | int bridge::platform::id(lua_State* L) { 11 | return getString(L, js_bridge_platform_id); 12 | } 13 | 14 | int bridge::platform::language(lua_State* L) { 15 | return getString(L, js_bridge_platform_language); 16 | } 17 | 18 | int bridge::platform::tld(lua_State* L) { 19 | return getString(L, js_bridge_platform_tld); 20 | } 21 | 22 | int bridge::platform::payload(lua_State* L) { 23 | return getString(L, js_bridge_platform_payload); 24 | } 25 | 26 | int bridge::platform::getServerTime(lua_State* L) { 27 | return makeCallback(L, js_bridge_platform_getServerTime, true); 28 | } 29 | 30 | int bridge::platform::sendMessage(lua_State* L) { 31 | return makeCallbackWithString(L, js_bridge_platform_sendMessage, false); 32 | } 33 | 34 | int bridge::platform::isAudioEnabled(lua_State* L) { 35 | return getBoolean(L, js_bridge_platform_isAudioEnabled); 36 | } 37 | 38 | int bridge::platform::isGetAllGamesSupported(lua_State* L) { 39 | return getBoolean(L, js_bridge_platform_isGetAllGamesSupported); 40 | } 41 | 42 | int bridge::platform::getAllGames(lua_State* L) { 43 | return makeCallback(L, js_bridge_platform_getAllGames, false); 44 | } 45 | 46 | int bridge::platform::isGetGameByIdSupported(lua_State* L) { 47 | return getBoolean(L, js_bridge_platform_isGetGameByIdSupported); 48 | } 49 | 50 | int bridge::platform::getGameById(lua_State* L) { 51 | return makeCallbackWithJson(L, js_bridge_platform_getGameById, false); 52 | } 53 | 54 | #endif -------------------------------------------------------------------------------- /bridge/bridge_storage.lua: -------------------------------------------------------------------------------- 1 | local storage = {} 2 | 3 | -- Local variables 4 | local app_name = sys.get_config_string("project.title", "defold_game") 5 | local path_to_save_file = sys.get_save_file(app_name, "bridge_storage_data") 6 | local load_data = {} 7 | 8 | function storage.default_type() 9 | return "local_storage" 10 | end 11 | 12 | function storage.is_supported(storage_type) 13 | if storage_type == "local_storage" then 14 | return true 15 | elseif storage_type == "platform_internal" then 16 | return false 17 | end 18 | end 19 | 20 | function storage.is_available(storage_type) 21 | if storage_type == "local_storage" then 22 | return true 23 | elseif storage_type == "platform_internal" then 24 | return false 25 | end 26 | end 27 | 28 | function storage.get(table_keys, on_success, on_failure, storage_type) 29 | load_data = sys.load(path_to_save_file) 30 | 31 | local game_data = {} 32 | 33 | for k, v in pairs(table_keys) do 34 | if load_data[v] then 35 | game_data[v] = load_data[v] 36 | end 37 | end 38 | if on_success then 39 | on_success(_, game_data) 40 | end 41 | 42 | end 43 | 44 | function storage.set(table_data, on_success, on_failure, storage_type) 45 | for k, v in pairs(table_data) do 46 | if not load_data[k] then 47 | load_data[k] = v 48 | end 49 | end 50 | sys.save(path_to_save_file, load_data) 51 | 52 | if on_success then 53 | on_success() 54 | end 55 | end 56 | 57 | function storage.delete(table_keys, on_success, on_failure, storage_type) 58 | for k, v in pairs(table_keys) do 59 | if load_data[v] then 60 | load_data[v] = nil 61 | end 62 | end 63 | sys.save(path_to_save_file, load_data) 64 | 65 | if on_success then 66 | on_success() 67 | end 68 | end 69 | 70 | return storage -------------------------------------------------------------------------------- /bridge/include/bridge_advertisement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(DM_PLATFORM_HTML5) 4 | #include "bridge_helper.h" 5 | #include 6 | 7 | extern "C" { 8 | #pragma region Banner 9 | bool js_bridge_advertisement_isBannerSupported(); 10 | 11 | void js_bridge_advertisement_showBanner(const char* position, const char* placement); 12 | 13 | void js_bridge_advertisement_hideBanner(); 14 | 15 | char* js_bridge_advertisement_bannerState(); 16 | 17 | void js_bridge_advertisement_on(OnHandler handler, 18 | const char* eventName, 19 | dmScript::LuaCallbackInfo* callback); 20 | #pragma region 21 | 22 | #pragma region Interstitial 23 | bool js_bridge_advertisement_isInterstitialSupported(); 24 | 25 | int js_bridge_advertisement_minimumDelayBetweenInterstitial(); 26 | 27 | void js_bridge_advertisement_setMinimumDelayBetweenInterstitial(int delay); 28 | 29 | char* js_bridge_advertisement_interstitialState(); 30 | 31 | void js_bridge_advertisement_showInterstitial(const char* placement); 32 | #pragma endregion 33 | 34 | #pragma region Rewarded 35 | bool js_bridge_advertisement_isRewardedSupported(); 36 | 37 | char* js_bridge_advertisement_rewardedState(); 38 | 39 | char* js_bridge_advertisement_rewardedPlacement(); 40 | 41 | void js_bridge_advertisement_showRewarded(const char* placement); 42 | #pragma endregion 43 | 44 | #pragma region Adblock 45 | void js_bridge_advertisement_checkAdBlock(UniversalHandler handler, 46 | dmScript::LuaCallbackInfo* onSuccess, 47 | dmScript::LuaCallbackInfo* onFailure); 48 | #pragma endregion 49 | } 50 | 51 | #endif -------------------------------------------------------------------------------- /bridge/include/bridge_platform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "bridge_helper.h" 5 | 6 | #if defined(DM_PLATFORM_HTML5) 7 | 8 | extern "C" { 9 | void js_bridge_platform_on(OnHandler handler, 10 | const char* eventName, 11 | dmScript::LuaCallbackInfo* callback); 12 | 13 | char* js_bridge_platform_id(); 14 | 15 | char* js_bridge_platform_language(); 16 | 17 | char* js_bridge_platform_payload(); 18 | 19 | char* js_bridge_platform_tld(); 20 | 21 | void js_bridge_platform_sendMessage(UniversalHandler handler, 22 | const char* eventName, 23 | dmScript::LuaCallbackInfo* success, 24 | dmScript::LuaCallbackInfo* failure); 25 | 26 | void js_bridge_platform_getServerTime(UniversalHandler handler, 27 | dmScript::LuaCallbackInfo* success, 28 | dmScript::LuaCallbackInfo* failure); 29 | 30 | bool js_bridge_platform_isAudioEnabled(); 31 | 32 | bool js_bridge_platform_isGetAllGamesSupported(); 33 | 34 | void js_bridge_platform_getAllGames(UniversalHandler handler, 35 | dmScript::LuaCallbackInfo* success, 36 | dmScript::LuaCallbackInfo* failure); 37 | 38 | bool js_bridge_platform_isGetGameByIdSupported(); 39 | 40 | void js_bridge_platform_getGameById(UniversalHandler handler, 41 | const char* json, 42 | dmScript::LuaCallbackInfo* success, 43 | dmScript::LuaCallbackInfo* failure); 44 | } 45 | 46 | #endif -------------------------------------------------------------------------------- /bridge/bridge_social.lua: -------------------------------------------------------------------------------- 1 | local social = {} 2 | 3 | -- Share 4 | function social.is_share_supported() 5 | return false 6 | end 7 | 8 | function social.share(options, on_success, on_failure) 9 | if on_failure then 10 | on_failure() 11 | end 12 | end 13 | 14 | -- Join Community 15 | function social.is_join_community_supported() 16 | return false 17 | end 18 | 19 | function social.join_community(options, on_success, on_failure) 20 | if on_failure then 21 | on_failure() 22 | end 23 | end 24 | 25 | -- Invite Friends 26 | function social.is_invite_friends_supported() 27 | return false 28 | end 29 | 30 | function social.invite_friends(options, on_success, on_failure) 31 | if on_failure then 32 | on_failure() 33 | end 34 | end 35 | 36 | -- Create Post 37 | function social.is_create_post_supported() 38 | return false 39 | end 40 | 41 | function social.create_post(options, on_success, on_failure) 42 | if on_failure then 43 | on_failure() 44 | end 45 | end 46 | 47 | -- Add to Favorites 48 | function social.is_add_to_favorites_supported() 49 | return false 50 | end 51 | 52 | function social.add_to_favorites(on_success, on_failure) 53 | if on_failure then 54 | on_failure() 55 | end 56 | end 57 | 58 | -- Add to Home Screen 59 | function social.is_add_to_home_screen_supported() 60 | return false 61 | end 62 | 63 | function social.add_to_home_screen(on_success, on_failure) 64 | if on_failure then 65 | on_failure() 66 | end 67 | end 68 | 69 | -- Rate Game 70 | function social.is_rate_supported() 71 | return false 72 | end 73 | 74 | function social.rate(on_success, on_failure) 75 | if on_failure then 76 | on_failure() 77 | end 78 | end 79 | 80 | -- External Links 81 | function social.is_external_links_allowed() 82 | return true 83 | end 84 | 85 | return social -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Playgama Bridge 2 | One SDK for cross-platform publishing HTML5 games. 3 | 4 | ## Supported platforms 5 | + [Playgama](https://playgama.com/?utm_source=github&utm_medium=bridge) 6 | + [Game Distribution](https://gamedistribution.com) 7 | + [Crazy Games](https://crazygames.com) 8 | + [Yandex Games](https://yandex.com/games) 9 | + [Y8](https://y8.com) 10 | + [PlayDeck](https://playdeck.io) 11 | + [Telegram](https://core.telegram.org/bots/webapps) 12 | + [VK](https://vk.com) 13 | + [OK](https://ok.ru) 14 | + [Absolute Games](https://ag.ru) 15 | + [Lagged](https://lagged.com) 16 | + [Facebook](https://www.facebook.com/games/instantgames) 17 | + [Poki](https://poki.com/) 18 | + [MSN](https://www.msn.com/en-us/play) 19 | + [Discord](https://discord.com/gaming) 20 | + [BitQuest](https://t.me/BitquestGamesBot/start) 21 | + [Huawei](https://appgallery.huawei.com) 22 | + [JioGames](https://play.jiogames.com) 23 | + [YouTube](https://www.youtube.com/playables) 24 | + [Reddit](https://www.reddit.com/r/GamesOnReddit/) 25 | + [Xiaomi](https://global.app.mi.com/details?lo=ES&la=en&id=com.xiaomi.glgm) 26 | + Other [Work In Progress] 27 | 28 | ## Plugins for game engines 29 | + [JS](https://github.com/playgama/bridge) 30 | + [Construct 3](https://github.com/playgama/bridge-construct) 31 | + Unity [Plugin](https://github.com/playgama/bridge-unity) | [Examples](https://github.com/playgama/bridge-unity-examples) 32 | + [Godot 3](https://github.com/playgama/bridge-godot) 33 | + [Godot 4](https://github.com/playgama/bridge-godot-4) 34 | + [GameMaker](https://github.com/playgama/bridge-gamemaker) 35 | + [Defold](https://github.com/playgama/bridge-defold) 36 | + [GDevelop](https://github.com/playgama/bridge-gdevelop) 37 | + [Cocos Creator](https://github.com/playgama/bridge-cocos-creator) 38 | + [Scratch](https://github.com/playgama/bridge-scratch) 39 | 40 | ## Useful links 41 | + [Documentation](https://wiki.playgama.com/?utm_source=github&utm_medium=bridge) 42 | + [Discord](https://discord.gg/pzqd2upxr8) 43 | + [Game Publishing](https://developer.playgama.com/?utm_source=github&utm_medium=bridge) 44 | -------------------------------------------------------------------------------- /bridge/lib/web/bridge_achievements.js: -------------------------------------------------------------------------------- 1 | let js_bridge_achievements = { 2 | js_bridge_achievements_isSupported: function () { 3 | return bridge.achievements.isSupported; 4 | }, 5 | 6 | js_bridge_achievements_isGetListSupported: function () { 7 | return bridge.achievements.isGetListSupported; 8 | }, 9 | 10 | js_bridge_achievements_isNativePopupSupported: function () { 11 | return bridge.achievements.isNativePopupSupported; 12 | }, 13 | 14 | js_bridge_achievements_unlock: function (handler, options, onSuccess, onFailure) { 15 | var jsOptions = JSON.parse(UTF8ToString(options)); 16 | bridge.achievements.unlock(jsOptions) 17 | .then(result => { 18 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson(result)); 19 | }) 20 | .catch(error => { 21 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 22 | }) 23 | }, 24 | 25 | js_bridge_achievements_getList: function (handler, options, onSuccess, onFailure) { 26 | var jsOptions = JSON.parse(UTF8ToString(options)); 27 | bridge.achievements.getList(jsOptions) 28 | .then(result => { 29 | const jsonString = JSON.stringify(result); 30 | console.log(jsonString); 31 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson(jsonString)); 32 | }) 33 | .catch(error => { 34 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 35 | }) 36 | }, 37 | 38 | js_bridge_achievements_showNativePopup: function (handler, options, onSuccess, onFailure) { 39 | var jsOptions = JSON.parse(UTF8ToString(options)); 40 | bridge.achievements.showNativePopup(jsOptions) 41 | .then(() => { 42 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 43 | }) 44 | .catch(error => { 45 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson()); 46 | }) 47 | } 48 | } 49 | 50 | mergeInto(LibraryManager.library, js_bridge_achievements); -------------------------------------------------------------------------------- /bridge/lib/web/bridge_payments.js: -------------------------------------------------------------------------------- 1 | let js_bridge_payments = { 2 | js_bridge_payments_isSupported: function () { 3 | return bridge.payments.isSupported; 4 | }, 5 | 6 | js_bridge_payments_purchase: function (handler, id, options, onSuccess, onFailure) { 7 | var productId = UTF8ToString(id); 8 | var jsOptions = options ? JSON.parse(UTF8ToString(options)) : undefined; 9 | bridge.payments.purchase(productId, jsOptions) 10 | .then(purchase => { 11 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson(purchase)); 12 | }) 13 | .catch(error => { 14 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 15 | }) 16 | }, 17 | 18 | js_bridge_payments_consumePurchase: function (handler, id, onSuccess, onFailure) { 19 | bridge.payments.consumePurchase(UTF8ToString(id)) 20 | .then(purchase => { 21 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson(purchase)); 22 | }) 23 | .catch(error => { 24 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 25 | }) 26 | }, 27 | 28 | js_bridge_payments_getCatalog: function (handler, onSuccess, onFailure) { 29 | bridge.payments.getCatalog() 30 | .then(catalogItems => { 31 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson(catalogItems)); 32 | }) 33 | .catch(error => { 34 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 35 | }) 36 | }, 37 | 38 | js_bridge_payments_getPurchases: function (handler, onSuccess, onFailure) { 39 | bridge.payments.getPurchases() 40 | .then(purchases => { 41 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson(purchases)); 42 | }) 43 | .catch(error => { 44 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 45 | }) 46 | }, 47 | 48 | } 49 | 50 | mergeInto(LibraryManager.library, js_bridge_payments); -------------------------------------------------------------------------------- /bridge/src/bridge_social.cpp: -------------------------------------------------------------------------------- 1 | #if defined(DM_PLATFORM_HTML5) 2 | #include "bridge_social.h" 3 | #include "bridge.h" 4 | 5 | // Share 6 | int bridge::social::isShareSupported(lua_State* L) { 7 | return getBoolean(L, js_bridge_social_isShareSupported); 8 | } 9 | 10 | int bridge::social::share(lua_State* L) { 11 | return makeCallbackWithJson(L, js_bridge_social_share, false); 12 | } 13 | 14 | // Join Community 15 | int bridge::social::isJoinCommunitySupported(lua_State* L) { 16 | return getBoolean(L, js_bridge_social_isJoinCommunitySupported); 17 | } 18 | 19 | int bridge::social::joinCommunity(lua_State* L) { 20 | return makeCallbackWithJson(L, js_bridge_social_joinCommunity, false); 21 | } 22 | 23 | // Invite Friends 24 | int bridge::social::isInviteFriendsSupported(lua_State* L) { 25 | return getBoolean(L, js_bridge_social_isInviteFriendsSupported); 26 | } 27 | 28 | int bridge::social::inviteFriends(lua_State* L) { 29 | return makeCallbackWithJson(L, js_bridge_social_inviteFriends, false); 30 | } 31 | 32 | // Create Post 33 | int bridge::social::isCreatePostSupported(lua_State* L) { 34 | return getBoolean(L, js_bridge_social_isCreatePostSupported); 35 | } 36 | 37 | int bridge::social::createPost(lua_State* L) { 38 | return makeCallbackWithJson(L, js_bridge_social_createPost, false); 39 | } 40 | 41 | // Add to Favorites 42 | int bridge::social::isAddToFavoritesSupported(lua_State* L) { 43 | return getBoolean(L, js_bridge_social_isAddToFavoritesSupported); 44 | } 45 | 46 | int bridge::social::addToFavorites(lua_State* L) { 47 | return makeCallback(L, js_bridge_social_addToFavorites, false); 48 | } 49 | 50 | // Add to HomeScreen 51 | int bridge::social::isAddToHomeScreenSupported(lua_State* L) { 52 | return getBoolean(L, js_bridge_social_isAddToHomeScreenSupported); 53 | } 54 | 55 | int bridge::social::addToHomeScreen(lua_State* L) { 56 | return makeCallback(L, js_bridge_social_addToHomeScreen, false); 57 | } 58 | 59 | // Rate Game 60 | int bridge::social::isRateSupported(lua_State* L) { 61 | return getBoolean(L, js_bridge_social_isRateSupported); 62 | } 63 | 64 | int bridge::social::rate(lua_State* L) { 65 | return makeCallback(L, js_bridge_social_rate, false); 66 | } 67 | 68 | // External Links 69 | int bridge::social::isExternalLinksAllowed(lua_State* L) { 70 | return getBoolean(L, js_bridge_social_isExternalLinksAllowed); 71 | } 72 | 73 | #endif -------------------------------------------------------------------------------- /bridge/bridge.lua: -------------------------------------------------------------------------------- 1 | local bridge = {} 2 | if not _bridge then 3 | bridge.game = require "bridge.bridge_game" 4 | bridge.platform = require "bridge.bridge_platfrom" 5 | bridge.remote_config = require "bridge.bridge_remote_config" 6 | bridge.payments = require "bridge.bridge_payments" 7 | bridge.achievements = require "bridge.bridge_achievements" 8 | bridge.leaderboards = require "bridge.bridge_leaderboards" 9 | bridge.social = require "bridge.bridge_social" 10 | bridge.device = require "bridge.bridge_device" 11 | bridge.player = require "bridge.bridge_player" 12 | bridge.advertisement = require "bridge.bridge_advertisement" 13 | bridge.storage = require "bridge.bridge_storage" 14 | else 15 | bridge = _bridge 16 | end 17 | 18 | -- Constants 19 | 20 | bridge.EVENT_NAME = { 21 | INTERSTITIAL_STATE_CHANGED = "interstitial_state_changed", 22 | REWARDED_STATE_CHANGED = "rewarded_state_changed", 23 | BANNER_STATE_CHANGED = "banner_state_changed", 24 | VISIBILITY_STATE_CHANGED = "visibility_state_changed", 25 | AUDIO_STATE_CHANGED = "audio_state_changed", 26 | PAUSE_STATE_CHANGED = "pause_state_changed" 27 | } 28 | 29 | bridge.VISIBILITY_STATE = { 30 | VISIBLE = "visible", 31 | HIDDEN = "hidden", 32 | } 33 | 34 | bridge.INTERSTITIAL_STATE = { 35 | LOADING = "loading", 36 | OPENED = "opened", 37 | CLOSED = "closed", 38 | FAILED = "failed", 39 | } 40 | 41 | bridge.REWARDED_STATE = { 42 | LOADING = "loading", 43 | OPENED = "opened", 44 | REWARDED = "rewarded", 45 | CLOSED = "closed", 46 | FAILED = "failed", 47 | } 48 | 49 | bridge.BANNER_STATE = { 50 | LOADING = "loading", 51 | SHOWN = "shown", 52 | HIDDEN = "hidden", 53 | FAILED = "failed", 54 | } 55 | 56 | bridge.STORAGE_TYPE = { 57 | LOCAL_STORAGE = "local_storage", 58 | PLATFORM_INTERNAL = "platform_internal", 59 | } 60 | 61 | bridge.DEVICE_TYPE = { 62 | DESKTOP = "desktop", 63 | MOBILE = "mobile", 64 | TABLET = "tablet", 65 | TV = "tv", 66 | } 67 | 68 | bridge.PLATFORM_MESSAGE = { 69 | GAME_READY = "game_ready", 70 | IN_GAME_LOADING_STARTED = "in_game_loading_started", 71 | IN_GAME_LOADING_STOPPED = "in_game_loading_stopped", 72 | GAMEPLAY_STARTED = "gameplay_started", 73 | GAMEPLAY_STOPPED = "gameplay_stopped", 74 | PLAYER_GOT_ACHIEVEMENT = "player_got_achievement", 75 | GAME_OVER = "game_over", 76 | } 77 | 78 | bridge.LEADERBOARD_TYPE = { 79 | NOT_AVAILABLE = "not_available", 80 | IN_GAME = "in_game", 81 | NATIVE = "native", 82 | NATIVE_POPUP = "native_popup", 83 | } 84 | 85 | return bridge -------------------------------------------------------------------------------- /bridge/lib/web/bridge_storage.js: -------------------------------------------------------------------------------- 1 | let js_bridge_storage = { 2 | js_bridge_storage_defaultType() { 3 | return CStrOrNull(bridge.storage.defaultType); 4 | }, 5 | 6 | js_bridge_storage_isAvailable(storageType) { 7 | return bridge.storage.isAvailable(UTF8ToString(storageType)); 8 | }, 9 | 10 | js_bridge_storage_isSupported(storageType) { 11 | return bridge.storage.isSupported(UTF8ToString(storageType)); 12 | }, 13 | 14 | js_bridge_storage_get: function (handler, jsonString, onSuccess, onFailure, storageType) { 15 | const jsonObject = JSON.parse(UTF8ToString(jsonString)); 16 | const values = Object.values(jsonObject); 17 | bridge.storage.get(values, UTF8ToString(storageType), true) 18 | .then(data => { 19 | const obj = {}; 20 | for (let i = 0; i < values.length; i++) { 21 | if(!data[i]) 22 | continue; 23 | obj[values[i]] = data[i]; 24 | } 25 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson(obj)); 26 | }) 27 | .catch(error => { 28 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 29 | }); 30 | }, 31 | 32 | js_bridge_storage_set: function (handler, jsonString, onSuccess, onFailure, storageType) { 33 | const jsonObject = JSON.parse(UTF8ToString(jsonString)); 34 | const keys = Object.keys(jsonObject); 35 | const values = Object.values(jsonObject); 36 | bridge.storage.set(keys, values, UTF8ToString(storageType)) 37 | .then(() => { 38 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 39 | }) 40 | .catch(error => { 41 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 42 | }); 43 | }, 44 | 45 | js_bridge_storage_delete: function (handler, jsonString, onSuccess, onFailure, storageType) { 46 | const jsonObject = JSON.parse(UTF8ToString(jsonString)); 47 | const values = Object.values(jsonObject); 48 | bridge.storage.delete(values, UTF8ToString(storageType)) 49 | .then(() => { 50 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 51 | }) 52 | .catch(error => { 53 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 54 | }); 55 | } 56 | } 57 | 58 | mergeInto(LibraryManager.library, js_bridge_storage); -------------------------------------------------------------------------------- /bridge/include/bridge_social.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(DM_PLATFORM_HTML5) 4 | 5 | #include "bridge_helper.h" 6 | #include 7 | 8 | using sss = void(int dsfs); 9 | 10 | extern "C" { 11 | // Share 12 | bool js_bridge_social_isShareSupported(); 13 | void js_bridge_social_share(UniversalHandler handler, 14 | const char* json, 15 | dmScript::LuaCallbackInfo* onSuccess, 16 | dmScript::LuaCallbackInfo* onFailure); 17 | // Join Community 18 | bool js_bridge_social_isJoinCommunitySupported(); 19 | void js_bridge_social_joinCommunity(UniversalHandler handler, 20 | const char* json, 21 | dmScript::LuaCallbackInfo* onSuccess, 22 | dmScript::LuaCallbackInfo* onFailure); 23 | // Invite Friends 24 | bool js_bridge_social_isInviteFriendsSupported(); 25 | void js_bridge_social_inviteFriends(UniversalHandler handler, 26 | const char* json, 27 | dmScript::LuaCallbackInfo* onSuccess, 28 | dmScript::LuaCallbackInfo* onFailure); 29 | // Add to Favorites 30 | bool js_bridge_social_isAddToFavoritesSupported(); 31 | void js_bridge_social_addToFavorites(UniversalHandler handler, 32 | dmScript::LuaCallbackInfo* onSuccess, 33 | dmScript::LuaCallbackInfo* onFailure); 34 | 35 | // Create Post 36 | bool js_bridge_social_isCreatePostSupported(); 37 | void js_bridge_social_createPost(UniversalHandler handler, 38 | const char* json, 39 | dmScript::LuaCallbackInfo* onSuccess, 40 | dmScript::LuaCallbackInfo* onFailure); 41 | // Add to Favorites 42 | bool js_bridge_social_isAddToHomeScreenSupported(); 43 | void js_bridge_social_addToHomeScreen(UniversalHandler handler, 44 | dmScript::LuaCallbackInfo* onSuccess, 45 | dmScript::LuaCallbackInfo* onFailure); 46 | // Rate Game 47 | bool js_bridge_social_isRateSupported(); 48 | void js_bridge_social_rate(UniversalHandler handler, 49 | dmScript::LuaCallbackInfo* onSuccess, 50 | dmScript::LuaCallbackInfo* onFailure); 51 | // External Links 52 | bool js_bridge_social_isExternalLinksAllowed(); 53 | } 54 | 55 | #endif -------------------------------------------------------------------------------- /bridge/include/bridge_helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(DM_PLATFORM_HTML5) 4 | #include 5 | 6 | typedef void (*UniversalHandler)(dmScript::LuaCallbackInfo* onSuccess, // destroy callback by calling 7 | dmScript::LuaCallbackInfo* onFailure, 8 | const int callbackType, 9 | char* data); 10 | 11 | typedef void (*OnHandler)(dmScript::LuaCallbackInfo* callback, // not destroy callback by calling 12 | char* data); 13 | 14 | void cppUniversalHandler(dmScript::LuaCallbackInfo* onSuccess, dmScript::LuaCallbackInfo* onFailure, int callbackType, char* data); 15 | void cppOnHandler(dmScript::LuaCallbackInfo* onSuccess, char* data); 16 | 17 | using StringFunction = char*(); 18 | using BooleanFunction = bool(); 19 | using BooleanStringFunction = bool(const char*); 20 | using CallbacksFunction = void(UniversalHandler, dmScript::LuaCallbackInfo* onSuccess, dmScript::LuaCallbackInfo* onFailure); 21 | using CallbacksWithStringFunction = void(UniversalHandler, const char* option, dmScript::LuaCallbackInfo* onSuccess, dmScript::LuaCallbackInfo* onFailure); 22 | using CallbacksWithStringAndJsonFunction = void(UniversalHandler, const char* id, const char* json, dmScript::LuaCallbackInfo* onSuccess, dmScript::LuaCallbackInfo* onFailure); 23 | using OnFunction = void(OnHandler handler, const char* eventName, dmScript::LuaCallbackInfo* onSuccess); 24 | using LeaderboardsSetScoreFunction = void(UniversalHandler handler, const char* id, int score, dmScript::LuaCallbackInfo* onSuccess, dmScript::LuaCallbackInfo* onFailure); 25 | using StorageFunction = void(UniversalHandler handler, const char* json, dmScript::LuaCallbackInfo* onSuccess, dmScript::LuaCallbackInfo* onFailure, const char* storageType); 26 | 27 | int getString(lua_State* L, StringFunction func); 28 | int getBoolean(lua_State* L, BooleanFunction func); 29 | int getBooleanWithString(lua_State* L, BooleanStringFunction func); 30 | int makeCallback(lua_State* L, CallbacksFunction func, bool isRequiredFirstCallback); 31 | int makeCallbackWithString(lua_State* L, CallbacksWithStringFunction func, bool isRequiredFirstCallback); 32 | int makeCallbackWithJson(lua_State* L, CallbacksWithStringFunction func, bool isRequiredFirstCallback); 33 | int makeCallbackWithStringAndJson(lua_State* L, CallbacksWithStringAndJsonFunction func, bool isRequiredFirstCallback); 34 | int makeCallbackStorage(lua_State* L, StorageFunction func, bool isRequiredFirstCallback); 35 | int makeCallbackLeaderboardsSetScore(lua_State* L, LeaderboardsSetScoreFunction func, bool isRequiredFirstCallback); 36 | int makeOnCallback(lua_State* L, OnFunction func); 37 | 38 | 39 | #endif -------------------------------------------------------------------------------- /bridge/lib/web/bridge_advertisement.js: -------------------------------------------------------------------------------- 1 | let js_bridge_advertisement = { 2 | // #region Banner 3 | js_bridge_advertisement_isBannerSupported: function () { 4 | return bridge.advertisement.isBannerSupported; 5 | }, 6 | 7 | js_bridge_advertisement_showBanner: function (position, placement) { 8 | bridge.advertisement.showBanner(UTF8ToString(position), UTF8ToString(placement)); 9 | }, 10 | 11 | js_bridge_advertisement_bannerState: function() { 12 | return CStrOrNull(bridge.advertisement.bannerState); 13 | }, 14 | 15 | js_bridge_advertisement_on: function (handler, event_name, callback) { 16 | bridge.advertisement.on(UTF8ToString(event_name), state => { 17 | {{{ makeDynCall('vii', 'handler') }}} (callback, packToJson(state)); 18 | }); 19 | }, 20 | 21 | js_bridge_advertisement_hideBanner: function() { 22 | bridge.advertisement.hideBanner(); 23 | }, 24 | // #endregion 25 | 26 | // #region Interstitial 27 | js_bridge_advertisement_isInterstitialSupported: function () { 28 | return bridge.advertisement.isInterstitialSupported; 29 | }, 30 | 31 | js_bridge_advertisement_minimumDelayBetweenInterstitial: function() { 32 | return bridge.advertisement.minimumDelayBetweenInterstitial; 33 | }, 34 | 35 | js_bridge_advertisement_setMinimumDelayBetweenInterstitial: function(delay) { 36 | bridge.advertisement.setMinimumDelayBetweenInterstitial(delay); 37 | }, 38 | 39 | js_bridge_advertisement_interstitialState: function() { 40 | return CStrOrNull(bridge.advertisement.interstitialState); 41 | }, 42 | 43 | js_bridge_advertisement_showInterstitial: function(placement) { 44 | bridge.advertisement.showInterstitial(UTF8ToString(placement)); 45 | }, 46 | // #endregion 47 | 48 | // #region Rewarded 49 | js_bridge_advertisement_isRewardedSupported: function () { 50 | return bridge.advertisement.isRewardedSupported; 51 | }, 52 | 53 | js_bridge_advertisement_rewardedState: function() { 54 | return CStrOrNull(bridge.advertisement.rewardedState); 55 | }, 56 | 57 | js_bridge_advertisement_rewardedPlacement: function() { 58 | return CStrOrNull(bridge.advertisement.rewardedPlacement); 59 | }, 60 | 61 | js_bridge_advertisement_showRewarded: function(placement) { 62 | bridge.advertisement.showRewarded(UTF8ToString(placement)); 63 | }, 64 | 65 | js_bridge_advertisement_checkAdBlock: function(handler, onSuccess, onFailure) { 66 | bridge.advertisement.checkAdBlock() 67 | .then(result => { 68 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson(result)); 69 | }) 70 | .catch(error => { 71 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 72 | }); 73 | } 74 | // #endregion 75 | } 76 | 77 | mergeInto(LibraryManager.library, js_bridge_advertisement); -------------------------------------------------------------------------------- /bridge/lib/web/bridge_platform.js: -------------------------------------------------------------------------------- 1 | let js_bridge_platform = { 2 | js_bridge_platform_on: function (handler, event_name, callback) { 3 | bridge.platform.on(UTF8ToString(event_name), state => { 4 | {{{ makeDynCall('vii', 'handler') }}} (callback, packToJson(state)); 5 | }); 6 | }, 7 | 8 | js_bridge_platform_id: function () { 9 | return CStrOrNull(bridge.platform.id); 10 | }, 11 | 12 | js_bridge_platform_language: function () { 13 | return CStrOrNull(bridge.platform.language); 14 | }, 15 | 16 | js_bridge_platform_payload: function () { 17 | return CStrOrNull(bridge.platform.payload); 18 | }, 19 | 20 | js_bridge_platform_tld: function () { 21 | return CStrOrNull(bridge.platform.tld); 22 | }, 23 | 24 | js_bridge_platform_sendMessage: function (handler, message, onSuccess, onFailure) { 25 | bridge.platform.sendMessage(UTF8ToString(message)) 26 | .then(() => { 27 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 28 | }) 29 | .catch(error => { 30 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 31 | }) 32 | }, 33 | 34 | js_bridge_platform_getServerTime: function (handler, onSuccess, onFailure) { 35 | bridge.platform.getServerTime() 36 | .then(result => { 37 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson(result)); 38 | }) 39 | .catch(error => { 40 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 41 | }) 42 | }, 43 | 44 | js_bridge_platform_isAudioEnabled: function () { 45 | return bridge.platform.isAudioEnabled; 46 | }, 47 | 48 | js_bridge_platform_isGetAllGamesSupported: function () { 49 | return bridge.platform.isGetAllGamesSupported; 50 | }, 51 | 52 | js_bridge_platform_isGetGameByIdSupported: function () { 53 | return bridge.platform.isGetGameByIdSupported; 54 | }, 55 | 56 | js_bridge_platform_getAllGames: function (handler, onSuccess, onFailure) { 57 | bridge.platform.getAllGames() 58 | .then(result => { 59 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson(result)); 60 | }) 61 | .catch(error => { 62 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 63 | }) 64 | }, 65 | 66 | js_bridge_platform_getGameById: function (handler, options, onSuccess, onFailure) { 67 | var jsOptions = JSON.parse(UTF8ToString(options)); 68 | bridge.platform.getGameById(jsOptions) 69 | .then(result => { 70 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson(result)); 71 | }) 72 | .catch(error => { 73 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 74 | }) 75 | }, 76 | }; 77 | 78 | mergeInto(LibraryManager.library, js_bridge_platform); -------------------------------------------------------------------------------- /bridge/src/bridge_advertisement.cpp: -------------------------------------------------------------------------------- 1 | #if defined(DM_PLATFORM_HTML5) 2 | #include "bridge_advertisement.h" 3 | #include "bridge.h" 4 | 5 | #pragma region Banner 6 | int bridge::advertisement::on(lua_State* L) { 7 | return makeOnCallback(L, js_bridge_advertisement_on); 8 | } 9 | 10 | int bridge::advertisement::isBannerSupported(lua_State* L) { 11 | return getBoolean(L, js_bridge_advertisement_isBannerSupported); 12 | } 13 | 14 | int bridge::advertisement::showBanner(lua_State* L) { 15 | DM_LUA_STACK_CHECK(L, 0); 16 | 17 | const char* position = NULL; 18 | if (lua_isstring(L, 1)) 19 | position = lua_tostring(L, 1); 20 | 21 | const char* placement = NULL; 22 | if (lua_isstring(L, 2)) 23 | placement = lua_tostring(L, 2); 24 | 25 | js_bridge_advertisement_showBanner(position, placement); 26 | return 0; 27 | } 28 | 29 | int bridge::advertisement::bannerState(lua_State* L) { 30 | return getString(L, js_bridge_advertisement_bannerState); 31 | } 32 | 33 | int bridge::advertisement::hideBanner(lua_State* L) { 34 | DM_LUA_STACK_CHECK(L, 0); 35 | js_bridge_advertisement_hideBanner(); 36 | return 0; 37 | } 38 | #pragma region 39 | 40 | #pragma region Interstitial 41 | int bridge::advertisement::isInterstitialSupported(lua_State* L) { 42 | return getBoolean(L, js_bridge_advertisement_isInterstitialSupported); 43 | } 44 | 45 | int bridge::advertisement::showInterstitial(lua_State* L) { 46 | DM_LUA_STACK_CHECK(L, 0); 47 | 48 | const char* placement = NULL; 49 | if (lua_isstring(L, 1)) 50 | placement = lua_tostring(L, 1); 51 | 52 | js_bridge_advertisement_showInterstitial(placement); 53 | return 0; 54 | } 55 | 56 | int bridge::advertisement::minimumDelayBetweenInterstitial(lua_State* L) { 57 | DM_LUA_STACK_CHECK(L, 1); 58 | int delay = js_bridge_advertisement_minimumDelayBetweenInterstitial(); 59 | lua_pushinteger(L, delay); 60 | return 1; 61 | } 62 | 63 | int bridge::advertisement::setMinimumDelayBetweenInterstitial(lua_State* L) { 64 | DM_LUA_STACK_CHECK(L, 0); 65 | int delay = luaL_checkinteger(L, 1); 66 | js_bridge_advertisement_setMinimumDelayBetweenInterstitial(delay); 67 | return 0; 68 | } 69 | 70 | int bridge::advertisement::interstitialState(lua_State* L) { 71 | return getString(L, js_bridge_advertisement_interstitialState); 72 | } 73 | #pragma endregion 74 | 75 | #pragma region Rewarded 76 | int bridge::advertisement::isRewardedSupported(lua_State* L) { 77 | return getBoolean(L, js_bridge_advertisement_isRewardedSupported); 78 | } 79 | 80 | int bridge::advertisement::rewardedState(lua_State* L) { 81 | return getString(L, js_bridge_advertisement_rewardedState); 82 | } 83 | 84 | int bridge::advertisement::rewardedPlacement(lua_State* L) { 85 | return getString(L, js_bridge_advertisement_rewardedPlacement); 86 | } 87 | 88 | int bridge::advertisement::showRewarded(lua_State* L) { 89 | DM_LUA_STACK_CHECK(L, 0); 90 | 91 | const char* placement = NULL; 92 | if (lua_isstring(L, 1)) 93 | placement = lua_tostring(L, 1); 94 | 95 | js_bridge_advertisement_showRewarded(placement); 96 | return 0; 97 | } 98 | #pragma endregion 99 | 100 | #pragma region Adblock 101 | 102 | int bridge::advertisement::checkAdBlock(lua_State* L) { 103 | return makeCallback(L, js_bridge_advertisement_checkAdBlock, true); 104 | } 105 | 106 | #pragma endregion 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /bridge/bridge_advertisement.lua: -------------------------------------------------------------------------------- 1 | local advertisement = {} 2 | 3 | -- Local variables 4 | local banner_state = "hidden" 5 | local banner_changed_callback = nil 6 | local simulate_banner_states = {"loading", "shown"} 7 | 8 | local delay_between_interstitial = 60 9 | local interstitial_state = "closed" 10 | local interstitial_changed_callback = nil 11 | local simulate_interstitial_states = {"loading", "opened", "closed"} 12 | 13 | local rewarded_state = "closed" 14 | local rewarded_placement = nil 15 | local rewarded_changed_callback = nil 16 | local simulate_rewarded_states = {"loading", "opened", "rewarded", "closed"} 17 | 18 | local get_state = function(state) 19 | return coroutine.wrap(function() 20 | for k, v in pairs(state) do 21 | coroutine.yield(v) 22 | end 23 | end) 24 | end 25 | 26 | -- Banner 27 | function advertisement.is_banner_supported() 28 | return true 29 | end 30 | 31 | function advertisement.banner_state() 32 | return banner_state 33 | end 34 | 35 | function advertisement.show_banner(position, placement) 36 | local getter = get_state(simulate_banner_states) 37 | timer.delay(0.1, true, function(_, handle) 38 | local state = getter() 39 | if not state then 40 | timer.cancel(handle) 41 | return 42 | end 43 | 44 | banner_state = state 45 | if banner_changed_callback then 46 | banner_changed_callback(_, banner_state) 47 | end 48 | end) 49 | end 50 | 51 | function advertisement.hide_banner() 52 | banner_state = "hidden" 53 | if banner_changed_callback then 54 | banner_changed_callback(_, banner_state) 55 | end 56 | end 57 | 58 | function advertisement.on(event_name, callback) 59 | if event_name == "banner_state_changed" then 60 | banner_changed_callback = callback 61 | 62 | elseif event_name == "interstitial_state_changed" then 63 | interstitial_changed_callback = callback 64 | 65 | elseif event_name == "rewarded_state_changed" then 66 | rewarded_changed_callback = callback 67 | end 68 | end 69 | 70 | -- Interstitial 71 | function advertisement.is_interstitial_supported() 72 | return true 73 | end 74 | 75 | function advertisement.minimum_delay_between_interstitial() 76 | return delay_between_interstitial 77 | end 78 | 79 | function advertisement.set_minimum_delay_between_interstitial(delay) 80 | delay_between_interstitial = delay 81 | end 82 | 83 | function advertisement.interstitial_state() 84 | return interstitial_state 85 | end 86 | 87 | function advertisement.show_interstitial(placement) 88 | local getter = get_state(simulate_interstitial_states) 89 | timer.delay(0.1, true, function(_, handle) 90 | local state = getter() 91 | if not state then 92 | timer.cancel(handle) 93 | return 94 | end 95 | 96 | interstitial_state = state 97 | if interstitial_changed_callback then 98 | interstitial_changed_callback(_, interstitial_state) 99 | end 100 | end) 101 | end 102 | 103 | -- Rewarded 104 | function advertisement.is_rewarded_supported() 105 | return true 106 | end 107 | 108 | function advertisement.rewarded_state() 109 | return rewarded_state 110 | end 111 | 112 | function advertisement.rewarded_placement() 113 | return rewarded_placement 114 | end 115 | 116 | function advertisement.show_rewarded(placement) 117 | rewarded_placement = placement 118 | 119 | local getter = get_state(simulate_rewarded_states) 120 | timer.delay(0.1, true, function(_, handle) 121 | local state = getter() 122 | if not state then 123 | timer.cancel(handle) 124 | return 125 | end 126 | 127 | rewarded_state = state 128 | if rewarded_changed_callback then 129 | rewarded_changed_callback(_, rewarded_state) 130 | end 131 | end) 132 | end 133 | 134 | function advertisement.check_ad_block(on_success, on_failure) 135 | on_success(_, false) 136 | end 137 | 138 | return advertisement -------------------------------------------------------------------------------- /bridge/include/bridge.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace bridge { 6 | namespace platform { 7 | int on(lua_State* L); 8 | 9 | int id(lua_State* L); 10 | int language(lua_State* L); 11 | int tld(lua_State* L); 12 | int payload(lua_State* L); 13 | 14 | int sendMessage(lua_State* L); 15 | int getServerTime(lua_State* L); 16 | 17 | int isAudioEnabled(lua_State* L); 18 | 19 | int isGetAllGamesSupported(lua_State* L); 20 | int isGetGameByIdSupported(lua_State* L); 21 | 22 | int getAllGames(lua_State* L); 23 | int getGameById(lua_State* L); 24 | } // namespace platform 25 | 26 | namespace game { 27 | int on(lua_State* L); 28 | int visibilityState(lua_State* L); 29 | } // namespace game 30 | 31 | namespace storage { 32 | int defaultType(lua_State* L); 33 | int isSupported(lua_State* L); 34 | int isAvailable(lua_State* L); 35 | int get(lua_State* L); 36 | int set(lua_State* L); 37 | int deleteData(lua_State* L); 38 | } // namespace store 39 | 40 | namespace advertisement { 41 | // Banner 42 | int isBannerSupported(lua_State* L); 43 | int showBanner(lua_State* L); 44 | int bannerState(lua_State* L); 45 | int on(lua_State* L); 46 | int hideBanner(lua_State* L); 47 | 48 | // Interstitial 49 | int isInterstitialSupported(lua_State* L); 50 | int minimumDelayBetweenInterstitial(lua_State* L); 51 | int setMinimumDelayBetweenInterstitial(lua_State* L); 52 | int interstitialState(lua_State* L); 53 | int showInterstitial(lua_State* L); 54 | 55 | int isRewardedSupported(lua_State* L); 56 | int showRewarded(lua_State* L); 57 | int rewardedState(lua_State* L); 58 | int rewardedPlacement(lua_State* L); 59 | 60 | // AdBlock 61 | int checkAdBlock(lua_State* L); 62 | } // namespace advertisement 63 | 64 | namespace device { 65 | int type(lua_State* L); 66 | } // namespace device 67 | 68 | namespace player { 69 | int isAuthorizationSupported(lua_State* L); 70 | int isAuthorized(lua_State* L); 71 | int id(lua_State* L); 72 | int name(lua_State* L); 73 | int extra(lua_State* L); 74 | int photos(lua_State* L); 75 | int authorize(lua_State* L); 76 | } // namespace player 77 | 78 | namespace social { 79 | // Share 80 | int isShareSupported(lua_State* L); 81 | int share(lua_State* L); 82 | 83 | // Join Community 84 | int isJoinCommunitySupported(lua_State* L); 85 | int joinCommunity(lua_State* L); 86 | 87 | // Invite Friends 88 | int isInviteFriendsSupported(lua_State* L); 89 | int inviteFriends(lua_State* L); 90 | 91 | // Add to Favorites 92 | int isAddToFavoritesSupported(lua_State* L); 93 | int addToFavorites(lua_State* L); 94 | 95 | // Create Post 96 | int isCreatePostSupported(lua_State* L); 97 | int createPost(lua_State* L); 98 | 99 | // Add to Favorites 100 | int isAddToHomeScreenSupported(lua_State* L); 101 | int addToHomeScreen(lua_State* L); 102 | 103 | // Rate Game 104 | int isRateSupported(lua_State* L); 105 | int rate(lua_State* L); 106 | 107 | // External Links 108 | int isExternalLinksAllowed(lua_State* L); 109 | } // namespace device 110 | 111 | namespace leaderboards { 112 | int type(lua_State* L); 113 | int setScore(lua_State* L); 114 | int getEntries(lua_State* L); 115 | int showNativePopup(lua_State* L); 116 | } // namespace leaderboards 117 | 118 | namespace achievements { 119 | int isSupported(lua_State* L); 120 | int isGetListSupported(lua_State* L); 121 | int isNativePopupSupported(lua_State* L); 122 | int unlock(lua_State* L); 123 | int getList(lua_State* L); 124 | int showNativePopup(lua_State* L); 125 | } // namespace achievements 126 | 127 | namespace payments { 128 | int isSupported(lua_State* L); 129 | int purchase(lua_State* L); 130 | int consumePurchase(lua_State* L); 131 | int getCatalog(lua_State* L); 132 | int getPurchases(lua_State* L); 133 | } // namespace payments 134 | 135 | namespace remoteConfig { 136 | int isSupported(lua_State* L); 137 | int get(lua_State* L); 138 | } // namespace remoteConfig 139 | 140 | } // namespace bridge -------------------------------------------------------------------------------- /bridge/lib/web/bridge_social.js: -------------------------------------------------------------------------------- 1 | let js_bridge_social = { 2 | // #region Share 3 | js_bridge_social_isShareSupported: function () { 4 | return bridge.social.isShareSupported; 5 | }, 6 | 7 | js_bridge_social_share: function (handler, options, onSuccess, onFailure) { 8 | var jsOptions = JSON.parse(UTF8ToString(options)); 9 | bridge.social.share(jsOptions) 10 | .then(() => { 11 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 12 | }) 13 | .catch(error => { 14 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 15 | }) 16 | }, 17 | // #endregion 18 | 19 | // #region Join Community 20 | js_bridge_social_isJoinCommunitySupported: function () { 21 | return bridge.social.isJoinCommunitySupported; 22 | }, 23 | 24 | js_bridge_social_joinCommunity: function (handler, options, onSuccess, onFailure) { 25 | var jsOptions = JSON.parse(UTF8ToString(options)); 26 | bridge.social.joinCommunity(jsOptions) 27 | .then(() => { 28 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 29 | }) 30 | .catch(error => { 31 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 32 | }) 33 | }, 34 | // #endregion 35 | 36 | // #region Invite Friends 37 | js_bridge_social_isInviteFriendsSupported: function () { 38 | return bridge.social.isInviteFriendsSupported; 39 | }, 40 | 41 | js_bridge_social_inviteFriends: function (handler, options, onSuccess, onFailure) { 42 | var jsOptions = JSON.parse(UTF8ToString(options)); 43 | bridge.social.inviteFriends(jsOptions) 44 | .then(() => { 45 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 46 | }) 47 | .catch(error => { 48 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 49 | }) 50 | }, 51 | // #endregion 52 | 53 | // #region Create Post 54 | js_bridge_social_isCreatePostSupported: function () { 55 | return bridge.social.isCreatePostSupported; 56 | }, 57 | 58 | js_bridge_social_createPost: function (handler, options, onSuccess, onFailure) { 59 | var jsOptions = JSON.parse(UTF8ToString(options)); 60 | bridge.social.createPost(jsOptions) 61 | .then(() => { 62 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 63 | }) 64 | .catch(error => { 65 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 66 | }) 67 | }, 68 | // #endregion 69 | 70 | // #region Add to Favorites 71 | js_bridge_social_isAddToFavoritesSupported: function () { 72 | return bridge.social.isAddToFavoritesSupported; 73 | }, 74 | 75 | js_bridge_social_addToFavorites: function (handler, onSuccess, onFailure) { 76 | bridge.social.addToFavorites() 77 | .then(() => { 78 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 79 | }) 80 | .catch(error => { 81 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 82 | }) 83 | }, 84 | // #endregion 85 | 86 | // #region Add to Home Screen 87 | js_bridge_social_isAddToHomeScreenSupported: function () { 88 | return bridge.social.isAddToHomeScreenSupported; 89 | }, 90 | 91 | js_bridge_social_addToHomeScreen: function (handler, onSuccess, onFailure) { 92 | bridge.social.addToHomeScreen() 93 | .then(() => { 94 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 95 | }) 96 | .catch(error => { 97 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 98 | }) 99 | }, 100 | // #endregion 101 | 102 | // #region Rate Game 103 | js_bridge_social_isRateSupported: function () { 104 | return bridge.social.isRateSupported; 105 | }, 106 | 107 | js_bridge_social_rate: function (handler, onSuccess, onFailure) { 108 | bridge.social.rate() 109 | .then(() => { 110 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 0, packToJson()); 111 | }) 112 | .catch(error => { 113 | {{{ makeDynCall('viiii', 'handler') }}} (onSuccess, onFailure, 1, packToJson(error)); 114 | }) 115 | }, 116 | // #endregion 117 | 118 | // #region External Links 119 | js_bridge_social_isExternalLinksAllowed: function () { 120 | return bridge.social.isExternalLinksAllowed; 121 | }, 122 | // #endregion 123 | } 124 | 125 | mergeInto(LibraryManager.library, js_bridge_social); -------------------------------------------------------------------------------- /bridge/engine_template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | {{project.title}} {{project.version}} 11 | 69 | 70 | 71 |
72 | 77 | 81 |
82 | 83 |
84 |
85 | {{#html5.show_fullscreen_button}} 86 |
Fullscreen
87 | {{/html5.show_fullscreen_button}} 88 | {{#html5.show_made_with_defold}} 89 | 90 | {{/html5.show_made_with_defold}} 91 |
92 |
93 | 94 | 95 | 96 | 100 | 162 | 163 | -------------------------------------------------------------------------------- /bridge/src/bridge_helper.cpp: -------------------------------------------------------------------------------- 1 | #if defined(DM_PLATFORM_HTML5) 2 | #include "bridge_helper.h" 3 | #include 4 | 5 | namespace { 6 | void destroyCallbacks(dmScript::LuaCallbackInfo* onSuccess, dmScript::LuaCallbackInfo* onFailure) { 7 | if (dmScript::IsCallbackValid(onSuccess)) { 8 | dmScript::DestroyCallback(onSuccess); 9 | } 10 | if (dmScript::IsCallbackValid(onFailure)) { 11 | dmScript::DestroyCallback(onFailure); 12 | } 13 | } 14 | 15 | void callCallback(dmScript::LuaCallbackInfo* callback, const char* data) { 16 | if (!dmScript::IsCallbackValid(callback)) 17 | return; 18 | 19 | if (!dmScript::SetupCallback(callback)) { 20 | dmLogError("Failed to setup onSuccess"); 21 | return; 22 | } 23 | 24 | lua_State* L = dmScript::GetCallbackLuaContext(callback); 25 | if (data) { 26 | dmScript::JsonToLua(L, data, strlen(data)); 27 | lua_pushstring(L, "data"); 28 | lua_gettable(L, -2); // get data from table 29 | lua_replace(L, -2); // replace table to data 30 | } else { 31 | lua_pushnil(L); // if data == null push nil like default value 32 | } 33 | dmScript::PCall(L, 2, 0); 34 | dmScript::TeardownCallback(callback); 35 | } 36 | } 37 | 38 | void cppUniversalHandler(dmScript::LuaCallbackInfo* onSuccess, dmScript::LuaCallbackInfo* onFailure, int callbackType, char* data) { 39 | if (callbackType == 0) { 40 | callCallback(onSuccess, data); 41 | } 42 | 43 | if (callbackType == 1) { 44 | callCallback(onFailure, data); 45 | } 46 | 47 | destroyCallbacks(onSuccess, onFailure); 48 | free(data); 49 | } 50 | 51 | void cppOnHandler(dmScript::LuaCallbackInfo* onSuccess, char* data) { 52 | callCallback(onSuccess, data); 53 | free(data); 54 | } 55 | 56 | int getString(lua_State* L, StringFunction func) { 57 | DM_LUA_STACK_CHECK(L, 1); 58 | char* str = func(); 59 | lua_pushstring(L, str); 60 | free(str); 61 | return 1; 62 | } 63 | 64 | int getBoolean(lua_State* L, BooleanFunction func) { 65 | DM_LUA_STACK_CHECK(L, 1); 66 | bool isAvailable = func(); 67 | lua_pushboolean(L, isAvailable); 68 | return 1; 69 | } 70 | 71 | int makeCallback(lua_State* L, CallbacksFunction func, bool isRequiredFirstCallback) { 72 | DM_LUA_STACK_CHECK(L, 0); 73 | dmScript::LuaCallbackInfo* onSuccess = NULL; 74 | dmScript::LuaCallbackInfo* onFailure = NULL; 75 | if (isRequiredFirstCallback) { 76 | onSuccess = dmScript::CreateCallback(L, 1); 77 | } else if (lua_isfunction(L, 1)) { 78 | onSuccess = dmScript::CreateCallback(L, 1); 79 | } 80 | 81 | if (lua_isfunction(L, 2)) 82 | onFailure = dmScript::CreateCallback(L, 2); 83 | 84 | func((UniversalHandler)cppUniversalHandler, onSuccess, onFailure); 85 | return 0; 86 | } 87 | 88 | int makeCallbackWithString(lua_State* L, CallbacksWithStringFunction func, bool isRequiredFirstCallback) { 89 | DM_LUA_STACK_CHECK(L, 0); 90 | size_t len; 91 | const char* event = luaL_checklstring(L, 1, &len); 92 | dmScript::LuaCallbackInfo* onSuccess = NULL; 93 | dmScript::LuaCallbackInfo* onFailure = NULL; 94 | 95 | if (isRequiredFirstCallback) { 96 | onSuccess = dmScript::CreateCallback(L, 2); 97 | } else if (lua_isfunction(L, 2)) { 98 | onSuccess = dmScript::CreateCallback(L, 2); 99 | } 100 | 101 | if (lua_isfunction(L, 3)) 102 | onFailure = dmScript::CreateCallback(L, 3); 103 | 104 | func((UniversalHandler)cppUniversalHandler, event, onSuccess, onFailure); 105 | return 0; 106 | } 107 | 108 | int makeOnCallback(lua_State* L, OnFunction func) { 109 | DM_LUA_STACK_CHECK(L, 0); 110 | dmScript::LuaCallbackInfo* callback = NULL; 111 | const char* event_name = luaL_checkstring(L, 1); 112 | callback = dmScript::CreateCallback(L, 2); 113 | func(cppOnHandler, event_name, callback); 114 | return 0; 115 | } 116 | 117 | int makeCallbackWithJson(lua_State* L, CallbacksWithStringFunction func, bool isRequiredFirstCallback) { 118 | DM_LUA_STACK_CHECK(L, 0); 119 | dmScript::LuaCallbackInfo* onSuccess = NULL; 120 | dmScript::LuaCallbackInfo* onFailure = NULL; 121 | 122 | char* json; 123 | size_t json_len; 124 | int res = dmScript::LuaToJson(L, &json, &json_len); 125 | 126 | if (isRequiredFirstCallback) { 127 | onSuccess = dmScript::CreateCallback(L, 2); 128 | } else if (lua_isfunction(L, 2)) { 129 | onSuccess = dmScript::CreateCallback(L, 2); 130 | } 131 | 132 | if (lua_isfunction(L, 3)) 133 | onFailure = dmScript::CreateCallback(L, 3); 134 | 135 | func((UniversalHandler)cppUniversalHandler, json, onSuccess, onFailure); 136 | free(json); 137 | return 0; 138 | } 139 | 140 | int makeCallbackWithStringAndJson(lua_State* L, CallbacksWithStringAndJsonFunction func, bool isRequiredFirstCallback) { 141 | DM_LUA_STACK_CHECK(L, 0); 142 | 143 | size_t len; 144 | const char* id = luaL_checklstring(L, 1, &len); 145 | char* json = NULL; 146 | 147 | if (lua_istable(L, 2)) { 148 | size_t json_len; 149 | lua_pushvalue(L, 2); 150 | lua_replace(L, 1); 151 | dmScript::LuaToJson(L, &json, &json_len); 152 | } 153 | 154 | dmScript::LuaCallbackInfo* onSuccess = NULL; 155 | dmScript::LuaCallbackInfo* onFailure = NULL; 156 | 157 | if (isRequiredFirstCallback) { 158 | onSuccess = dmScript::CreateCallback(L, 3); 159 | } else if (lua_isfunction(L, 3)) { 160 | onSuccess = dmScript::CreateCallback(L, 3); 161 | } 162 | 163 | if (lua_isfunction(L, 4)) 164 | onFailure = dmScript::CreateCallback(L, 4); 165 | 166 | func((UniversalHandler)cppUniversalHandler, id, json, onSuccess, onFailure); 167 | 168 | if (json) { 169 | free(json); 170 | } 171 | 172 | return 0; 173 | } 174 | 175 | int getBooleanWithString(lua_State* L, BooleanStringFunction func) { 176 | DM_LUA_STACK_CHECK(L, 1); 177 | const char* lstring = luaL_checkstring(L, 1); 178 | bool isAvailable = func(lstring); 179 | lua_pushboolean(L, isAvailable); 180 | return 1; 181 | } 182 | 183 | int makeCallbackStorage(lua_State* L, StorageFunction func, bool isRequiredFirstCallback) { 184 | DM_LUA_STACK_CHECK(L, 0); 185 | luaL_checktype(L, 1, LUA_TTABLE); // table 186 | char* json; 187 | size_t json_len; 188 | int res = dmScript::LuaToJson(L, &json, &json_len); 189 | 190 | dmScript::LuaCallbackInfo* onSuccess = NULL; 191 | dmScript::LuaCallbackInfo* onFailure = NULL; 192 | const char* storageType = NULL; 193 | 194 | if (isRequiredFirstCallback) { 195 | onSuccess = dmScript::CreateCallback(L, 2); 196 | } else if (lua_isfunction(L, 2)) { 197 | onSuccess = dmScript::CreateCallback(L, 2); 198 | } 199 | 200 | if (lua_isfunction(L, 3)) 201 | onFailure = dmScript::CreateCallback(L, 3); 202 | 203 | if (lua_isstring(L, 4)) 204 | storageType = lua_tostring(L, 4); 205 | 206 | func((UniversalHandler)cppUniversalHandler, json, onSuccess, onFailure, storageType); 207 | free(json); 208 | return 0; 209 | } 210 | 211 | int makeCallbackLeaderboardsSetScore(lua_State* L, LeaderboardsSetScoreFunction func, bool isRequiredFirstCallback) { 212 | DM_LUA_STACK_CHECK(L, 0); 213 | 214 | size_t len; 215 | const char* id = luaL_checklstring(L, 1, &len); 216 | int score = luaL_checkinteger(L, 2); 217 | 218 | dmScript::LuaCallbackInfo* onSuccess = NULL; 219 | dmScript::LuaCallbackInfo* onFailure = NULL; 220 | 221 | if (isRequiredFirstCallback) { 222 | onSuccess = dmScript::CreateCallback(L, 3); 223 | } else if (lua_isfunction(L, 3)) { 224 | onSuccess = dmScript::CreateCallback(L, 3); 225 | } 226 | 227 | if (lua_isfunction(L, 4)) 228 | onFailure = dmScript::CreateCallback(L, 4); 229 | 230 | func((UniversalHandler)cppUniversalHandler, id, score, onSuccess, onFailure); 231 | return 0; 232 | } 233 | 234 | #endif -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: WebKit 3 | AccessModifierOffset: -4 4 | AlignAfterOpenBracket: Align 5 | AlignArrayOfStructures: None 6 | AlignConsecutiveAssignments: 7 | Enabled: false 8 | AcrossEmptyLines: false 9 | AcrossComments: false 10 | AlignCompound: false 11 | AlignFunctionPointers: false 12 | PadOperators: true 13 | AlignConsecutiveBitFields: 14 | Enabled: false 15 | AcrossEmptyLines: false 16 | AcrossComments: false 17 | AlignCompound: false 18 | AlignFunctionPointers: false 19 | PadOperators: false 20 | AlignConsecutiveDeclarations: 21 | Enabled: false 22 | AcrossEmptyLines: false 23 | AcrossComments: false 24 | AlignCompound: false 25 | AlignFunctionDeclarations: true 26 | AlignFunctionPointers: false 27 | PadOperators: false 28 | AlignConsecutiveMacros: 29 | Enabled: false 30 | AcrossEmptyLines: false 31 | AcrossComments: false 32 | AlignCompound: false 33 | AlignFunctionPointers: false 34 | PadOperators: false 35 | AlignConsecutiveShortCaseStatements: 36 | Enabled: false 37 | AcrossEmptyLines: false 38 | AcrossComments: false 39 | AlignCaseArrows: false 40 | AlignCaseColons: false 41 | AlignConsecutiveTableGenBreakingDAGArgColons: 42 | Enabled: false 43 | AcrossEmptyLines: false 44 | AcrossComments: false 45 | AlignCompound: false 46 | AlignFunctionPointers: false 47 | PadOperators: false 48 | AlignConsecutiveTableGenCondOperatorColons: 49 | Enabled: false 50 | AcrossEmptyLines: false 51 | AcrossComments: false 52 | AlignCompound: false 53 | AlignFunctionPointers: false 54 | PadOperators: false 55 | AlignConsecutiveTableGenDefinitionColons: 56 | Enabled: false 57 | AcrossEmptyLines: false 58 | AcrossComments: false 59 | AlignCompound: false 60 | AlignFunctionPointers: false 61 | PadOperators: false 62 | AlignEscapedNewlines: Right 63 | AlignOperands: DontAlign 64 | AlignTrailingComments: 65 | Kind: Never 66 | OverEmptyLines: 0 67 | AllowAllArgumentsOnNextLine: true 68 | AllowAllParametersOfDeclarationOnNextLine: true 69 | AllowBreakBeforeNoexceptSpecifier: Never 70 | AllowShortBlocksOnASingleLine: Empty 71 | AllowShortCaseExpressionOnASingleLine: true 72 | AllowShortCaseLabelsOnASingleLine: false 73 | AllowShortCompoundRequirementOnASingleLine: true 74 | AllowShortEnumsOnASingleLine: true 75 | AllowShortFunctionsOnASingleLine: All 76 | AllowShortIfStatementsOnASingleLine: Never 77 | AllowShortLambdasOnASingleLine: All 78 | AllowShortLoopsOnASingleLine: false 79 | AlwaysBreakAfterDefinitionReturnType: None 80 | AlwaysBreakBeforeMultilineStrings: false 81 | AttributeMacros: 82 | - __capability 83 | BinPackArguments: true 84 | BinPackParameters: true 85 | BitFieldColonSpacing: Both 86 | BraceWrapping: 87 | AfterCaseLabel: false 88 | AfterClass: false 89 | AfterControlStatement: Never 90 | AfterEnum: false 91 | AfterFunction: false 92 | AfterNamespace: false 93 | AfterObjCDeclaration: false 94 | AfterStruct: false 95 | AfterUnion: false 96 | AfterExternBlock: false 97 | BeforeCatch: false 98 | BeforeElse: false 99 | BeforeLambdaBody: false 100 | BeforeWhile: false 101 | IndentBraces: false 102 | SplitEmptyFunction: true 103 | SplitEmptyRecord: true 104 | SplitEmptyNamespace: true 105 | BreakAdjacentStringLiterals: true 106 | BreakAfterAttributes: Leave 107 | BreakAfterJavaFieldAnnotations: false 108 | BreakAfterReturnType: None 109 | BreakArrays: true 110 | BreakBeforeBinaryOperators: All 111 | BreakBeforeBraces: Custom 112 | BreakBeforeConceptDeclarations: Always 113 | BreakBeforeInlineASMColon: OnlyMultiline 114 | BreakBeforeTernaryOperators: true 115 | BreakConstructorInitializers: BeforeComma 116 | BreakFunctionDefinitionParameters: false 117 | BreakInheritanceList: BeforeColon 118 | BreakStringLiterals: true 119 | BreakTemplateDeclarations: MultiLine 120 | ColumnLimit: 0 121 | CommentPragmas: "^ IWYU pragma:" 122 | CompactNamespaces: false 123 | ConstructorInitializerIndentWidth: 4 124 | ContinuationIndentWidth: 4 125 | Cpp11BracedListStyle: false 126 | DerivePointerAlignment: false 127 | DisableFormat: false 128 | EmptyLineAfterAccessModifier: Never 129 | EmptyLineBeforeAccessModifier: LogicalBlock 130 | ExperimentalAutoDetectBinPacking: false 131 | FixNamespaceComments: false 132 | ForEachMacros: 133 | - foreach 134 | - Q_FOREACH 135 | - BOOST_FOREACH 136 | IfMacros: 137 | - KJ_IF_MAYBE 138 | IncludeBlocks: Preserve 139 | IncludeCategories: 140 | - Regex: ^"(llvm|llvm-c|clang|clang-c)/ 141 | Priority: 2 142 | SortPriority: 0 143 | CaseSensitive: false 144 | - Regex: ^(<|"(gtest|gmock|isl|json)/) 145 | Priority: 3 146 | SortPriority: 0 147 | CaseSensitive: false 148 | - Regex: .* 149 | Priority: 1 150 | SortPriority: 0 151 | CaseSensitive: false 152 | IncludeIsMainRegex: (Test)?$ 153 | IncludeIsMainSourceRegex: "" 154 | IndentAccessModifiers: false 155 | IndentCaseBlocks: false 156 | IndentCaseLabels: false 157 | IndentExternBlock: Indent 158 | IndentGotoLabels: true 159 | IndentPPDirectives: None 160 | IndentRequiresClause: true 161 | IndentWidth: 4 162 | IndentWrappedFunctionNames: false 163 | InsertBraces: false 164 | InsertNewlineAtEOF: false 165 | InsertTrailingCommas: None 166 | IntegerLiteralSeparator: 167 | Binary: 0 168 | BinaryMinDigits: 0 169 | Decimal: 0 170 | DecimalMinDigits: 0 171 | Hex: 0 172 | HexMinDigits: 0 173 | JavaScriptQuotes: Leave 174 | JavaScriptWrapImports: true 175 | KeepEmptyLines: 176 | AtEndOfFile: false 177 | AtStartOfBlock: true 178 | AtStartOfFile: true 179 | LambdaBodyIndentation: Signature 180 | Language: Cpp 181 | LineEnding: DeriveLF 182 | MacroBlockBegin: "" 183 | MacroBlockEnd: "" 184 | MainIncludeChar: Quote 185 | MaxEmptyLinesToKeep: 1 186 | NamespaceIndentation: All 187 | ObjCBinPackProtocolList: Auto 188 | ObjCBlockIndentWidth: 4 189 | ObjCBreakBeforeNestedBlockParam: true 190 | ObjCSpaceAfterProperty: true 191 | ObjCSpaceBeforeProtocolList: true 192 | PPIndentWidth: -1 193 | PackConstructorInitializers: BinPack 194 | PenaltyBreakAssignment: 2 195 | PenaltyBreakBeforeFirstCallParameter: 19 196 | PenaltyBreakComment: 300 197 | PenaltyBreakFirstLessLess: 120 198 | PenaltyBreakOpenParenthesis: 0 199 | PenaltyBreakScopeResolution: 500 200 | PenaltyBreakString: 1000 201 | PenaltyBreakTemplateDeclaration: 10 202 | PenaltyExcessCharacter: 1000000 203 | PenaltyIndentedWhitespace: 0 204 | PenaltyReturnTypeOnItsOwnLine: 60 205 | PointerAlignment: Left 206 | QualifierAlignment: Leave 207 | ReferenceAlignment: Pointer 208 | ReflowComments: true 209 | RemoveBracesLLVM: false 210 | RemoveParentheses: Leave 211 | RemoveSemicolon: false 212 | RequiresClausePosition: OwnLine 213 | RequiresExpressionIndentation: OuterScope 214 | SeparateDefinitionBlocks: Leave 215 | ShortNamespaceLines: 1 216 | SkipMacroDefinitionBody: false 217 | SortIncludes: CaseSensitive 218 | SortJavaStaticImport: Before 219 | SortUsingDeclarations: LexicographicNumeric 220 | SpaceAfterCStyleCast: false 221 | SpaceAfterLogicalNot: false 222 | SpaceAfterTemplateKeyword: true 223 | SpaceAroundPointerQualifiers: Default 224 | SpaceBeforeAssignmentOperators: true 225 | SpaceBeforeCaseColon: false 226 | SpaceBeforeCpp11BracedList: true 227 | SpaceBeforeCtorInitializerColon: true 228 | SpaceBeforeInheritanceColon: true 229 | SpaceBeforeJsonColon: false 230 | SpaceBeforeParens: ControlStatements 231 | SpaceBeforeParensOptions: 232 | AfterControlStatements: true 233 | AfterForeachMacros: true 234 | AfterFunctionDeclarationName: false 235 | AfterFunctionDefinitionName: false 236 | AfterIfMacros: true 237 | AfterOverloadedOperator: false 238 | AfterPlacementOperator: true 239 | AfterRequiresInClause: false 240 | AfterRequiresInExpression: false 241 | BeforeNonEmptyParentheses: false 242 | SpaceBeforeRangeBasedForLoopColon: true 243 | SpaceBeforeSquareBrackets: false 244 | SpaceInEmptyBlock: true 245 | SpacesBeforeTrailingComments: 1 246 | SpacesInAngles: Never 247 | SpacesInContainerLiterals: true 248 | SpacesInLineCommentPrefix: 249 | Minimum: 1 250 | Maximum: -1 251 | SpacesInParens: Never 252 | SpacesInParensOptions: 253 | ExceptDoubleParentheses: false 254 | InConditionalStatements: false 255 | InCStyleCasts: false 256 | InEmptyParentheses: false 257 | Other: false 258 | SpacesInSquareBrackets: false 259 | Standard: Latest 260 | StatementAttributeLikeMacros: 261 | - Q_EMIT 262 | StatementMacros: 263 | - Q_UNUSED 264 | - QT_REQUIRE_VERSION 265 | TabWidth: 4 266 | TableGenBreakInsideDAGArg: DontBreak 267 | UseTab: Never 268 | VerilogBreakBetweenInstancePorts: true 269 | WhitespaceSensitiveMacros: 270 | - BOOST_PP_STRINGIZE 271 | - CF_SWIFT_NAME 272 | - NS_SWIFT_NAME 273 | - PP_STRINGIZE 274 | - STRINGIZE 275 | -------------------------------------------------------------------------------- /bridge/src/bridge.cpp: -------------------------------------------------------------------------------- 1 | #define LIB_NAME "Bridge" 2 | #define MODULE_NAME "Bridge" 3 | #include 4 | 5 | #if defined(DM_PLATFORM_HTML5) 6 | #include "bridge.h" 7 | 8 | // Functions exposed to Lua 9 | static const luaL_reg platform_methods[] = { 10 | { "on", bridge::platform::on }, 11 | { "id", bridge::platform::id }, 12 | { "language", bridge::platform::language }, 13 | { "payload", bridge::platform::payload }, 14 | { "tld", bridge::platform::tld }, 15 | { "send_message", bridge::platform::sendMessage }, 16 | { "get_server_time", bridge::platform::getServerTime }, 17 | { "is_audio_enabled", bridge::platform::isAudioEnabled }, 18 | { "is_get_all_games_supported", bridge::platform::isGetAllGamesSupported }, 19 | { "is_get_game_by_id_supported", bridge::platform::isGetGameByIdSupported }, 20 | { "get_all_games", bridge::platform::getAllGames }, 21 | { "get_game_by_id", bridge::platform::getGameById }, 22 | { 0, 0 } 23 | }; 24 | 25 | static const luaL_reg game_methods[] = { 26 | { "on", bridge::game::on }, 27 | { "visibility_state", bridge::game::visibilityState }, 28 | { 0, 0 } 29 | }; 30 | 31 | static const luaL_reg storage_methods[] = { 32 | { "default_type", bridge::storage::defaultType }, 33 | { "is_supported", bridge::storage::isSupported }, 34 | { "is_available", bridge::storage::isAvailable }, 35 | { "get", bridge::storage::get }, 36 | { "set", bridge::storage::set }, 37 | { "delete", bridge::storage::deleteData }, 38 | { 0, 0 } 39 | }; 40 | 41 | static const luaL_reg advertisement_methods[] = { 42 | // Banner 43 | { "show_banner", bridge::advertisement::showBanner }, 44 | { "hide_banner", bridge::advertisement::hideBanner }, 45 | { "banner_state", bridge::advertisement::bannerState }, 46 | { "is_banner_supported", bridge::advertisement::isBannerSupported }, 47 | { "on", bridge::advertisement::on }, 48 | 49 | // Interstitial 50 | { "is_interstitial_supported", bridge::advertisement::isInterstitialSupported }, 51 | { "show_interstitial", bridge::advertisement::showInterstitial }, 52 | { "minimum_delay_between_interstitial", bridge::advertisement::minimumDelayBetweenInterstitial }, 53 | { "set_minimum_delay_between_interstitial", bridge::advertisement::setMinimumDelayBetweenInterstitial }, 54 | { "interstitial_state", bridge::advertisement::interstitialState }, 55 | 56 | // Rewarded 57 | { "is_rewarded_supported", bridge::advertisement::isRewardedSupported }, 58 | { "rewarded_state", bridge::advertisement::rewardedState }, 59 | { "rewarded_placement", bridge::advertisement::rewardedPlacement }, 60 | { "show_rewarded", bridge::advertisement::showRewarded }, 61 | 62 | // Ad Block 63 | { "check_ad_block", bridge::advertisement::checkAdBlock }, 64 | { 0, 0 } 65 | }; 66 | 67 | static const luaL_reg device_methods[] = { 68 | { "type", bridge::device::type }, 69 | { 0, 0 } 70 | }; 71 | 72 | static const luaL_reg player_methods[] = { 73 | { "id", bridge::player::id }, 74 | { "name", bridge::player::name }, 75 | { "extra", bridge::player::extra }, 76 | { "photos", bridge::player::photos }, 77 | { "is_authorization_supported", bridge::player::isAuthorizationSupported }, 78 | { "is_authorized", bridge::player::isAuthorized }, 79 | { "authorize", bridge::player::authorize }, 80 | { 0, 0 } 81 | }; 82 | 83 | static const luaL_reg social_methods[] = { 84 | // Share 85 | { "is_share_supported", bridge::social::isShareSupported }, 86 | { "share", bridge::social::share }, 87 | 88 | // Join Community 89 | { "is_join_community_supported", bridge::social::isJoinCommunitySupported }, 90 | { "join_community", bridge::social::joinCommunity }, 91 | 92 | // Invite Friends 93 | { "is_invite_friends_supported", bridge::social::isInviteFriendsSupported }, 94 | { "invite_friends", bridge::social::inviteFriends }, 95 | 96 | // Create Post 97 | { "is_create_post_supported", bridge::social::isCreatePostSupported }, 98 | { "createPost", bridge::social::createPost }, 99 | 100 | // Add to Home Screen 101 | { "is_add_to_home_screen_supported", bridge::social::isAddToHomeScreenSupported }, 102 | { "add_to_home_screen", bridge::social::addToHomeScreen }, 103 | 104 | // Add to Favorites 105 | { "is_add_to_favorites_supported", bridge::social::isAddToFavoritesSupported }, 106 | { "add_to_favorites", bridge::social::addToFavorites }, 107 | 108 | // Rate Game 109 | { "is_rate_supported", bridge::social::isRateSupported }, 110 | { "rate", bridge::social::rate }, 111 | 112 | // External Links 113 | { "is_external_links_allowed", bridge::social::isExternalLinksAllowed }, 114 | { 0, 0 } 115 | }; 116 | 117 | static const luaL_reg leaderboards_methods[] = { 118 | { "type", bridge::leaderboards::type }, 119 | { "set_score", bridge::leaderboards::setScore }, 120 | { "get_entries", bridge::leaderboards::getEntries }, 121 | { "show_native_popup", bridge::leaderboards::showNativePopup }, 122 | { 0, 0 } 123 | }; 124 | 125 | static const luaL_reg achievements_methods[] = { 126 | { "is_supported", bridge::achievements::isSupported }, 127 | { "is_get_list_supported", bridge::achievements::isGetListSupported }, 128 | { "is_native_popup_supported", bridge::achievements::isNativePopupSupported }, 129 | { "unlock", bridge::achievements::unlock }, 130 | { "get_list", bridge::achievements::getList }, 131 | { "show_native_popup", bridge::achievements::showNativePopup }, 132 | { 0, 0 } 133 | }; 134 | 135 | static const luaL_reg payments_methods[] = { 136 | { "is_supported", bridge::payments::isSupported }, 137 | { "purchase", bridge::payments::purchase }, 138 | { "consume_purchase", bridge::payments::consumePurchase }, 139 | { "get_catalog", bridge::payments::getCatalog }, 140 | { "get_purchases", bridge::payments::getPurchases }, 141 | { 0, 0 } 142 | }; 143 | 144 | static const luaL_reg remoteConfig_methods[] = { 145 | { "is_supported", bridge::remoteConfig::isSupported }, 146 | { "get", bridge::remoteConfig::get }, 147 | { 0, 0 } 148 | }; 149 | 150 | #endif 151 | 152 | #pragma region Defold 153 | static void LuaInit(lua_State* L) { 154 | int top = lua_gettop(L); 155 | #if defined(DM_PLATFORM_HTML5) 156 | 157 | lua_newtable(L); // create _bridge table (root) 158 | lua_pushvalue(L, -1); 159 | lua_setglobal(L, "_bridge"); 160 | { 161 | lua_pushstring(L, "platform"); // create platform table 162 | lua_newtable(L); 163 | luaL_register(L, NULL, platform_methods); 164 | lua_settable(L, -3); 165 | 166 | lua_pushstring(L, "game"); // create game table 167 | lua_newtable(L); 168 | luaL_register(L, NULL, game_methods); 169 | lua_settable(L, -3); 170 | 171 | lua_pushstring(L, "storage"); // create storage table 172 | lua_newtable(L); 173 | luaL_register(L, NULL, storage_methods); 174 | lua_settable(L, -3); 175 | 176 | lua_pushstring(L, "advertisement"); // create advertisement table 177 | lua_newtable(L); 178 | luaL_register(L, NULL, advertisement_methods); 179 | lua_settable(L, -3); 180 | 181 | lua_pushstring(L, "device"); // create device table 182 | lua_newtable(L); 183 | luaL_register(L, NULL, device_methods); 184 | lua_settable(L, -3); 185 | 186 | lua_pushstring(L, "player"); // create player table 187 | lua_newtable(L); 188 | luaL_register(L, NULL, player_methods); 189 | lua_settable(L, -3); 190 | 191 | lua_pushstring(L, "social"); // create social table 192 | lua_newtable(L); 193 | luaL_register(L, NULL, social_methods); 194 | lua_settable(L, -3); 195 | 196 | lua_pushstring(L, "leaderboards"); // create leaderboards table 197 | lua_newtable(L); 198 | luaL_register(L, NULL, leaderboards_methods); 199 | lua_settable(L, -3); 200 | 201 | lua_pushstring(L, "achievements"); // create achievements table 202 | lua_newtable(L); 203 | luaL_register(L, NULL, achievements_methods); 204 | lua_settable(L, -3); 205 | 206 | lua_pushstring(L, "payments"); // create payments table 207 | lua_newtable(L); 208 | luaL_register(L, NULL, payments_methods); 209 | lua_settable(L, -3); 210 | 211 | lua_pushstring(L, "remote_config"); // create remote_config table 212 | lua_newtable(L); 213 | luaL_register(L, NULL, remoteConfig_methods); 214 | lua_settable(L, -3); 215 | } 216 | lua_pop(L, 1); 217 | #endif 218 | assert(top == lua_gettop(L)); 219 | } 220 | 221 | dmExtension::Result InitializeMyExtension(dmExtension::Params* params) { 222 | // Init Lua 223 | LuaInit(params->m_L); 224 | printf("Registered %s Extension\n", MODULE_NAME); 225 | return dmExtension::RESULT_OK; 226 | } 227 | 228 | DM_DECLARE_EXTENSION(Bridge, LIB_NAME, 0, 0, InitializeMyExtension, 0, 0, 0) 229 | #pragma endregion -------------------------------------------------------------------------------- /bridge/api/bridge.script_api: -------------------------------------------------------------------------------- 1 | - name: bridge 2 | type: table 3 | desc: Functions and constants for interacting with bridge 4 | members: 5 | 6 | 7 | 8 | 9 | - name: platform 10 | type: table 11 | desc: At any time, you can retrieve values for specific parameters that you might use in your game, such as the user's browser language. 12 | members: 13 | - name: on 14 | type: function 15 | desc: State changed events. 16 | parameters: 17 | - name: event_name 18 | type: string 19 | 20 | - name: callback 21 | type: function 22 | desc: function(_, state) 23 | 24 | - name: id 25 | type: function 26 | desc: Identify the platform on which the game is currently running to customize features and settings accordingly. 27 | returns: 28 | - name: result 29 | type: string | nil 30 | 31 | - name: tld 32 | type: function 33 | desc: Retrieve the top-level domain of the platform to handle domain-specific configurations and behavior. 34 | returns: 35 | - name: result 36 | type: string | nil 37 | 38 | - name: language 39 | type: function 40 | desc: Get the language set by the user on the platform or the browser language if not provided by the platform, to localize game content. 41 | returns: 42 | - name: result 43 | type: string 44 | 45 | - name: payload 46 | type: function 47 | desc: Embed auxiliary information into the game URL to pass additional data or settings when launching the game. 48 | returns: 49 | - name: result 50 | type: string | nil 51 | 52 | - name: send_message 53 | type: function 54 | desc: Send predefined messages to the platform to trigger specific actions or events, such as signaling that the game is ready. 55 | parameters: 56 | - name: message 57 | type: string 58 | desc: "One of message types: 59 | `game_ready` 60 | `in_game_loading_started`" 61 | - name: on_success 62 | type: function 63 | - name: on_failure 64 | type: function 65 | 66 | - name: get_server_time 67 | type: function 68 | desc: Server Time 69 | parameters: 70 | - name: on_success 71 | type: function 72 | desc: function(_, time) 73 | - name: on_failure 74 | type: function 75 | desc: function(_, error) 76 | 77 | - name: is_audio_enabled 78 | type: function 79 | desc: Check if the audio is enabled on the platform. 80 | returns: 81 | - name: result 82 | type: boolean 83 | 84 | - name: is_get_all_games_supported 85 | type: function 86 | desc: Verify if the get_all_games is supported on the platform to ensure compatibility. 87 | returns: 88 | - name: result 89 | type: boolean 90 | 91 | - name: is_get_game_by_id_supported 92 | type: function 93 | desc: Verify if the get_game_by_id is supported on the platform to ensure compatibility. 94 | returns: 95 | - name: result 96 | type: boolean 97 | 98 | - name: get_all_games 99 | type: function 100 | desc: Get all games on the platform. 101 | parameters: 102 | - name: on_success 103 | type: function 104 | desc: function(_, data) 105 | - name: on_failure 106 | type: function 107 | desc: function(_, error) 108 | 109 | - name: get_game_by_id 110 | type: function 111 | desc: Get game by ID on the platform. 112 | parameters: 113 | - name: options 114 | type: table 115 | - name: on_success 116 | type: function 117 | desc: function(_, data) 118 | - name: on_failure 119 | type: function 120 | desc: function(_, error) 121 | 122 | 123 | - name: game 124 | type: table 125 | desc: Functions and constants for interacting with game 126 | members: 127 | - name: on 128 | type: function 129 | desc: Check if the game tab is visible or hidden, and adjust game behavior accordingly, such as muting sound when hidden. 130 | parameters: 131 | - name: event_name 132 | type: string 133 | 134 | - name: callback 135 | type: function 136 | desc: function(_, state) 137 | 138 | - name: visibility_state 139 | type: function 140 | desc: Returns the current visibility state of the game (the tab with the game). 141 | returns: 142 | - name: result 143 | type: string 144 | 145 | 146 | 147 | 148 | - name: storage 149 | type: table 150 | desc: Store and manage player data to enhance gameplay experience and retain progress. 151 | members: 152 | - name: default_type 153 | type: function 154 | desc: Identify the default storage type to understand where data is being saved (local or server). 155 | returns: 156 | - name: result 157 | type: string 158 | 159 | - name: is_available 160 | type: function 161 | desc: Check if the specified storage type is currently available for use to manage data storage effectively. 162 | parameters: 163 | - name: storage_type 164 | type: string 165 | returns: 166 | - name: result 167 | type: boolean 168 | 169 | - name: is_supported 170 | type: function 171 | desc: Verify if the specified storage type is supported on the platform to ensure compatibility. 172 | parameters: 173 | - name: storage_type 174 | type: string 175 | returns: 176 | - name: result 177 | type: boolean 178 | 179 | - name: get 180 | type: function 181 | desc: Retrieve stored data based on a key or multiple keys to restore player progress or settings. 182 | parameters: 183 | - name: table_keys 184 | type: table 185 | - name: on_success 186 | type: function 187 | desc: function(_, data) 188 | - name: on_failure 189 | type: function 190 | desc: function(_, error) 191 | - name: storage_type 192 | type: string 193 | - name: set 194 | type: function 195 | desc: Save data to the specified storage with a key to retain player progress or settings. 196 | parameters: 197 | - name: table_data 198 | type: table 199 | - name: on_success 200 | type: function 201 | desc: function(_) 202 | - name: on_failure 203 | type: function 204 | desc: function(_, error) 205 | - name: storage_type 206 | type: string 207 | - name: delete 208 | type: function 209 | desc: Remove data from the specified storage by key to manage player data and settings effectively. 210 | parameters: 211 | - name: table_keys 212 | type: table 213 | - name: on_success 214 | type: function 215 | desc: function(_) 216 | - name: on_failure 217 | type: function 218 | desc: function(_, error) 219 | - name: storage_type 220 | type: string 221 | 222 | 223 | 224 | 225 | - name: advertisement 226 | type: table 227 | desc: Monetize your game by integrating various types of advertisements, including banners, interstitials, and rewarded ads. 228 | members: 229 | - name: show_banner 230 | type: function 231 | desc: Display a banner ad within your game to generate revenue through advertising. 232 | parameters: 233 | - name: position 234 | type: string 235 | - name: placement 236 | type: string 237 | 238 | - name: hide_banner 239 | type: function 240 | desc: Hide the currently displayed banner ad when it is no longer needed. 241 | 242 | - name: banner_state 243 | type: function 244 | desc: Hide the currently displayed banner ad when it is no longer needed. 245 | 246 | - name: is_banner_supported 247 | type: function 248 | desc: Check if the platform supports displaying banner ads. Use this to determine if you can include banner advertisements in your game. 249 | returns: 250 | - name: result 251 | type: string 252 | 253 | - name: is_interstitial_supported 254 | type: function 255 | desc: Check if the platform supports displaying interstitial ads. Use this to determine if you can include interstitial advertisements in your game. 256 | returns: 257 | - name: result 258 | type: string 259 | 260 | - name: is_rewarded_supported 261 | type: function 262 | desc: Check if the platform supports displaying rewarded ads. Use this to determine if you can include rewarded advertisements in your game. 263 | returns: 264 | - name: result 265 | type: string 266 | 267 | - name: on 268 | type: function 269 | desc: State changed events. 270 | parameters: 271 | - name: event_name 272 | type: string 273 | - name: callback 274 | type: function 275 | desc: function(_, state) 276 | 277 | - name: show_interstitial 278 | type: function 279 | desc: Display an interstitial ad at appropriate moments, such as during level transitions or game over screens. 280 | parameters: 281 | - name: placement 282 | type: string 283 | 284 | - name: interstitial_state 285 | type: function 286 | desc: Track the state of the interstitial ad to manage ad display and user experience. 287 | 288 | - name: minimum_delay_between_interstitial 289 | type: function 290 | desc: Minimum time interval between interstitial ad displays to comply with platform requirements and improve user experience. 291 | returns: 292 | - name: result 293 | type: number 294 | 295 | - name: set_minimum_delay_between_interstitial 296 | type: function 297 | desc: Set the minimum time interval between interstitial ad displays to comply with platform requirements and improve user experience. 298 | parameters: 299 | - name: delay 300 | type: number 301 | desc: 60 from default 302 | 303 | - name: rewarded_state 304 | type: function 305 | desc: Monitor the state of the rewarded ad (loading, opened, closed, rewarded, failed) to manage the reward process. 306 | 307 | - name: rewarded_placement 308 | type: function 309 | desc: Monitor the placement of the rewarded ad to manage the reward process. 310 | 311 | - name: show_rewarded 312 | type: function 313 | desc: Display a rewarded ad and provide incentives to players for watching the entire ad. 314 | parameters: 315 | - name: placement 316 | type: string 317 | 318 | - name: check_ad_block 319 | type: function 320 | desc: Check if the ad blocker is enabled. 321 | parameters: 322 | - name: on_success 323 | type: function 324 | desc: function(_, bool) 325 | - name: on_failure 326 | type: function 327 | desc: function(_, error) 328 | 329 | 330 | 331 | 332 | - name: device 333 | type: table 334 | desc: You can also retrieve various information about the player device. 335 | members: 336 | - name: type 337 | type: function 338 | desc: Determine the type of device (mobile, tablet, desktop, tv) the game is being played on to adjust the game`s interface and performance settings. 339 | returns: 340 | - name: result 341 | type: string 342 | 343 | 344 | 345 | 346 | - name: player 347 | type: table 348 | desc: You can also retrieve various information about the player. 349 | members: 350 | - name: is_authorization_supported 351 | type: function 352 | desc: Check if the platform supports player authorization to enable features that require user authentication, such as saving game progress or accessing social features. 353 | returns: 354 | - name: result 355 | type: boolean 356 | 357 | - name: is_authorized 358 | type: function 359 | desc: Verify if the player is currently authorized on the platform. This allows you to enable personalized features, such as saving high scores or providing user-specific content. 360 | returns: 361 | - name: result 362 | type: boolean 363 | 364 | - name: id 365 | type: function 366 | desc: Get the player’s unique ID on the platform to manage user-specific data and settings. Use this ID to track player progress, achievements, and purchases. 367 | returns: 368 | - name: result 369 | type: string | nil 370 | 371 | - name: name 372 | type: function 373 | desc: Retrieve the player's name to personalize the game experience. Display the name in leaderboards, friend lists, or when sending notifications and messages. 374 | returns: 375 | - name: result 376 | type: string | nil 377 | 378 | - name: extra 379 | type: function 380 | desc: Get the extra information about player. 381 | returns: 382 | - name: result 383 | type: table 384 | 385 | - name: photos 386 | type: function 387 | desc: Get the count of player avatars available. Use this to manage and display user profile images effectively, such as showing the avatar in multiplayer lobbies or profile screens. 388 | returns: 389 | - name: result 390 | type: table 391 | 392 | - name: authorize 393 | type: function 394 | desc: Authorize the player on the platform to access protected features and personalize the game experience. For example, prompting the player to log in to save their progress or unlock social sharing features. 395 | parameters: 396 | - name: options 397 | type: table 398 | - name: on_success 399 | type: function 400 | desc: function() 401 | - name: on_failure 402 | type: function 403 | desc: function(_, error) 404 | 405 | 406 | 407 | 408 | - name: social 409 | type: table 410 | desc: Enable social features to enhance player engagement by allowing them to share, join communities, invite friends, and more. 411 | members: 412 | - name: is_share_supported 413 | type: function 414 | desc: Check if the share functionality is supported on the platform. 415 | returns: 416 | - name: result 417 | type: boolean 418 | 419 | - name: share 420 | type: function 421 | desc: Use this to allow players to share game content or achievements on social media platforms. 422 | parameters: 423 | - name: options 424 | type: table 425 | - name: on_success 426 | type: function 427 | desc: function(_) 428 | - name: on_failure 429 | type: function 430 | desc: function(_) 431 | 432 | - name: is_join_community_supported 433 | type: function 434 | desc: Check if the join community functionality is supported on the platform. 435 | returns: 436 | - name: result 437 | type: boolean 438 | 439 | 440 | - name: join_community 441 | type: function 442 | desc: Use this to allow players to share game content or achievements on social media platforms. 443 | parameters: 444 | - name: options 445 | type: table 446 | - name: on_success 447 | type: function 448 | desc: function(_) 449 | - name: on_failure 450 | type: function 451 | desc: function(_) 452 | 453 | - name: is_invite_friends_supported 454 | type: function 455 | desc: Check if the invite friends functionality is supported on the platform. 456 | returns: 457 | - name: result 458 | type: boolean 459 | 460 | - name: invite_friends 461 | type: function 462 | desc: Allow players to invite their friends to play the game, helping to grow your player base organically. 463 | parameters: 464 | - name: options 465 | type: table 466 | - name: on_success 467 | type: function 468 | desc: function(_) 469 | - name: on_failure 470 | type: function 471 | desc: function(_) 472 | 473 | - name: is_create_post_supported 474 | type: function 475 | desc: Check if the create post functionality is supported on the platform. 476 | returns: 477 | - name: result 478 | type: boolean 479 | 480 | - name: create_post 481 | type: function 482 | desc: Use this to let players create posts about their achievements or updates directly from the game. 483 | parameters: 484 | - name: options 485 | type: table 486 | - name: on_success 487 | type: function 488 | desc: function(_) 489 | - name: on_failure 490 | type: function 491 | desc: function(_) 492 | 493 | - name: is_add_to_favorites_supported 494 | type: function 495 | desc: Check if the add to favorites functionality is supported on the platform. 496 | returns: 497 | - name: result 498 | type: boolean 499 | 500 | - name: add_to_favorites 501 | type: function 502 | desc: Allow players to bookmark your game for easy access in the future. 503 | parameters: 504 | - name: on_success 505 | type: function 506 | desc: function(_) 507 | - name: on_failure 508 | type: function 509 | desc: function(_) 510 | 511 | - name: is_add_to_home_screen_supported 512 | type: function 513 | desc: Check if the add to home screen functionality is supported on the platform. 514 | returns: 515 | - name: result 516 | type: boolean 517 | 518 | - name: add_to_home_screen 519 | type: function 520 | desc: Enable players to add a shortcut to your game on their home screen for quick access. 521 | parameters: 522 | - name: on_success 523 | type: function 524 | desc: function(_) 525 | - name: on_failure 526 | type: function 527 | desc: function(_) 528 | 529 | - name: is_rate_supported 530 | type: function 531 | desc: Check if the rate game functionality is supported on the platform. 532 | returns: 533 | - name: result 534 | type: boolean 535 | 536 | - name: rate 537 | type: function 538 | desc: Encourage players to rate your game, providing valuable feedback and improving visibility. 539 | parameters: 540 | - name: on_success 541 | type: function 542 | desc: function(_) 543 | - name: on_failure 544 | type: function 545 | desc: function(_) 546 | 547 | - name: is_external_links_allowed 548 | type: function 549 | desc: Check if external links are allowed on the platform. 550 | returns: 551 | - name: result 552 | type: boolean 553 | 554 | 555 | 556 | 557 | - name: payments 558 | type: table 559 | desc: Enable players to purchase items, upgrades, or currency within your game to enhance their experience and generate revenue. 560 | members: 561 | - name: is_supported 562 | type: function 563 | desc: Check if in-game purchases are supported to offer items or upgrades within the game. 564 | returns: 565 | - name: result 566 | type: boolean 567 | 568 | - name: purchase 569 | type: function 570 | desc: Allow players to buy items or upgrades in your game to enhance their gameplay experience. 571 | parameters: 572 | - name: id 573 | type: string 574 | - name: on_success 575 | type: function 576 | desc: function(_, purchase) 577 | - name: on_failure 578 | type: function 579 | desc: function(_, error) 580 | 581 | - name: consume_purchase 582 | type: function 583 | desc: Consume purchased items, such as in-game currency, once they are used, to manage inventory and player progression. 584 | parameters: 585 | - name: id 586 | type: string 587 | - name: on_success 588 | type: function 589 | desc: function(_, purchase) 590 | - name: on_failure 591 | type: function 592 | desc: function(_, error) 593 | 594 | - name: get_catalog 595 | type: function 596 | desc: Retrieve a list of all available in-game items that players can purchase to display in the game store. 597 | parameters: 598 | - name: on_success 599 | type: function 600 | desc: function(_, catalogItems) 601 | - name: on_failure 602 | type: function 603 | desc: function(_, error) 604 | 605 | - name: get_purchases 606 | type: function 607 | desc: Retrieve a list of items that the player has purchased to manage their inventory and provide access to purchased content. 608 | parameters: 609 | - name: on_success 610 | type: function 611 | desc: function(nil, purchases) 612 | - name: on_failure 613 | type: function 614 | desc: function(_, error) 615 | 616 | 617 | 618 | 619 | - name: achievements 620 | type: table 621 | desc: Achievements in HTML5 games are an exciting and rewarding feature that adds an extra layer of engagement for players. They serve as milestones, celebrating a player's progress, skill, and dedication. 622 | members: 623 | - name: is_supported 624 | type: function 625 | desc: Use this to determine if you can implement achievements for your game on the current platform. 626 | returns: 627 | - name: result 628 | type: boolean 629 | 630 | - name: is_get_list_supported 631 | type: function 632 | desc: Check if getting list of achievements is supported. 633 | returns: 634 | - name: result 635 | type: boolean 636 | 637 | - name: is_native_popup_supported 638 | type: function 639 | desc: Check if built-in popup is supported. 640 | returns: 641 | - name: result 642 | type: boolean 643 | 644 | - name: unlock 645 | type: function 646 | desc: Unlocks achievement for a player. 647 | parameters: 648 | - name: options 649 | type: table 650 | - name: on_success 651 | type: function 652 | desc: function(_, result) 653 | - name: on_failure 654 | type: function 655 | desc: function(_, error) 656 | 657 | - name: get_list 658 | type: function 659 | desc: Returns the achievement list in JSON. 660 | parameters: 661 | - name: options 662 | type: table 663 | - name: on_success 664 | type: function 665 | desc: function(_, list) 666 | - name: on_failure 667 | type: function 668 | desc: function(_, error) 669 | 670 | - name: show_native_popup 671 | type: function 672 | desc: Returns the achievement list in JSON. 673 | parameters: 674 | - name: options 675 | type: table 676 | - name: on_success 677 | type: function 678 | desc: function() 679 | - name: on_failure 680 | type: function 681 | desc: function(_, error) 682 | 683 | 684 | 685 | 686 | - name: leaderboards 687 | type: table 688 | desc: Enhance competitiveness by integrating leaderboards, allowing players to compare their scores and achievements. 689 | members: 690 | - name: type 691 | type: function 692 | desc: Check the leaderboards type on the platform. 693 | returns: 694 | - name: result 695 | type: string 696 | 697 | 698 | - name: set_score 699 | type: function 700 | desc: Submit the player's score to the leaderboard to update their rank and position. 701 | parameters: 702 | - name: id 703 | type: string 704 | - name: score 705 | type: number 706 | - name: on_success 707 | type: function 708 | desc: function() 709 | - name: on_failure 710 | type: function 711 | desc: function(_, error) 712 | 713 | - name: get_entries 714 | type: function 715 | desc: Retrieve entries from the leaderboard, including the player's rank and score, to display a comprehensive leaderboard. 716 | parameters: 717 | - name: id 718 | type: string 719 | - name: on_success 720 | type: function 721 | desc: function(_, entries) 722 | - name: on_failure 723 | type: function 724 | desc: function(_, error) 725 | 726 | - name: show_native_popup 727 | type: function 728 | desc: Show native popup leaderboard. 729 | parameters: 730 | - name: id 731 | type: string 732 | - name: on_success 733 | type: function 734 | desc: function() 735 | - name: on_failure 736 | type: function 737 | desc: function(_, error) 738 | 739 | 740 | 741 | 742 | - name: remote_config 743 | type: table 744 | desc: Manage your game settings remotely without releasing updates, allowing for dynamic adjustments and feature toggling. 745 | members: 746 | - name: is_supported 747 | type: function 748 | desc: Check if remote configuration is supported to manage game settings without releasing updates. 749 | returns: 750 | - name: result 751 | type: boolean 752 | 753 | - name: get 754 | type: function 755 | desc: Encourage players to rate your game, providing valuable feedback and improving visibility. 756 | parameters: 757 | - name: options 758 | type: table 759 | - name: on_success 760 | type: function 761 | desc: function(_, data) 762 | - name: on_failure 763 | type: function 764 | desc: function(_) 765 | --------------------------------------------------------------------------------