commit bbca35c8c02d44d26ee713e54d876078044d8460
parent 3ab51b60d447bcf6ea52ce9661534e6d50041b5e
Author: anon <anon@example.com>
Date: Wed, 11 Nov 2026 09:27:35 +0000
Open mobile inventory actions on tap and move items on hold
Diffstat:
11 files changed, 369 insertions(+), 30 deletions(-)
diff --git a/DEVELOPERS.md b/DEVELOPERS.md
@@ -415,9 +415,12 @@ and drag with two fingers to orbit. Spread or pinch those fingers to zoom in or
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 the game to left-click, drag to move windows or items, and hold briefly for
-a right-click. Native inventory icon positions persist in browser storage for
-each server URL and character, including after reload. Touch controls hide while
+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
+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
+reload. Touch controls hide while
settings or the chat composer is open.
Tap Chat to open the phone keyboard; Send enters the message through the game's
chat input. The composer accepts the game's Windows-1252 character set and
diff --git a/client/browser/index.html b/client/browser/index.html
@@ -656,6 +656,8 @@ show();
const heldKeys = new Set();
const overlayTouches = new Set();
let canvasTouch = null, moveTouch = null;
+ let itemMenu = null;
+ let touchFrame = 0;
let canvasTouchInput = false;
let orbitTouch = null, autoRun = false, moveForward = false;
let touchRegions = null;
@@ -666,7 +668,16 @@ show();
document.querySelector('#chat-button').disabled = !isMobileBrowser || !gameReady;
positionChat();
};
- Module.onTouchRegions = bounds => { touchRegions = bounds; updateTouchControls(); };
+ Module.onTouchRegions = bounds => {
+ touchRegions = bounds;
+ if (itemMenu && bounds.itemMenu) {
+ itemMenu.ready = true;
+ } else if (itemMenu?.ready) cancelItemMenu();
+ updateTouchControls();
+ };
+ Module.onTouchFrame = request => {
+ if (itemMenu?.request === request) mouse('mousedown', itemMenu.x, itemMenu.y, 2);
+ };
const savedTouchMode = localStorage.getItem('ao-touch-controls');
touchEnabled.checked = isMobileBrowser && savedTouchMode !== 'false';
touchEnabled.disabled = !isMobileBrowser;
@@ -696,8 +707,12 @@ show();
const bounds = canvas.getBoundingClientRect();
x = (x - bounds.left) * touchRegions.screenWidth / bounds.width;
y = (y - bounds.top) * touchRegions.screenHeight / bounds.height;
- return touchRegions.regions.find(region =>
+ const regions = touchRegions.regions.filter(region =>
x >= region.left && x < region.right && y >= region.top && y < region.bottom);
+ // Window detectors set input modes without taking the hit from their item icons.
+ if (regions[0]?.detector)
+ return {...regions[0], item: regions.find(region => !region.detector)?.item === true};
+ return regions[0];
}
// Route camera motion separately from native UI scrolling; neither needs a click.
canvas.addEventListener('wheel', event => {
@@ -728,6 +743,13 @@ show();
mouse('mouseup', canvasTouch.x, canvasTouch.y, canvasTouch.button);
canvasTouch = null;
}
+ function cancelItemMenu() {
+ if (!itemMenu) return;
+ // Release away from all native hotspots, including while the hold menu is pending.
+ mouse('mousemove', -1, -1);
+ mouse('mouseup', -1, -1, 2);
+ itemMenu = null;
+ }
function finishOrbit() {
if (!orbitTouch || orbitTouch.points.size !== 2) return;
Module._browser_orbit(0, 0, 0);
@@ -739,6 +761,8 @@ show();
setKey(119, autoRun || moveForward);
}
function releaseControls() {
+ if (canvasTouch?.menu) canvasTouch.button = null;
+ cancelItemMenu();
finishCanvasTouch();
if (gameReady) Module._browser_orbit(0, 0, 0);
orbitTouch = null;
@@ -837,6 +861,7 @@ show();
// Cancelling pointerdown can suppress other fingers in Firefox. CSS owns touch gestures.
event.stopImmediatePropagation();
if (!gameReady || orbitTouch || playerMenu.open) return;
+ if (itemMenu && !itemMenu.ready) { cancelItemMenu(); return; }
const region = touchRegion(event.clientX, event.clientY);
const bounds = canvas.getBoundingClientRect();
const history = chatBounds?.history;
@@ -864,11 +889,20 @@ 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,
camera: touchEnabled.checked && touchRegion(event.clientX, event.clientY)?.world === true};
mouse('mousemove', event.clientX, event.clientY);
+ if (itemMenu) { canvasTouch.button = 2; return; }
canvasTouch.timer = setTimeout(() => {
- canvasTouch.button = 2;
- mouse('mousedown', canvasTouch.x, canvasTouch.y, 2);
+ if (canvasTouch.item) {
+ // Native inventory pickup completes on a click, even while the finger stays down.
+ mouse('mousedown', canvasTouch.startX, canvasTouch.startY);
+ mouse('mouseup', canvasTouch.startX, canvasTouch.startY);
+ canvasTouch.picked = true;
+ } else {
+ canvasTouch.button = 2;
+ mouse('mousedown', canvasTouch.x, canvasTouch.y, 2);
+ }
}, 450);
}, true);
canvas.addEventListener('pointermove', event => {
@@ -903,8 +937,11 @@ show();
}
return;
}
- if (canvasTouch.button === null && Math.hypot(event.clientX - canvasTouch.startX, event.clientY - canvasTouch.startY) > 8) {
+ if (canvasTouch.button === null && !canvasTouch.picked &&
+ Math.hypot(event.clientX - canvasTouch.startX, event.clientY - canvasTouch.startY) > 8) {
clearTimeout(canvasTouch.timer);
+ // Moving before the hold threshold cancels an item gesture instead of picking it up.
+ if (canvasTouch.item) { canvasTouch.cancel = true; return; }
canvasTouch.button = canvasTouch.camera ? 2 : 0;
if (canvasTouch.camera) {
const [x, y] = cameraAnchor(canvasTouch.startX, canvasTouch.startY);
@@ -922,13 +959,25 @@ show();
if (orbitTouch) return;
if (!canvasTouch || event.pointerId !== canvasTouch.id) return;
if (canvasTouch.chat) { finishCanvasTouch(); return; }
+ if (canvasTouch.cancel) { finishCanvasTouch(); return; }
canvasTouch.x = event.clientX + canvasTouch.offsetX;
canvasTouch.y = event.clientY + canvasTouch.offsetY;
mouse('mousemove', canvasTouch.x, canvasTouch.y);
- if (canvasTouch.button === null) {
- canvasTouch.button = 0;
- mouse('mousedown', event.clientX, event.clientY);
+ if (canvasTouch.picked) {
+ if (Math.hypot(event.clientX - canvasTouch.startX, event.clientY - canvasTouch.startY) > 8) {
+ canvasTouch.button = 0;
+ mouse('mousedown', event.clientX, event.clientY);
+ }
+ } 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);
+ } else {
+ canvasTouch.button = 0;
+ mouse('mousedown', event.clientX, event.clientY);
+ }
}
+ if (canvasTouch.menu) itemMenu = null;
finishCanvasTouch();
});
for (const type of ['pointerup', 'pointercancel', 'lostpointercapture']) {
@@ -938,7 +987,10 @@ show();
orbitTouch.points.delete(event.pointerId);
if (!orbitTouch.points.size) orbitTouch = null;
}
- if (event.pointerId === canvasTouch?.id) finishCanvasTouch();
+ if (event.pointerId === canvasTouch?.id) {
+ if (canvasTouch.menu) { canvasTouch.button = null; cancelItemMenu(); }
+ finishCanvasTouch();
+ }
});
}
diff --git a/client/runtime/browser_host.js b/client/runtime/browser_host.js
@@ -128,15 +128,18 @@ addToLibrary({
history: {x: outputX, y: outputY, width: outputWidth, height: outputHeight}});
},
ao_touch_regions__proxy: 'sync',
- ao_touch_regions: (bounds, count, screenWidth, screenHeight) => {
+ ao_touch_regions: (bounds, count, screenWidth, screenHeight, itemMenu) => {
const regions = Array.from({length: count}, (_, index) => {
const offset = (bounds >> 2) + index * 5;
return {left: HEAP32[offset], top: HEAP32[offset + 1],
right: HEAP32[offset + 2], bottom: HEAP32[offset + 3],
- world: HEAP32[offset + 4] === 1, chat: HEAP32[offset + 4] === 2};
+ world: HEAP32[offset + 4] === 1, chat: HEAP32[offset + 4] === 2,
+ item: HEAP32[offset + 4] === 3, detector: HEAP32[offset + 4] === 4};
});
- Module.onTouchRegions?.({regions, screenWidth, screenHeight});
+ Module.onTouchRegions?.({regions, screenWidth, screenHeight, itemMenu: !!itemMenu});
},
+ ao_touch_frame__proxy: 'async',
+ ao_touch_frame: (request) => { Module.onTouchFrame?.(request); },
ao_creation_state__proxy: 'sync',
ao_creation_state__deps: ['$UTF8ToString', '$stringToNewUTF8', 'free', 'browser_creation_finish'],
ao_creation_state: (bounds, name) => {
diff --git a/client/runtime/browser_loop.c b/client/runtime/browser_loop.c
@@ -10,6 +10,7 @@ void ao_frame_complete(void);
void ao_frame_begin(double timestamp);
void ao_game_closed(void);
void browser_test_frame(void);
+void browser_touch_frame_complete(void);
void browser_select_character(unsigned character_id);
int browser_graphics_ready(void);
void sub_28002DA0(void);
@@ -38,6 +39,7 @@ static bool browser_frame(double timestamp, void *argument)
/* FFR s_nCharID changes when the creator accepts the server's new identity. */
browser_select_character(MEM32(0x2f01f008));
browser_test_frame();
+ browser_touch_frame_complete();
ao_frame_complete();
return true;
}
diff --git a/client/runtime/browser_resolution.c b/client/runtime/browser_resolution.c
@@ -17,6 +17,7 @@ static _Atomic int orbit_zoom;
static _Atomic int cursor_hidden;
static _Atomic uint32_t hud_insets;
static _Atomic int chat_scroll_pixels;
+static _Atomic unsigned touch_frame_request;
static _Atomic(char *) requested_creation_name;
static int chat_scroll_remainder;
static uint32_t chat_width_owner;
@@ -30,8 +31,23 @@ static struct {
} mobile_chat;
void ao_chat_bounds(int x, int y, int width, int height, int screen_width, int screen_height,
int output_x, int output_y, int output_width, int output_height);
-void ao_touch_regions(const int *regions, unsigned count, int screen_width, int screen_height);
+void ao_touch_regions(const int *regions, unsigned count, int screen_width, int screen_height, int item_menu);
void ao_creation_state(const int *bounds, const char *name);
+void ao_touch_frame(unsigned request);
+
+EMSCRIPTEN_KEEPALIVE void browser_touch_frame(unsigned request)
+{
+ atomic_store(&touch_frame_request, request);
+}
+
+void browser_touch_frame_complete(void)
+{
+ /* A request can arrive after this frame's input poll. Acknowledge it only
+ after the following complete frame has consumed the queued pointer motion. */
+ static unsigned pending;
+ if (pending) ao_touch_frame(pending);
+ pending = atomic_exchange(&touch_frame_request, 0);
+}
static void publish_creation_state(void)
{
@@ -75,22 +91,32 @@ static void publish_touch_regions(void)
for (uint32_t node = head ? MEM32(head) : 0; node && node != head; node = MEM32(node))
if (MEM8(MEM32(node + 8) + 8)) ++count;
- int regions[2 + count * 5];
+ int regions[3 + count * 5];
regions[0] = MEM32(0x27048be8);
regions[1] = MEM32(0x27048bec);
+ regions[2] = MEM32(0x27048b98) != 0;
+ uint32_t drag = MEM32(0x27048b6c);
+ int dragging = drag && MEM32(drag + 0x20);
uint32_t action = MEM32(0x2b0ee640);
uint32_t world = action ? MEM32(action + 0x10) : 0;
uint32_t chat = MEM32(0x2b0ee6a4);
uint32_t history = chat ? MEM32(MEM32(chat + 0xc) + 0x18) : 0;
- unsigned offset = 2;
+ uint32_t inventory = MEM32(0x2b0eea14);
+ unsigned offset = 3;
for (uint32_t node = head ? MEM32(head) : 0; node && node != head; node = MEM32(node)) {
uint32_t hotspot = MEM32(node + 8);
if (!MEM8(hotspot + 8)) continue;
for (unsigned i = 0; i < 4; ++i) regions[offset++] = MEM32(hotspot + 0x2c + i * 4);
- regions[offset++] = hotspot == world ? 1 : hotspot == history ? 2 : 0;
+ /* CCR DragObject_t's class, identity and dummy flag distinguish carried
+ inventory items from buttons, empty cells and placement destinations. */
+ int item = !dragging && MEM32(hotspot) == 0x27034278 && !MEM8(hotspot + 0x70) &&
+ MEM32(hotspot + 0x54) == 104 && MEM32(hotspot + 0x58) >= 48 && MEM32(hotspot + 0x58) < 78;
+ /* InventoryView_t::sub_2B03E040 binds its pass-through mouse detector at +0x1c. */
+ regions[offset++] = hotspot == world ? 1 : hotspot == history ? 2 : item ? 3 :
+ inventory && hotspot == MEM32(inventory + 0x1c) ? 4 : 0;
}
- /* Publish only layout changes; the synchronous copy keeps the snapshot stable. */
+ /* Publish changed hit regions and menu state; copy synchronously to keep the snapshot stable. */
static int *previous;
static size_t previous_size;
if (previous_size == sizeof(regions) && !memcmp(previous, regions, sizeof(regions))) return;
@@ -98,7 +124,7 @@ static void publish_touch_regions(void)
if (!previous) abort();
previous_size = sizeof(regions);
memcpy(previous, regions, sizeof(regions));
- ao_touch_regions(previous + 2, count, regions[0], regions[1]);
+ ao_touch_regions(previous + 3, count, regions[0], regions[1], regions[2]);
}
static void publish_chat_bounds(void)
diff --git a/client/runtime/browser_testing.c b/client/runtime/browser_testing.c
@@ -270,6 +270,22 @@ void browser_test_frame(void)
commands ? MEM32(commands + 0x70) : 0, commands ? MEM32(commands + 0x74) : 0,
dragged ? MEM32(dragged + 0x54) : 0, dragged ? MEM32(dragged + 0x58) : 0);
+ /* CCR IconMenu_t owns the action hotspots and selected command. */
+ uint32_t menu = MEM32(0x27048b98);
+ fputs("\"itemMenu\":", output);
+ if (menu) {
+ fprintf(output, "{\"identity\":[%u,%u],\"actions\":[", MEM32(menu), MEM32(menu + 4));
+ for (unsigned i = 0; i < MEM32(menu + 0x10); ++i) {
+ uint32_t button = MEM32(menu + 0x14 + i * 4);
+ if (i) fputc(',', output);
+ fprintf(output, "{\"command\":%u,\"bounds\":[%d,%d,%d,%d]}", MEM32(button + 0x5c),
+ (int32_t)MEM32(button + 0x68), (int32_t)MEM32(button + 0x6c),
+ (int32_t)MEM32(button + 0x68) + 32, (int32_t)MEM32(button + 0x6c) + 32);
+ }
+ fputs("]}", output);
+ } else fputs("null", output);
+ fputc(',', output);
+
/* CCR's pointer owner and artwork table expose the native click hotspot. */
uint32_t cursor = MEM32(0x27048bb4);
fputs("\"cursor\":", output);
diff --git a/client/tests/browser_controls.mjs b/client/tests/browser_controls.mjs
@@ -93,6 +93,8 @@ function page({navigator = {userAgent: 'Mozilla/5.0 (Android) Gecko Firefox/149.
context.Module._browser_request_resize = (width, height) => sizes.push([width, height]);
context.Module._browser_chat_viewport = bottom => chatViewports.push(bottom);
context.Module._browser_chat_scroll = pixels => scrolls.push(pixels);
+ let touchFrame;
+ context.Module._browser_touch_frame = request => { touchFrame = request; };
const audio = {state: 'running', resumes: 0, resume() {
++this.resumes;
this.state = 'running';
@@ -117,6 +119,7 @@ function page({navigator = {userAgent: 'Mozilla/5.0 (Android) Gecko Firefox/149.
graphics: lost => context.Module.onGraphicsStatus(lost),
chatBounds: bounds => context.Module.onChatBounds(bounds),
touchRegions: bounds => context.Module.onTouchRegions(bounds),
+ touchFrame: () => context.Module.onTouchFrame(touchFrame),
requests, respond: value => { response = value; },
creationNames, creationState: state => context.Module.onCreationState(state),
element: selector => document.querySelector(selector),
@@ -720,6 +723,106 @@ test('holding a touch makes a right click and another finger cannot release it',
]);
});
+test('inventory taps hold the native menu open until the next tap', () => {
+ const game = page();
+ game.touchRegions({screenWidth: 844, screenHeight: 390,
+ regions: [{left: 60, top: 80, right: 200, bottom: 200, detector: true},
+ {left: 80, top: 100, right: 120, bottom: 140, item: true}]});
+
+ game.fire('#canvas', 'pointerdown');
+ game.fire('#canvas', 'pointerup');
+ game.hold();
+
+ assert.deepEqual(game.mouse.filter(event => event[0] !== 'mousemove'), []);
+ game.touchFrame();
+ assert.deepEqual(game.mouse.filter(event => event[0] !== 'mousemove'), [['mousedown', 100, 120, 2]]);
+
+ game.touchRegions({screenWidth: 844, screenHeight: 390, regions: [], itemMenu: true});
+ game.fire('#canvas', 'pointerdown', {clientX: 60, clientY: 150});
+ game.fire('#canvas', 'pointerup', {clientX: 60, clientY: 150});
+ assert.deepEqual(game.mouse.filter(event => event[0] !== 'mousemove'), [
+ ['mousedown', 100, 120, 2], ['mouseup', 60, 150, 2]
+ ]);
+});
+
+test('an inventory hold picks up an item and an occupied destination keeps left-click placement', () => {
+ 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.hold();
+ game.fire('#canvas', 'pointermove', {clientX: 160, clientY: 120});
+ game.fire('#canvas', 'pointerup', {clientX: 160, clientY: 120});
+ game.touchRegions({screenWidth: 844, screenHeight: 390,
+ regions: [{left: 80, top: 100, right: 120, bottom: 140, item: false}]});
+ game.fire('#canvas', 'pointerdown');
+ game.fire('#canvas', 'pointerup');
+
+ assert.deepEqual(game.mouse.filter(event => event[0] !== 'mousemove'), [
+ ['mousedown', 100, 120, 0], ['mouseup', 100, 120, 0],
+ ['mousedown', 160, 120, 0], ['mouseup', 160, 120, 0],
+ ['mousedown', 100, 120, 0], ['mouseup', 100, 120, 0]
+ ]);
+});
+
+test('a window covering an inventory item retains its normal tap', () => {
+ const game = page();
+ game.touchRegions({screenWidth: 844, screenHeight: 390, regions: [
+ {left: 60, top: 80, right: 200, bottom: 200, detector: true},
+ {left: 60, top: 80, right: 200, bottom: 200},
+ {left: 80, top: 100, right: 120, bottom: 140, item: true}
+ ]});
+
+ game.fire('#canvas', 'pointerdown');
+ game.fire('#canvas', 'pointerup');
+
+ assert.deepEqual(game.mouse.filter(event => event[0] !== 'mousemove'), [
+ ['mousedown', 100, 120, 0], ['mouseup', 100, 120, 0]
+ ]);
+});
+
+test('lifting a stationary inventory hold leaves the item picked up', () => {
+ 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.hold();
+ game.fire('#canvas', 'pointerup');
+
+ assert.deepEqual(game.mouse.filter(event => event[0] !== 'mousemove'), [
+ ['mousedown', 100, 120, 0], ['mouseup', 100, 120, 0]
+ ]);
+});
+
+test('moving an inventory touch before the hold threshold cancels pickup', () => {
+ 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', 'pointermove', {clientX: 160});
+ game.hold();
+ game.fire('#canvas', 'pointerup', {clientX: 160});
+
+ assert.deepEqual(game.mouse.filter(event => event[0] !== 'mousemove'), []);
+});
+
+test('blur cancels a pending 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.window.dispatchEvent(new Event('blur'));
+ game.touchFrame();
+ game.touchRegions({screenWidth: 844, screenHeight: 390, regions: [], itemMenu: true});
+
+ assert.deepEqual(game.mouse.slice(-2), [['mousemove', -1, -1, 0], ['mouseup', -1, -1, 2]]);
+});
+
test('movement and camera work together and opening settings releases both', () => {
const game = page();
game.element('#move-pad').clientWidth = game.element('#move-pad').clientHeight = 112;
diff --git a/client/tests/browser_loop.c b/client/tests/browser_loop.c
@@ -23,6 +23,7 @@ void ao_frame_begin(double timestamp)
}
void ao_frame_complete(void) { ++completed; }
void browser_test_frame(void) { assert(frames == completed + 1); }
+void browser_touch_frame_complete(void) { assert(frames == completed + 1); }
void ao_game_closed(void) { ++closed; }
void browser_select_character(unsigned character_id)
{
diff --git a/client/tests/browser_resolution.c b/client/tests/browser_resolution.c
@@ -10,6 +10,10 @@ void browser_zoom(int amount);
void browser_hud_insets(unsigned right, unsigned top);
void browser_chat_scroll(int pixels);
void browser_resize_frame(void);
+void browser_touch_frame(unsigned request);
+void browser_touch_frame_complete(void);
+static unsigned touch_frame_reply;
+void ao_touch_frame(unsigned request) { touch_frame_reply = request; }
static unsigned calls, width, height, resize_calls;
static int graphics_ready = 1, request_during_resize;
static unsigned freed_images, rebuilt_panels;
@@ -26,7 +30,7 @@ static unsigned ui_redraws;
static unsigned toolbar_changes;
static int touch_regions[10];
static unsigned touch_count, touch_updates;
-static int touch_width, touch_height;
+static int touch_width, touch_height, touch_item_menu;
static int creation_bounds[7];
static char creation_name[256];
static unsigned creation_updates;
@@ -115,13 +119,14 @@ static void invalidate_ui(void)
g_esp += 4;
}
-void ao_touch_regions(const int *regions, unsigned count, int screen_width, int screen_height)
+void ao_touch_regions(const int *regions, unsigned count, int screen_width, int screen_height, int item_menu)
{
assert(count <= 2);
memcpy(touch_regions, regions, count * 5 * sizeof(int));
touch_count = count;
touch_width = screen_width;
touch_height = screen_height;
+ touch_item_menu = item_menu;
++touch_updates;
}
@@ -501,6 +506,61 @@ static void wheel_camera_preserves_an_active_touch_orbit(void)
assert(orbit_stops == 1);
}
+static void inventory_touch_regions_follow_native_item_state(void)
+{
+ MEM8(0x50004608) = 1;
+ MEM32(0x50004600) = 0x27034278;
+ MEM32(0x50004654) = 104;
+ MEM32(0x50004658) = 48;
+ MEM32(0x27048b6c) = 0x50006000;
+
+ browser_resize_frame();
+
+ assert(touch_count == 2 && touch_regions[4] == 3);
+ assert(!touch_item_menu);
+
+ MEM8(0x50004670) = 1;
+ browser_resize_frame();
+ assert(touch_regions[4] == 0);
+ MEM8(0x50004670) = 0;
+ MEM32(0x50006020) = 0x50004600;
+ browser_resize_frame();
+ assert(touch_regions[4] == 0);
+ MEM32(0x50006020) = 0;
+ MEM32(0x50004658) = 6;
+ browser_resize_frame();
+ assert(touch_regions[4] == 0);
+ MEM32(0x2b0eea14) = 0x50006200;
+ MEM32(0x5000621c) = 0x50004600;
+ browser_resize_frame();
+ assert(touch_regions[4] == 4);
+
+ MEM32(0x27048b98) = 0x50006100;
+ browser_resize_frame();
+ assert(touch_item_menu);
+ MEM32(0x27048b98) = 0;
+ MEM8(0x50004608) = 0;
+ MEM32(0x27048b6c) = 0;
+ MEM32(0x2b0eea14) = 0;
+}
+
+static void touch_frame_acknowledges_consumed_pointer_motion(void)
+{
+ browser_touch_frame(1);
+
+ browser_touch_frame_complete();
+ assert(touch_frame_reply == 0);
+ browser_touch_frame_complete();
+
+ assert(touch_frame_reply == 1);
+ browser_touch_frame(2);
+ browser_touch_frame(3);
+ browser_touch_frame_complete();
+ assert(touch_frame_reply == 1);
+ browser_touch_frame_complete();
+ assert(touch_frame_reply == 3);
+}
+
int main(void)
{
assert(guest_map("display globals", 0x25230000, 0x10000));
@@ -807,6 +867,7 @@ int main(void)
assert(touch_count == 1 && touch_regions[4] == 1);
assert(touch_updates == published + 1);
+ inventory_touch_regions_follow_native_item_state();
assert(guest_map("camera interface", 0x2d010000, 0x10000));
MEM32(0x2d01752c) = 0x50003f00;
uint32_t stack = g_esp;
@@ -1024,6 +1085,7 @@ int main(void)
stopping_camera_cancels_pending_wheels();
wheel_camera_preserves_an_active_touch_orbit();
creator_name_tracks_native_field_and_random_replies();
+ touch_frame_acknowledges_consumed_pointer_motion();
puts("Browser resize, guest state, mobile chat, camera orbit, wheel and pinch zoom checks passed");
return 0;
}
diff --git a/client/tests/browser_testing.c b/client/tests/browser_testing.c
@@ -429,6 +429,29 @@ static void snapshots_observe_cursor_artwork_without_mutation(void)
assert(g_eax == 123 && g_esp == 456);
}
+static void snapshots_include_native_item_menu_actions(void)
+{
+ guest_map("test item menu", 0x52000000, 0x10000);
+ MEM32(0x27048b98) = 0x52000000;
+ MEM32(0x52000000) = 104;
+ MEM32(0x52000004) = 48;
+ MEM32(0x52000010) = 1;
+ MEM32(0x52000014) = 0x52000100;
+ MEM32(0x5200015c) = 5;
+ MEM32(0x52000168) = 100;
+ MEM32(0x5200016c) = 120;
+
+ browser_test_request();
+ browser_test_frame();
+
+ assert(strstr(snapshot, "\"itemMenu\":{\"identity\":[104,48],\"actions\":[{\"command\":5,\"bounds\":[100,120,132,152]}]}"));
+ assert(MEM32(0x5200015c) == 5 && g_eax == 123 && g_esp == 456);
+ MEM32(0x27048b98) = 0;
+ browser_test_request();
+ browser_test_frame();
+ assert(strstr(snapshot, "\"itemMenu\":null"));
+}
+
int main(void)
{
snapshot_copies_native_state_without_changing_guest_registers();
@@ -445,6 +468,7 @@ int main(void)
snapshots_distinguish_raw_and_effective_armor_without_mutation();
snapshots_observe_door_animation_without_mutation();
snapshots_observe_cursor_artwork_without_mutation();
+ snapshots_include_native_item_menu_actions();
free(snapshot);
puts("PASS: frame snapshots, native inventory, directory clearing and guest state preservation");
}
diff --git a/tests/e2e/cursor.test.mjs b/tests/e2e/cursor.test.mjs
@@ -181,7 +181,7 @@ test('browser cursor preserves native shapes, camera controls and item dragging'
});
});
-test('mobile cursor stays suppressed while touch transfers an inventory item', {timeout: 120_000}, async () => {
+test('mobile inventory taps open native actions and holds move items', {timeout: 120_000}, async () => {
await withFixture('cursor-touch', async fixture => {
const context = await fixture.browser.newContext({viewport: {width: 1024, height: 768},
userAgent: 'Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 Chrome/130.0.0.0 Mobile Safari/537.36',
@@ -191,22 +191,69 @@ test('mobile cursor stays suppressed while touch transfers an inventory item', {
const items = (await fixture.state(context)).items;
const game = await fixture.game(context);
await game.key('i');
- const tap = async index => {
+ await game.key('F1');
+ const point = async index => {
const cell = game.state.grids.flatMap(grid => grid.cells).find(cell =>
cell.index === index);
assert(cell);
- const point = await game.point((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2);
- await game.page.touchscreen.tap(point.x, point.y);
+ return game.point((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2);
+ };
+ const tap = async index => {
+ const {x, y} = await point(index);
+ await game.page.touchscreen.tap(x, y);
};
+ const input = await context.newCDPSession(game.page);
+
+ await tap(0);
+ await game.wait('native item menu after a short tap', state => state.itemMenu);
+ assert.deepEqual(game.state.itemMenu.identity, [104, 48]);
+ assert.deepEqual(game.state.dragged, [0, 0]);
+ await game.save(fixture.output + '/item-menu');
+ await game.page.touchscreen.tap(450, 300);
+ await game.wait('outside tap dismisses menu', state => !state.itemMenu);
+ assert.deepEqual((await fixture.state(context)).items, items);
+ // Opening settings during the native hold delay must cancel without using the item.
await tap(0);
- await game.wait('touch pickup', state => state.dragged[0] !== 0);
+ await game.page.locator('#menu-button').click();
+ await game.page.locator('#player-menu').getByRole('button', {name: 'Close', exact: true}).click();
+
+ await input.send('Input.dispatchTouchEvent', {type: 'touchStart', touchPoints: [await point(0)]});
+ try {
+ await game.wait('long hold picks up item', state => state.dragged[0] === 104 && state.dragged[1] === 48);
+ } finally {
+ await input.send('Input.dispatchTouchEvent', {type: 'touchEnd', touchPoints: []});
+ }
+ await tap(1);
+ await game.wait('occupied destination displaces its item', state => state.dragged[0] === 104 &&
+ state.dragged[1] === 49 && state.grids[0].cells.some(cell =>
+ cell.index === 1 && cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy));
await tap(8);
await game.wait('touch drop', state => state.dragged[0] === 0 && state.grids[0].cells.some(cell =>
- cell.index === 8 && cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy));
+ cell.index === 8 && cell.identity[0] === 104 && cell.identity[1] === 49 && !cell.dummy));
- assert.equal(await game.page.locator('canvas').evaluate(canvas => getComputedStyle(canvas).cursor), 'none');
+ await input.send('Input.dispatchTouchEvent', {type: 'touchStart', touchPoints: [await point(8)]});
+ try {
+ await game.wait('hold before dragging', state => state.dragged[0] === 104 && state.dragged[1] === 49);
+ await input.send('Input.dispatchTouchEvent', {type: 'touchMove', touchPoints: [await point(0)]});
+ } finally {
+ await input.send('Input.dispatchTouchEvent', {type: 'touchEnd', touchPoints: []});
+ }
+ await game.wait('hold then drag places the item on release', state => state.dragged[0] === 0 &&
+ state.grids[0].cells.some(cell => cell.index === 0 && cell.identity[1] === 49 && !cell.dummy));
assert.deepEqual((await fixture.state(context)).items, items);
+
+ await tap(0);
+ await game.wait('first aid opens its native menu', state => state.itemMenu);
+ const use = game.state.itemMenu.actions.find(action => action.command === 5);
+ assert(use, 'First aid offers the native Use action');
+ const target = await game.point((use.bounds[0] + use.bounds[2]) / 2, (use.bounds[1] + use.bounds[3]) / 2);
+ await game.page.touchscreen.tap(target.x, target.y);
+ await game.wait('menu use consumes one first aid charge', state => !state.itemMenu &&
+ game.local(state).inventory.some(item => item.id === items[1].id && item.count === 2));
+
+ 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));
assert.deepEqual(game.errors, []);
});
});