<commit_before>var game = zepto

var stdout;

function StampedEvent (ticks, event) {
    this.t = ticks;
    this.e = event;
};

function recordizeEvent(event) {
    return {"type": event.type,
            "keyCode": event.keyCode
           };
};


var pathlist = {

    addLocal : function (path) {

        var div = this.makeElement(path);

        if (path.endCheckpoint != "gameover") {
            $(div).children('input').prop('checked', true);
        }

        $('#pathlist').append(div);
        pathlist.refreshPreview();

        $.ajax({type:'POST',
                url:'newpath',
                data:JSON.stringify(path)
               })
           .done( function (data) {
           })
           .fail( function (xhr, status, thrown) {
               console.log('error: ' + thrown + " " + xhr.responseText);
           });
    },

    addRemote : function (path) {

        var div = this.makeElement(path);

        $('#remotepathlist').append(div);
    },


    // if path is null, make the 'Game Start' element
    makeElement : function (path) {
        var div = document.createElement('div');

        var input = document.createElement('input');
        $(input).attr('type', 'radio')
                .attr('name','path');

        if (!path) {
            this.gameStartRadioButton = input;
        }

        var endState = undefined;
        if (path) {
            endState = path.endState;
        }

        $(input).css('display', 'none');

        div.appendChild(input);

        // set up the preview
        $(input).change(function () {
            game.load(endState);
            game.render();
        });


        $(input).bind('startPlaying', function () {
            playMode.start(path);
        });

        $(input).bind('startReplaying', function () {
            if (path) {
                replayMode.start(path);
            }
        });

        var label = document.createElement('label');
        if (path) {
            label.innerHTML = path.username + ': from ' + path.startCheckpoint +
                ' at ' + path.startTicks + ' ticks ' +
                ' to ' + path.endCheckpoint +
                ' at ' + path.endTicks + ' ticks ';
            // + (new Date(path.startTime)).toUTCString();
        } else {
            label.innerHTML = "Game Start";
        }


        $(label).click(function (){
            $(input).prop('checked', true);
            pathlist.refreshPreview();
        });

        var closebutton = document.createElement('button');
        closebutton.innerHTML = '&times;';


        if (!path) {
            $(closebutton).prop('disabled', true);
        }


        $(closebutton).click(function () {
            var parent = $(this).parent();

            if (parent.children('input').is(":checked")) {
                pathlist.selectGameStart();
            }

            parent.slideUp(100, function () {
                parent.remove();
                pathlist.refreshPreview();
            });
        })


        div.appendChild(closebutton);

        div.appendChild(input);
        div.appendChild(label);

        return div;
    },

    gameStartRadioButton : null,

    selectGameStart : function () {
        $(this.gameStartRadioButton).prop('checked', true);
        pathlist.refreshPreview();
    },

    refreshPreview : function () {
        $('[name="path"]').each (function (idx, elt) {
            if ($(elt).is(':checked')) {
                $(elt).trigger('change');
                $(elt).parent().children('label')
                   .css('border', '1px solid')
                   .css('color', '#FFFFFF');
            } else {
                $(elt).parent().children('label')
                   .css('border', 'none')
                   .css('color', '#AAAAAA');
            }
        });

    },

    playSelected : function() {
        return $('[name="path"]:checked').trigger('startPlaying');
    },

    replaySelected : function() {
        return $('[name="path"]:checked').trigger('startReplaying');
    },

    hide : function() {
        $('.pathlist').css('display','none');
    },

    show : function() {
        $('.pathlist').show();
    }
};

