aorecomp

Anarchy Online classic in the browser

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


commit a121ac321ac439f91c2c2c262d033ffc04b7a38d
parent 688f308e9a133b505f7d98d8fa2327d0cb342b77
Author: anon <anon@example.com>
Date:   Wed, 11 Nov 2026 04:05:40 +0000

Fix source map focus for unmapped interiors

Diffstat:
Mserver/assets/map.js | 23++++++++++++++---------
Mtools/client/test_item_sources.mjs | 23+++++++++++++++++++++++
2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/server/assets/map.js b/server/assets/map.js @@ -205,15 +205,20 @@ class AOMap { focusSource(source) { const zone = this.zones.get(source.playfield); - if (!zone) { - this.location.textContent = `${source.name}: playfield ${source.playfield} has no map.`; - return; + const view = this.element.querySelector("[data-map-view]"); + // Unmapped interiors still have local coordinates, but no known map bounds. + if (!zone && view && !view.querySelector(`option[value='${source.playfield}']`)) { + const option = document.createElement("option"); + option.value = source.playfield; + option.textContent = `Playfield ${source.playfield} (no map imagery)`; + option.disabled = true; + view.append(option); } this.initialized = true; - this.view = zone.origin ? "world" : String(zone.id); + this.view = zone?.origin ? "world" : String(source.playfield); this.center = this.playerPoint(source); this.scale = 1; - this.location.textContent = `${source.name}: ${zone.name} (${zone.id}), X ${source.position[0].toFixed(1)}, Z ${source.position[2].toFixed(1)}.`; + this.location.textContent = `${source.name}: ${zone ? `${zone.name} (${zone.id})` : `playfield ${source.playfield}`}, X ${source.position[0].toFixed(1)}, Z ${source.position[2].toFixed(1)}.`; this.renderSoon(); } @@ -454,6 +459,7 @@ class AOMap { point[1] -= zone.origin[1]; } else { zone = this.zones.get(Number(this.view)); + if (!zone) return; if (this.form) this.form.elements.playfield.replaceChildren(new Option(zone.name, zone.id)); } if (!this.contains(zone, point)) { @@ -487,6 +493,7 @@ class AOMap { render() { const view = this.element.querySelector("[data-map-view]"); if (view) view.value = this.view; + const zone = this.zones.get(Number(this.view)); const ctx = this.context; ctx.fillStyle = "#222"; ctx.fillRect(0, 0, this.width, this.height); @@ -510,8 +517,7 @@ class AOMap { for (const zone of this.manifest.zones) { if (zone.origin && zone.boundary) ctx.stroke(this.boundaryPath(zone, zone.origin)); } - } else { - const zone = this.zones.get(Number(this.view)); + } else if (zone) { this.layer(zone.levels, [0, 0, zone.width, zone.height]); ctx.strokeStyle = "#aaa"; ctx.lineWidth = 1; @@ -605,8 +611,7 @@ class AOMap { this.tiles.delete(path); } this.loadTiles(); - const zone = this.zones.get(Number(this.view)); - const detail = zone && (!zone.levels || !zone.levels.length) ? " No extracted imagery for this playfield yet." : ""; + const detail = this.view !== "world" && !zone?.levels?.length ? " No extracted imagery for this playfield yet." : ""; const failures = [...this.tiles.values()].filter(tile => tile.failed).length; this.status.textContent = `${this.sources.length ? "Drag to pan. Pinch or scroll to zoom." : `${this.players.filter(player => player.connected).length} connected players.`} ${this.element.querySelector("[data-map-npcs]")?.checked ? (this.detailVisible("npcs") ? `${this.entities.npcs.length} NPCs in view.` : "Zoom in to see NPCs.") : ""}${this.entities.limited ? " Marker limit reached; zoom in." : ""}${detail}${failures ? ` ${failures} tiles failed to load.` : ""}`; } diff --git a/tools/client/test_item_sources.mjs b/tools/client/test_item_sources.mjs @@ -81,6 +81,29 @@ try { assert.deepEqual(liveFeeds, []); assert.deepEqual(errors, []); + // Interior source links must focus their coordinates even without extracted map imagery. + await page.goto(url + 'admin/items/catalog/200199'); + const tarasque = page.getByRole('link', {name: 'Tarasque (levels 200-200) - Camelot (120), X 111.3 Z 307.0', exact: true}).first(); + const viewportRequest = page.waitForRequest(request => request.url().includes('admin/map-entities?view=120&')); + + await tarasque.click(); + const viewport = new URL((await viewportRequest).url()).searchParams; + await page.waitForFunction(() => { + const canvas = document.querySelector('canvas'); + const pixel = canvas.getContext('2d').getImageData(canvas.width / 2, canvas.height / 2, 1, 1).data; + return pixel[0] === 33 && pixel[1] === 219 && pixel[2] === 135; + }); + + assert.equal(page.url(), url + 'admin/map?playfield=120&x=111.25214&z=307.01544'); + assert.equal(await page.locator('[data-map-view]').inputValue(), '120'); + assert.match(await page.locator('[data-map-status]').textContent(), /No extracted imagery for this playfield/); + assert.match(await page.locator('[data-map-location]').textContent(), /playfield 120, X 111.3, Z 307.0/); + assert(Math.abs((Number(viewport.get('left')) + Number(viewport.get('right'))) / 2 - 111.25214) < 0.00001); + assert(Math.abs((Number(viewport.get('bottom')) + Number(viewport.get('top'))) / 2 - 307.01544) < 0.00001); + assert.equal(Number(viewport.get('right')) - Number(viewport.get('left')), + await page.locator('canvas').evaluate(canvas => canvas.clientWidth)); + assert.deepEqual(errors, []); + // General map controls still select and render standalone outdoor playfields. await page.goto(url + 'admin/map'); await page.locator('[data-map-view] option[value="950"]').waitFor({state: 'attached'});