v1.2
This commit is contained in:
parent
f500279abd
commit
cefa2ace5a
27 changed files with 1275 additions and 314 deletions
|
|
@ -5,12 +5,18 @@
|
|||
if (!ctx?.canvas) return false;
|
||||
const { canvas, world, uiCache } = ctx;
|
||||
ctx.bindMobileModeControls();
|
||||
const isMobileAutoScrollMode = () => {
|
||||
const mode = ctx.mobileInputMode?.() || "auto";
|
||||
const touchMobile = document.body.classList.contains("touch-mobile-ui") || window.matchMedia?.("(max-width: 980px)")?.matches;
|
||||
return touchMobile && mode === "auto" && (!world.tool || world.tool === "observe");
|
||||
};
|
||||
|
||||
canvas.addEventListener("touchstart", (e) => {
|
||||
if (!e.touches?.length) return;
|
||||
e.preventDefault();
|
||||
uiCache.touchMoved = false;
|
||||
const mode = ctx.mobileInputMode();
|
||||
const autoPageScroll = isMobileAutoScrollMode();
|
||||
if (!autoPageScroll) e.preventDefault();
|
||||
if (mode === "camera" && e.touches.length === 1) {
|
||||
const t = e.touches[0];
|
||||
uiCache.touchStartX = t.clientX;
|
||||
|
|
@ -62,12 +68,12 @@
|
|||
return;
|
||||
}
|
||||
if (world.tool === "pinch" && p.inside && ctx.beginGrab(p, t.clientX, t.clientY, { touchMode: "grab" })) return;
|
||||
uiCache.touchMode = mode === "tool" ? "toolTapOnly" : "panOrTap";
|
||||
uiCache.touchMode = autoPageScroll ? "autoTapOrScroll" : (mode === "tool" ? "toolTapOnly" : "panOrTap");
|
||||
}, { passive: false });
|
||||
|
||||
canvas.addEventListener("touchmove", (e) => {
|
||||
if (!e.touches?.length || !uiCache.touchMode) return;
|
||||
e.preventDefault();
|
||||
if (uiCache.touchMode !== "autoTapOrScroll") e.preventDefault();
|
||||
if (uiCache.touchMode === "pinchZoom" && e.touches.length >= 2) {
|
||||
const c = ctx.touchCenter(e.touches);
|
||||
const distNow = Math.max(1, ctx.touchDistance(e.touches));
|
||||
|
|
@ -116,6 +122,10 @@
|
|||
ctx.moveGrab(p, t.clientX, t.clientY, { touch: true, renderFrame: true });
|
||||
return;
|
||||
}
|
||||
if (uiCache.touchMode === "autoTapOrScroll") {
|
||||
if (totalMove > 7) uiCache.touchMoved = true;
|
||||
return;
|
||||
}
|
||||
if (uiCache.touchMode === "panOrTap") {
|
||||
if (totalMove > 7) {
|
||||
uiCache.touchMoved = true;
|
||||
|
|
@ -126,7 +136,7 @@
|
|||
}, { passive: false });
|
||||
|
||||
canvas.addEventListener("touchend", (e) => {
|
||||
e.preventDefault();
|
||||
if (uiCache.touchMode !== "autoTapOrScroll") e.preventDefault();
|
||||
if (uiCache.areaDeleting) ctx.endAreaDelete();
|
||||
if (uiCache.hosing) { ctx.endHose(); if (uiCache.hoseHoldTimer) { clearInterval(uiCache.hoseHoldTimer); uiCache.hoseHoldTimer = null; } }
|
||||
if (uiCache.shooting) ctx.endShoot();
|
||||
|
|
@ -138,6 +148,13 @@
|
|||
window.TarinaiCommands?.dispatch?.(world, { type: "pointer.primary", x: p.x, y: p.y });
|
||||
renderStats();
|
||||
}
|
||||
} else if (uiCache.touchMode === "autoTapOrScroll" && !uiCache.touchMoved) {
|
||||
e.preventDefault();
|
||||
const p = ctx.screenToWorldClient(uiCache.touchLastX || uiCache.touchStartX, uiCache.touchLastY || uiCache.touchStartY);
|
||||
if (p.inside) {
|
||||
window.TarinaiCommands?.dispatch?.(world, { type: "pointer.primary", x: p.x, y: p.y });
|
||||
renderStats();
|
||||
}
|
||||
} else if (uiCache.touchMode === "panOrTap" && !uiCache.touchMoved) {
|
||||
const p = ctx.screenToWorldClient(uiCache.touchLastX || uiCache.touchStartX, uiCache.touchLastY || uiCache.touchStartY);
|
||||
if (p.inside) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue