aorecomp

Anarchy Online classic in the browser

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


commit 62a2bcf3b168b254be2a8c8c85c397f922444506
parent 0deb33f40e4a41ebb5b90a1ec11ba7869e75c103
Author: anon <anon@example.com>
Date:   Sun,  8 Nov 2026 18:27:08 +0000

Fix browser zoom, add laptop camera shortcuts, and prevent Firefox Quick Find

Diffstat:
MDEVELOPERS.md | 3+++
MTODO.md | 17+++++++++++++++++
Mclient/browser/index.html | 14++++++++++++--
Mclient/game/Clientr.exe/lifted-0000.c | 29+++++++++++++++++++++++++++++
Mclient/game/ccr.dll/lifted-0001.c | 22++++++++++++++++++++++
Mclient/runtime/browser_resolution.c | 6+++---
Mclient/runtime/browser_testing.c | 3+++
Mclient/tests/browser_controls.mjs | 48+++++++++++++++++++++++++++++++++++++++---------
Mclient/tests/browser_resolution.c | 4+++-
Mclient/tests/browser_testing.c | 3+++
Mclient/tests/native_input.c | 38++++++++++++++++++++++++++++++++++++++
Atests/e2e/camera.test.mjs | 154+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12 files changed, 326 insertions(+), 15 deletions(-)

