format input.js according to new guidelines

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
Victor Seiji Hariki 2022-11-21 00:02:25 -03:00
parent 096d8770f2
commit 80c446da3d

View file

@ -95,7 +95,7 @@ window.onmousedown = (evn) => {
const onhold = (key) => () => { const onhold = (key) => () => {
if (_double_click_timeout[key]) { if (_double_click_timeout[key]) {
// ondclick event // ondclick event
['window', 'canvas', 'world'].forEach((ctx) => ["window", "canvas", "world"].forEach((ctx) =>
mouse.listen[ctx][key].ondclick.emit({ mouse.listen[ctx][key].ondclick.emit({
target: evn.target, target: evn.target,
buttonId: evn.button, buttonId: evn.button,
@ -114,7 +114,7 @@ window.onmousedown = (evn) => {
// Set drag start timeout // Set drag start timeout
_drag_start_timeout[key] = setTimeout(() => { _drag_start_timeout[key] = setTimeout(() => {
['window', 'canvas', 'world'].forEach((ctx) => { ["window", "canvas", "world"].forEach((ctx) => {
mouse.listen[ctx][key].ondragstart.emit({ mouse.listen[ctx][key].ondragstart.emit({
target: evn.target, target: evn.target,
buttonId: evn.button, buttonId: evn.button,
@ -122,14 +122,13 @@ window.onmousedown = (evn) => {
y: mouse[ctx].pos.y, y: mouse[ctx].pos.y,
timestamp: new Date(), timestamp: new Date(),
}); });
if (mouse[ctx].dragging[key]) if (mouse[ctx].dragging[key]) mouse[ctx].dragging[key].drag = true;
mouse[ctx].dragging[key].drag = true;
delete _drag_start_timeout[key]; delete _drag_start_timeout[key];
}); });
}, inputConfig.clickTiming); }, inputConfig.clickTiming);
['window', 'canvas', 'world'].forEach((ctx) => { ["window", "canvas", "world"].forEach((ctx) => {
mouse.buttons[key] = time; mouse.buttons[key] = time;
mouse[ctx].dragging[key] = {}; mouse[ctx].dragging[key] = {};
Object.assign(mouse[ctx].dragging[key], mouse[ctx].pos); Object.assign(mouse[ctx].dragging[key], mouse[ctx].pos);
@ -146,7 +145,7 @@ window.onmousedown = (evn) => {
}; };
// Runs the correct handler // Runs the correct handler
const buttons = [onhold('left'), onhold('middle'), onhold('right')]; const buttons = [onhold("left"), onhold("middle"), onhold("right")];
buttons[evn.button] && buttons[evn.button](); buttons[evn.button] && buttons[evn.button]();
}; };
@ -156,7 +155,7 @@ window.onmouseup = (evn) => {
// Processes for a named button // Processes for a named button
const onrelease = (key) => () => { const onrelease = (key) => () => {
['window', 'canvas', 'world'].forEach((ctx) => { ["window", "canvas", "world"].forEach((ctx) => {
const start = { const start = {
x: mouse[ctx].dragging[key].x, x: mouse[ctx].dragging[key].x,
y: mouse[ctx].dragging[key].y, y: mouse[ctx].dragging[key].y,
@ -169,8 +168,7 @@ window.onmouseup = (evn) => {
if ( if (
time.getTime() - mouse.buttons[key].getTime() < time.getTime() - mouse.buttons[key].getTime() <
inputConfig.clickTiming && inputConfig.clickTiming &&
dx * dx + dy * dy < dx * dx + dy * dy < inputConfig.clickRadius * inputConfig.clickRadius
inputConfig.clickRadius * inputConfig.clickRadius
) )
mouse.listen[ctx][key].onclick.emit({ mouse.listen[ctx][key].onclick.emit({
target: evn.target, target: evn.target,
@ -210,11 +208,7 @@ window.onmouseup = (evn) => {
}; };
// Runs the correct handler // Runs the correct handler
const buttons = [ const buttons = [onrelease("left"), onrelease("middle"), onrelease("right")];
onrelease('left'),
onrelease('middle'),
onrelease('right'),
];
buttons[evn.button] && buttons[evn.button](); buttons[evn.button] && buttons[evn.button]();
}; };
@ -222,21 +216,21 @@ window.onmouseup = (evn) => {
window.onmousemove = (evn) => { window.onmousemove = (evn) => {
// Set Window Coordinates // Set Window Coordinates
Object.assign(mouse.window.prev, mouse.window.pos); Object.assign(mouse.window.prev, mouse.window.pos);
mouse.window.pos = { x: evn.clientX, y: evn.clientY }; mouse.window.pos = {x: evn.clientX, y: evn.clientY};
// Set Canvas Coordinates (using overlay canvas as reference) // Set Canvas Coordinates (using overlay canvas as reference)
if (evn.target.id === 'overlayCanvas') { if (evn.target.id === "overlayCanvas") {
Object.assign(mouse.canvas.prev, mouse.canvas.pos); Object.assign(mouse.canvas.prev, mouse.canvas.pos);
mouse.canvas.pos = { x: evn.layerX, y: evn.layerY }; mouse.canvas.pos = {x: evn.layerX, y: evn.layerY};
} }
// Set World Coordinates (For now the same as canvas coords; Will be useful with infinite canvas) // Set World Coordinates (For now the same as canvas coords; Will be useful with infinite canvas)
if (evn.target.id === 'overlayCanvas') { if (evn.target.id === "overlayCanvas") {
Object.assign(mouse.world.prev, mouse.world.pos); Object.assign(mouse.world.prev, mouse.world.pos);
mouse.world.pos = { x: evn.layerX, y: evn.layerY }; mouse.world.pos = {x: evn.layerX, y: evn.layerY};
} }
['window', 'canvas', 'world'].forEach((ctx) => { ["window", "canvas", "world"].forEach((ctx) => {
mouse.listen[ctx].onmousemove.emit({ mouse.listen[ctx].onmousemove.emit({
target: evn.target, target: evn.target,
px: mouse[ctx].prev.x, px: mouse[ctx].prev.x,
@ -245,7 +239,7 @@ window.onmousemove = (evn) => {
y: mouse[ctx].pos.y, y: mouse[ctx].pos.y,
timestamp: new Date(), timestamp: new Date(),
}); });
['left', 'middle', 'right'].forEach((key) => { ["left", "middle", "right"].forEach((key) => {
// ondrag event // ondrag event
if (mouse[ctx].dragging[key] && mouse[ctx].dragging[key].drag) if (mouse[ctx].dragging[key] && mouse[ctx].dragging[key].drag)
mouse.listen[ctx][key].ondrag.emit({ mouse.listen[ctx][key].ondrag.emit({