format input.js according to new guidelines
Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
parent
096d8770f2
commit
80c446da3d
1 changed files with 208 additions and 214 deletions
30
js/input.js
30
js/input.js
|
@ -95,7 +95,7 @@ window.onmousedown = (evn) => {
|
|||
const onhold = (key) => () => {
|
||||
if (_double_click_timeout[key]) {
|
||||
// ondclick event
|
||||
['window', 'canvas', 'world'].forEach((ctx) =>
|
||||
["window", "canvas", "world"].forEach((ctx) =>
|
||||
mouse.listen[ctx][key].ondclick.emit({
|
||||
target: evn.target,
|
||||
buttonId: evn.button,
|
||||
|
@ -114,7 +114,7 @@ window.onmousedown = (evn) => {
|
|||
|
||||
// Set drag start timeout
|
||||
_drag_start_timeout[key] = setTimeout(() => {
|
||||
['window', 'canvas', 'world'].forEach((ctx) => {
|
||||
["window", "canvas", "world"].forEach((ctx) => {
|
||||
mouse.listen[ctx][key].ondragstart.emit({
|
||||
target: evn.target,
|
||||
buttonId: evn.button,
|
||||
|
@ -122,14 +122,13 @@ window.onmousedown = (evn) => {
|
|||
y: mouse[ctx].pos.y,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
if (mouse[ctx].dragging[key])
|
||||
mouse[ctx].dragging[key].drag = true;
|
||||
if (mouse[ctx].dragging[key]) mouse[ctx].dragging[key].drag = true;
|
||||
|
||||
delete _drag_start_timeout[key];
|
||||
});
|
||||
}, inputConfig.clickTiming);
|
||||
|
||||
['window', 'canvas', 'world'].forEach((ctx) => {
|
||||
["window", "canvas", "world"].forEach((ctx) => {
|
||||
mouse.buttons[key] = time;
|
||||
mouse[ctx].dragging[key] = {};
|
||||
Object.assign(mouse[ctx].dragging[key], mouse[ctx].pos);
|
||||
|
@ -146,7 +145,7 @@ window.onmousedown = (evn) => {
|
|||
};
|
||||
|
||||
// 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]();
|
||||
};
|
||||
|
@ -156,7 +155,7 @@ window.onmouseup = (evn) => {
|
|||
|
||||
// Processes for a named button
|
||||
const onrelease = (key) => () => {
|
||||
['window', 'canvas', 'world'].forEach((ctx) => {
|
||||
["window", "canvas", "world"].forEach((ctx) => {
|
||||
const start = {
|
||||
x: mouse[ctx].dragging[key].x,
|
||||
y: mouse[ctx].dragging[key].y,
|
||||
|
@ -169,8 +168,7 @@ window.onmouseup = (evn) => {
|
|||
if (
|
||||
time.getTime() - mouse.buttons[key].getTime() <
|
||||
inputConfig.clickTiming &&
|
||||
dx * dx + dy * dy <
|
||||
inputConfig.clickRadius * inputConfig.clickRadius
|
||||
dx * dx + dy * dy < inputConfig.clickRadius * inputConfig.clickRadius
|
||||
)
|
||||
mouse.listen[ctx][key].onclick.emit({
|
||||
target: evn.target,
|
||||
|
@ -210,11 +208,7 @@ window.onmouseup = (evn) => {
|
|||
};
|
||||
|
||||
// Runs the correct handler
|
||||
const buttons = [
|
||||
onrelease('left'),
|
||||
onrelease('middle'),
|
||||
onrelease('right'),
|
||||
];
|
||||
const buttons = [onrelease("left"), onrelease("middle"), onrelease("right")];
|
||||
|
||||
buttons[evn.button] && buttons[evn.button]();
|
||||
};
|
||||
|
@ -225,18 +219,18 @@ window.onmousemove = (evn) => {
|
|||
mouse.window.pos = {x: evn.clientX, y: evn.clientY};
|
||||
|
||||
// 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);
|
||||
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)
|
||||
if (evn.target.id === 'overlayCanvas') {
|
||||
if (evn.target.id === "overlayCanvas") {
|
||||
Object.assign(mouse.world.prev, mouse.world.pos);
|
||||
mouse.world.pos = {x: evn.layerX, y: evn.layerY};
|
||||
}
|
||||
|
||||
['window', 'canvas', 'world'].forEach((ctx) => {
|
||||
["window", "canvas", "world"].forEach((ctx) => {
|
||||
mouse.listen[ctx].onmousemove.emit({
|
||||
target: evn.target,
|
||||
px: mouse[ctx].prev.x,
|
||||
|
@ -245,7 +239,7 @@ window.onmousemove = (evn) => {
|
|||
y: mouse[ctx].pos.y,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
['left', 'middle', 'right'].forEach((key) => {
|
||||
["left", "middle", "right"].forEach((key) => {
|
||||
// ondrag event
|
||||
if (mouse[ctx].dragging[key] && mouse[ctx].dragging[key].drag)
|
||||
mouse.listen[ctx][key].ondrag.emit({
|
||||
|
|
Loading…
Reference in a new issue