<commit_before>$(function(){
    window._gr = {
        map: {
            units: [],
            highlightedArea: [],
            ground: []
        },

        global: {
            movingUnit: {
                unit: null,
                x:0, y:0,
                path: null,
                currentNode: 0
            },
            darkenedUnits: []
        },

        /**
         * automaticaly called once
         */
        init: function(){
            var val = level.mapSize.split(",");

            _c.setSize({w:val[0], h:val[1]});

            var tile2ground = function(id){
                var tile = tiles.filter(function(elem){
                    return elem.id == id;
                })[0];

                if(tile === undefined) return 0;

                return tile.ground;
            };


            _c.layers.clearBuffer();

            for(var i=0; _c.const.world.grid.w > i; i++){
                _gr.map.units.push([]);
                _gr.map.highlightedArea.push([]);
                _gr.map.ground.push([]);
                for(var j=0; _c.const.world.grid.h > j; j++){
                    _gr.map.units[i].push(null);
                    _gr.map.highlightedArea[i].push(null);
                    _gr.map.ground[i].push(tile2ground(level.tiles[i][j]));

                    _c.layers.drawTile({
                        tileId: level.tiles[i][j],
                        x: i, y: j
                    });
                }
            }
            _c.layers.blitBuffer(_c.layers.background, true);

            // load buildings
            _c.layers.clearBuffer();
            for(var i=0; i<_c.const.world.grid.w; ++i){
                for(var j=0; j<_c.const.world.grid.h; ++j){
                    _c.layers.drawBuilding({
                        buildingId: level.buildings[i][j],
                        x: i, y: j
                    });
                }
            }
            _c.layers.blitBuffer(_c.layers.buildings, true);
        },

        /**
         *
         * @param btns an array of butons {(string) name, (bool) disabled, (func) callback}
         */
        showMenu: function(btns){

        },

        /**
         * sends a string to the other player via the server
         * see also: receiveStr
         * @param str the string to send
         */
        sendStr: function(str){
            $url = $('#game-container').data('send-str');

            $.get($url, {msg: str});
        },

        /**
         * check to see if the other player sent a string via the sendStr method.
         * If onNoMessage is not specified, this method will keep sending request to the server until a message is found
         * @param onSuccess callback when a message is found with the message as parameter
         * @param onNoMessage callback when no message is found
         */
        receiveStr: function(onSuccess, onNoMessage){
            if(onNoMessage == undefined)
                onNoMessage = function(){
                    _gr.receiveStr(onSuccess);
                };

            $url = $('#game-container').data('receive-str');

            $.get($url, null, function(data){
                if(data === null)
                    onNoMessage();
                else{
                    onSuccess(data.message);
                }
            }, 'json');
        },

        /**
         * returns true if the player initiated the game and false if he was invited to play
         */
        isMaster: function(){
            return $('#game-container').data('is-master') == 1;
        },

        /**
         * add a unit to a specific point on the map.
         * if a unit is already on the specified location it will be replaced
         * @param x
         * @param y
         * @param unit an object formatted as follow: {(int) id, (str) color[, (int) hp, (bool) sleeping, (bool) darkened]}
         */
        addUnit: function(x, y, unit){
            unit = _c.setDefaultParams(unit, {
                hp: null,
                color: "red",
                sleeping: false,
                darkened: false,
                dir: "right"

            });

            unit.opacity = 0;
            unit.createdAt = new Date().getTime();

            _gr.map.units[x][y] = unit;
        },

        /**
         * move a unit according to a specific path
         * @param x
         * @param y
         * @param path [{x, y}, {x, y}, ...]
         * @param callback
         */
        moveUnit: function(x, y, path, callback){
            _gr.global.movingUnit.unit = _gr.map.units[x][y];
            _gr.map.units[x][y] = null;

            _gr.global.movingUnit.x = x;
            _gr.global.movingUnit.y = y;
            _gr.global.movingUnit.path = path;
            _gr.global.movingUnit.currentNode = 0;
            _gr.global.movingUnit.callback = callback;
        },

        /**
         * kill a unit and play the animation. The function will not return until the animation is complete.
         * @param x
         * @param y
         * @param callback
         */
        killUnit: function(x, y, callback){
            callback();
            // TODO
        },

        /**
         * play an attack animation. The function will not return until the animation is complete.
         * @param attacker {x, y}
         * @param target {x, y}
         * @param callback
         */
        attackUnit: function(attacker, target, callback){
            callback();
            // TODO
        },

        /**
         * show the defense animation for a specific unit. The function will not return until the animation is complete.
         * @param x
         * @param y
         * @param callback
         */
        showDefenseAnim: function(x, y, callback){
            callback();
            // TODO
        },

        /**
         * show the assassin animation for a specific unit. The function will not return until the animation is complete.
         * @param x
         * @param y
         * @param callback
         */
        showAssassinAnim: function(x, y, callback){
            callback();
            // TODO
        },

        /**
         * highlight a specific cell forever.
         * @param x
         * @param y<commit_msg>comit moi tout ce que ta foutu<commit_after>$(function(){
    window._gr = {
        map: {
            units: [],
            highlightedArea: [],
            ground: []
        },

        global: {
            movingUnit: {
                unit: null,
                x:0, y:0,
                path: null,
                currentNode: 0
            },
            darkenedUnits: []
        },

        /**
         * automaticaly called once
         */
        init: function(){
            var val = level.mapSize.split(",");

            _c.setSize({w:val[0], h:val[1]});

            var tile2ground = function(id){
                var tile = tiles.filter(function(elem){
                    return elem.id == id;
                })[0];

                if(tile === undefined) return 0;

                return tile.ground;
            };


            _c.layers.clearBuffer();

            for(var i=0; _c.const.world.grid.w > i; i++){
                _gr.map.units.push([]);
                _gr.map.highlightedArea.push([]);
                _gr.map.ground.push([]);
                for(var j=0; _c.const.world.grid.h > j; j++){
                    _gr.map.units[i].push(null);
                    _gr.map.highlightedArea[i].push(null);
                    _gr.map.ground[i].push(tile2ground(level.tiles[i][j]));

                    _c.layers.drawTile({
                        tileId: level.tiles[i][j],
                        x: i, y: j
                    });
                }
            }
            _c.layers.blitBuffer(_c.layers.background, true);

            // load buildings
            _c.layers.clearBuffer();
            for(var i=0; i<_c.const.world.grid.w; ++i){
                for(var j=0; j<_c.const.world.grid.h; ++j){
                    _c.layers.drawBuilding({
                        buildingId: level.buildings[i][j],
                        x: i, y: j
                    });
                }
            }
            _c.layers.blitBuffer(_c.layers.buildings, true);
        },

        /**
         *
         * @param btns an array of butons {(string) name, (bool) disabled, (func) callback}
         */
        showMenu: function(btns){

        },

        /**
         * sends a string to the other player via the server
         * see also: receiveStr
         * @param str the string to send
         */
        sendStr: function(str){
            $url = $('#game-container').data('send-str');

            $.get($url, {msg: str});
        },

        /**
         * check to see if the other player sent a string via the sendStr method.
         * If onNoMessage is not specified, this method will keep sending request to the server until a message is found
         * @param onSuccess callback when a message is found with the message as parameter
         * @param onNoMessage callback when no message is found
         */
        receiveStr: function(onSuccess, onNoMessage){
            if(onNoMessage == undefined)
                onNoMessage = function(){
                    _gr.receiveStr(onSuccess);
                };

            $url = $('#game-container').data('receive-str');

            $.get($url, null, function(data){
                if(data === null)
                    onNoMessage();
                else{
                    onSuccess(data.message);
                }
            }, 'json');
        },

        /**
         * returns true if the player initiated the game and false if he was invited to play
         */
        isMaster: function(){
            return $('#game-container').data('is-master') == 1;
        },

        /**
         * add a unit to a specific point on the map.
         * if a unit is already on the specified location it will be replaced
         * @param x
         * @param y
         * @param unit an object formatted as follow: {(int) id, (str) color[, (int) hp, (bool) sleeping, (bool) darkened]}
         */
        addUnit: function(x, y, unit){
            unit = _c.setDefaultParams(unit, {
                hp: null,
                color: "red",
                sleeping: false,
                darkened: false,
                dir: "right"

            });

            unit.opacity = 0;
            unit.createdAt = new Date().getTime();

            _gr.map.units[x][y] = unit;
        },

        /**
         * move a unit according to a specific path
         * @param x
         * @param y
         * @param path [{x, y}, {x, y}, ...]
         * @param callback
         */
        moveUnit: function(x, y, path, callback){
            console.log(path);
            _gr.global.movingUnit.unit = _gr.map.units[x][y];
            _gr.map.units[x][y] = null;

            _gr.global.movingUnit.x = x;
            _gr.global.movingUnit.y = y;
            _gr.global.movingUnit.path = path;
            _gr.global.movingUnit.currentNode = 0;
            _gr.global.movingUnit.callback = callback;
        },

        /**
         * kill a unit and play the animation. The function will not return until the animation is complete.
         * @param x
         * @param y
         * @param callback
         */
        killUnit: function(x, y, callback){
            if(callback != undefined)
            callback();
            // TODO
        },

        /**
         * play an attack animation. The function will not return until the animation is complete.
         * @param attacker {x, y}
         * @param target {x, y}
         * @param callback
         */
        attackUnit: function(attacker, target, callback){
            if(callback != undefined)
            callback();
            // TODO
        },

        /**
         * show the defense animation for a specific unit. The function will not return until the animation is complete.
         * @param x
         * @param y
         * @param callback
         */
        showDefenseAnim: function(x, y, callback){
            if(callback != undefined)
            callback();
            // TODO
        },

        /**
         * show the assassin animation for a specific unit. The function will not return until the animation is complete.
         * @param x
         * @param y
         * @param callback
         */
        showAssassinAnim: function(x, y, callback){
            if(callback != undefined)
            callback();
            // TODO
        },

        /**
         * highlight a specific cell forever.
         * @param x
         * @param y
{'fraction_non_alphanumeric': 0.11804570527974784, 'fraction_numerical': 0.00252167060677699, 'mean_word_length': 1.2362995594713657, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '7212231', 'n_tokens_mistral': 3473, 'n_tokens_neox': 3286, 'n_words': 928}