Rex's plugins for Construct2
  • Home
  • Map
  • Tutorial/Templates
  • News
  • About

rex_firebase_savedata

Plugin, ACE table, Discussion thread
Dependence: 
rex_firebase_apiV3

Introduction
Save slot on
firebase.
It is designed to save game status on cloud (
firebase).

Usage
Sample capx, sample capx v3

Concept
Each user has a dedicate slots set. Each slot has two parts - header and body.

Header
Header is a 1d hash table, i.e. key - value pair, to describe
this slot, all headers of this owner user would be read at the same time to be indexes of these slots.
Body
Body is a 1d hash table, to put main saving data. Read a specific slot body by slot nam
e.

Set Owner
Each user has a dedicate slots set. So first step is to set the owner user by "Action:Set owner". The parameter "User ID" might come from authentication.
Save
Follow these steps to save a slot on cloud after set owner done.
  1. Call "Action:Set value" or "Action:Set boolean value" to assign value with key into header or body
  2. Call "Action:Save" to push this slot on cloud by slot name.
  3. "Condition:On save complete" will be triggered if saving completed, otherwise "Condition:On save error" will be triggered.
Older slot will be updated by these new key-value pairs.
Key with dot-notation
Parameter key in "Action:Set value", or "Action:Set boolean value" is a string, like "Gold", or a string with dot-notation like "pos.x", to store a JSON structure.
Cache
Sample capx
Saved data ("Action:Save") will update current load headers or body (Expression:BodyValue), see next section.

Load
Follow these steps to load a slot from cloud after set owner.

Get headers
1. Call "Action:Get all headers" to get all headers of this owner user. "Condition:On get headers" will be triggered if get all headers.
2. There are three ways to retrieve header for showing them at UI -
- a. Uses "Condition:For each header" to retrieve each header, then get each slot name by "Expression:CurSlotName", and get value by "Expression:CurHeaderValue( key )". Or retrieve each key of a header by "Condition:For each key" under "Load - header" category, then read key and value by  "Expression:CurKey", and "Expression:CurValue".
- b. get value by "Expression:HeaderValue(  slotName, key )".
- c. The other is to get headers JSON string by "Expression:HeadersToJSON".
Get body
3. Call "Action:Get body" with a slot name parameter to get selected slot body. "Condition:On get body complete" will be triggered if get body. "Condition:On get unused body" will be triggered if got unused slot body.
4. After got body completed -
- a. Get body value by "Expression:BodyValue( key )". Or retrieve each key of a body by "Condition:For each key" under "Load - body" category, then read key and value by  "Expression:CurKey", and "Expression:CurValue".
- b. Or get body JSON string by "Expression:BodyToJSON".
If there is only a slot, the slot body could be load directly by step 3, 4.
After got headers, there are some conditions could be used to test if a slot is existed.
  • "Condition:Empty" is used to test if there is no slot.
  • "Condition:Is occupied" is used to test if a specific slot had been used.
Get value by key and default value
These expressions will read value by key,
  • Expression:CurHeaderValue( key )
  • Expression:HeaderValue( slotName, key )
  • Expression:BodyValue( key )
Or get value by key or return the default value if key does not exist.
  • Expression:CurHeaderValue( key , default_value )
  • Expression:HeaderValue( slotName, key, default_value )
  • Expression:BodyValue( key, default_value )
Or get all keys in JSON string
  • Expression:CurHeaderValue
  • Expression:HeaderValue( slotName ) , a header in JSON
  • Expression:HeaderValue( slotName ) , all header in JSON
  • Expression:BodyValue

Clean
Call "
Action:Clean slot" to clean a slot, header and body. Or call "Action:Clean all slots" to clean all slots.
"Condition:On clean complete" will be triggered if clean completed, otherwise "Condition:On clean error" will be triggered.

Security Rules
Sample capx
Only author can write and read his own data. Assume that the sub-doman is "save-data", replace it according to your project.
{"rules":
    {"save-data":
        {"$user":
            {".read":"auth.uid === $user",
              ".write":"auth.uid === $user"}
        }
    }
}

    

Debug message
Current loaded slot header and body values will be shown at debug panel.

Create a free web site with Weebly
  • Home
  • Map
  • Tutorial/Templates
  • News
  • About