From 2fbcab1743bcb78028f7dd399b36ba109538d915 Mon Sep 17 00:00:00 2001 From: alexeyfeskov Date: Sat, 3 Apr 2021 17:07:45 +0700 Subject: [PATCH 1/2] Add maxsdk.script_api --- .gitattributes | 3 + extension-maxsdk/api/maxsdk.script_api | 292 +++++++++++++++++++++++++ 2 files changed, 295 insertions(+) create mode 100644 extension-maxsdk/api/maxsdk.script_api diff --git a/.gitattributes b/.gitattributes index 187cdf4..1b652b8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -40,3 +40,6 @@ *.render_script linguist-language=Lua *.script linguist-language=Lua *.gui_script linguist-language=Lua + +# Defold YAML Files +*.script_api=YAML diff --git a/extension-maxsdk/api/maxsdk.script_api b/extension-maxsdk/api/maxsdk.script_api new file mode 100644 index 0000000..a611e42 --- /dev/null +++ b/extension-maxsdk/api/maxsdk.script_api @@ -0,0 +1,292 @@ +- name: maxsdk + type: table + desc: Functions and constants for interacting with AppLovin Max SDK + + members: + +#***************************************************************************************************** + + - name: initialize + type: function + +#***************************************************************************************************** + + - name: set_callback + type: function + + parameters: + - name: callback + type: function + + parameters: + - name: self + type: object + + - name: message_id + type: number + + - name: message + type: table + +#***************************************************************************************************** + + - name: set_muted + type: function + + parameters: + - name: bool + type: boolean + +#***************************************************************************************************** + + - name: set_verbose_logging + type: function + + parameters: + - name: bool + type: boolean + +#***************************************************************************************************** + + - name: set_has_user_consent + type: function + + parameters: + - name: bool + type: boolean + +#***************************************************************************************************** + + - name: set_is_age_restricted_user + type: function + + parameters: + - name: bool + type: boolean + +#***************************************************************************************************** + + - name: set_do_not_sell + type: function + + parameters: + - name: bool + type: boolean + +#***************************************************************************************************** + + - name: set_fb_data_processing_options + type: function + + parameters: + - name: mode + type: string + + - name: country + type: number + + - name: state + type: number + +#***************************************************************************************************** + + - name: load_interstitial + type: function + + parameters: + - name: ad_unit + type: string + +#***************************************************************************************************** + + - name: show_interstitial + type: function + + parameters: + - name: placement + type: string + optional: true + +#***************************************************************************************************** + + - name: is_interstitial_loaded + type: function + + returns: + - name: ready + type: boolean + + +#***************************************************************************************************** + + - name: load_rewarded + type: function + + parameters: + - name: ad_unit + type: string + +#***************************************************************************************************** + + - name: show_rewarded + type: function + + parameters: + - name: placement + type: string + optional: true + +#***************************************************************************************************** + + - name: is_rewarded_loaded + type: function + + returns: + - name: ready + type: boolean + + +#***************************************************************************************************** + + - name: load_banner + type: function + + parameters: + - name: ad_unit + type: string + + - name: size_type + type: number + +#***************************************************************************************************** + + - name: show_banner + type: function + + parameters: + - name: position + type: number + + - name: placement + type: string + optional: true + + +#***************************************************************************************************** + + - name: hide_banner + type: function + +#***************************************************************************************************** + + - name: is_banner_loaded + type: function + + returns: + - name: ready + type: boolean + +#***************************************************************************************************** + + - name: is_banner_shown + type: function + + returns: + - name: visible + type: boolean + +#***************************************************************************************************** + + - name: destroy_banner + type: function + +#***************************************************************************************************** + + - name: MSG_INITIALIZATION + type: number + + - name: MSG_INTERSTITIAL + type: number + + - name: MSG_REWARDED + type: number + + - name: MSG_BANNER + type: number + +#***************************************************************************************************** + + - name: EVENT_CLOSED + type: number + + - name: EVENT_FAILED_TO_SHOW + type: number + + - name: EVENT_OPENING + type: number + + - name: EVENT_FAILED_TO_LOAD + type: number + + - name: EVENT_LOADED + type: number + + - name: EVENT_NOT_LOADED + type: number + + - name: EVENT_EARNED_REWARD + type: number + + - name: EVENT_COMPLETE + type: number + + - name: EVENT_CLICKED + type: number + + - name: EVENT_DESTROYED + type: number + + - name: EVENT_EXPANDED + type: number + + - name: EVENT_COLLAPSED + type: number + +#***************************************************************************************************** + + - name: SIZE_BANNER + type: number + + - name: SIZE_LEADER + type: number + + - name: SIZE_MREC + type: number + +#***************************************************************************************************** + + - name: POS_NONE + type: number + + - name: POS_TOP_LEFT + type: number + + - name: POS_TOP_CENTER + type: number + + - name: POS_TOP_RIGHT + type: number + + - name: POS_BOTTOM_LEFT + type: number + + - name: POS_BOTTOM_CENTER + type: number + + - name: POS_BOTTOM_RIGHT + type: number + + - name: POS_CENTER + type: number + +#***************************************************************************************************** From 80d6195d925e8f1d036892bdd2bf49b3f65ca3bf Mon Sep 17 00:00:00 2001 From: alexeyfeskov Date: Sat, 3 Apr 2021 17:09:33 +0700 Subject: [PATCH 2/2] Fix readme about placement param --- README.md | 201 +++++++++++++++++++++-------------------- example/ads.gui_script | 2 +- 2 files changed, 102 insertions(+), 101 deletions(-) diff --git a/README.md b/README.md index d75b46d..5ad8aa3 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ or point to the ZIP file of a [specific release](https://github.com/alexeyfeskov ## Example -See the [example folder](https://github.com/alexeyfeskov/defold-maxsdk/tree/master/example) for understand how to use extension. Especially [ui.gui_script](https://github.com/alexeyfeskov/defold-maxsdk/blob/master//example/ads.gui_script) file. +See the [example folder](https://github.com/alexeyfeskov/defold-maxsdk/tree/master/example) for understand how to use extension. Especially [ads.gui_script](https://github.com/alexeyfeskov/defold-maxsdk/blob/master/example/ads.gui_script) file. ## LUA Api @@ -30,123 +30,124 @@ Please, read original [Android API docs](https://dash.applovin.com/documentation -- Initialize SDK and start load ads -- --------------------------------------- if maxsdk then - -- To enable LDU with geolocation https://developers.facebook.com/docs/audience-network/guides/ccpa - maxsdk.set_fb_data_processing_options("LDU", 0, 0) - maxsdk.set_has_user_consent(true) -- GDPR - maxsdk.set_is_age_restricted_user(false) - maxsdk.set_do_not_sell(false) -- CCPA for all others mediated networks - - maxsdk.set_muted(false) - maxsdk.set_verbose_logging(true) - - maxsdk.set_callback(maxsdk_callback) - maxsdk.initialize() - - -- all `load_***` functions can recieve last optional `string` arg to define placement_id - maxsdk.load_interstitial(interstitial_ad_unit) - maxsdk.load_rewarded(rewarded_ad_unit) - maxsdk.load_banner(banner_ad_unit, maxsdk.SIZE_BANNER) - -- Supported banner sizes: - -- maxsdk.SIZE_BANNER - -- maxsdk.SIZE_LEADER - -- maxsdk.SIZE_MREC (use separate ad_unit, all other APIs are same to banners) + -- To enable LDU with geolocation https://developers.facebook.com/docs/audience-network/guides/ccpa + maxsdk.set_fb_data_processing_options("LDU", 0, 0) + maxsdk.set_has_user_consent(true) -- GDPR + maxsdk.set_is_age_restricted_user(false) + maxsdk.set_do_not_sell(false) -- CCPA for all others mediated networks + + maxsdk.set_muted(false) + maxsdk.set_verbose_logging(true) + + maxsdk.set_callback(maxsdk_callback) + maxsdk.initialize() + + maxsdk.load_interstitial(interstitial_ad_unit) + maxsdk.load_rewarded(rewarded_ad_unit) + maxsdk.load_banner(banner_ad_unit, maxsdk.SIZE_BANNER) + -- Supported banner sizes: + -- maxsdk.SIZE_BANNER + -- maxsdk.SIZE_LEADER + -- maxsdk.SIZE_MREC (use separate ad_unit, all other APIs are same to banners) end -------------- -- Show ads -- -------------- +-- all `show_***` functions have optional `string` parameter to define placement if maxsdk and maxsdk.is_interstitial_loaded() then - maxsdk.show_interstitial() + maxsdk.show_interstitial() end if maxsdk and maxsdk.is_rewarded_loaded() then - maxsdk.show_rewarded() + maxsdk.show_rewarded() end if maxsdk and maxsdk.is_banner_loaded() then - maxsdk.show_banner(maxsdk.POS_TOP_CENTER) - -- Supported banner positions: - -- maxsdk.POS_BOTTOM_CENTER - -- maxsdk.POS_BOTTOM_LEFT - -- maxsdk.POS_BOTTOM_RIGHT - -- maxsdk.POS_NONE - -- maxsdk.POS_TOP_LEFT - -- maxsdk.POS_TOP_CENTER - -- maxsdk.POS_TOP_RIGHT - -- maxsdk.POS_CENTER - - -- Also you can: temporary hide banner - maxsdk.hide_banner() - -- ..show in other position - maxsdk.show_banner(maxsdk.POS_BOTTOM_CENTER) - -- ..or unload - maxsdk.destroy_banner() + maxsdk.show_banner(maxsdk.POS_TOP_CENTER) + -- Supported banner positions: + -- maxsdk.POS_BOTTOM_CENTER + -- maxsdk.POS_BOTTOM_LEFT + -- maxsdk.POS_BOTTOM_RIGHT + -- maxsdk.POS_NONE + -- maxsdk.POS_TOP_LEFT + -- maxsdk.POS_TOP_CENTER + -- maxsdk.POS_TOP_RIGHT + -- maxsdk.POS_CENTER + + -- Also you can: temporary hide banner + maxsdk.hide_banner() + -- ..show in other position + maxsdk.show_banner(maxsdk.POS_BOTTOM_CENTER) + -- ..or unload + maxsdk.destroy_banner() end ------------------------ -- Receive SDK events -- ------------------------ function maxsdk_callback(self, message_id, message) - if message_id == maxsdk.MSG_INITIALIZATION then - print("MSG_INITIALIZATION") - - elseif message_id == maxsdk.MSG_INTERSTITIAL then - if message.event == maxsdk.EVENT_CLOSED then - print("EVENT_CLOSED: Interstitial AD closed") - elseif message.event == maxsdk.EVENT_CLICKED then - print("EVENT_CLICKED: Interstitial AD clicked") - elseif message.event == maxsdk.EVENT_FAILED_TO_SHOW then - print("EVENT_FAILED_TO_SHOW: Interstitial AD failed to show", message.code, message.error) - elseif message.event == maxsdk.EVENT_OPENING then - print("EVENT_OPENING: Interstitial AD is opening") - elseif message.event == maxsdk.EVENT_FAILED_TO_LOAD then - print("EVENT_FAILED_TO_LOAD: Interstitial AD failed to load", message.code, message.error) - elseif message.event == maxsdk.EVENT_LOADED then - print("EVENT_LOADED: Interstitial AD loaded. Network:", message.network) - elseif message.event == maxsdk.EVENT_NOT_LOADED then - print("EVENT_NOT_LOADED: can't call show_interstitial() before EVENT_LOADED", message.code, message.error) - end - - elseif message_id == maxsdk.MSG_REWARDED then - if message.event == maxsdk.EVENT_CLOSED then - print("EVENT_CLOSED: Rewarded AD closed") - elseif message.event == maxsdk.EVENT_FAILED_TO_SHOW then - print("EVENT_FAILED_TO_SHOW: Rewarded AD failed to show", message.code, message.error) - elseif message.event == maxsdk.EVENT_OPENING then - print("EVENT_OPENING: Rewarded AD is opening") - elseif message.event == maxsdk.EVENT_FAILED_TO_LOAD then - print("EVENT_FAILED_TO_LOAD: Rewarded AD failed to load", message.code, message.error) - elseif message.event == maxsdk.EVENT_LOADED then - print("EVENT_LOADED: Rewarded AD loaded. Network:", message.network) - elseif message.event == maxsdk.EVENT_NOT_LOADED then - print("EVENT_NOT_LOADED: can't call show_rewarded() before EVENT_LOADED", message.code, message.error) - elseif message.event == maxsdk.EVENT_EARNED_REWARD then - print("EVENT_EARNED_REWARD: Reward: ", message.amount, message.type) - end - - elseif message_id == maxsdk.MSG_BANNER then - if message.event == maxsdk.EVENT_LOADED then - print("EVENT_LOADED: Banner AD loaded. Network:", message.network) - elseif message.event == maxsdk.EVENT_OPENING then - print("EVENT_OPENING: Banner AD is opening") - elseif message.event == maxsdk.EVENT_FAILED_TO_LOAD then - print("EVENT_FAILED_TO_LOAD: Banner AD failed to load", message.code, message.error) - elseif message.event == maxsdk.EVENT_FAILED_TO_SHOW then - print("EVENT_FAILED_TO_SHOW: Banner AD failed to show", message.code, message.error) - elseif message.event == maxsdk.EVENT_EXPANDED then - print("EVENT_EXPANDED: Banner AD expanded") - elseif message.event == maxsdk.EVENT_COLLAPSED then - print("EVENT_COLLAPSED: Banner AD coppalsed") - elseif message.event == maxsdk.EVENT_CLICKED then - print("EVENT_CLICKED: Banner AD clicked") - elseif message.event == maxsdk.EVENT_CLOSED then - print("EVENT_CLOSED: Banner AD closed") - elseif message.event == maxsdk.EVENT_DESTROYED then - print("EVENT_DESTROYED: Banner AD destroyed") - elseif message.event == maxsdk.EVENT_NOT_LOADED then - print("EVENT_NOT_LOADED: can't call show_banner() before EVENT_LOADED", message.code, message.error) - end - end + if message_id == maxsdk.MSG_INITIALIZATION then + print("MSG_INITIALIZATION") + + elseif message_id == maxsdk.MSG_INTERSTITIAL then + if message.event == maxsdk.EVENT_CLOSED then + print("EVENT_CLOSED: Interstitial AD closed") + elseif message.event == maxsdk.EVENT_CLICKED then + print("EVENT_CLICKED: Interstitial AD clicked") + elseif message.event == maxsdk.EVENT_FAILED_TO_SHOW then + print("EVENT_FAILED_TO_SHOW: Interstitial AD failed to show", message.code, message.error) + elseif message.event == maxsdk.EVENT_OPENING then + print("EVENT_OPENING: Interstitial AD is opening") + elseif message.event == maxsdk.EVENT_FAILED_TO_LOAD then + print("EVENT_FAILED_TO_LOAD: Interstitial AD failed to load", message.code, message.error) + elseif message.event == maxsdk.EVENT_LOADED then + print("EVENT_LOADED: Interstitial AD loaded. Network:", message.network) + elseif message.event == maxsdk.EVENT_NOT_LOADED then + print("EVENT_NOT_LOADED: can't call show_interstitial() before EVENT_LOADED", message.code, message.error) + end + + elseif message_id == maxsdk.MSG_REWARDED then + if message.event == maxsdk.EVENT_CLOSED then + print("EVENT_CLOSED: Rewarded AD closed") + elseif message.event == maxsdk.EVENT_FAILED_TO_SHOW then + print("EVENT_FAILED_TO_SHOW: Rewarded AD failed to show", message.code, message.error) + elseif message.event == maxsdk.EVENT_OPENING then + print("EVENT_OPENING: Rewarded AD is opening") + elseif message.event == maxsdk.EVENT_FAILED_TO_LOAD then + print("EVENT_FAILED_TO_LOAD: Rewarded AD failed to load", message.code, message.error) + elseif message.event == maxsdk.EVENT_LOADED then + print("EVENT_LOADED: Rewarded AD loaded. Network:", message.network) + elseif message.event == maxsdk.EVENT_NOT_LOADED then + print("EVENT_NOT_LOADED: can't call show_rewarded() before EVENT_LOADED", message.code, message.error) + elseif message.event == maxsdk.EVENT_EARNED_REWARD then + print("EVENT_EARNED_REWARD: Reward: ", message.amount, message.type) + end + + elseif message_id == maxsdk.MSG_BANNER then + if message.event == maxsdk.EVENT_LOADED then + print("EVENT_LOADED: Banner AD loaded. Network:", message.network) + elseif message.event == maxsdk.EVENT_OPENING then + print("EVENT_OPENING: Banner AD is opening") + elseif message.event == maxsdk.EVENT_FAILED_TO_LOAD then + print("EVENT_FAILED_TO_LOAD: Banner AD failed to load", message.code, message.error) + elseif message.event == maxsdk.EVENT_FAILED_TO_SHOW then + print("EVENT_FAILED_TO_SHOW: Banner AD failed to show", message.code, message.error) + elseif message.event == maxsdk.EVENT_EXPANDED then + print("EVENT_EXPANDED: Banner AD expanded") + elseif message.event == maxsdk.EVENT_COLLAPSED then + print("EVENT_COLLAPSED: Banner AD coppalsed") + elseif message.event == maxsdk.EVENT_CLICKED then + print("EVENT_CLICKED: Banner AD clicked") + elseif message.event == maxsdk.EVENT_CLOSED then + print("EVENT_CLOSED: Banner AD closed") + elseif message.event == maxsdk.EVENT_DESTROYED then + print("EVENT_DESTROYED: Banner AD destroyed") + elseif message.event == maxsdk.EVENT_NOT_LOADED then + print("EVENT_NOT_LOADED: can't call show_banner() before EVENT_LOADED", message.code, message.error) + end + end +end ``` Feel free to push a Pull Request with other features implementation. \ No newline at end of file diff --git a/example/ads.gui_script b/example/ads.gui_script index 71c02cc..0ae25b6 100644 --- a/example/ads.gui_script +++ b/example/ads.gui_script @@ -1,6 +1,6 @@ local dirtylarry = require "dirtylarry/dirtylarry" -local MAX_LOG_LINES = 37 +local MAX_LOG_LINES = 36 --log logic local gprint = print