const LEADERBOARD_SIZE = 10;

class leaderboard {

    constructor () {
        this.db = fbApp.database();
    }

    refresh (callback) {
        this.db.ref('leaderboard').orderByValue().limitToLast(LEADERBOARD_SIZE).once('value', (snapshot) => {
            this.board = [];
            snapshot.forEach((data) => {
                this.board.push({user: data.key, score: data.val()});
            });
            this.board.reverse();
            if (callback)
                callback(this.board);
        });
    }

    update (username, score) {
        this.db.ref('leaderboard/' + username).on('value', (snapshot) => {
            this.db.ref('leaderboard/' + username).set(Math.max(score, snapshot.val()));
        });
    }

}
const LEADERBOARD_SIZE = 10;

class leaderboard {

    constructor () {
        this.db = fbApp.database();
    }

    refreshScores (callback) {
        this.db.ref('leaderboard').orderByValue().limitToLast(LEADERBOARD_SIZE).once('value', (snapshot) => {
            var board = [];
            snapshot.forEach((data) => {
                board.push({user: data.key, score: data.val()});
            });
            board.reverse();
            callback(board);
        });
    }

    updateScore (username, score) {
        this.db.ref('leaderboard/' + username).on('value', (snapshot) => {
            this.db.ref('leaderboard/' + username).set(Math.max(score, snapshot.val()));
        });
    }

    updatePassedLevel (username, levelNumber) {
        this.db.ref('passedLevels/' + username + '/' + levelNumber.toString()).set(1);
    }

    getPassedLevels (username, callback) {
        this.db.ref('passedLevels/' + username + '/').orderByKey().once('value', (snapshot) => {
            var levels = [];
            snapshot.forEach((data) => {
                levels.push(data.key * 1);
            });
            callback(levels);
        });
    }

}
Add storage for "level passed" info
[LEADERBOARD/USERDATA] Add storage for "level passed" info
