tslint changes

This commit is contained in:
Jeremy Simpson
2019-08-30 01:52:40 -07:00
parent 7603879d35
commit 7f7efbb94b
446 changed files with 70650 additions and 70661 deletions
+73 -73
View File
@@ -5,83 +5,83 @@ import { clamp } from '../../common/utils';
const MOUSE_BUTTONS = [Key.MOUSE_BUTTON1, Key.MOUSE_BUTTON3, Key.MOUSE_BUTTON2];
export class MouseController implements InputController {
private initialized = false;
private element?: HTMLElement;
constructor(private manager: InputManager) {
}
initialize(element: HTMLElement) {
if (!this.initialized) {
this.initialized = true;
this.element = element;
element.addEventListener('mousemove', this.mousemove);
element.addEventListener('mousedown', this.mousedown);
element.addEventListener('mouseup', this.mouseup);
element.addEventListener('mousewheel', this.mousewheel);
element.addEventListener('contextmenu', this.contextmenu);
element.addEventListener('click', this.click);
window.addEventListener('blur', this.blur);
}
}
release() {
this.initialized = false;
private initialized = false;
private element?: HTMLElement;
constructor(private manager: InputManager) {
}
initialize(element: HTMLElement) {
if (!this.initialized) {
this.initialized = true;
this.element = element;
element.addEventListener('mousemove', this.mousemove);
element.addEventListener('mousedown', this.mousedown);
element.addEventListener('mouseup', this.mouseup);
element.addEventListener('mousewheel', this.mousewheel);
element.addEventListener('contextmenu', this.contextmenu);
element.addEventListener('click', this.click);
window.addEventListener('blur', this.blur);
}
}
release() {
this.initialized = false;
if (this.element) {
this.element.removeEventListener('mousemove', this.mousemove);
this.element.removeEventListener('mousedown', this.mousedown);
this.element.removeEventListener('mouseup', this.mouseup);
this.element.removeEventListener('mousewheel', this.mousewheel);
this.element.removeEventListener('contextmenu', this.contextmenu);
this.element.removeEventListener('click', this.click);
this.element = undefined;
}
if (this.element) {
this.element.removeEventListener('mousemove', this.mousemove);
this.element.removeEventListener('mousedown', this.mousedown);
this.element.removeEventListener('mouseup', this.mouseup);
this.element.removeEventListener('mousewheel', this.mousewheel);
this.element.removeEventListener('contextmenu', this.contextmenu);
this.element.removeEventListener('click', this.click);
this.element = undefined;
}
window.removeEventListener('blur', this.blur);
}
update() {
}
clear() {
}
private mousemove = (e: MouseEvent) => {
if (this.element) {
const rect = this.element.getBoundingClientRect();
this.manager.setValue(Key.MOUSE_X, Math.floor(e.clientX - rect.left));
this.manager.setValue(Key.MOUSE_Y, Math.floor(e.clientY - rect.top));
}
}
private mousedown = (e: MouseEvent) => {
e.preventDefault();
e.stopPropagation();
window.removeEventListener('blur', this.blur);
}
update() {
}
clear() {
}
private mousemove = (e: MouseEvent) => {
if (this.element) {
const rect = this.element.getBoundingClientRect();
this.manager.setValue(Key.MOUSE_X, Math.floor(e.clientX - rect.left));
this.manager.setValue(Key.MOUSE_Y, Math.floor(e.clientY - rect.top));
}
}
private mousedown = (e: MouseEvent) => {
e.preventDefault();
e.stopPropagation();
this.manager.usingTouch = false;
this.manager.usingTouch = false;
const button = MOUSE_BUTTONS[e.button];
const button = MOUSE_BUTTONS[e.button];
if (button) {
this.manager.setValue(button, 1);
}
}
private mouseup = (e: MouseEvent) => {
const button = MOUSE_BUTTONS[e.button];
if (button) {
this.manager.setValue(button, 1);
}
}
private mouseup = (e: MouseEvent) => {
const button = MOUSE_BUTTONS[e.button];
if (button) {
this.manager.setValue(button, 0);
}
}
private mousewheel: any = (e: MouseWheelEvent) => {
this.manager.addValue(Key.MOUSE_WHEEL_X, clamp(e.deltaX, -1, 1));
this.manager.addValue(Key.MOUSE_WHEEL_Y, clamp(e.deltaY, -1, 1));
}
private contextmenu = (e: Event) => {
e.preventDefault();
e.stopPropagation();
}
private click = (e: Event) => {
e.preventDefault();
e.stopPropagation();
}
private blur = () => {
for (const button of MOUSE_BUTTONS) {
this.manager.setValue(button, 0);
}
}
if (button) {
this.manager.setValue(button, 0);
}
}
private mousewheel: any = (e: MouseWheelEvent) => {
this.manager.addValue(Key.MOUSE_WHEEL_X, clamp(e.deltaX, -1, 1));
this.manager.addValue(Key.MOUSE_WHEEL_Y, clamp(e.deltaY, -1, 1));
}
private contextmenu = (e: Event) => {
e.preventDefault();
e.stopPropagation();
}
private click = (e: Event) => {
e.preventDefault();
e.stopPropagation();
}
private blur = () => {
for (const button of MOUSE_BUTTONS) {
this.manager.setValue(button, 0);
}
}
}