- // Retrieve any live game from its identifiers (locally, running or not)
- // NOTE: need callback because result is obtained asynchronously
- get: function(gameId, callback)
- {
- dbOperation((db) => {
- let objectStore = db.transaction('games').objectStore('games');
- if (!gameId) //retrieve all
- {
- let games = [];
- objectStore.openCursor().onsuccess = function(event) {
- let cursor = event.target.result;
- // if there is still another cursor to go, keep running this code
- if (cursor)
- {
- games.push(cursor.value);
- cursor.continue();
- }
- else
- callback(games);
- }
- }
- else //just one game
- {
- objectStore.get(gameId).onsuccess = function(event) {
- callback(event.target.result);
- }
- }
+ // Retrieve all local games (running, completed, imported...)
+ getAll: function(callback) {
+ dbOperation((err,db) => {
+ let objectStore = db.transaction("games").objectStore("games");
+ let games = [];
+ objectStore.openCursor().onsuccess = function(event) {
+ let cursor = event.target.result;
+ // if there is still another cursor to go, keep running this code
+ if (cursor) {
+ let g = cursor.value;
+ // Do not retrieve moves or clocks (unused in list mode)
+ g.movesCount = g.moves.length;
+ delete g.moves;
+ delete g.clocks;
+ delete g.initime;
+ games.push(g);
+ cursor.continue();
+ } else callback(games);
+ };