Skip to content

Commit

Permalink
Remove FIR cpp SDK (#11)
Browse files Browse the repository at this point in the history
* Remove FIR cpp SDK (#10)

* Revert "Auxiliary commit to revert individual files from 0580656"

This reverts commit ab49f2e253b1c23c8d54a007b26381c4fb656c6a.

* initial commit without setDefaults

* fix documentation

* add SetDefaults for Android

* update events in documantation

* add defaults iOS

* add bundle folder

* fix readme

* fix documentation

* fix broken api docs

---------

Co-authored-by: Sippul <[email protected]>
  • Loading branch information
AGulev and Sippul authored Jan 18, 2024
1 parent 1d95b41 commit bb3188b
Show file tree
Hide file tree
Showing 23 changed files with 1,283 additions and 552 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ google-services.xml
dependencies.json
GoogleService-Info.plist
Info.plist
/debug.keystore
/debug.keystore.pass.txt
/manifest.private.der
/manifest.public.der
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
[![Actions Status Alpha](https://github.com/defold/extension-firebase-remoteconfig/actions/workflows/bob.yml/badge.svg)](https://github.com/defold/extension-firebase-remoteconfig/actions)

![](https://img.shields.io/badge/Firebase%20CPP%20SDK-8.10.0-green)
![](https://img.shields.io/badge/Firebase%20iOS%20SDK-8.13.0-green)

# Firebase Remote Config for Defold

Defold [native extension](https://www.defold.com/manuals/extensions/) that integrates [Firebase Remote Config](https://firebase.google.com/docs/remote-config) functionality on Android and iOS.
Expand Down
Binary file added docs/add-dependency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 43 additions & 49 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ This extension allows you to interact with Firebase Remote Config in a uniform w


## Installation
To use this library in your Defold project, add the following URLs to your `game.project` dependencies:

| Firebase C++ SDK | Firebase iOS SDK | Dependencies |
|-------------------------|-------------------------|--------------|
| Firebase C++ SDK 8.10.0 | Firebase iOS SDK 8.13.0 | [https://github.com/defold/extension-firebase/archive/refs/tags/1.4.2.zip](https://github.com/defold/extension-firebase/archive/refs/tags/1.4.2.zip)<br>[https://github.com/defold/extension-firebase-remoteconfig/archive/refs/tags/1.3.1.zip](https://github.com/defold/extension-firebase-remoteconfig/archive/refs/tags/1.3.1.zip) |
To use Firabase in your Defold project, add a version of the Firebase extension to your `game.project` dependencies from the list of available [Firebase Releases](https://github.com/defold/extension-firebase/releases) and corresponding [Firebase Config Release](https://github.com/defold/extension-firebase-remoteconfig/releases).
Find the version you want for both extensions, copy the URLs to ZIP archive of the release and add it to the project dependencies.

![](add-dependency.png)

## Setup
Follow the [main setup guide for integration of Firebase in Defold](https://www.defold.com/extension-firebase).
Expand All @@ -23,58 +21,54 @@ Follow the [main setup guide for integration of Firebase in Defold](https://www.
## Usage

```lua
function init(self)
-- use firebase only if it is supported on the current platform
if not firebase then
return
end

-- initialise firebase and check that it was successful
local ok, err = firebase.init()
if not ok then
print(err)
local function firebase_config_callback(self, message_id, message)
if message_id == remoteconfig.MSG_ERROR then
-- an error was detected when performing a remote config operation
print("Firebase Remote Config error: ", message.error)
return
end

-- initialise remote config and set up a listener to react to
-- remote config state changes
firebase.remoteconfig.init(function(self, event)
-- an error was detected when performing a remote config operation
if event == firebase.remoteconfig.CONFIG_ERROR then
return
end

if message_id == remoteconfig.MSG_INITIALIZED then
-- remote config is initialized and ready for use
-- setup default values for your remote config
-- these values will be used until you have loaded updated values from
-- the server
if event == firebase.remoteconfig.CONFIG_INITIALIZED then
firebase.remoteconfig.set_defaults({
score_bonus = 0,
score_multiplier = 1,
holiday_theme = "Christmas",
holiday_promo_enabled = false,
})
return
end

-- the defaults have been set and we're now ready to use remote config
if event == firebase.remoteconfig.CONFIG_DEFAULTS_SET then
-- you can use get_string(), get_boolean(), get_number() and get_data()
print("Theme:", firebase.remoteconfig.get_string("holiday_theme")) -- Christmas
print("Promo enabled:", firebase.remoteconfig.get_boolean("holiday_promo_enabled")) -- false
print("Score multiplier:", firebase.remoteconfig.get_number("score_multiplier")) -- 1

-- get and activate new remote config values from the server
firebase.remoteconfig.fetch_and_activate()
return
end

firebase.remoteconfig.set_defaults({
score_bonus = 0,
score_multiplier = 1,
holiday_theme = "Christmas",
holiday_promo_enabled = false,
})
elseif message_id == remoteconfig.MSG_DEFAULTS_SET then
-- you can use get_string(), get_boolean(), get_number() and get_data()
print("Theme:", firebase.remoteconfig.get_string("holiday_theme")) -- Christmas
print("Promo enabled:", firebase.remoteconfig.get_boolean("holiday_promo_enabled")) -- false
print("Score multiplier:", firebase.remoteconfig.get_number("score_multiplier")) -- 1

-- get and activate new remote config values from the server
firebase.remoteconfig.fetch_and_activate()
elseif message_id == remoteconfig.MSG_FETCHED then
print("Data Fetched")
pprint("KEYS:", remoteconfig.get_keys())
elseif message_id == remoteconfig.MSG_ACTIVATED then
-- a recently fetched remote config has been activated and is now ready
-- for use
if event == firebase.remoteconfig.CONFIG_ACTIVATED then
print(firebase.remoteconfig.get_string("holiday_theme")) -- Easter
return
print(firebase.remoteconfig.get_string("holiday_theme")) -- Easter
elseif message_id == remoteconfig.MSG_SETTINGS_UPDATED then
print("Settings updated")
end
end

function init(self)
-- use firebase only if it is supported on the current platform
if not firebase then
return
end

-- initialise firebase and check that it was successful
firebase.set_callback(function(self, message_id, message)
if message_id == firebase.MSG_INITIALIZED then
firebase.remoteconfig.set_callback(firebase_config_callback)
firebase.remoteconfig.initialize()
end
end)
end
Expand Down
143 changes: 85 additions & 58 deletions example/example.script
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,105 @@ local remoteconfig = firebase and firebase.remoteconfig
local LOG_ENTRIES = {}

local function log(...)
local text = ""
for _,v in ipairs({...}) do
text = text .. tostring(v)
end
table.insert(LOG_ENTRIES, 1, text)
table.remove(LOG_ENTRIES, 21)
print(text)
label.set_text("#label", table.concat(LOG_ENTRIES, "\n"))
local text = ""
for _,v in ipairs({...}) do
if type(v) == "table" then
local value = "table {"
for _, v1 in pairs(v) do
value = value..v1..","
end
if next(v) then
value = value:sub(1, -2)
else
value = value .. "empty table"
end
value = value .. "}"
v = value
end
text = text .. tostring(v)
end
table.insert(LOG_ENTRIES, 1, text)
table.remove(LOG_ENTRIES, 21)
print(text)
label.set_text("#label", table.concat(LOG_ENTRIES, "\n"))
end

local function set_defaults()
remoteconfig.set_defaults({
score_bonus = 0,
score_multiplier = 1,
holiday_theme = "Christmas",
holiday_promo_enabled = false,
story = "Once upon a time",
})
log("SET DEFAULTS")
remoteconfig.set_defaults({
score_bonus = 0,
score_multiplier = 1,
holiday_theme = "Christmas",
holiday_promo_enabled = false,
story = "Once upon a time",
})
end

local function print_values()
log("score_bonus: ", remoteconfig.get_number("score_bonus"))
log("score_multiplier: ", remoteconfig.get_number("score_multiplier"))
log("holiday_theme: ", remoteconfig.get_string("holiday_theme"))
log("holiday_promo_enabled: ", remoteconfig.get_boolean("holiday_promo_enabled"))
log("story: ", remoteconfig.get_string("story"))
log("story (data): ", remoteconfig.get_data("story"))
log("score_bonus: ", remoteconfig.get_number("score_bonus"))
log("score_multiplier: ", remoteconfig.get_number("score_multiplier"))
log("holiday_theme: ", remoteconfig.get_string("holiday_theme"))
log("holiday_promo_enabled: ", remoteconfig.get_boolean("holiday_promo_enabled"))
log("story: ", remoteconfig.get_string("story"))
log("story (data): ", remoteconfig.get_data("story"))
end

local function firebase_config_callback(self, message_id, message)
if message_id == remoteconfig.MSG_ERROR then
log("Firebase Remote Config error: ", message.error)
return
end
if message_id == remoteconfig.MSG_INITIALIZED then
log("Firebase Remote Config initialized")
set_defaults()
elseif message_id == remoteconfig.MSG_DEFAULTS_SET then
log("MSG_DEFAULTS_SET")
print_values()
elseif message_id == remoteconfig.MSG_FETCHED then
log("Fetched")
log("KEYS:", remoteconfig.get_keys())
elseif message_id == remoteconfig.MSG_ACTIVATED then
log("Activated")
print_values()
elseif message_id == remoteconfig.MSG_SETTINGS_UPDATED then
log("Settings updated")
else
log("Unknown event", message_id)
end
end

local function init_firebase_config()
log("Init Firebase Remote Config")
remoteconfig.set_callback(firebase_config_callback)
remoteconfig.initialize()
end

function init(self)
msg.post("@render:", "use_fixed_fit_projection")
go.animate("logo", "euler.z", go.PLAYBACK_LOOP_FORWARD, 360, go.EASING_LINEAR, 3)
msg.post("@render:", "use_fixed_fit_projection")
go.animate("logo", "euler.z", go.PLAYBACK_LOOP_FORWARD, 360, go.EASING_LINEAR, 3)

if not firebase then
log("Firebase not supported")
return
end

if not firebase then
log("Firebase not supported")
return
end
msg.post(".", "acquire_input_focus")

log("Init Firebase")

msg.post(".", "acquire_input_focus")

log("Init Firebase")
log("Click to fetch and activate values")
local ok, err = firebase.init()
if not ok then
log(err)
return
end
firebase.set_callback(function(self, message_id, message)
if message_id == firebase.MSG_INITIALIZED then
log("Firebase initialized")
init_firebase_config()
end
end)

log("Init Firebase Remote Config")
remoteconfig.init(function(self, event)
if event == remoteconfig.CONFIG_ERROR then
log("Firebase Remote Config error")
return
end
if event == remoteconfig.CONFIG_INITIALIZED then
set_defaults()
elseif event == remoteconfig.CONFIG_DEFAULTS_SET then
print_values()
elseif event == remoteconfig.CONFIG_FETCHED then
log("Fetched")
elseif event == remoteconfig.CONFIG_ACTIVATED then
log("Activated")
print_values()
else
log("Unknown event", event)
end
end)
firebase.initialize()
end


function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
remoteconfig.fetch_and_activate()
end
if action_id == hash("touch") and action.pressed then
remoteconfig.fetch_and_activate()
end
end
Loading

0 comments on commit bb3188b

Please sign in to comment.