From 8e8f89068f1b518b3ed2df41e877c87184a11e9c Mon Sep 17 00:00:00 2001 From: Alexander Guryanov Date: Sat, 6 Jul 2024 11:23:33 +0700 Subject: [PATCH] v8.1.14, #304: fix regression in capture mode --- index.html | 1 + package.json | 2 +- src/window/dos/controls/mouse/mount.ts | 11 +++----- .../dos/controls/mouse/mouse-not-locked.ts | 12 ++++----- src/window/dos/controls/mouse/mouse-swipe.ts | 27 ++++++++++++------- 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/index.html b/index.html index 4d686ec4..b8eea291 100644 --- a/index.html +++ b/index.html @@ -36,6 +36,7 @@ // url: "https://cdn.dos.zone/original/2X/7/744842062905f72648a4d492ccc2526d039b3702.jsdos", // sim-city // url: "https://cdn.dos.zone/custom/dos/war2.jsdos", // warcraft-2 // url: "https://cdn.dos.zone/original/2X/5/5f21f221e023bbca253396824c5f652438eeef8c.jsdos", // поле чудес + // url: "https://cdn.dos.zone/custom/dos/homm_2.jsdos", // dosboxConf: diabloConf, // loginUrl: "http://localhost:8080/subscription.html", // autoStart: true, diff --git a/package.json b/package.json index 114cdb37..d6ef543e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-dos", - "version": "8.1.12", + "version": "8.1.14", "description": "Full-featured DOS player with multiple emulator backends", "type": "module", "keywords": [ diff --git a/src/window/dos/controls/mouse/mount.ts b/src/window/dos/controls/mouse/mount.ts index fe5dd555..8d2d306b 100644 --- a/src/window/dos/controls/mouse/mount.ts +++ b/src/window/dos/controls/mouse/mount.ts @@ -1,25 +1,22 @@ import { pointer, getPointerState } from "./pointer"; export function mount(el: HTMLElement, - pointerButton: number, - onMouseDown: (x: number, y: number, button: number) => void, + onMouseDown: (x: number, y: number, button?: number) => void, onMouseMove: (x: number, y: number, mX: number, mY: number) => void, - onMouseUp: (x: number, y: number, button: number) => void, + onMouseUp: (x: number, y: number, button?: number) => void, onMouseLeave: (x: number, y: number) => void) { // eslint-disable-next-line function preventDefaultIfNeeded(e: Event) { // not needed yet } - let pressedButton = 0; const onStart = (e: Event) => { if (e.target !== el) { return; } const state = getPointerState(e, el); - pressedButton = state.button === undefined ? pointerButton : state.button; - onMouseDown(state.x, state.y, pressedButton); + onMouseDown(state.x, state.y, state.button); e.stopPropagation(); preventDefaultIfNeeded(e); @@ -38,7 +35,7 @@ export function mount(el: HTMLElement, const onEnd = (e: Event) => { const state = getPointerState(e, el); - onMouseUp(state.x, state.y, pressedButton); + onMouseUp(state.x, state.y, state.button); e.stopPropagation(); preventDefaultIfNeeded(e); }; diff --git a/src/window/dos/controls/mouse/mouse-not-locked.ts b/src/window/dos/controls/mouse/mouse-not-locked.ts index 4576e688..8a4001b0 100644 --- a/src/window/dos/controls/mouse/mouse-not-locked.ts +++ b/src/window/dos/controls/mouse/mouse-not-locked.ts @@ -3,7 +3,7 @@ import { mount } from "./mount"; const insensitivePadding = 1 / 100; -export function mouseDefault(pointerNumber: number, +export function mouseDefault(pointerButton: number, el: HTMLElement, ci: CommandInterface) { const mapXY = (x: number, y: number) => doMapXY(x, y, el, ci); @@ -12,16 +12,16 @@ export function mouseDefault(pointerNumber: number, document.exitPointerLock(); } - function onMouseDown(x: number, y: number, button: number) { + function onMouseDown(x: number, y: number, button?: number) { const xy = mapXY(x, y); ci.sendMouseMotion(xy.x, xy.y); - ci.sendMouseButton(button, true); + ci.sendMouseButton(button ?? pointerButton, true); } - function onMouseUp(x: number, y: number, button: number) { + function onMouseUp(x: number, y: number, button?: number) { const xy = mapXY(x, y); ci.sendMouseMotion(xy.x, xy.y); - ci.sendMouseButton(button, false); + ci.sendMouseButton(button ?? pointerButton, false); } function onMouseMove(x: number, y: number, mX: number, mY: number) { @@ -34,7 +34,7 @@ export function mouseDefault(pointerNumber: number, ci.sendMouseMotion(xy.x, xy.y); } - return mount(el, pointerNumber, onMouseDown, onMouseMove, onMouseUp, onMouseLeave); + return mount(el, onMouseDown, onMouseMove, onMouseUp, onMouseLeave); } function doMapXY(eX: number, diff --git a/src/window/dos/controls/mouse/mouse-swipe.ts b/src/window/dos/controls/mouse/mouse-swipe.ts index fd2e6d85..d9c4b965 100644 --- a/src/window/dos/controls/mouse/mouse-swipe.ts +++ b/src/window/dos/controls/mouse/mouse-swipe.ts @@ -13,11 +13,15 @@ export function mouseSwipe(sensitivity: number, let prevX = 0; let prevY = 0; - const onMouseDown = (x: number, y: number) => { + const onMouseDown = (x: number, y: number, mouseButton?: number) => { startedAt = Date.now(); acc = 0; prevX = x; prevY = y; + + if (mouseButton !== undefined) { + ci.sendMouseButton(mouseButton, true); + } }; function onMouseMove(x: number, y: number, mX: number, mY: number) { @@ -37,20 +41,25 @@ export function mouseSwipe(sensitivity: number, } acc += Math.abs(mX) + Math.abs(mY); - (ci as any).sendMouseRelativeMotion(mX * sensitivity * 2, mY * sensitivity * 2); + + ci.sendMouseRelativeMotion(mX * sensitivity * 2, mY * sensitivity * 2); } - const onMouseUp = (x: number, y: number) => { - const delay = Date.now() - startedAt; + const onMouseUp = (x: number, y: number, mouseButton?: number) => { + if (mouseButton !== undefined) { + ci.sendMouseButton(mouseButton, false); + } else { + const delay = Date.now() - startedAt; - if (delay < clickDelay && acc < clickThreshold) { - const button = pointerButton ?? 0; - ci.sendMouseButton(button, true); - setTimeout(() => ci.sendMouseButton(button, false), 60); + if (delay < clickDelay && acc < clickThreshold) { + const button = mouseButton ?? pointerButton; + ci.sendMouseButton(button, true); + setTimeout(() => ci.sendMouseButton(button, false), 60); + } } }; const noop = () => {}; - return mount(el, pointerButton, onMouseDown, onMouseMove, onMouseUp, noop); + return mount(el, onMouseDown, onMouseMove, onMouseUp, noop); }