change doubleclick to also register double-touch

closes #21
This commit is contained in:
HF 2022-07-11 21:47:52 +02:00
parent 4182f1a6e3
commit 393369a9b8
2 changed files with 41 additions and 0 deletions

View File

@ -151,6 +151,9 @@ document.addEventListener('DOMContentLoaded', () => {
window.addEventListener('resize', onWindowResize, false);
/*
* update coords
*/
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
const coorbox = document.getElementById('coorbox');
@ -184,6 +187,9 @@ document.addEventListener('DOMContentLoaded', () => {
setInterval(onDocumentMouseMove, 1000);
/*
* double click to teleport to canvas
*/
function onDocumentDblClick(event) {
if (!object) {
return;
@ -202,6 +208,33 @@ document.addEventListener('DOMContentLoaded', () => {
}
}
/*
* detect double-touch on touchscreen
*/
let lastClick = 0;
const lastCoords = [0, 0];
function onTouch(event) {
if (event.touches.length > 1) {
lastClick = 0;
return;
}
const now = Date.now();
const { pageX: mx, pageY: my } = event.touches[0];
if (lastClick > now - 500
&& (lastCoords[0] - mx) ** 2 + (lastCoords[1] - my) ** 2 < 400
) {
event.clientX = mx;
event.clientY = my;
onDocumentDblClick(event);
return;
}
lastClick = now;
lastCoords[0] = mx;
lastCoords[1] = my;
}
document.addEventListener('mousemove', onDocumentMouseMove, false);
// document.addEventListener('dblclick', onDocumentDblClick, false);
document.addEventListener('touchstart', onTouch, false);
document.addEventListener('dblclick', onDocumentDblClick, false);
});

View File

@ -77,7 +77,15 @@ export function buildWebpackClientConfig(
resolve: {
alias: {
/*
* have to mock it, because we don't ship ttag itself with the client,
* we have a script for every language
*/
ttag: 'ttag/dist/mock',
/*
* if we don't do that,we might load different versions of three
*/
three: path.resolve(__dirname, './node_modules/three'),
},
extensions: ['.js', '.jsx'],
},