<commit_before>require("../../../assets/images/logo.png");
require("../../../assets/images/cloud1.png");
require("../../../assets/images/cloud2.png");
require("../../../assets/styles/index.css");

export default class {

    preload() {
        this.game.load.image('tower', 'assets/images/tower3.png');
        this.game.load.image('logo', 'assets/images/logo.png');
        this.game.load.image('towerFilter', 'assets/images/towerFilter1.png');
        this.game.load.image('onelife', 'assets/images/onelife.png');
        this.game.load.image('nolife', 'assets/images/nolife.png');
        this.game.load.image('cloud1', 'assets/images/cloud1.png');
        this.game.load.image('cloud2', 'assets/images/cloud2.png');
        this.game.load.image('arrow', 'assets/images/arrow1.png');
    }

    constructor(game) {

    }

    create() {
        this.background;
        this.gameplay;
        this.gui;
        this.cloud;
        this.timerClouds = 0;
        this.game.time.events.duration;
        this.cloudSwitch = true;

        //  Background ----------------
        this.background = this.game.add.physicsGroup();

        ////>sky
        this.background.stage.backgroundColor = "#4ab4e6";
        this.background.stage.position = 'absolute';

        ////>clouds
        this.cloud = this.background.game.add.physicsGroup();
        for (var i= 0; i<5; i++){
            var y =  this.game.rnd.between(0,800);
            var x =  this.game.rnd.between(0,600);
            var cloud1 = this.cloud.create(x, y, i%2 === 0 ? 'cloud1' :'cloud2');
            cloud1.body.velocity.x = this.game.rnd.between(2, 10);
        }
        ////>logo
        this.game.add.sprite(680, 0, 'logo');

        const game = this.game;

        this.overlay = $(`<div class="overlay content-center">
			<div style="color:#FFF; width:50%">			
				<h1>game over</h1>
                <p style="padding-bottom: 1em;">your score is ${window.score}</p>
                <p style="padding-bottom: 1em;">your best score is <span id="bestScore">0</span></p>

				<table style="width:100%">
                    <form class="menu">
                        <input type="submit" value="play again" style="display:block; width: 100%"/>
                    </form>
				</table>
			</div>
		</div>`)
            .on('click', 'input[type=submit]', function(e) {
            e.preventDefault();
            game.state.start('Menu')
        });

        this.overlay.appendTo(document.body);
       
        this.game.input.keyboard.addCallbacks(this, e => {
            this.game.input.keyboard.destroy();
            this.game.input.keyboard.start();
            this.game.state.start("Game");
        });

        const login = localStorage.getItem('login');
        this.displayBestScore(login);
        this.saveBestScore(login, window.score);
    }

    displayBestScore(login) {
        const ref = new Webcom(`https://io.datasync.orange.com/base/bigbraintower/scores/${login}`);
        ref.on('value', snap => {
            document.getElementById('bestScore').innerHTML = (snap.val() && snap.val().score) || 0;
        }); 
    }

    getBestScore(login) {
        return new Promise(resolve => {
            const ref = new Webcom(`https://io.datasync.orange.com/base/bigbraintower/scores/${login}`);
            ref.once('value', snap => {
                resolve((snap.val() && snap.val().score) || 0);
            }); 
        })
    }

    saveBestScore(login, score) {
        return this.getBestScore(login).then(bestScore => {
            return new Promise(resolve => {
                bestScore = Number(bestScore);
                if (score > bestScore) {
                    login = login.replace('/','');
                    const ref = new Webcom(`https://io.datasync.orange.com/base/bigbraintower/scores/${login}`);
                    ref.update({
                        score
                    }, () => resolve);
                }
                resolve();
            });            
        })
    }

    update() {

    }

    shutdown() {
        this.overlay.remove();
    }
}<commit_msg>fix: save best score with a strange username (with slashes)<commit_after>require("../../../assets/images/logo.png");
require("../../../assets/images/cloud1.png");
require("../../../assets/images/cloud2.png");
require("../../../assets/styles/index.css");

