aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit c3b0cac3f9f6fb9aa9b794dcb619da3a1641db96
parent bbca35c8c02d44d26ee713e54d876078044d8460
Author: anon <anon@example.com>
Date:   Wed, 11 Nov 2026 16:36:51 +0000

Support double-tap item use and mobile control guidance

Diffstat:
MDEVELOPERS.md | 3++-
Mclient/browser/index.html | 40++++++++++++++++++++++++++++++++--------
Mclient/tests/browser_controls.mjs | 53++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mtests/e2e/cursor.test.mjs | 10++++++++++
4 files changed, 96 insertions(+), 10 deletions(-)

diff --git a/DEVELOPERS.md b/DEVELOPERS.md @@ -416,7 +416,8 @@ Autorun keeps moving after releasing Move. Jump, Attack and Use buttons provide the common keyboard actions; inventory uses the game's native INV button. Tap an inventory item to open its native action menu, then tap an action or tap -outside to dismiss it. Hold an inventory item briefly to pick it up, then drag +outside to dismiss it. Double-tap an item to use or equip it (the native right-click +action). Hold an inventory item briefly to pick it up, then drag or tap a destination to place it. Elsewhere, tap to left-click, drag to move windows, and hold briefly for a right-click. Native inventory icon positions persist in browser storage for each server URL and character, including after diff --git a/client/browser/index.html b/client/browser/index.html @@ -108,14 +108,16 @@ <option value="retina">Retina pixels</option> </select> <output id="render-size"></output> - <p>Camera: F8 toggles first/third person. Wheel or - / = (+) zooms. + <p id="desktop-controls">Camera: F8 toggles first/third person. Wheel or - / = (+) zooms. Shift + arrows (or Shift + wheel) rotates the camera. Shift + 5 resets it; Shift + 7 saves the preferred angle. Shift + 0 toggles autorun; W stops it. Numpad controls also work.</p> <div id="mobile-options" hidden> <button id="view-button">Toggle 1P / 3P</button> <label><input id="touch-enabled" type="checkbox"> Touch controls</label> - <p>Left pad: move. Swipe: steer. Two fingers: orbit and pinch to zoom. Hold: right click.</p> + <p>Left pad: move. Swipe: steer. Two fingers: orbit and pinch to zoom.</p> + <p>Items: tap for menu, double-tap to use/equip, hold to move. + Tap outside the menu to close it. Elsewhere, hold to right-click.</p> </div> <section id="account-panel" hidden> <p id="account-current"></p> @@ -676,12 +678,20 @@ show(); updateTouchControls(); }; Module.onTouchFrame = request => { - if (itemMenu?.request === request) mouse('mousedown', itemMenu.x, itemMenu.y, 2); + if (!itemMenu || itemMenu.request !== request) return; + mouse('mousedown', itemMenu.x, itemMenu.y, 2); + itemMenu.pressed = true; + if (itemMenu.use) { + mouse('mouseup', itemMenu.x, itemMenu.y, 2); + itemMenu = null; + } }; const savedTouchMode = localStorage.getItem('ao-touch-controls'); touchEnabled.checked = isMobileBrowser && savedTouchMode !== 'false'; touchEnabled.disabled = !isMobileBrowser; document.querySelector('#mobile-options').hidden = !isMobileBrowser; + document.querySelector('#desktop-controls').hidden = isMobileBrowser; + if (isMobileBrowser) menuButton.title = 'Options'; // Queue virtual keys through SDL, including releases before focus changes. function setKey(key, down) { @@ -745,9 +755,12 @@ show(); } function cancelItemMenu() { if (!itemMenu) return; + clearTimeout(itemMenu.timer); // Release away from all native hotspots, including while the hold menu is pending. - mouse('mousemove', -1, -1); - mouse('mouseup', -1, -1, 2); + if (itemMenu.pressed) { + mouse('mousemove', -1, -1); + mouse('mouseup', -1, -1, 2); + } itemMenu = null; } function finishOrbit() { @@ -861,6 +874,9 @@ show(); // Cancelling pointerdown can suppress other fingers in Firefox. CSS owns touch gestures. event.stopImmediatePropagation(); if (!gameReady || orbitTouch || playerMenu.open) return; + const doubleTap = !canvasTouch && itemMenu?.timer && + Math.hypot(event.clientX - itemMenu.x, event.clientY - itemMenu.y) <= 20; + if (doubleTap) cancelItemMenu(); if (itemMenu && !itemMenu.ready) { cancelItemMenu(); return; } const region = touchRegion(event.clientX, event.clientY); const bounds = canvas.getBoundingClientRect(); @@ -889,7 +905,7 @@ show(); canvas.setPointerCapture(event.pointerId); canvasTouch = {id: event.pointerId, x: event.clientX, y: event.clientY, startX: event.clientX, startY: event.clientY, offsetX: 0, offsetY: 0, button: null, - item: region?.item === true, menu: !!itemMenu, + item: region?.item === true, menu: !!itemMenu, doubleTap: !!doubleTap, camera: touchEnabled.checked && touchRegion(event.clientX, event.clientY)?.world === true}; mouse('mousemove', event.clientX, event.clientY); if (itemMenu) { canvasTouch.button = 2; return; } @@ -970,8 +986,16 @@ show(); } } else if (canvasTouch.button === null) { if (canvasTouch.item) { - itemMenu = {ready: false, request: ++touchFrame, x: event.clientX, y: event.clientY}; - Module._browser_touch_frame(itemMenu.request); + itemMenu = {ready: false, request: ++touchFrame, x: event.clientX, y: event.clientY, + use: canvasTouch.doubleTap}; + if (itemMenu.use) Module._browser_touch_frame(itemMenu.request); + else { + // Give a second tap time to choose the native default action before opening the menu. + itemMenu.timer = setTimeout(() => { + itemMenu.timer = null; + Module._browser_touch_frame(itemMenu.request); + }, 300); + } } else { canvasTouch.button = 0; mouse('mousedown', event.clientX, event.clientY); diff --git a/client/tests/browser_controls.mjs b/client/tests/browser_controls.mjs @@ -766,6 +766,38 @@ test('an inventory hold picks up an item and an occupied destination keeps left- ]); }); +test('double tapping an inventory item sends one native right click without opening a menu', () => { + const game = page(); + game.touchRegions({screenWidth: 844, screenHeight: 390, + regions: [{left: 80, top: 100, right: 120, bottom: 140, item: true}]}); + + game.fire('#canvas', 'pointerdown'); + game.fire('#canvas', 'pointerup'); + game.fire('#canvas', 'pointerdown'); + game.fire('#canvas', 'pointerup'); + game.touchFrame(); + game.hold(); + + assert.deepEqual(game.mouse.filter(event => event[0] !== 'mousemove'), [ + ['mousedown', 100, 120, 2], ['mouseup', 100, 120, 2] + ]); +}); + +test('tapping another item during the double-tap window does not use either item', () => { + const game = page(); + game.touchRegions({screenWidth: 844, screenHeight: 390, + regions: [{left: 80, top: 100, right: 200, bottom: 140, item: true}]}); + + game.fire('#canvas', 'pointerdown'); + game.fire('#canvas', 'pointerup'); + game.fire('#canvas', 'pointerdown', {clientX: 160}); + game.fire('#canvas', 'pointerup', {clientX: 160}); + game.hold(); + game.touchFrame(); + + assert.deepEqual(game.mouse.filter(event => event[0] !== 'mousemove'), []); +}); + test('a window covering an inventory item retains its normal tap', () => { const game = page(); game.touchRegions({screenWidth: 844, screenHeight: 390, regions: [ @@ -809,7 +841,7 @@ test('moving an inventory touch before the hold threshold cancels pickup', () => assert.deepEqual(game.mouse.filter(event => event[0] !== 'mousemove'), []); }); -test('blur cancels a pending inventory menu away from the item', () => { +test('blur cancels a delayed inventory menu before any right click', () => { const game = page(); game.touchRegions({screenWidth: 844, screenHeight: 390, regions: [{left: 80, top: 100, right: 120, bottom: 140, item: true}]}); @@ -817,9 +849,24 @@ test('blur cancels a pending inventory menu away from the item', () => { game.fire('#canvas', 'pointerup'); game.window.dispatchEvent(new Event('blur')); + game.hold(); game.touchFrame(); game.touchRegions({screenWidth: 844, screenHeight: 390, regions: [], itemMenu: true}); + assert.deepEqual(game.mouse.filter(event => event[0] !== 'mousemove'), []); +}); + +test('blur releases an opened inventory menu away from the item', () => { + const game = page(); + game.touchRegions({screenWidth: 844, screenHeight: 390, + regions: [{left: 80, top: 100, right: 120, bottom: 140, item: true}]}); + game.fire('#canvas', 'pointerdown'); + game.fire('#canvas', 'pointerup'); + game.hold(); + game.touchFrame(); + + game.window.dispatchEvent(new Event('blur')); + assert.deepEqual(game.mouse.slice(-2), [['mousemove', -1, -1, 0], ['mouseup', -1, -1, 2]]); }); @@ -1280,6 +1327,9 @@ test('unsupported chat characters stay editable and are not sent', () => { test('mobile options toggle the native view and return focus to the game', () => { const game = page(); game.fire('#menu-button', 'click'); + assert.equal(game.element('#desktop-controls').hidden, true); + assert.equal(game.element('#mobile-options').hidden, false); + assert.equal(game.element('#menu-button').title, 'Options'); game.fire('#view-button', 'click'); @@ -1303,6 +1353,7 @@ test('desktop resolution settings remain available without enabling mobile overl assert.equal(game.element('#touch-controls').hidden, true); assert.equal(game.element('#game-toolbar').hidden, false); assert.equal(game.element('#mobile-options').hidden, true); + assert.equal(game.element('#desktop-controls').hidden, false); assert.deepEqual(game.keys, []); assert.equal(game.element('#touch-enabled').checked, false); assert.equal(game.element('#touch-enabled').disabled, true); diff --git a/tests/e2e/cursor.test.mjs b/tests/e2e/cursor.test.mjs @@ -216,6 +216,8 @@ test('mobile inventory taps open native actions and holds move items', {timeout: // Opening settings during the native hold delay must cancel without using the item. await tap(0); await game.page.locator('#menu-button').click(); + assert.equal(await game.page.locator('#desktop-controls').isVisible(), false); + assert.match(await game.page.locator('#mobile-options').innerText(), /double-tap to use\/equip/); await game.page.locator('#player-menu').getByRole('button', {name: 'Close', exact: true}).click(); await input.send('Input.dispatchTouchEvent', {type: 'touchStart', touchPoints: [await point(0)]}); @@ -254,6 +256,14 @@ test('mobile inventory taps open native actions and holds move items', {timeout: assert.equal(await game.page.locator('canvas').evaluate(canvas => getComputedStyle(canvas).cursor), 'none'); assert.deepEqual((await fixture.state(context)).items, items.map((item, index) => index === 1 ? {...item, count: 2} : item)); + + // The weapon's native menu has no Use action; a double tap must perform its default right click. + await tap(3); + await tap(3); + await game.wait('double tap equips the starter weapon', state => !state.itemMenu && + game.local(state).inventory.some(item => item.id === items[3].id && item.slot === 6)); + assert.deepEqual((await fixture.state(context)).items, items.map((item, index) => + index === 1 ? {...item, count: 2} : index === 3 ? {...item, slot: 6} : item)); assert.deepEqual(game.errors, []); }); });