From b1c31bc152ef48f9f899ae5d8a1f52283ebd1769 Mon Sep 17 00:00:00 2001 From: bimaswara Date: Fri, 8 Nov 2024 13:27:59 +0700 Subject: [PATCH 1/3] feat (core) : onResume --- wortal/include/wortal.h | 38 +++++++----- wortal/lib/web/lib_wortal.js | 75 ++++++++++++++++-------- wortal/src/wortal.cpp | 110 ++++++++++++++++++++++++++--------- 3 files changed, 155 insertions(+), 68 deletions(-) diff --git a/wortal/include/wortal.h b/wortal/include/wortal.h index 703c93c..e89b364 100644 --- a/wortal/include/wortal.h +++ b/wortal/include/wortal.h @@ -4,36 +4,42 @@ #if defined(DM_PLATFORM_HTML5) -class Wortal { +class Wortal +{ public: typedef void (*OnPauseCallback)(const int success); - typedef void (*OnHapticFeedbackCallback)(const int success, const char* error); - typedef void (*OnInitializeCallback)(const int success, const char* error); - typedef void (*OnStartGameCallback)(const int success, const char* error); + typedef void (*OnResumeCallback)(const int success); + typedef void (*OnHapticFeedbackCallback)(const int success, const char *error); + typedef void (*OnInitializeCallback)(const int success, const char *error); + typedef void (*OnStartGameCallback)(const int success, const char *error); - static int IsInitialized(lua_State* L); - static int InitializeAsync(lua_State* L); - static int StartGameAsync(lua_State* L); - static int SetLoadingProgress(lua_State* L); - static int SetPauseCallback(lua_State* L); - static int PerformHapticFeedback(lua_State* L); - static int GetSupportedAPIs(lua_State* L); + static int IsInitialized(lua_State *L); + static int InitializeAsync(lua_State *L); + static int StartGameAsync(lua_State *L); + static int SetLoadingProgress(lua_State *L); + static int SetPauseCallback(lua_State *L); + static int SetResumeCallback(lua_State *L); + static int PerformHapticFeedback(lua_State *L); + static int GetSupportedAPIs(lua_State *L); private: - static void OnInitialize(const int success, const char* error); - static void OnStartGame(const int success, const char* error); + static void OnInitialize(const int success, const char *error); + static void OnStartGame(const int success, const char *error); static void OnPause(const int success); - static void OnHapticFeedback(const int success, const char* error); + static void OnResume(const int success); + static void OnHapticFeedback(const int success, const char *error); }; -extern "C" { +extern "C" +{ int Wortal_isInitialized(); void Wortal_initializeAsync(Wortal::OnInitializeCallback callback); void Wortal_startGameAsync(Wortal::OnStartGameCallback callback); void Wortal_setLoadingProgress(const int progress); void Wortal_onPause(Wortal::OnPauseCallback callback); + void Wortal_onResume(Wortal::OnResumeCallback callback); void Wortal_performHapticFeedback(Wortal::OnHapticFeedbackCallback callback); - char* Wortal_getSupportedAPIs(); + char *Wortal_getSupportedAPIs(); } #endif diff --git a/wortal/lib/web/lib_wortal.js b/wortal/lib/web/lib_wortal.js index 833cbc4..b1e00bb 100644 --- a/wortal/lib/web/lib_wortal.js +++ b/wortal/lib/web/lib_wortal.js @@ -2,65 +2,94 @@ var WortalLib = { $Utils: { _onPauseCallbackPtr: null, + _onResumeCallbackPtr: null, - onPauseCallback: function () { - {{{ makeDynCall("vi", "Utils._onPauseCallbackPtr") }}}(1); + onPauseCallback: function () + { + { { { makeDynCall("vi", "Utils._onPauseCallbackPtr") } } } (1); }, - allocateString: function(str) { + onResumCallback: function () + { + { { { makeDynCall("vi", "Utils._onResumeCallbackPtr") } } } (1); + }, + + allocateString: function (str) + { return stringToUTF8OnStack(str); }, - toObjectFromJsonString: function(str) { + toObjectFromJsonString: function (str) + { return JSON.parse(UTF8ToString(str) || "{}"); } }, - Wortal_isInitialized: function () { + Wortal_isInitialized: function () + { return window.Wortal.isInitialized(); }, - Wortal_initializeAsync: function (callback) { + Wortal_initializeAsync: function (callback) + { window.Wortal.initializeAsync() - .then(() => { - {{{ makeDynCall("vii", "callback") }}}(1, 0); + .then(() => + { + { { { makeDynCall("vii", "callback") } } } (1, 0); }) - .catch(error => { - {{{ makeDynCall("vii", "callback") }}}(0, Utils.allocateString(JSON.stringify(error))); + .catch(error => + { + { { { makeDynCall("vii", "callback") } } } (0, Utils.allocateString(JSON.stringify(error))); }); }, - Wortal_startGameAsync: function (callback) { + Wortal_startGameAsync: function (callback) + { window.Wortal.startGameAsync() - .then(() => { - {{{ makeDynCall("vii", "callback") }}}(1, 0); + .then(() => + { + { { { makeDynCall("vii", "callback") } } } (1, 0); }) - .catch(error => { - {{{ makeDynCall("vii", "callback") }}}(0, Utils.allocateString(JSON.stringify(error))); + .catch(error => + { + { { { makeDynCall("vii", "callback") } } } (0, Utils.allocateString(JSON.stringify(error))); }); }, - Wortal_setLoadingProgress: function (progress) { + Wortal_setLoadingProgress: function (progress) + { window.Wortal.setLoadingProgress(progress); }, - Wortal_onPause: function (callback) { + Wortal_onPause: function (callback) + { Utils._onPauseCallbackPtr = callback; window.Wortal.onPause(() => Utils.onPauseCallback); }, - Wortal_performHapticFeedback: function (callback) { + Wortal_onResume: function (callback) + { + Utils._onResumeCallbackPtr = callback; + + window.Wortal.onResume(() => Utils.onResumCallback); + }, + + Wortal_performHapticFeedback: function (callback) + { window.Wortal.performHapticFeedbackAsync() - .then(() => { - {{{ makeDynCall("vii", "callback") }}}(1, 0); + .then(() => + { + { { { makeDynCall("vii", "callback") } } } (1, 0); }) - .catch(error => { - {{{ makeDynCall("vii", "callback") }}}(0, Utils.allocateString(JSON.stringify(error))); + .catch(error => + { + { { { makeDynCall("vii", "callback") } } } (0, Utils.allocateString(JSON.stringify(error))); }); }, - Wortal_getSupportedAPIs: function () { + Wortal_getSupportedAPIs: function () + { return Utils.allocateString(JSON.stringify(window.Wortal.getSupportedAPIs())); } diff --git a/wortal/src/wortal.cpp b/wortal/src/wortal.cpp index cb92b06..8384efc 100644 --- a/wortal/src/wortal.cpp +++ b/wortal/src/wortal.cpp @@ -23,10 +23,12 @@ lua_Listener onInitializeListener; lua_Listener onStartGameListener; lua_Listener onPauseListener; +lua_Listener onResumeListener; lua_Listener onHapticFeedbackListener; -void Wortal::OnInitialize(const int success, const char* error) { - lua_State* L = onInitializeListener.m_L; +void Wortal::OnInitialize(const int success, const char *error) +{ + lua_State *L = onInitializeListener.m_L; int top = lua_gettop(L); lua_pushlistener(L, onInitializeListener); @@ -34,15 +36,17 @@ void Wortal::OnInitialize(const int success, const char* error) { lua_pushstring(L, error); int ret = lua_pcall(L, 3, 0, 0); - if (ret != 0) { + if (ret != 0) + { lua_pop(L, 1); } assert(top == lua_gettop(L)); } -void Wortal::OnStartGame(const int success, const char* error) { - lua_State* L = onStartGameListener.m_L; +void Wortal::OnStartGame(const int success, const char *error) +{ + lua_State *L = onStartGameListener.m_L; int top = lua_gettop(L); lua_pushlistener(L, onStartGameListener); @@ -50,30 +54,51 @@ void Wortal::OnStartGame(const int success, const char* error) { lua_pushstring(L, error); int ret = lua_pcall(L, 3, 0, 0); - if (ret != 0) { + if (ret != 0) + { lua_pop(L, 1); } assert(top == lua_gettop(L)); } -void Wortal::OnPause(const int success) { - lua_State* L = onPauseListener.m_L; +void Wortal::OnPause(const int success) +{ + lua_State *L = onPauseListener.m_L; int top = lua_gettop(L); lua_pushlistener(L, onPauseListener); lua_pushboolean(L, success); int ret = lua_pcall(L, 2, 0, 0); - if (ret != 0) { + if (ret != 0) + { lua_pop(L, 1); } assert(top == lua_gettop(L)); } -void Wortal::OnHapticFeedback(const int success, const char* error) { - lua_State* L = onHapticFeedbackListener.m_L; +void Wortal::OnResume(const int success) +{ + lua_State *L = onResumeListener.m_L; + int top = lua_gettop(L); + + lua_pushListener(L, onResumeListener); + lua_pushBoolean(L, success); + + int ret = lua_pcall(L, 2, 0, 0); + if (ret != 0) + { + lua_pop(L, 1); + } + + assert(top == lua_gettop(L)); +} + +void Wortal::OnHapticFeedback(const int success, const char *error) +{ + lua_State *L = onHapticFeedbackListener.m_L; int top = lua_gettop(L); lua_pushlistener(L, onHapticFeedbackListener); @@ -81,14 +106,16 @@ void Wortal::OnHapticFeedback(const int success, const char* error) { lua_pushstring(L, error); int ret = lua_pcall(L, 3, 0, 0); - if (ret != 0) { + if (ret != 0) + { lua_pop(L, 1); } assert(top == lua_gettop(L)); } -int Wortal::IsInitialized(lua_State* L) { +int Wortal::IsInitialized(lua_State *L) +{ int top = lua_gettop(onInitializeListener.m_L); lua_pushboolean(onInitializeListener.m_L, Wortal_isInitialized()); @@ -97,7 +124,8 @@ int Wortal::IsInitialized(lua_State* L) { return 1; } -int Wortal::InitializeAsync(lua_State* L) { +int Wortal::InitializeAsync(lua_State *L) +{ int top = lua_gettop(L); luaL_checklistener(L, 1, onInitializeListener); @@ -108,7 +136,8 @@ int Wortal::InitializeAsync(lua_State* L) { return 0; } -int Wortal::StartGameAsync(lua_State* L) { +int Wortal::StartGameAsync(lua_State *L) +{ int top = lua_gettop(L); luaL_checklistener(L, 1, onStartGameListener); @@ -119,7 +148,8 @@ int Wortal::StartGameAsync(lua_State* L) { return 0; } -int Wortal::SetLoadingProgress(lua_State* L) { +int Wortal::SetLoadingProgress(lua_State *L) +{ int top = lua_gettop(L); int progress = luaL_checkinteger(L, 1); @@ -129,7 +159,8 @@ int Wortal::SetLoadingProgress(lua_State* L) { return 0; } -int Wortal::SetPauseCallback(lua_State* L) { +int Wortal::SetPauseCallback(lua_State *L) +{ int top = lua_gettop(L); luaL_checklistener(L, 1, onPauseListener); @@ -140,7 +171,20 @@ int Wortal::SetPauseCallback(lua_State* L) { return 0; } -int Wortal::PerformHapticFeedback(lua_State* L) { +int Wortal::SetResumeCallback(lua_State *L) +{ + int top = lua_gettop(L); + + luaL_checklistener(L, 1, onResumeListener); + + Wortal_onResume(Wortal::OnResume); + + assert(top == lua_gettop(L)); + return 0; +} + +int Wortal::PerformHapticFeedback(lua_State *L) +{ int top = lua_gettop(L); luaL_checklistener(L, 1, onHapticFeedbackListener); @@ -151,14 +195,17 @@ int Wortal::PerformHapticFeedback(lua_State* L) { return 0; } -int Wortal::GetSupportedAPIs(lua_State* L) { +int Wortal::GetSupportedAPIs(lua_State *L) +{ int top = lua_gettop(L); - const char* data = Wortal_getSupportedAPIs(); - if (data) { + const char *data = Wortal_getSupportedAPIs(); + if (data) + { lua_pushstring(L, data); } - else { + else + { lua_pushnil(L); } @@ -173,6 +220,7 @@ static const luaL_reg Module_methods[] = { {"is_initialized", Wortal::IsInitialized}, {"set_loading_progress", Wortal::SetLoadingProgress}, {"on_pause", Wortal::SetPauseCallback}, + {"on_resume", Wortal::SetResumeCallback}, {"perform_haptic_feedback", Wortal::PerformHapticFeedback}, {"get_supported_apis", Wortal::GetSupportedAPIs}, @@ -261,10 +309,10 @@ static const luaL_reg Module_methods[] = { {"tournament_share", WortalTournament::ShareAsync}, {"tournament_join", WortalTournament::JoinAsync}, - {0, 0} -}; + {0, 0}}; -static void LuaInit(lua_State* L) { +static void LuaInit(lua_State *L) +{ int top = lua_gettop(L); luaL_register(L, MODULE_NAME, Module_methods); @@ -273,22 +321,26 @@ static void LuaInit(lua_State* L) { assert(top == lua_gettop(L)); } -dmExtension::Result InitializeWortalSdk(dmExtension::Params* params) { +dmExtension::Result InitializeWortalSdk(dmExtension::Params *params) +{ LuaInit(params->m_L); return dmExtension::RESULT_OK; } -dmExtension::Result FinalizeWortalSdk(dmExtension::Params* params) { +dmExtension::Result FinalizeWortalSdk(dmExtension::Params *params) +{ return dmExtension::RESULT_OK; } #else // unsupported platforms -dmExtension::Result InitializeWortalSdk(dmExtension::Params *params) { +dmExtension::Result InitializeWortalSdk(dmExtension::Params *params) +{ return dmExtension::RESULT_OK; } -dmExtension::Result FinalizeWortalSdk(dmExtension::Params *params) { +dmExtension::Result FinalizeWortalSdk(dmExtension::Params *params) +{ return dmExtension::RESULT_OK; } From e1a2ed6eac7f23f3917720d3e759a28b19d77554 Mon Sep 17 00:00:00 2001 From: bimaswara Date: Fri, 8 Nov 2024 13:59:31 +0700 Subject: [PATCH 2/3] feat (session) : gameplayStart, gameplayStop, isAudioEnabled, onAudioStatusChange, happyTime --- wortal/include/wortal_session.h | 65 +++++---- wortal/lib/web/lib_wortal_session.js | 83 ++++++++--- wortal/src/wortal_session.cpp | 203 ++++++++++++++++++++------- 3 files changed, 258 insertions(+), 93 deletions(-) diff --git a/wortal/include/wortal_session.h b/wortal/include/wortal_session.h index 611f27e..754060c 100644 --- a/wortal/include/wortal_session.h +++ b/wortal/include/wortal_session.h @@ -4,40 +4,53 @@ #if defined(DM_PLATFORM_HTML5) -class WortalSession { +class WortalSession +{ public: - typedef void (*OnGetEntryPointCallback)(const char* data, const char* error); - typedef void (*OnOrientationChangeCallback)(const char* orientation); - typedef void (*OnSwitchGameCallback)(const int success, const char* error); + typedef void (*OnGetEntryPointCallback)(const char *data, const char *error); + typedef void (*OnOrientationChangeCallback)(const char *orientation); + typedef void (*OnSwitchGameCallback)(const int success, const char *error); + typedef void (*OnAudioStatusChangeCallback)(const bool *isAudioEnabled); - static int GetEntryPointData(lua_State* L); - static int GetLocale(lua_State* L); - static int GetTrafficSource(lua_State* L); - static int SetSessionData(lua_State* L); - static int GetEntryPointAsync(lua_State* L); - static int GetPlatform(lua_State* L); - static int GetDevice(lua_State* L); - static int GetOrientation(lua_State* L); - static int OnOrientationChange(lua_State* L); - static int SwitchGameAsync(lua_State* L); + static int GetEntryPointData(lua_State *L); + static int GameplayStart(lua_State *L); + static int GameplayStop(lua_State *L); + static int HappyTime(lua_State *L); + static int GetLocale(lua_State *L); + static int GetTrafficSource(lua_State *L); + static int SetSessionData(lua_State *L); + static int GetEntryPointAsync(lua_State *L); + static int GetPlatform(lua_State *L); + static int GetDevice(lua_State *L); + static int GetOrientation(lua_State *L); + static int OnOrientationChange(lua_State *L); + static int SwitchGameAsync(lua_State *L); + static int IsAudioEnabled(lua_State *L); private: - static void OnGetEntryPoint(const char* entryPoint, const char* error); - static void OnOrientationChange(const char* orientation); - static void OnSwitchGame(const int success, const char* error); + static void OnGetEntryPoint(const char *entryPoint, const char *error); + static void OnOrientationChange(const char *orientation); + static void OnSwitchGame(const int success, const char *error); + static void OnAudioStatusChange(const bool *isAudioEnabled); }; -extern "C" { - char* Wortal_session_getEntryPointData(); - char* Wortal_session_getLocale(); - char* Wortal_session_getTrafficSource(); - void Wortal_session_setSessionData(const char* data); +extern "C" +{ + char *Wortal_session_getEntryPointData(); + void Wortal_session_gameplayStart(); + void Wortal_session_gameplayStop(); + void Wortal_session_happyTime(); + char *Wortal_session_getLocale(); + char *Wortal_session_getTrafficSource(); + void Wortal_session_setSessionData(const char *data); void Wortal_session_getEntryPointAsync(WortalSession::OnGetEntryPointCallback callback); - char* Wortal_session_getPlatform(); - char* Wortal_session_getDevice(); - char* Wortal_session_getOrientation(); + char *Wortal_session_getPlatform(); + char *Wortal_session_getDevice(); + char *Wortal_session_getOrientation(); void Wortal_session_onOrientationChange(WortalSession::OnOrientationChangeCallback callback); - void Wortal_session_switchGameAsync(const char* gameID, WortalSession::OnSwitchGameCallback callback); + void Wortal_session_switchGameAsync(const char *gameID, WortalSession::OnSwitchGameCallback callback); + int Wortal_session_isAudioEnabled(); + void Wortal_session_onAudioStatusChange(WortalSession::OnAudioStatusChangeCallback callback); } #endif diff --git a/wortal/lib/web/lib_wortal_session.js b/wortal/lib/web/lib_wortal_session.js index c2c5ae0..9fb63a4 100644 --- a/wortal/lib/web/lib_wortal_session.js +++ b/wortal/lib/web/lib_wortal_session.js @@ -1,57 +1,100 @@ var WortalSession = { - Wortal_session_getEntryPointData: function () { + Wortal_session_gameplayStart: function () + { + window.Wortal.session.gameplayStart(); + }, + + Wortal_session_gameplayStop: function () + { + window.Wortal.session.gameplayStop(); + }, + + Wortal_session_happyTime: function () + { + window.Wortal.session.happyTime(); + }, + + Wortal_session_getEntryPointData: function () + { return Utils.allocateString(JSON.stringify(window.Wortal.session.getEntryPointData())); }, - Wortal_session_getLocale: function () { + Wortal_session_getLocale: function () + { return Utils.allocateString(window.Wortal.session.getLocale()); }, - Wortal_session_getTrafficSource: function () { + Wortal_session_getTrafficSource: function () + { return Utils.allocateString(JSON.stringify(window.Wortal.session.getTrafficSource())); }, - Wortal_session_setSessionData: function (data) { + Wortal_session_setSessionData: function (data) + { window.Wortal.session.setSessionData(Utils.toObjectFromJsonString(data)); }, - Wortal_session_getEntryPointAsync: function (callback) { + Wortal_session_getEntryPointAsync: function (callback) + { window.Wortal.session.getEntryPointAsync() - .then(entryPoint => { - {{{ makeDynCall("vii", "callback") }}}(Utils.allocateString(entryPoint), 0); + .then(entryPoint => + { + { { { makeDynCall("vii", "callback") } } } (Utils.allocateString(entryPoint), 0); }) - .catch(error => { - {{{ makeDynCall("vii", "callback") }}}(0, Utils.allocateString(JSON.stringify(error))); + .catch(error => + { + { { { makeDynCall("vii", "callback") } } } (0, Utils.allocateString(JSON.stringify(error))); }); }, - Wortal_session_getPlatform: function () { + Wortal_session_getPlatform: function () + { return Utils.allocateString(window.Wortal.session.getPlatform()); }, - Wortal_session_getDevice: function () { + Wortal_session_getDevice: function () + { return Utils.allocateString(window.Wortal.session.getDevice()); }, - Wortal_session_getOrientation: function () { + Wortal_session_getOrientation: function () + { return Utils.allocateString(window.Wortal.session.getOrientation()); }, - Wortal_session_onOrientationChange: function (callback) { - window.Wortal.session.onOrientationChange(orientation => { - {{{ makeDynCall("vi", "callback") }}}(Utils.allocateString(orientation)); + Wortal_session_onOrientationChange: function (callback) + { + window.Wortal.session.onOrientationChange(orientation => + { + { { { makeDynCall("vi", "callback") } } } (Utils.allocateString(orientation)); }); }, - Wortal_session_switchGameAsync: function (gameId, callback) { + Wortal_session_switchGameAsync: function (gameId, callback) + { window.Wortal.session.switchGameAsync(gameId) - .then(() => { - {{{ makeDynCall("vii", "callback") }}}(0, 0); + .then(() => + { + { { { makeDynCall("vii", "callback") } } } (0, 0); }) - .catch(error => { - {{{ makeDynCall("vii", "callback") }}}(Utils.allocateString(JSON.stringify(error)), 0); + .catch(error => + { + { { { makeDynCall("vii", "callback") } } } (Utils.allocateString(JSON.stringify(error)), 0); }); + }, + + Wortal_session_isAudioEnabled: function () + { + return window.Wortal.session.isAudioEnabled() ? 1 : 0; + }, + + Wortal_session_onAudioStatusChange: function (callback) + { + window.Wortal.session.onAudioStatusChange(isAudioEnabled => + { + { { { makeDynCall("vi", "callback") } } } (isAudioEnabled); + }) } } diff --git a/wortal/src/wortal_session.cpp b/wortal/src/wortal_session.cpp index 75d1cb5..9eec22e 100644 --- a/wortal/src/wortal_session.cpp +++ b/wortal/src/wortal_session.cpp @@ -6,82 +6,151 @@ lua_Listener onSessionGetEntryPointListener; lua_Listener onOrientationChangeListener; lua_Listener onSwitchGameListener; +lua_Listener onAudioStatusChangeListener; -void WortalSession::OnGetEntryPoint(const char* entryPoint, const char* error) { - lua_State* L = onSessionGetEntryPointListener.m_L; +void WortalSession::OnGetEntryPoint(const char *entryPoint, const char *error) +{ + lua_State *L = onSessionGetEntryPointListener.m_L; int top = lua_gettop(L); lua_pushlistener(L, onSessionGetEntryPointListener); - if (entryPoint) { + if (entryPoint) + { lua_pushstring(L, entryPoint); } - else { + else + { lua_pushnil(L); } - if (error) { + if (error) + { lua_pushstring(L, error); } - else { + else + { lua_pushnil(L); } int ret = lua_pcall(L, 3, 0, 0); - if (ret != 0) { + if (ret != 0) + { lua_pop(L, 1); } assert(top == lua_gettop(L)); } -void WortalSession::OnOrientationChange(const char* orientation) { - lua_State* L = onOrientationChangeListener.m_L; +int WortalSession::GameplayStart(lua_State *L) +{ + int top = lua_gettop(L); + + Wortal_session_gameplayStart(); + + assert(top == lua_gettop(L)); + return 0; +} + +int WortalSession::GameplayStop(lua_State *L) +{ + int top = lua_gettop(L); + + Wortal_session_gameplayStop(); + + assert(top == lua_gettop(L)); + return 0; +} + +int WortalSession::HappyTime(lua_State *L) +{ + int top = lua_gettop(L); + + Wortal_session_happyTime(); + + assert(top == lua_gettop(L)); + return 0; +} + +void WortalSession::OnOrientationChange(const char *orientation) +{ + lua_State *L = onOrientationChangeListener.m_L; int top = lua_gettop(L); lua_pushlistener(L, onOrientationChangeListener); - if (orientation) { + if (orientation) + { lua_pushstring(L, orientation); } - else { + else + { lua_pushnil(L); } int ret = lua_pcall(L, 2, 0, 0); - if (ret != 0) { + if (ret != 0) + { + lua_pop(L, 1); + } + + assert(top == lua_gettop(L)); +} + +void WortalSession::OnAudioStatusChange(const bool *isAudioEnabled) +{ + lua_State *L = onAudioStatusChangeListener.m_L; + int top = lua_gettop(L); + + lua_pushlistener(L, onAudioStatusChangeListener); + lua_pushboolean(L, *isAudioEnabled); + + int ret = lua_pcall(L, 2, 0, 0); + if (ret != 0) + { + // just for debugging purpose. + const char *error = lua_tostring(L, -1); + std::cerr << "Lua error in OnAudioStatusChange : " << error << std::endl; + lua_pop(L, 1); } assert(top == lua_gettop(L)); } -void WortalSession::OnSwitchGame(const int success, const char* error) { - lua_State* L = onSwitchGameListener.m_L; +void WortalSession::OnSwitchGame(const int success, const char *error) +{ + lua_State *L = onSwitchGameListener.m_L; int top = lua_gettop(L); lua_pushlistener(L, onSwitchGameListener); lua_pushboolean(L, success); - if (error) { + if (error) + { lua_pushstring(L, error); } - else { + else + { lua_pushnil(L); } int ret = lua_pcall(L, 3, 0, 0); - if (ret != 0) { + if (ret != 0) + { lua_pop(L, 1); } assert(top == lua_gettop(L)); } -int WortalSession::GetEntryPointData(lua_State* L) { +int WortalSession::GetEntryPointData(lua_State *L) +{ int top = lua_gettop(L); - const char* data = Wortal_session_getEntryPointData(); - if (data) { + const char *data = Wortal_session_getEntryPointData(); + if (data) + { lua_pushstring(L, data); } - else { + else + { lua_pushnil(L); } @@ -89,14 +158,17 @@ int WortalSession::GetEntryPointData(lua_State* L) { return 1; } -int WortalSession::GetLocale(lua_State* L) { +int WortalSession::GetLocale(lua_State *L) +{ int top = lua_gettop(L); - const char* data = Wortal_session_getLocale(); - if (data) { + const char *data = Wortal_session_getLocale(); + if (data) + { lua_pushstring(L, data); } - else { + else + { lua_pushnil(L); } @@ -104,14 +176,17 @@ int WortalSession::GetLocale(lua_State* L) { return 1; } -int WortalSession::GetTrafficSource(lua_State* L) { +int WortalSession::GetTrafficSource(lua_State *L) +{ int top = lua_gettop(L); - const char* data = Wortal_session_getTrafficSource(); - if (data) { + const char *data = Wortal_session_getTrafficSource(); + if (data) + { lua_pushstring(L, data); } - else { + else + { lua_pushnil(L); } @@ -119,17 +194,19 @@ int WortalSession::GetTrafficSource(lua_State* L) { return 1; } -int WortalSession::SetSessionData(lua_State* L) { +int WortalSession::SetSessionData(lua_State *L) +{ int top = lua_gettop(L); - const char* data = luaL_checkstring(L, 1); + const char *data = luaL_checkstring(L, 1); Wortal_session_setSessionData(data); assert(top == lua_gettop(L)); return 0; } -int WortalSession::GetEntryPointAsync(lua_State* L) { +int WortalSession::GetEntryPointAsync(lua_State *L) +{ int top = lua_gettop(L); luaL_checklistener(L, 1, onSessionGetEntryPointListener); @@ -139,14 +216,17 @@ int WortalSession::GetEntryPointAsync(lua_State* L) { return 0; } -int WortalSession::GetPlatform(lua_State* L) { +int WortalSession::GetPlatform(lua_State *L) +{ int top = lua_gettop(L); - const char* data = Wortal_session_getPlatform(); - if (data) { + const char *data = Wortal_session_getPlatform(); + if (data) + { lua_pushstring(L, data); } - else { + else + { lua_pushnil(L); } @@ -154,14 +234,17 @@ int WortalSession::GetPlatform(lua_State* L) { return 1; } -int WortalSession::GetDevice(lua_State* L) { +int WortalSession::GetDevice(lua_State *L) +{ int top = lua_gettop(L); - const char* data = Wortal_session_getDevice(); - if (data) { + const char *data = Wortal_session_getDevice(); + if (data) + { lua_pushstring(L, data); } - else { + else + { lua_pushnil(L); } @@ -169,14 +252,17 @@ int WortalSession::GetDevice(lua_State* L) { return 1; } -int WortalSession::GetOrientation(lua_State* L) { +int WortalSession::GetOrientation(lua_State *L) +{ int top = lua_gettop(L); - const char* data = Wortal_session_getOrientation(); - if (data) { + const char *data = Wortal_session_getOrientation(); + if (data) + { lua_pushstring(L, data); } - else { + else + { lua_pushnil(L); } @@ -184,7 +270,8 @@ int WortalSession::GetOrientation(lua_State* L) { return 1; } -int WortalSession::OnOrientationChange(lua_State* L) { +int WortalSession::OnOrientationChange(lua_State *L) +{ int top = lua_gettop(L); luaL_checklistener(L, 1, onOrientationChangeListener); @@ -194,10 +281,11 @@ int WortalSession::OnOrientationChange(lua_State* L) { return 0; } -int WortalSession::SwitchGameAsync(lua_State* L) { +int WortalSession::SwitchGameAsync(lua_State *L) +{ int top = lua_gettop(L); - const char* gameID = luaL_checkstring(L, 1); + const char *gameID = luaL_checkstring(L, 1); luaL_checklistener(L, 2, onSwitchGameListener); Wortal_session_switchGameAsync(gameID, WortalSession::OnSwitchGame); @@ -205,4 +293,25 @@ int WortalSession::SwitchGameAsync(lua_State* L) { return 0; } +int WortalSession::IsAudioEnabled(lua_State *L) +{ + int top = lua_gettop(L); + + lua_pushboolean(L, Wortal_session_isAudioEnabled()); + + assert(top + 1 == lua_gettop(L)); + return 1; +} + +int WortalSession::OnAudioStatusChange(lua_State *L) +{ + int top = lua_gettop(L); + + luaL_checklistener(L, 1, onAudioStatusChangeListener); + Wortal_session_onAudioStatusChange(WortalSession::OnAudioStatusChange); + + assert(top == lua_gettop(L)); + return 0; +} + #endif From 2b4e13039b3e92d703527ce6747fc0e813daeafa Mon Sep 17 00:00:00 2001 From: bimaswara Date: Fri, 8 Nov 2024 14:01:32 +0700 Subject: [PATCH 3/3] chore: bump version to 3.0.3 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c0f943..4d39d0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.0.3] - 2024-11-8 +### Added +- Session + - gameplayStart + - gameplayStop + - happyTime + - isAudioEnabled + - onAudioStatusChange + ## [3.0.2] - 2024-09-24 ### Added - Ads