<commit_before>﻿function userInput(args) {
    var keys = [];
    var keysPressed = 0;
    var mouseCoordinates = { x: 0, y: 0 };

    var keyDown = function (e) {
        if (keys.indexOf(e.which) == -1)
            keys.push(e.which);

        notifyKeysChanged();
    };

    var keyUp = function (e) {
        keys.splice(keys.indexOf(e.which), 1);
        notifyKeysChanged();
    };

    function notifyKeysChanged() {
        var newKeys = buildDirectionKey();

        keysPressed = newKeys;
        var mouse = { x: mouseCoordinates.x, y: mouseCoordinates.y };

        args.inputChanged({ direction: keysPressed, mouse: mouse });
    }

    function buildDirectionKey() {
        var keyPressed = keys.reduce(function (prev, current) {
            if (current === 87 || current === 119 || current === 38 || current === 3)
                return prev | keysInput.Up;

            if (current === 83 || current === 115 || current === 40 || current === 2)
                return prev | keysInput.Down;

            if (current === 65 || current === 97 || current === 37 || current === 5)
                return prev | keysInput.Left;

            if (current === 68 || current === 100 || current === 39 || current === 4)
                return prev | keysInput.Right;

            if (current === 1)
                return prev | keysInput.MouseLeft;
        }, 0);

        return keyPressed;
    }

    function mouseMove(e) {
        var targetRect = document.getElementById("arena").children[0].getBoundingClientRect();
        mouseCoordinates = { x: e.clientX - targetRect.left, y: e.clientY - targetRect.top };

        notifyKeysChanged();
    }

    function mouseDown(e) {
        if ((e.buttons && 1) && (keys.indexOf(1) === -1)) {
            keys.push(1);
        }
        notifyKeysChanged();
    }

    function mouseUp(e) {
        if (keys.indexOf(1) >= 0) {
            keys.splice(keys.indexOf(1), 1);
        }
        notifyKeysChanged();
    }

    var mainTouch = null;
    function touchStart(e) {
        if (mainTouch) return;
        var touch = e.changedTouches[0];
        mainTouch = copyTouch(touch);
    }

    function touchEnd(e) {
        for (var i = 0; i < e.changedTouches.length; i++) {
            var touch = e.changedTouches[i];
            if (mainTouch && mainTouch.identifier === touch.identifier) {
                mainTouch = null;
                keys.splice(keys.indexOf(2));
                keys.splice(keys.indexOf(3));
                keys.splice(keys.indexOf(4));
                keys.splice(keys.indexOf(5));
                notifyKeysChanged();
                return;
            }
        }
    }

    function touchCancel(e) {
        touchEnd(e);
    }

    function touchMove(e) {
        if (!mainTouch) return;

        var ongoingTouch = null;
        for (var i = 0; i < e.changedTouches.length; i++) {
            var t = e.changedTouches[i];
            if (mainTouch.identifier === t.identifier) {
                ongoingTouch = t;
                break;
            }
        }

        keys.splice(keys.indexOf(2));
        keys.splice(keys.indexOf(3));
        keys.splice(keys.indexOf(4));
        keys.splice(keys.indexOf(5));

        if (ongoingTouch.pageY > mainTouch.pageY + 10) {
            keys.push(2);
        }
        if (ongoingTouch.pageY < mainTouch.pageY - 10) {
            keys.push(3);
        }
        if (ongoingTouch.pageX > mainTouch.pageX + 10) {<commit_msg>stop event propagation when touch handling<commit_after>﻿function userInput(args) {
    var keys = [];
    var keysPressed = 0;
    var mouseCoordinates = { x: 0, y: 0 };

    var keyDown = function (e) {
        if (keys.indexOf(e.which) == -1)
            keys.push(e.which);

        notifyKeysChanged();
    };

    var keyUp = function (e) {
        keys.splice(keys.indexOf(e.which), 1);
        notifyKeysChanged();
    };

    function notifyKeysChanged() {
        var newKeys = buildDirectionKey();

        keysPressed = newKeys;
        var mouse = { x: mouseCoordinates.x, y: mouseCoordinates.y };

        args.inputChanged({ direction: keysPressed, mouse: mouse });
    }

    function buildDirectionKey() {
        var keyPressed = keys.reduce(function (prev, current) {
            if (current === 87 || current === 119 || current === 38 || current === 3)
                return prev | keysInput.Up;

            if (current === 83 || current === 115 || current === 40 || current === 2)
                return prev | keysInput.Down;

            if (current === 65 || current === 97 || current === 37 || current === 5)
                return prev | keysInput.Left;

            if (current === 68 || current === 100 || current === 39 || current === 4)
                return prev | keysInput.Right;

            if (current === 1)
                return prev | keysInput.MouseLeft;
        }, 0);

        return keyPressed;
    }

    function mouseMove(e) {
        var targetRect = document.getElementById("arena").children[0].getBoundingClientRect();
        mouseCoordinates = { x: e.clientX - targetRect.left, y: e.clientY - targetRect.top };

        notifyKeysChanged();
    }

    function mouseDown(e) {
        if ((e.buttons && 1) && (keys.indexOf(1) === -1)) {
            keys.push(1);
        }
        notifyKeysChanged();
    }

    function mouseUp(e) {
        if (keys.indexOf(1) >= 0) {
            keys.splice(keys.indexOf(1), 1);
        }
        notifyKeysChanged();
    }

    var mainTouch = null;
    function touchStart(e) {
        if (mainTouch) return;

        e.preventDefault();
        var touch = e.changedTouches[0];
        mainTouch = copyTouch(touch);
    }

    function touchEnd(e) {
        for (var i = 0; i < e.changedTouches.length; i++) {
            var touch = e.changedTouches[i];
            if (mainTouch && mainTouch.identifier === touch.identifier) {
                e.preventDefault();
                mainTouch = null;
                keys.splice(keys.indexOf(2));
                keys.splice(keys.indexOf(3));
                keys.splice(keys.indexOf(4));
                keys.splice(keys.indexOf(5));
                notifyKeysChanged();
                return;
            }
        }
    }

    function touchCancel(e) {
        touchEnd(e);
    }

    function touchMove(e) {
        if (!mainTouch) return;

        e.preventDefault();
        var ongoingTouch = null;
        for (var i = 0; i < e.changedTouches.length; i++) {
            var t = e.changedTouches[i];
            if (mainTouch.identifier === t.identifier) {
                ongoingTouch = t;
                break;
            }
        }

        keys.splice(keys.indexOf(2));
        keys.splice(keys.indexOf(3));
        keys.splice(keys.indexOf(4));
        keys.splice(keys.indexOf(5));

        if (ongoingTouch.pageY > mainTouch.pageY + 10) {
            keys.push(2);
        }
        if (ongoingTouch.pageY < mainTouch.pageY - 10) {
            keys.push(3);
        }
        if (ongoingTouch.pageX > mainTouch.pageX + 10) {
{'fraction_non_alphanumeric': 0.1382344592676696, 'fraction_numerical': 0.018734033494181096, 'mean_word_length': 1.7388262728332686, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2467982', 'n_tokens_mistral': 2185, 'n_tokens_neox': 2016, 'n_words': 454}