API

Chad Engler edited this page Jan 24, 2013 · 3 revisions
Clone this wiki locally

WikiAPI

WORK IN PROGRESS

Contents

## loadChunk(id, callback)

Loads a chunk from the underlying store. Once the chunk has been loaded the chunkLoaded event is emitted.

Arguments

  • id - The id of the chunk to load (like '0|1|0')
  • callback(err, chunk) (optional) - The callback to call with the chunk data

Example

store.loadChunk('0|1|0', function(err, chunk) {
    //chunk holds the chunk data from IDB
});
## loadChunks(ids, callback)

Loads the specified chunks from the underlying store, if no ids are specified all chunks are loaded. Each chunk loaded will emit the chunkLoaded event, and the chunksLoaded event is emitted once all chunks have been loaded.

Arguments

  • ids (optional) - The ids of the chunks to load (like ['0|1|0', '0|1|1']). If not specified all chunks are loaded.
  • callback(err, chunks) (optional) - The callback to call with the chunks data.

Example

store.loadChunks(function(err, chunks) {
    //chunks holds the chunks data from IDB
});
## loadItem(id, callback)

Loads an item from the underlying store. Once the item has been loaded the itemLoaded event is emitted.

Arguments

  • id - The id of the item to load (like '0|1|0')
  • callback(err, item) (optional) - The callback to call with the item data.

Example

store.loadItem('0|1|0', function(err, item) {
    //item holds the item data from IDB
});
## loadItems(ids, callback)

Loads the specified items from the underlying store, if no ids are specified all items are loaded. Each item loaded will emit the itemLoaded event, and the itemsLoaded event is emitted once all items have been loaded.

Arguments

  • ids - The ids of the chunks to load (like ['0|1|0', '0|1|1'])
  • callback(err, items) (optional) - The callback to call with the item data.

Example

store.loadItems(function(err, items) {
    //items holds the items data from IDB
});
## loadPlayer(callback)

Loads the player from the underlying store. Once the player has been loaded the playerLoaded event is emitted.

Arguments

  • callback(err, player) (optional) - The callback to call with the player data.

Example

store.loadPlayer('0|1|0', function(err, player) {
    //player holds the player data from IDB
});
## loadGame(callback)

Loads all the chunks, items, and the player in this game store. Each loaded chunk, item, and player will emit their respective events.

Arguments

  • callback(err, game) (optional) - The callback to call with the game data.

Example

store.loadGame(function(err, game) {
    //game holds the game data from IDB
    game.chunks; //chunks loaded
    game.items; //items loaded
    game.player; //player loaded
});
## storeChunk(chunk, callback)

Stores a chunk to the underlying store. Once the chunk has been stored the chunkStored event is emitted.

Arguments

  • chunk - The chunk of the chunk to store.
  • callback(err) (optional) - The callback to call once the chunk is stored.

Example

store.storeChunk(chunk, function(err) {
});
## storeChunks(chunks, callback)

Stores the specified chunks to the underlying store. Each chunk stored will emit the chunkStored event, and the chunksStored event is emitted once all chunks have been stored.

Arguments

  • chunks - The chunks to store.
  • callback(err) (optional) - The callback to call once the chunks are stored.

Example

store.storeChunks(chunks, function(err) {
});
## storeItem(item, callback)

Stores an item to the underlying store. Once the item has been storeed the itemStored event is emitted.

Arguments

  • item - The item to store.
  • callback(err) (optional) - The callback to call once the item is stored.

Example

store.storeItem(item, function(err) {
});
## storeItems(items, callback)

Stores the specified items to the underlying store. Each item stored will emit the itemStored event, and the itemsStored event is emitted once all items have been stored.

Arguments

  • items - Theitems to store.
  • callback(err) (optional) - The callback to call once the items are stored.

Example

store.storeItems(items, function(err) {
});
## storePlayer(player, callback)

Stores the player to the underlying store. Once the player has been stored the playerStored event is emitted.

Arguments

  • player - The player object to be stored.
  • callback(err) (optional) - The callback to call once the player is stored.

Example

store.storePlayer(player, function(err) {
});
## storeGame(callback)

Stores all the chunks, items, and the player in this game to the underlying store. Each stored chunk, item, and player will emit their respective events.

Arguments

  • callback(err) (optional) - The callback to call once the game is stored.

Example

store.storeGame(function(err) {
});
## export(callback)

Loads all the chunks, items, and the player in this game from the underlying store and builds a blob out of it. This blob can be used to create an ObjectURL that the user can save the file with.

Arguments

  • callback(err, blob) (optional) - The callback to call once the blob is created.

Example

store.export(function(err, blob) {
    if(!err) {
        //open a save-as prompt on the browser
        window.href = window.URL.createObjectURL(blob);
    }
});
## Event: chunkLoaded ## Event: chunksLoaded ## Event: itemLoaded ## Event: itemsLoaded ## Event: playerLoaded ## Event: gameLoaded ## Event: chunkStored ## Event: chunksStored ## Event: itemStored ## Event: itemsStored ## Event: playerStored ## Event: gameStored ## Event: exported