<commit_before>/// <reference path="Interface.ts" />
/// <reference path="../Core/Interface.ts" />
/// <reference path="../Core/Worker.ts" />
/// <reference path="../Core/GameLauncher.ts" />

module TameGame {
    /**
     * Sends mouse input from an HTML element to a particular game worker
     */
    export var attachMouseInput = (canvas: HTMLElement, targetWorker: Worker) => {
        // We eventually generate a way to stop the mouse input
        var detachMouseInput: Cancellable;

        // When the pointer is over the control, it has a pressure of 1.0
        // (This allows for the game to track the pointer and also detect enter/leave events)
        var pointerPressure = 0.0;

        // Function to send a mouse event to the worker
        var sendMouseEvent = (control: string, location: number[], pressure: number) => {
            var mouseMessage: WorkerMessage = {
                action: workerMessages.inputControl,
                data: {
                    input: {
                        device:     controlDevice.mouse,
                        control:    control,
                        pressure:   pressure,
                        location:   location,
                        when:       perf.now()
                    }
                }
            }

            targetWorker.postMessage(mouseMessage);
        }

        // Function to return the position relative to the canvas as a whole (from 0,0 to 1,1)
        var getPosition = (evt: MouseEvent): number[] => {
            var clientPos   = [ evt.clientX, evt.clientY ];
            var canvasSize  = [ canvas.offsetWidth, canvas.offsetHeight ];
            var relativePos = [ clientPos[0]/canvasSize[0], clientPos[1]/canvasSize[1] ];

            return relativePos;
        }

        // Function to determine the control that a particular button maps to
        var controlForButton = (button: number): string => {
            switch (button) {
                case 0:
                    return mouseControl.button1;
                case 1:
                    return mouseControl.button2;
                case 2:
                    return mouseControl.button3;
                case 3:
                    return mouseControl.button4;
                case 4:<commit_msg>Want to use offsetX rather than clientX when reading mouse coordinates<commit_after>/// <reference path="Interface.ts" />
/// <reference path="../Core/Interface.ts" />
/// <reference path="../Core/Worker.ts" />
/// <reference path="../Core/GameLauncher.ts" />

module TameGame {
    /**
     * Sends mouse input from an HTML element to a particular game worker
     */
    export var attachMouseInput = (canvas: HTMLElement, targetWorker: Worker) => {
        // We eventually generate a way to stop the mouse input
        var detachMouseInput: Cancellable;

        // When the pointer is over the control, it has a pressure of 1.0
        // (This allows for the game to track the pointer and also detect enter/leave events)
        var pointerPressure = 0.0;

        // Function to send a mouse event to the worker
        var sendMouseEvent = (control: string, location: number[], pressure: number) => {
            var mouseMessage: WorkerMessage = {
                action: workerMessages.inputControl,
                data: {
                    input: {
                        device:     controlDevice.mouse,
                        control:    control,
                        pressure:   pressure,
                        location:   location,
                        when:       perf.now()
                    }
                }
            }

            targetWorker.postMessage(mouseMessage);
        }

        // Function to return the position relative to the canvas as a whole (from 0,0 to 1,1)
        var getPosition = (evt: MouseEvent): number[] => {
            var clientPos   = [ evt.offsetX, evt.offsetY ];
            var canvasSize  = [ canvas.offsetWidth, canvas.offsetHeight ];
            var relativePos = [ clientPos[0]/canvasSize[0], clientPos[1]/canvasSize[1] ];

            return relativePos;
        }

        // Function to determine the control that a particular button maps to
        var controlForButton = (button: number): string => {
            switch (button) {
                case 0:
                    return mouseControl.button1;
                case 1:
                    return mouseControl.button2;
                case 2:
                    return mouseControl.button3;
                case 3:
                    return mouseControl.button4;
                case 4:
{'fraction_non_alphanumeric': 0.08950684336302411, 'fraction_numerical': 0.009124484032152944, 'mean_word_length': 1.5338470005503577, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '3073949', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1072, 'n_words': 367}