diff --git a/DEVELOPERS.md b/DEVELOPERS.md @@ -803,6 +803,9 @@ The snapshot's `cursor` records the native shape, visibility, hotspot and drawn size. `node --test tests/e2e/cursor.test.mjs` checks the browser pointer through low-FPS input, canvas re-entry, contextual selection, camera controls, inventory transfers, resizing and mobile touch input using the isolated test server. +`node --test tests/e2e/camera.test.mjs` checks wheel/main-keyboard zoom, +laptop camera shortcuts, autorun and punctuation in native chat. Camera snapshots +include the current vehicle position for observed zoom and orbit checks. `node --test tests/e2e/storage.test.mjs` checks startup and native inventory layout writes/reload with persistent storage available or denied, preserving server-owned items in both cases. diff --git a/TODO.md b/TODO.md @@ -459,6 +459,23 @@ rewriting this document does not close them. later mouse motion leaves camera, character and server facing unchanged. Native modifier/binding regressions and all three Chromium cursor scenarios pass, including ordinary dragging and mobile touch transfers. +- [x] **Make camera zoom and numpad actions usable on laptop keyboards.** + November 8 report: the world wheel appears to zoom only inward and the main + minus key does nothing. Completion: wheel zoom changes distance in both + directions, main - / = (+) controls zoom, and camera rotation/reset/preferred + view plus autorun have documented alternatives. Verify real browser input, + modifier release, native text entry and unchanged UI wheel scrolling. + November 8: wheel zoom now works in both directions; main - / = (+), Shift + arrows, Shift-5/7 and Shift-0 invoke camera and autorun actions. Options lists + the controls. Native binding/release tests, three Chromium camera/chat scenarios + and the inventory grid wheel regression in headless Chromium pass. +- [x] **Keep Firefox Quick Find from stealing native chat input.** November 8 + report: typing `/` opens browser search. Completion: slash and apostrophe reach + native chat while the focused game canvas prevents Quick Find; ordinary page + controls retain their normal keyboard behavior. + November 8: the focused canvas cancels Quick Find keypress defaults before SDL + forwards input to the worker. Real Firefox keyboard input verifies the guard; + Chromium verifies exact native chat text. All 87 browser-control tests pass. - [x] **Use external assets by default; make single-executable bundling opt-in.** The assets directory currently occupies about 1.2 GB and is unconditionally embedded into the server/test build. Default development builds should read diff --git a/client/browser/index.html b/client/browser/index.html @@ -106,6 +106,10 @@ <option value="retina">Retina pixels</option> </select> <output id="render-size"></output> + <p>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> @@ -571,8 +575,10 @@ show(); else if (event.deltaMode === 1) scale = 1 / 3; else scale = 80; if (touchRegion(event.clientX, event.clientY)?.world === true) { - Module._browser_camera_wheel(Math.round(event.deltaX * scale * 100 / bounds.width * 65536), - Math.round(event.deltaY * scale * 100 / bounds.height * 65536)); + if (event.shiftKey) + Module._browser_camera_wheel(Math.round(event.deltaX * scale * 100 / bounds.width * 65536), + Math.round(event.deltaY * scale * 100 / bounds.height * 65536)); + else Module._browser_zoom(Math.round(event.deltaY * scale * 0.15 * 65536)); } else { Module._browser_input_wheel(Math.round((event.clientX - bounds.left) * width / bounds.width), Math.round((event.clientY - bounds.top) * height / bounds.height), @@ -1011,6 +1017,10 @@ show(); } else if (gameReady && document.activeElement === canvas && event.key === 'Tab') { // Keep target cycling in the game while SDL receives the original key. event.preventDefault(); + } else if (gameReady && document.activeElement === canvas && type === 'keypress' && + (event.key === '/' || event.key === "'")) { + // Cancel Firefox Quick Find before the event is proxied to SDL's worker. + event.preventDefault(); } else if (gameReady && keypadKeys[event.code]) { event.preventDefault(); event.stopImmediatePropagation(); diff --git a/client/game/Clientr.exe/lifted-0000.c b/client/game/Clientr.exe/lifted-0000.c @@ -105700,6 +105700,17 @@ L_28003C2A: L_28003C2C: eax = MEM32(ebp + 0x14); /* 0x28003C2C: mov eax, dword ptr [ebp + 0x14] */ L_28003C2F: + /* Main-keyboard zoom keys share the keypad commands. Keep WM_CHAR intact + * so native text fields still receive '-', '=', '+' and '_'. */ + if (MEM32(ebp + 0x14) == 0xbd || MEM32(ebp + 0x14) == 0xbb) { + /* InputConfig_t::CheckMode(3), ccr.dll::sub_27003ED0, owns typing. + * Always forward releases so opening chat cannot leave zoom held. */ + uint32_t input_config = MEM32(0x27048b44); + if (!input_config || (!MEM8(input_config + 0x1f) && !MEM8(input_config + 0x5e)) || + MEM32(ebp + 0x10) == 0x101 || MEM32(ebp + 0x10) == 0x105) + MEM32(ebp + (-0x10)) = MEM32(ebp + 0x14) == 0xbd ? 68 : 69; + goto L_2800442E; + } SET_LO8(ecx, MEM8(ebp + 0xB)); /* 0x28003C2F: mov cl, byte ptr [ebp + 0xb] */ L_28003C32: /* test LO8(ecx), LO8(ecx) */ /* 0x28003C32: test cl, cl */ @@ -106765,6 +106776,9 @@ L_280044AF: _cf = 0; _flag_k = FK_TEST; L_280044B6: + /* Shift produces '+' on the main keyboard; it is not a zoom modifier. */ + if (MEM32(ebp + 0x14) == 0xbd || MEM32(ebp + 0x14) == 0xbb) + MEM32(ebp + (-0x10)) &= ~0x00020000u; ecx = ebp + (-0x10); /* 0x280044B6: lea ecx, [ebp - 0x10] */ L_280044B9: PUSH32(esp, ecx); /* 0x280044B9: push ecx */ @@ -108126,6 +108140,9 @@ L_280044AF: _cf = 0; _flag_k = FK_TEST; L_280044B6: + /* Shift produces '+' on the main keyboard; it is not a zoom modifier. */ + if (MEM32(ebp + 0x14) == 0xbd || MEM32(ebp + 0x14) == 0xbb) + MEM32(ebp + (-0x10)) &= ~0x00020000u; ecx = ebp + (-0x10); /* 0x280044B6: lea ecx, [ebp - 0x10] */ PUSH32(esp, ecx); /* 0x280044B9: push ecx */ RECOMP_ICALL(MEM32(0x28006254)); /* 0x280044BA: call dword ptr [0x28006254] */ @@ -108298,6 +108315,9 @@ L_280044AF: _cf = 0; _flag_k = FK_TEST; L_280044B6: + /* Shift produces '+' on the main keyboard; it is not a zoom modifier. */ + if (MEM32(ebp + 0x14) == 0xbd || MEM32(ebp + 0x14) == 0xbb) + MEM32(ebp + (-0x10)) &= ~0x00020000u; ecx = ebp + (-0x10); /* 0x280044B6: lea ecx, [ebp - 0x10] */ PUSH32(esp, ecx); /* 0x280044B9: push ecx */ RECOMP_ICALL(MEM32(0x28006254)); /* 0x280044BA: call dword ptr [0x28006254] */ @@ -108425,6 +108445,9 @@ L_280044AF: _cf = 0; _flag_k = FK_TEST; L_280044B6: + /* Shift produces '+' on the main keyboard; it is not a zoom modifier. */ + if (MEM32(ebp + 0x14) == 0xbd || MEM32(ebp + 0x14) == 0xbb) + MEM32(ebp + (-0x10)) &= ~0x00020000u; ecx = ebp + (-0x10); /* 0x280044B6: lea ecx, [ebp - 0x10] */ PUSH32(esp, ecx); /* 0x280044B9: push ecx */ RECOMP_ICALL(MEM32(0x28006254)); /* 0x280044BA: call dword ptr [0x28006254] */ @@ -108553,6 +108576,9 @@ L_280044AF: _cf = 0; _flag_k = FK_TEST; L_280044B6: + /* Shift produces '+' on the main keyboard; it is not a zoom modifier. */ + if (MEM32(ebp + 0x14) == 0xbd || MEM32(ebp + 0x14) == 0xbb) + MEM32(ebp + (-0x10)) &= ~0x00020000u; ecx = ebp + (-0x10); /* 0x280044B6: lea ecx, [ebp - 0x10] */ PUSH32(esp, ecx); /* 0x280044B9: push ecx */ RECOMP_ICALL(MEM32(0x28006254)); /* 0x280044BA: call dword ptr [0x28006254] */ @@ -108749,6 +108775,9 @@ L_280044AF: _cf = 0; _flag_k = FK_TEST; L_280044B6: + /* Shift produces '+' on the main keyboard; it is not a zoom modifier. */ + if (MEM32(ebp + 0x14) == 0xbd || MEM32(ebp + 0x14) == 0xbb) + MEM32(ebp + (-0x10)) &= ~0x00020000u; ecx = ebp + (-0x10); /* 0x280044B6: lea ecx, [ebp - 0x10] */ PUSH32(esp, ecx); /* 0x280044B9: push ecx */ RECOMP_ICALL(MEM32(0x28006254)); /* 0x280044BA: call dword ptr [0x28006254] */ diff --git a/client/game/ccr.dll/lifted-0001.c b/client/game/ccr.dll/lifted-0001.c @@ -4020,6 +4020,28 @@ void sub_270046E0(void) { RECOMP_REGS_LOCALS RECOMP_ENTER(0x270046E0u); + /* InputConfig_t::CheckMode(3) identifies native text entry. Remember each + * shortcut press so releasing Shift first still ends the action. */ + static unsigned char held_aliases[120]; + uint32_t input = MEM32(esp + 4), key = MEM32(input) & 0xffffu; + if (!MEM8(input + 4) && key < sizeof(held_aliases)) { + uint32_t release = MEM32(input) & 0x00100000u; + unsigned alias = held_aliases[key]; + if (!release && !alias && !MEM8(ecx) && !MEM8(ecx + 0x1f) && !MEM8(ecx + 0x5e)) { + switch (MEM32(input)) { + case 0x20020: alias = 74; break; /* Shift-left: camera left. */ + case 0x20021: alias = 76; break; /* Shift-right: camera right. */ + case 0x20022: alias = 72; break; /* Shift-up: camera up. */ + case 0x20023: alias = 78; break; /* Shift-down: camera down. */ + case 0x20070: alias = 75; break; /* Shift-5: reset camera. */ + case 0x20072: alias = 77; break; /* Shift-7: preferred camera. */ + case 0x20075: alias = 70; break; /* Shift-0: autorun. */ + } + } + if (alias) MEM32(input) = alias | release; + held_aliases[key] = release ? 0 : alias; + } + L_270046E0: PUSH32(esp, ebp); /* 0x270046E0: push ebp */ ebp = esp; /* 0x270046E1: mov ebp, esp */ diff --git a/client/runtime/browser_resolution.c b/client/runtime/browser_resolution.c @@ -224,11 +224,11 @@ static void orbit_frame(void) { /* Consume each wheel once, even when several events arrive between frames. */ int x = atomic_exchange(&wheel_x, 0), y = atomic_exchange(&wheel_y, 0); - int active = atomic_load(&orbit_active) || x || y; + int zoom = atomic_exchange(&orbit_zoom, 0); + int active = atomic_load(&orbit_active) || x || y || zoom; if (!active && !orbit_running) return; x += atomic_exchange(&orbit_x, 0); y += atomic_exchange(&orbit_y, 0); - int zoom = atomic_exchange(&orbit_zoom, 0); uint32_t engine = MEM32(0x2d01752c); if (!engine) { orbit_running = 0; return; } @@ -701,7 +701,7 @@ void browser_resize_frame(void) { if (!atomic_load(&requested_size) && !atomic_load(&chat_viewport_bottom) && !mobile_chat.chat && !atomic_load(&orbit_active) && !orbit_running && !atomic_load(&wheel_x) && - !atomic_load(&wheel_y) && !atomic_load(&hud_insets) && !hud_adjusted && + !atomic_load(&wheel_y) && !atomic_load(&orbit_zoom) && !atomic_load(&hud_insets) && !hud_adjusted && !atomic_load(&requested_creation_name)) { publish_chat_bounds(); publish_touch_regions(); diff --git a/client/runtime/browser_testing.c b/client/runtime/browser_testing.c @@ -288,6 +288,9 @@ void browser_test_frame(void) if (camera) { fprintf(output, "{\"firstPerson\":%s,\"angles\":", MEM32(camera + 0x19c) ? "false" : "true"); vector(output, camera + 0xc4, 2); + uint32_t vehicle = MEM32(camera + 0x60); + fputs(",\"position\":", output); + vector(output, vehicle + (MEM32(vehicle + 0x28) ? 0xe8 : 0x54), 3); fputc('}', output); } else fputs("null", output); diff --git a/client/tests/browser_controls.mjs b/client/tests/browser_controls.mjs @@ -255,6 +255,18 @@ test('wheel over native UI bypasses the camera gesture and preserves wheel units assert.deepEqual(game.mouse, []); }); +test('world wheel zooms in both directions without moving the orbit', () => { + const game = page(); + + game.fire('#canvas', 'wheel', {deltaX: 0, deltaY: 100, deltaMode: 0}); + game.fire('#canvas', 'wheel', {deltaX: 0, deltaY: -3, deltaMode: 1}); + + assert.deepEqual(game.zooms, [9830, -9830]); + assert.deepEqual(game.cameraWheels, []); + assert.deepEqual(game.wheels, []); + assert.deepEqual(game.mouse, []); +}); + test('world wheel captures its camera target and UI hit testing follows Retina coordinates', () => { const game = page(); game.element('#pixel-mode').value = 'retina'; @@ -267,7 +279,7 @@ test('world wheel captures its camera target and UI hit testing follows Retina c game.canvas.addEventListener('wheel', event => cameraEvents.push(event)); game.fire('#canvas', 'wheel', {deltaX: 0, deltaY: 100, deltaMode: 0}); - const world = game.fire('#canvas', 'wheel', {clientX: 300, deltaX: 12, deltaY: -50, deltaMode: 0}); + const world = game.fire('#canvas', 'wheel', {clientX: 300, deltaX: 12, deltaY: -50, deltaMode: 0, shiftKey: true}); assert.deepEqual(game.wheels, [[200, 240, -1]]); assert.deepEqual(game.cameraWheels, [[932, -8402]]); @@ -295,7 +307,7 @@ test('world to UI wheels never synthesize buttons and focus loss stops pending c {left: 0, top: 0, right: 844, bottom: 390, world: true} ]}); - game.fire('#canvas', 'wheel', {clientX: 300, deltaX: 0.5, deltaY: -0.25, deltaMode: 0}); + game.fire('#canvas', 'wheel', {clientX: 300, deltaX: 0.5, deltaY: -0.25, deltaMode: 0, shiftKey: true}); game.fire('#canvas', 'wheel', {deltaX: 0, deltaY: 100, deltaMode: 0}); game.window.dispatchEvent(new Event('blur')); @@ -323,19 +335,37 @@ test('Tab stays in the focused game and still reaches native key handlers', () = assert.deepEqual(game.keys, []); }); -test('Tab retains normal navigation outside the ready game canvas', () => { +test('Firefox Quick Find keys reach native chat without opening browser search', () => { + const game = page(); + const delivered = []; + game.window.addEventListener('keypress', event => delivered.push(event.key)); + + for (const key of ['/', "'"]) { + for (const type of ['keydown', 'keypress', 'keyup']) { + const event = new Event(type, {cancelable: true}); + Object.assign(event, {key}); + game.window.dispatchEvent(event); + assert.equal(event.defaultPrevented, type === 'keypress'); + } + } + + assert.deepEqual(delivered, ['/', "'"]); + assert.deepEqual(game.characters, []); +}); + +test('Tab and Quick Find retain normal behavior outside the ready game canvas', () => { for (const scenario of ['loading', 'options', 'chat', 'button']) { const game = page({ready: scenario !== 'loading'}); if (scenario === 'options') game.fire('#menu-button', 'click'); if (scenario === 'chat') game.fire('#chat-button', 'click'); if (scenario === 'button') game.element('#menu-button').focus(); game.keys.length = 0; - const event = new Event('keydown', {cancelable: true}); - Object.assign(event, {key: 'Tab', code: 'Tab'}); - - game.window.dispatchEvent(event); - - assert.equal(event.defaultPrevented, false, scenario); + for (const [type, key] of [['keydown', 'Tab'], ['keypress', '/'], ['keypress', "'"]]) { + const event = new Event(type, {cancelable: true}); + Object.assign(event, {key}); + game.window.dispatchEvent(event); + assert.equal(event.defaultPrevented, false, scenario); + } assert.deepEqual(game.keys, [], scenario); } }); diff --git a/client/tests/browser_resolution.c b/client/tests/browser_resolution.c @@ -949,7 +949,6 @@ int main(void) *(float *)ADDR(0x50005374) = 10; memcpy((void *)ADDR(0x50005254), (float[]){4, 12, 30}, 12); - browser_orbit(0, 0, 1); browser_zoom(-32768); browser_zoom(-32768); browser_resize_frame(); @@ -974,6 +973,9 @@ int main(void) assert(fabsf(*(float *)ADDR(0x50005258) - 12) < 0.00001f); assert(*(float *)ADDR(0x5000525c) == 30); + /* Touch pinch uses the same zoom path while an orbit is held. */ + browser_orbit(0, 0, 1); + browser_zoom(655360); browser_resize_frame(); diff --git a/client/tests/browser_testing.c b/client/tests/browser_testing.c @@ -157,6 +157,8 @@ static void completed_picks_record_the_query_pixel_and_result(void) memcpy((void *)ADDR(0x5000f12c), (int32_t[]){13, 9, 814, 610}, 16); MEM32(0x3806ec04) = 0x5000d000; MEM32(0x5000d080) = 0x5000e000; + MEM32(0x5000e060) = 0x5000e200; + memcpy((void *)ADDR(0x5000e254), (float[]){10, 22, 35}, 12); memcpy((void *)ADDR(0x5000e108), (float[]){-0.5f, 0.25f}, 8); MEM32(0x5000e0f0) = 51005; MEM32(0x5000e0f4) = 75; @@ -166,6 +168,7 @@ static void completed_picks_record_the_query_pixel_and_result(void) browser_test_frame(); assert(strstr(snapshot, "\"pick\":{\"sequence\":1,\"position\":[213,234],\"identity\":[51005,75]}")); + assert(strstr(snapshot, "\"camera\":{\"firstPerson\":true,\"angles\":[0,0],\"position\":[10,22,35]}")); assert(strstr(snapshot, "\"hover\":[51050,99]")); assert(g_eax == 123 && g_esp == 456); } diff --git a/client/tests/native_input.c b/client/tests/native_input.c @@ -206,6 +206,42 @@ static void modified_release_outside_camera_keeps_its_binding(void) assert(command_references[0] == 100); } +static void laptop_shortcuts_release_after_shift(void) +{ + const unsigned keys[][2] = { + {32, 74}, {33, 76}, {34, 72}, {35, 78}, {112, 75}, {114, 77}, {117, 70}, + }; + for (unsigned i = 0; i < sizeof(keys) / sizeof(keys[0]); ++i) { + initialize_input(); + MEM8(0x5000017c + keys[i][1]) = 1; + MEM32(0x50000508) = keys[i][1]; + MEM32(0x50000548) = keys[i][1] | 0x100000; + queue_input(keys[i][0] | 0x20000, 100); + MEM8(0x50000604) = 0; /* Keyboard input. */ + + process_frame(); + queue_input(keys[i][0] | 0x100000, 100); + MEM8(0x50000604) = 0; + process_frame(); + + assert(command_count == 2); + } +} + +static void laptop_shortcuts_preserve_text_input(void) +{ + initialize_input(); + MEM8(0x5000005e) = 1; /* Native text-entry mode 3. */ + MEM32(0x50000508) = 70; + queue_input(0x20075, 100); /* Shift-0 must remain text, not autorun. */ + MEM8(0x50000604) = 0; + + process_frame(); + + assert(command_count == 0); + assert(MEM32(0x50000600) == 0x20075); +} + int main(void) { assert(guest_map("native input fixture", 0x50000000, 0x10000)); @@ -218,5 +254,7 @@ int main(void) later_empty_click_is_visible_to_earlier_click_commands(); camera_release_ignores_held_modifiers(); modified_release_outside_camera_keeps_its_binding(); + laptop_shortcuts_release_after_shift(); + laptop_shortcuts_preserve_text_input(); puts("native input: event coordinates, two-pass frame dispatch and shared hotspot references passed"); } diff --git a/tests/e2e/camera.test.mjs b/tests/e2e/camera.test.mjs @@ -0,0 +1,154 @@ +import assert from 'node:assert/strict'; +import {before, test} from 'node:test'; +import {buildServer, withFixture} from './fixture.mjs'; + +before(buildServer); + +function cameraDistance(game, state = game.state) { + return Math.hypot(...state.camera.position.map((value, index) => value - game.local(state).position[index])); +} + +test('camera zoom works in both wheel directions and without a numpad', {timeout: 120_000}, async () => { + await withFixture('camera-zoom', async fixture => { + const context = await fixture.visitor(); + await fixture.setup(context, 'position', {playfield: 705, position: [960, 16.5, 510], rotation: [0, 0, 0, 1]}); + const game = await fixture.game(context); + if (game.state.camera.firstPerson) await game.key('F8'); + const pose = await fixture.state(context); + const distance = cameraDistance(game); + + await game.hold('Minus', 'main minus zooms out', state => cameraDistance(game, state) > distance + 1); + const farther = cameraDistance(game); + await game.hold('Equal', 'main equals zooms in', state => cameraDistance(game, state) < farther - 1); + const near = cameraDistance(game); + await game.hold('NumpadSubtract', 'original numpad minus zooms out', state => cameraDistance(game, state) > near + 2); + const numpadOut = cameraDistance(game); + await game.hold('NumpadAdd', 'original numpad plus zooms in', state => cameraDistance(game, state) < numpadOut - 0.5); + const beforePlus = cameraDistance(game); + await game.page.keyboard.down('Shift'); + try { + await game.hold('Equal', 'main plus zooms in', state => cameraDistance(game, state) < beforePlus - 0.5); + } finally { await game.page.keyboard.up('Shift'); } + await game.page.mouse.move(500, 300); + const beforeWheel = cameraDistance(game); + const angles = game.state.camera.angles; + await game.page.mouse.wheel(0, 100); + await game.wait('wheel zooms out', state => cameraDistance(game, state) > beforeWheel + 0.1); + const wheelOut = cameraDistance(game); + await game.page.mouse.wheel(0, -100); + await game.wait('wheel zooms in', state => cameraDistance(game, state) < wheelOut - 0.1); + + const after = await fixture.state(context); + assert.deepEqual(after.position, pose.position); + assert.deepEqual(after.rotation, pose.rotation); + assert.deepEqual(game.state.camera.angles, angles); + assert.deepEqual(game.errors, []); + }); +}); + +test('laptop shortcuts rotate/reset the camera and toggle autorun', {timeout: 120_000}, async () => { + await withFixture('camera-shortcuts', async fixture => { + const context = await fixture.visitor(); + await fixture.setup(context, 'position', {playfield: 705, position: [960, 16.5, 510], rotation: [0, 0, 0, 1]}); + const game = await fixture.game(context); + const page = game.page; + if (game.state.camera.firstPerson) await game.key('F8'); + const pose = await fixture.state(context); + + const initialPosition = game.state.camera.position; + await page.keyboard.down('Shift'); + try { + await game.hold('ArrowLeft', 'choose a preferred camera angle', state => + state.camera.position.some((value, index) => Math.abs(value - initialPosition[index]) > 0.5)); + await game.key('Digit7'); + } finally { await page.keyboard.up('Shift'); } + const preferred = game.state.camera.position; + await page.keyboard.down('Shift'); + try { + await game.hold('ArrowRight', 'move away from preferred angle', state => + state.camera.position.some((value, index) => Math.abs(value - preferred[index]) > 0.5)); + const beforeReset = game.state.camera.position; + await game.key('Digit5'); + await game.wait('reset moves the camera', state => + state.camera.position.some((value, index) => Math.abs(value - beforeReset[index]) > 0.5)); + } finally { await page.keyboard.up('Shift'); } + for (const key of ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown']) { + const position = game.state.camera.position; + await page.keyboard.down('Shift'); + await page.keyboard.down(key); + try { + await game.wait(key + ' orbits the camera', state => + state.camera.position.some((value, index) => Math.abs(value - position[index]) > 0.05)); + } finally { + // Release the modifier first, then verify the camera stops. + await page.keyboard.up('Shift'); + await page.keyboard.up(key); + } + const releaseFrame = game.state.frame; + await game.wait('orbit key released', state => state.frame > releaseFrame + 2); + // Vertical orbit can touch the ground; wait for native collision recovery. + let settling = game.state; + await game.wait('camera settles after release', state => { + if (state.frame < settling.frame + 5) return false; + const stable = state.camera.position.every((value, index) => Math.abs(value - settling.camera.position[index]) < 0.001); + settling = state; + return stable; + }); + const released = game.state; + await game.wait('frames after camera release', state => state.frame > released.frame + 5); + assert(game.state.camera.position.every((value, index) => Math.abs(value - released.camera.position[index]) < 0.01)); + } + + const cameraPose = await fixture.state(context); + assert.deepEqual(cameraPose.position, pose.position); + assert.deepEqual(cameraPose.rotation, pose.rotation); + + await page.keyboard.down('Shift'); + try { await game.key('Digit0'); } + finally { await page.keyboard.up('Shift'); } + await game.wait('autorun moves the character', state => + Math.abs(game.local(state).position[2] - pose.position[2]) > 1); + await game.key('w'); + + await game.waitFor('server receives autorun movement', async () => + Math.abs((await fixture.state(context)).position[2] - pose.position[2]) > 0.5); + const stopped = game.local().position; + const frame = game.state.frame; + await game.wait('frames after autorun stops', state => state.frame > frame + 5); + assert.deepEqual(game.local().position, stopped); + assert.deepEqual(game.errors, []); + }); +}); + +test('zoom punctuation and shortcut digits remain text in native chat', {timeout: 120_000}, async () => { + await withFixture('camera-chat', async fixture => { + const context = await fixture.visitor(); + await fixture.setup(context, 'position', {playfield: 705, position: [960, 16.5, 510], rotation: [0, 0, 0, 1]}); + const replies = []; + context.on('page', page => page.on('websocket', socket => { + if (socket.url().endsWith('/browser-chat')) + socket.on('framereceived', ({payload}) => replies.push(Buffer.from(payload).toString())); + })); + const game = await fixture.game(context); + const page = game.page; + if (game.state.camera.firstPerson) await game.key('F8'); + const camera = game.state.camera; + const position = game.local().position; + + await game.key('Enter'); + await page.keyboard.type("camera punctuation / ' - ="); + for (const key of ['Equal', 'Minus', 'Digit0', 'Digit5', 'Digit7']) { + await page.keyboard.press('Space'); + await page.keyboard.press('Shift+' + key); + } + await game.key('Enter'); + + await game.wait('server echoes exact native chat text', () => + replies.some(reply => reply.includes("camera punctuation / ' - = + _ ) % &"))); + assert.equal(game.state.camera.firstPerson, camera.firstPerson); + assert.deepEqual(game.state.camera.angles, camera.angles); + assert(game.state.camera.position.every((value, index) => Math.abs(value - camera.position[index]) < 0.01)); + assert.deepEqual(game.local().position, position); + assert.deepEqual(game.errors, []); + }); +});