Skip to content

Commit

Permalink
Fix across no win bug, add fbinstant.get_platform(), add fbinstant.ge…
Browse files Browse the repository at this point in the history
…t_supported_apis() (#28)

* FIX: Across no win bug in XOXO sample
* NEW: fbinstant.get_platform()
* NEW: fbinstant.get_supported_apis()
* NEW: Added supported API check to XOXO before trying to show ads
  • Loading branch information
subsoap authored and britzl committed Mar 28, 2018
1 parent 6efabd7 commit 30d553c
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 12 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,21 @@ Each entry in the ```players``` table has the following values:
* ```photo``` (string) - URL to a photo of the user


## Platform functions

## fbinstant.get_platform()
Gets the active platform the game is running on.

**RETURN**
* ```platform``` (string) - The current platform one of "IOS" or "ANDROID" or "WEB" or "MOBILE_WEB".

## fbinstant.get_supported_apis()
Gets a list of supported apis by the current platform.

Check this list before attempting to use features which don't yet work on all platforms such as ads.

**RETURN**
* ```apis``` (string) - In the form of ["getLocale","getPlatform","getSDKVersion", ... "player.incrementStatsAsync","updateAsync"] etc. check the api version docs for complete API list https://developers.facebook.com/docs/games/instant-games/sdk/fbinstant6.1

## Share functions

Expand Down
3 changes: 3 additions & 0 deletions fbinstant/include/fbinstant.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ extern "C" {
char* FBInstant_PlatformGetPlayerPhoto();
char* FBInstant_PlatformGetPlayerLocale();

char* FBInstant_PlatformGetPlatform();
char* FBInstant_PlatformGetSupportedAPIs();

void FBInstant_PlatformLogEvent(const char* eventName, int valueToSum, const char* parametersJson);

void FBInstant_PlatformShareAsync(OnShareCallback callback, const char* payloadJson);
Expand Down
30 changes: 28 additions & 2 deletions fbinstant/lib/js-web/library_fbinstant.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ var FBInstantLibrary = {
}
return Utils.storeString("playerPhoto", photo);
},


// =====================================
// GetEntryPointData
// =====================================
Expand Down Expand Up @@ -388,7 +388,33 @@ var FBInstantLibrary = {
}
},


// =====================================
// GetPlatform
// =====================================
FBInstant_PlatformGetPlatform: function() {
var platform = FBInstant.getPlatform();
if (platform) {
return Utils.storeString("platform", platform);
}
else {
return null;
}
},

// =====================================
// GetSupportedAPIs
// =====================================
FBInstant_PlatformGetSupportedAPIs: function() {
var supportedAPIs = FBInstant.getSupportedAPIs();
if (supportedAPIs) {
return Utils.storeString("supportedAPIs", JSON.stringify(supportedAPIs));
}
else {
return null;
}
},

// =====================================
// LogEvent
// =====================================
Expand Down
40 changes: 40 additions & 0 deletions fbinstant/src/fbinstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,44 @@ static int FBInstant_GetPlayersInContextAsync(lua_State* L) {
}


// ===============================================
// GET PLATFORM ("IOS" | "ANDROID" | "WEB" | "MOBILE_WEB")
// ===============================================
static int FBInstant_GetPlatform(lua_State* L) {
int top = lua_gettop(L);

const char* data = FBInstant_PlatformGetPlatform();
if (data) {
lua_pushstring(L, data);
}
else {
lua_pushnil(L);
}

assert(top + 1 == lua_gettop(L));
return 1;
}


// ===============================================
// GET SUPPORTED APIS
// ===============================================
static int FBInstant_GetSupportedAPIs(lua_State* L) {
int top = lua_gettop(L);

const char* data = FBInstant_PlatformGetSupportedAPIs();
if (data) {
lua_pushstring(L, data);
}
else {
lua_pushnil(L);
}

assert(top + 1 == lua_gettop(L));
return 1;
}


// ===============================================
// SHARE
// ===============================================
Expand Down Expand Up @@ -941,6 +979,8 @@ static const luaL_reg Module_methods[] = {
{"log_event", FBInstant_LogEvent},

// misc
{"get_platform", FBInstant_GetPlatform},
{"get_supported_apis", FBInstant_GetSupportedAPIs},
{"share", FBInstant_ShareAsync},

// ads
Expand Down
11 changes: 11 additions & 0 deletions fbinstant/utils/mock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ end

local rxijson = require "fbinstant.utils.json"

fbinstant.mock = true

fbinstant.CONTEXT_SOLO = "SOLO"
fbinstant.CONTEXT_POST = "POST"
fbinstant.CONTEXT_THREAD = "THREAD"
Expand Down Expand Up @@ -103,6 +105,15 @@ function fbinstant.share(payload, cb)
cb(get_self(), true)
end

function fbinstant.get_platform()
print("get_platform")
return "WEB"
end

function fbinstant.get_supported_apis()
print("get_supported_apis")
return {}
end

--------------------------------
--------------- SESSION AND ENTRY DATA
Expand Down
5 changes: 5 additions & 0 deletions tictactoe/game/game.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ local function check_game_won(self)
or check_match(gs[3]))

local match_column =
-- down
check_match({ gs[1][1], gs[2][1], gs[3][1] })
or check_match({ gs[1][2], gs[2][2], gs[3][2] })
or check_match({ gs[1][3], gs[2][3], gs[3][3] })
-- across
or check_match({ gs[1][1], gs[1][2], gs[1][3] })
or check_match({ gs[2][1], gs[2][2], gs[2][3] })
or check_match({ gs[3][1], gs[3][2], gs[3][3] })

local match_cross =
check_match({ gs[1][1], gs[2][2], gs[3][3] })
Expand Down
41 changes: 31 additions & 10 deletions tictactoe/start/start.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,22 @@ local function show_play_button(self)
gui.set_enabled(gui.get_node("play/bg"), true)
end

local function table_contains(table, element)
for _, value in pairs(table) do
if value == element then
return true
end
end
return false
end

function init(self)

print("Supported APIs: ...")
pprint(fbinstant.get_supported_apis())

local supported_apis = json.decode(fbinstant.get_supported_apis())

gui.set_render_order(15)

msg.post(".", "acquire_input_focus")
Expand All @@ -26,17 +40,24 @@ function init(self)
show_select_opponent_button(self)
end

print("about to attempt to load interstitial")
local placement = "130801227620858_156771488357165"
fbinstant.load_interstitial_ad(placement, function(self, success)
print("loaded interstitial", success)
if not success then
return
end
fbinstant.show_interstitial_ad(placement, function(self, success)
print("showed interstitial", success)
local platform = fbinstant.get_platform() --Type: ("IOS" | "ANDROID" | "WEB" | "MOBILE_WEB")
print("Platform is... " .. platform)

if table_contains(supported_apis, "getInterstitialAdAsync") then
print("about to attempt to load interstitial")
local placement = "130801227620858_156771488357165"
fbinstant.load_interstitial_ad(placement, function(self, success)
print("loaded interstitial", success)
if not success then
return
end
fbinstant.show_interstitial_ad(placement, function(self, success)
print("showed interstitial", success)
end)
end)
end)
else
print("this platform does not supported interstitial ads: " .. platform)
end
end


Expand Down

0 comments on commit 30d553c

Please sign in to comment.