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

rex_firebase_itembook

Plugin, ACE table, Discussion thread
Dependence: 
rex_firebase_apiV3

Introduction
Item tables to save and query items. Each value is indexed by (tableID, itemID, key).
Compare with rex_firebase_itemtable plugin
This plugin contains multiple tables and it can modify multiple items across these tables in an atomic write process. i.e. values will be changed at the same time.
This plugin has querying function to pick items by a single condition.

Usage
Save items
Sample capx

There are two ways to build saved items, in enumeration or tree structure.
Enumeration
Call these actions in "Prepare - Enumeration" category to build items.
  • Action:Set value
  • Action:Set boolean value
  • Action:Set server timesetamp
  • Action:Set JSON
图片
Tree structure
Add "Condition:Table node" to create a table node, then add "Condition:Item node" to create an item node. Then call these actions in "Prepare - Tree" category to add values.
  • Action:Set value
  • Action:Set boolean value
  • Action:Set server timesetamp
  • Action:Set JSON
图片
Push item
Get a new itemID of "push" item by "Expression:GenerateKey", it will be saved in "Expression:LastGeneratedKey".
Set JSON by key
Sample capx
Key string contains "." or "/" will be splitted into levels to create a JSON object above the root key. For example, set key "pos.x" to 10, will add {"x":10} at key "pos". And get 10 back by key "pos.x" directly in ""Expression:CurItemContent", or "Expression:At".
User does not need to create or parse JSON by JSON plugin anymore.

Write to server
Call "Action:Update" to upload all items to firebase server. "Condition:On update complete" will be triggered while writing completed, otherwise "Condition:On update error" will be triggered.

Remove an item
Call "
Action:Remove" to remove a item.

"Condition:On remove complete" will be triggered if save completed, otherwise "Condition:On remove error" will be triggered.


Load items
Sample capx
Load all tables/a table/an item
Call "
Action:Load item" to load all tables/a table/an item.
  • Load all tables: Set tableID "" to load all tables.
  • Load a table: Set itemID to "" to load all items in the table.
  • Load an item: tableID and itemID are not "" either.
"Condition:On request complete" will be triggered while receiving items.
Table is empty
Check if a table has no item by "Condition:Table is empty".
Retrieve items
Get requested tableID by "Expression:LastTableID" under "Condition:On request complete".
Then retrieve items in this table under "Condition:For each itemID" by "Expression:CurItemID", and "Expression:CurItemContent".
"Expression:CurItemContent" has 3 types of output
  • Expression:CurItemContent : return JSON string of all key-value pairs.
  • Expression:CurItemContent( key ) : return the value of a specific key.
  • Expression:CurItemContent( key , default_value ) : return the value of a specific key, or the default value if the key does not exist.
Each key of a item could be retrieved under "Condition:For each key" by "Expression:CurKey" and "Expression:CurValue".
Or get a specific value by "Expression:At". This expression has 5 types of output
  • Expression:At : return JSON string of all tables
  • Expression:At( tableID ) : return JSON string of all items in a table
  • Expression:At( tableID , itemID ) : return JSON string of an item in a table
  • Expression:At( tableID , itemID , key ): return a value of a key in an item of a table
  • Expression:At( tableID , itemID , key , default_value ) : return a value of a key in an item of a table, or a default value of this key does not exist.
Items list
Sample capx
User could put items into rex_taffydb object by "Expression:AsItemList" to query and sort items locally.
"Expression:AsItemList" has 3 types of output.
  • Expression:AsItemList : return items in all tables
  • Expression:AsItemList( tableID ): return items in a table
  • Expression:AsItemList( tableID , itemID ): return a item
The key name of tableID and itemID is "tableID" and "itemID" by default. They could be changed by "Action:Set key name".
Querying
There are 2 querying actions
  • "Action:Get items by "In Range" - Get items by single condition-In Range (start to end) with count limit in a table. Set count to -1 to get all matched items
  • "Action:Get items by comparison" - Get items by single condition with count limit in a table. Set count to -1 to get all matched items.
"Condition:On request complete" will be triggered while receiving items.
Load items and put them into rex_taffydb object to do more complex querying.
Requests queue
Sample capx
Uses requests queue feature if there are more then 1 load request in the same time. Follows these steps to run a requests queue.
  • Call "Action:Start new request queue" to start a new queue
  • Add request into this queue by "Action:Load item", "Action:Get items by "In Range", "Action:Get items by comparison".
  • Call "Action:Process request queue" to start requests in queue
  • "Condition:On request complete" will be triggered while all requests competed.
Clean request result tables
Call "Action:Clean result table" to clean the request table. Set tableID to "" to clean all tables.

On disconnect
Sample capx

There are two ways to build saved items, in enumeration or tree structure, like building items for saving.
Reference: rex_firebase_itemmonitor plugin

Enumeration
Call these actions in "On disconnected - Enumeration" category to register a disconnected handler.
  • Action:Set value
  • Action:Set boolean value
  • Action:Set server timesetamp
  • Action:Set JSON
  • Action:Remove key
There are 4 kind of action in "Action:Remove key".
  • Set tableID to "" to remove all tables
  • Set itemID to "" to remove all items in the table
  • Set key to "" to remove all keys in the item
  • Otherwise, remove a key in an item.
图片
Tree structure
Call these actions in "On disconnected - Tree" category to register a disconnected handler.
  • Action:Set value
  • Action:Set boolean value
  • Action:Set server timesetamp
  • Action:Set JSON
Or add "Condition:Remove on disconnected" under a table node or an item node to remove a table or an item, or call "Action:Remove key" in "On disconnected - Tree" category to remove a key in an item.
图片

Reference path
Get reference path by "Expression:Ref", it has 4 type of output.
Expression:Ref : return the root of all tables
Expression:Ref( tableID ) : return the reference path of a table
Expression:Ref( tableID , itemID ) : return the reference path of an item.
Expression:Ref( tableID , itemID , key ) : return the reference path of a key in an item.

Shuffle items
Sample capx
Set a random string at a key to shuffle items after sorting by that key.
"Expression:RandomBase32( length )" can be used to get a random string, each character is picked from one of 32 character "0" - "9" , "a" - "z", excluded "a", "i", "l", "o".

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