var replayMode = {
    start : function (path) {
        pathlist.hide()
        // copy and reverse |events|
        this.events = path.events.slice().reverse();
        stdout.innerHTML = "REPLAY";
        game.load(path.startState);
        game.start()
        $(window).off('keyup keydown');
        $(window).keydown(this.kdown.bind(this));
        this.ticks = path.startTicks;
        this.ticker = window.setInterval(this.tick.bind(this), game.tickMillis);
    },

   stop : function () {
       clearInterval(this.ticker);
       pathlist.show();
       game.stop();
       pathlist.refreshPreview();
       mainMode.menu();
    },

    tick : function () {
        var stampedEvent = this.events[this.events.length - 1];
        while(stampedEvent && (stampedEvent.t <= this.ticks) &&
              (this.events.length > 0)) {
            stampedEvent = this.events.pop();
            var event = stampedEvent.e;
            switch (event.type) {
            case "keydown":
                game.kdown(event);
                break;
            case "keyup":
                game.kup(event);
                break;<commit_msg>press x to stop<commit_after>var game = zepto

var stdout;

function StampedEvent (ticks, event) {
    this.t = ticks;
    this.e = event;
};

function recordizeEvent(event) {
    return {"type": event.type,
            "keyCode": event.keyCode
           };
};


var pathlist = {

    addLocal : function (path) {

        var div = this.makeElement(path);

        if (path.endCheckpoint != "gameover") {
            $(div).children('input').prop('checked', true);
        }

        $('#pathlist').append(div);
        pathlist.refreshPreview();

        $.ajax({type:'POST',
                url:'newpath',
                data:JSON.stringify(path)
               })
           .done( function (data) {
           })
           .fail( function (xhr, status, thrown) {
               console.log('error: ' + thrown + " " + xhr.responseText);
           });
    },

    addRemote : function (path) {

        var div = this.makeElement(path);

        $('#remotepathlist').append(div);
    },


    // if path is null, make the 'Game Start' element
    makeElement : function (path) {
        var div = document.createElement('div');

        var input = document.createElement('input');
        $(input).attr('type', 'radio')
                .attr('name','path');

        if (!path) {
            this.gameStartRadioButton = input;
        }

        var endState = undefined;
        if (path) {
            endState = path.endState;
        }

        $(input).css('display', 'none');

        div.appendChild(input);

        // set up the preview
        $(input).change(function () {
            game.load(endState);
            game.render();
        });


        $(input).bind('startPlaying', function () {
            playMode.start(path);
        });

        $(input).bind('startReplaying', function () {
            if (path) {
                replayMode.start(path);
            }
        });

        var label = document.createElement('label');
        if (path) {
            label.innerHTML = path.username + ': from ' + path.startCheckpoint +
                ' at ' + path.startTicks + ' ticks ' +
                ' to ' + path.endCheckpoint +
                ' at ' + path.endTicks + ' ticks ';
            // + (new Date(path.startTime)).toUTCString();
        } else {
            label.innerHTML = "Game Start";
        }


        $(label).click(function (){
            $(input).prop('checked', true);
            pathlist.refreshPreview();
        });

        var closebutton = document.createElement('button');
        closebutton.innerHTML = '&times;';


        if (!path) {
            $(closebutton).prop('disabled', true);
        }


        $(closebutton).click(function () {
            var parent = $(this).parent();

            if (parent.children('input').is(":checked")) {
                pathlist.selectGameStart();
            }

            parent.slideUp(100, function () {
                parent.remove();
                pathlist.refreshPreview();
            });
        })


        div.appendChild(closebutton);

        div.appendChild(input);
        div.appendChild(label);

        return div;
    },

    gameStartRadioButton : null,

    selectGameStart : function () {
        $(this.gameStartRadioButton).prop('checked', true);
        pathlist.refreshPreview();
    },

    refreshPreview : function () {
        $('[name="path"]').each (function (idx, elt) {
            if ($(elt).is(':checked')) {
                $(elt).trigger('change');
                $(elt).parent().children('label')
                   .css('border', '1px solid')
                   .css('color', '#FFFFFF');
            } else {
                $(elt).parent().children('label')
                   .css('border', 'none')
                   .css('color', '#AAAAAA');
            }
        });

    },

    playSelected : function() {
        return $('[name="path"]:checked').trigger('startPlaying');
    },

    replaySelected : function() {
        return $('[name="path"]:checked').trigger('startReplaying');
    },

    hide : function() {
        $('.pathlist').css('display','none');
    },

    show : function() {
        $('.pathlist').show();
    }
};

var replayMode = {
    start : function (path) {
        pathlist.hide()
        // copy and reverse |events|
        this.events = path.events.slice().reverse();
        stdout.innerHTML = "REPLAY. Press 'X' to stop.";
        game.load(path.startState);
        game.start()
        $(window).off('keyup keydown');
        $(window).keydown(this.kdown.bind(this));
        this.ticks = path.startTicks;
        this.ticker = window.setInterval(this.tick.bind(this), game.tickMillis);
    },

   stop : function () {
       clearInterval(this.ticker);
       pathlist.show();
       game.stop();
       pathlist.refreshPreview();
       mainMode.menu();
    },

    tick : function () {
        var stampedEvent = this.events[this.events.length - 1];
        while(stampedEvent && (stampedEvent.t <= this.ticks) &&
              (this.events.length > 0)) {
            stampedEvent = this.events.pop();
            var event = stampedEvent.e;
            switch (event.type) {
            case "keydown":
                game.kdown(event);
                break;
            case "keyup":
                game.kup(event);
                break;
{'fraction_non_alphanumeric': 0.15935508061492312, 'fraction_numerical': 0.0011248593925759281, 'mean_word_length': 1.6513419483101393, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 5, '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': '5957605', 'n_tokens_mistral': 3031, 'n_tokens_neox': 2867, 'n_words': 520}