export default class {

    preload() {
        this.game.load.image('tower', 'assets/images/tower3.png');
        this.game.load.image('logo', 'assets/images/logo.png');
        this.game.load.image('towerFilter', 'assets/images/towerFilter1.png');
        this.game.load.image('onelife', 'assets/images/onelife.png');
        this.game.load.image('nolife', 'assets/images/nolife.png');
        this.game.load.image('cloud1', 'assets/images/cloud1.png');
        this.game.load.image('cloud2', 'assets/images/cloud2.png');
        this.game.load.image('arrow', 'assets/images/arrow1.png');
    }

    constructor(game) {

    }

    create() {
        this.background;
        this.gameplay;
        this.gui;
        this.cloud;
        this.timerClouds = 0;
        this.game.time.events.duration;
        this.cloudSwitch = true;

        //  Background ----------------
        this.background = this.game.add.physicsGroup();

        ////>sky
        this.background.stage.backgroundColor = "#4ab4e6";
        this.background.stage.position = 'absolute';

        ////>clouds
        this.cloud = this.background.game.add.physicsGroup();
        for (var i= 0; i<5; i++){
            var y =  this.game.rnd.between(0,800);
            var x =  this.game.rnd.between(0,600);
            var cloud1 = this.cloud.create(x, y, i%2 === 0 ? 'cloud1' :'cloud2');
            cloud1.body.velocity.x = this.game.rnd.between(2, 10);
        }
        ////>logo
        this.game.add.sprite(680, 0, 'logo');

        const game = this.game;

        this.overlay = $(`<div class="overlay content-center">
			<div style="color:#FFF; width:50%">			
				<h1>game over</h1>
                <p style="padding-bottom: 1em;">your score is ${window.score}</p>
                <p style="padding-bottom: 1em;">your best score is <span id="bestScore">0</span></p>

				<table style="width:100%">
                    <form class="menu">
                        <input type="submit" value="play again" style="display:block; width: 100%"/>
                    </form>
				</table>
			</div>
		</div>`)
            .on('click', 'input[type=submit]', function(e) {
            e.preventDefault();
            game.state.start('Menu')
        });

        this.overlay.appendTo(document.body);
       
        this.game.input.keyboard.addCallbacks(this, e => {
            this.game.input.keyboard.destroy();
            this.game.input.keyboard.start();
            this.game.state.start("Game");
        });

        const login = localStorage.getItem('login').replace('/', '');
        this.displayBestScore(login);
        this.saveBestScore(login, window.score);
    }

    displayBestScore(login) {
        const ref = new Webcom(`https://io.datasync.orange.com/base/bigbraintower/scores/${login}`);
        ref.on('value', snap => {
            document.getElementById('bestScore').innerHTML = (snap.val() && snap.val().score) || 0;
        }); 
    }

    getBestScore(login) {
        return new Promise(resolve => {
            const ref = new Webcom(`https://io.datasync.orange.com/base/bigbraintower/scores/${login}`);
            ref.once('value', snap => {
                resolve((snap.val() && snap.val().score) || 0);
            }); 
        })
    }

    saveBestScore(login, score) {
        return this.getBestScore(login).then(bestScore => {
            return new Promise(resolve => {
                bestScore = Number(bestScore);
                if (score > bestScore) {
                    const ref = new Webcom(`https://io.datasync.orange.com/base/bigbraintower/scores/${login}`);
                    ref.update({
                        score
                    }, () => resolve);
                }
                resolve();
            });            
        })
    }

    update() {

    }

    shutdown() {
        this.overlay.remove();
    }
}
{'fraction_non_alphanumeric': 0.1788410031653275, 'fraction_numerical': 0.01241782322863404, 'mean_word_length': 1.842560553633218, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 59, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7534729', 'n_tokens_mistral': 2594, 'n_tokens_neox': 2430, 'n_words': 367}