game_actor_component_input_component.js

import ActorComponent from "./actor_component.js";
import InputManager from "../../../input/input_manager.js";

/**
 * @module InputComponent
 * @fileoverview Contains InputComponent class.
 */

/**
 * Actor component for handling input.
 * @class
 * @extends ActorComponent
 */
class InputComponent extends ActorComponent {
    /**
     * Create a new input component.
     * @param {function} customCondition Function for checking if input manager should run events
     * @constructor
     */
    constructor(customCondition = null) {
        super();

        let condition = () => this.actor.space === $$.app.space;

        if (customCondition !== null)
            condition = () => customCondition() && this.actor.space === $$.app.space;

        this._input = new InputManager({
            condition: condition
        });
    }

    destructor() {
        super.destructor();

        this._input.destructor();
    }


    // Getters

    /**
     * Get the keyboard input handler.
     * @returns {KeyboardHandler} Keyboard input handler
     */
    get keyboard() {
        return this._input.keyboard;
    }

    /**
     * Get the mouse input handler.
     * @returns {MouseHandler} Mouse input handler.
     */
    get mouse() {
        return this._input.mouse;
    }
}

export default InputComponent;