aorecomp

Anarchy Online classic in the browser

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


commit 68a5331c1d9ccb3a5bda8708d681300416514db0
parent bdfb93c8f5261c44fe84f5b121cd5f3a5ab12978
Author: anon <anon@example.com>
Date:   Wed, 11 Nov 2026 04:24:19 +0000

Add deduplicated overworld overview to item catalog pages

Diffstat:
Mdocs/maps.md | 5+++++
Mserver/assets/map.js | 13++++++++++++-
Mserver/item_source_pages.go | 38++++++++++++++++++++++++++++++++++++++
Mserver/item_sources_test.go | 24++++++++++++++++++++++--
Mserver/loot_distribution_test.go | 4++--
Mserver/map_test.js | 32++++++++++++++++++++++++++++++++
Mserver/npc_loot_sources_test.go | 4++--
Mtools/client/test_item_sources.mjs | 21+++++++++++++++++----
8 files changed, 130 insertions(+), 11 deletions(-)

diff --git a/docs/maps.md b/docs/maps.md @@ -38,6 +38,11 @@ position is `[2092.245849609375, 52.798404693603516, 3821.69970703125]`. The source map uses this entrance independently of the unresolved gameplay arrival; it does not place Tarasque's interior coordinates on Rubi-Ka. +Individual catalog items include an overworld overview fitted to all known +source positions. Markers are deduplicated by playfield and X/Z, including +different loot sources sharing an indoor entrance. Sources without a known +overworld position remain in the details below the map. + ## Shipped planet imagery The default map is in diff --git a/server/assets/map.js b/server/assets/map.js @@ -95,7 +95,8 @@ class AOMap { this.canvas.scrollIntoView({block: "nearest"}); }); } - this.focusSource(this.sources[0]); + if (this.element.hasAttribute("data-map-overview")) this.focusSources(); + else this.focusSource(this.sources[0]); return; } const query = new URLSearchParams(window.location.search); @@ -203,6 +204,16 @@ class AOMap { zone.origin[1] + Math.max(...boundary.map(point => point[1]))]); } + focusSources() { + this.view = "world"; + const points = this.sources.map(source => this.playerPoint(source)).filter(point => point); + if (!points.length) return; + const xs = points.map(point => point[0]), zs = points.map(point => point[1]); + this.fit([Math.min(...xs) - 50, Math.min(...zs) - 50, Math.max(...xs) + 50, Math.max(...zs) + 50]); + this.scale = Math.min(this.scale, 1); + this.initialized = true; + } + focusSource(source) { const zone = this.zones.get(source.playfield); const view = this.element.querySelector("[data-map-view]"); diff --git a/server/item_source_pages.go b/server/item_source_pages.go @@ -18,6 +18,43 @@ type sourceMapLocation struct { Position [3]float32 `json:"position"` } +func sourceOverview(w http.ResponseWriter, sources []itemSource) { + // Plot each known overworld position once, regardless of source name or height. + locations := make([]sourceMapLocation, 0) + type mapPoint struct { + playfield uint32 + x, z float32 + } + seen := make(map[mapPoint]bool) + unmapped := false + for _, source := range sources { + for _, location := range source.locations { + if _, known := gamedata.MapCoordinates.Playfields[location.playfield]; !known { + unmapped = true + continue + } + key := mapPoint{location.playfield, location.position[0], location.position[2]} + if !seen[key] { + locations = append(locations, sourceMapLocation{location.name, location.playfield, location.position}) + seen[key] = true + } + } + } + if len(locations) == 0 { + return + } + data, err := json.Marshal(locations) + if err != nil { + panic(err) + } + fmt.Fprintf(w, "<section><h2>Source locations on Rubi-Ka</h2><p>%d unique mapped locations. Indoor sources are shown at their outdoor entrances.</p>", len(locations)) + if unmapped { + fmt.Fprint(w, "<p>Locations without a known overworld position are listed in the source details below.</p>") + } + fmt.Fprintf(w, "<script type='application/json' data-item-sources>%s</script>", data) + fmt.Fprint(w, "<div data-world-map data-map-overview><p data-map-status>Loading maps...</p><p data-map-location></p><canvas data-map-canvas width='1000' height='480' aria-label='Item source overworld overview'></canvas></div><script src='admin/control-map.js' defer></script></section>") +} + func sourceMap(w http.ResponseWriter, sources []itemSource) { locations := make([]sourceMapLocation, 0) seen := make(map[sourceMapLocation]bool) @@ -56,6 +93,7 @@ func (server *server) itemTemplatePage(w http.ResponseWriter, r *http.Request) { sources := server.itemSources()[itemFamily(definition.ID)] server.adminPageStart(w, adminName(definition.Name), "Items") fmt.Fprintf(w, "<p><a href='admin/items/catalog'>Item catalog</a></p><h1>%s%s</h1><table><tr><th scope='row'>Description</th><td>%s</td></tr><tr><th scope='row'>Mapped sources (QL family)</th><td>%s</td></tr></table>", itemIcon(definition), html.EscapeString(adminName(definition.Name)), html.EscapeString(definition.Description), html.EscapeString(itemSourceSummary(sources))) + sourceOverview(w, sources) fmt.Fprint(w, "<h2>Possible sources (QL family)</h2><table><tr><th>Type</th><th>Icon</th><th>Source</th><th>Offered QL</th><th>Details</th></tr>") for _, source := range sources { name := html.EscapeString(adminName(source.name)) diff --git a/server/item_sources_test.go b/server/item_sources_test.go @@ -121,6 +121,7 @@ func TestShopSourceMapUsesOutdoorEntrancesAndLocationLinks(t *testing.T) { gamedata.ShopMachines = map[uint32]gamedata.ShopMachine{ 1: {Template: 99491, Playfield: 1183, Position: [3]float32{180, 5, 135}}, 2: {Template: 99491, Playfield: 950, Position: [3]float32{50, 14, 60}}, + 3: {Template: 99491, Playfield: 1183, Position: [3]float32{190, 5, 140}}, } world.zoneLinks = map[string]map[uint32]zoneLinks{"target": { 705: {Doors: []zoneDoor{ @@ -148,11 +149,30 @@ func TestShopSourceMapUsesOutdoorEntrancesAndLocationLinks(t *testing.T) { t.Fatal("missing possible-source location link", link) } } - for _, removed := range []string{"Acquisition locations", "<div data-world-map", "data-item-sources", "admin/map?playfield=1183"} { + for _, removed := range []string{"Acquisition locations", "admin/map?playfield=1183"} { if strings.Contains(page.Body.String(), removed) { - t.Fatal("item page retains duplicate map or indoor machine link", removed) + t.Fatal("item page repeats the location list or retains an indoor machine link", removed) } } + _, data, found := strings.Cut(page.Body.String(), "data-item-sources>") + data, _, _ = strings.Cut(data, "</script>") + var locations []sourceMapLocation + if !found || json.Unmarshal([]byte(data), &locations) != nil { + t.Fatal("missing item source overview") + } + var placements []mapEntrance + for _, location := range locations { + if strings.Contains(location.Name, "(machine ") { + placements = append(placements, mapEntrance{location.Playfield, location.Position}) + } + } + if !slices.Equal(placements, []mapEntrance{ + {705, [3]float32{100, 20, 200}}, + {705, [3]float32{300, 20, 400}}, + {710, [3]float32{500, 20, 600}}, + }) { + t.Fatal("overview must deduplicate shared entrances and include only overworld positions", placements) + } continue } diff --git a/server/loot_distribution_test.go b/server/loot_distribution_test.go @@ -127,8 +127,8 @@ func TestDistributedCatalogShowsItemOddsAndNamedLocations(t *testing.T) { t.Fatal("pool detail missing", text) } } - if strings.Contains(page.Body.String(), "<div data-world-map") { - t.Fatal("duplicate map returned") + if strings.Count(page.Body.String(), "<div data-world-map data-map-overview") != 1 { + t.Fatal("missing single source overview") } } diff --git a/server/map_test.js b/server/map_test.js @@ -262,3 +262,35 @@ test('acquisition locations focus outdoor and interior coordinates and label tap assert.deepEqual(Array.from(map.center), [180, 135]); assert.equal(map.initialized, true); }); + +test('source overview fits every overworld marker into the viewport', () => { + const map = mapWithTiles(1000, 1, () => {}); + map.height = 500; + map.zones.set(505, {origin: [35214, 44566]}); + map.zones.set(705, {origin: [43756, 26526]}); + map.sources = [ + {playfield: 505, position: [2092, 0, 3822]}, + {playfield: 705, position: [960, 0, 510]}, + ]; + + map.focusSources(); + + assert.equal(map.view, 'world'); + assert.equal(map.initialized, true); + assert.deepEqual(Array.from(map.center), [41011, 37712]); + for (const source of map.sources) { + const [x, y] = map.toScreen(...map.playerPoint(source)); + assert(x > 6 && x < 994 && y > 6 && y < 494); + } +}); + +test('a single overview location has a finite useful zoom', () => { + const map = mapWithTiles(1000, 1, () => {}); + map.zones.set(505, {origin: [35214, 44566]}); + map.sources = [{playfield: 505, position: [2092, 0, 3822]}]; + + map.focusSources(); + + assert.deepEqual(Array.from(map.center), [37306, 48388]); + assert.equal(map.scale, 1); +}); diff --git a/server/npc_loot_sources_test.go b/server/npc_loot_sources_test.go @@ -102,8 +102,8 @@ func TestItemCatalogShowsLootChanceAndEvidence(t *testing.T) { t.Fatal("item details omitted evidence, inference or map link", expected) } } - if strings.Contains(detail.Body.String(), "<div data-world-map") { - t.Fatal("item details reintroduced the duplicate map") + if strings.Count(detail.Body.String(), "<div data-world-map data-map-overview") != 1 { + t.Fatal("item details need one source overview") } }) } diff --git a/tools/client/test_item_sources.mjs b/tools/client/test_item_sources.mjs @@ -20,7 +20,7 @@ try { await ruby.locator("a[href='admin/items/catalog/136627']").click(); await page.waitForLoadState('domcontentloaded'); assert(await page.locator('main').textContent().then(text => text.includes('AORebirth') && text.includes('Ruby on Writhetongue'))); - assert.equal(await page.locator('[data-world-map]').count(), 0); + assert.equal(await page.locator('[data-world-map][data-map-overview]').count(), 1); const nestedScrollers = await page.locator('main *').evaluateAll(elements => elements.filter(element => { const style = getComputedStyle(element); return /(auto|scroll)/.test(style.overflowY) && element.scrollHeight > element.clientHeight; @@ -29,7 +29,7 @@ try { await page.goto(url + 'admin/items/catalog/147073'); assert.match(await page.locator('main').textContent(), /Pool selection.*eligible families.*Item probability varies with NPC level/); - assert.equal(await page.locator('[data-world-map]').count(), 0); + assert.equal(await page.locator('[data-world-map][data-map-overview]').count(), 1); assert.equal(await page.locator('main *').evaluateAll(elements => elements.filter(element => { const style = getComputedStyle(element); return /(auto|scroll)/.test(style.overflowY) && element.scrollHeight > element.clientHeight; @@ -38,7 +38,7 @@ try { for (const path of ['admin/items/catalog/95577', 'admin/shops/99491']) { await page.goto(url + path); if (path === 'admin/items/catalog/95577') { - assert.equal(await page.locator('[data-world-map], [data-item-sources]').count(), 0); + assert.equal(await page.locator('[data-world-map], [data-item-sources]').count(), 2); const link = page.locator('a[href^="admin/map?playfield=705&"]').filter({hasText: 'entrance'}).first(); const destination = new URL(await link.getAttribute('href'), url); await link.click(); @@ -83,6 +83,19 @@ try { // Interior loot links must focus the outdoor entrance on the Rubi-Ka map. await page.goto(url + 'admin/items/catalog/200199'); + await page.waitForFunction(() => document.querySelector('[data-map-status]').textContent.startsWith('Drag to pan.')); + const overview = JSON.parse(await page.locator('[data-item-sources]').textContent()); + const manifest = await page.evaluate(async () => (await fetch('admin/map-assets/manifest.json')).json()); + const outdoor = new Set(manifest.zones.filter(zone => zone.origin).map(zone => zone.id)); + const links = await page.locator('a[href^="admin/map?playfield="]').evaluateAll(elements => elements.map(link => link.href)); + const expected = links.map(link => new URL(link).searchParams).filter(query => outdoor.has(Number(query.get('playfield')))) + .map(query => `${query.get('playfield')}:${Number(query.get('x'))}:${Number(query.get('z'))}`); + const markers = overview.map(source => `${source.playfield}:${source.position[0]}:${source.position[2]}`); + assert.deepEqual(markers.toSorted(), [...new Set(expected)].toSorted()); + assert.equal(markers.filter(point => point === '505:2092.2458:3821.6997').length, 1); + assert.equal(await page.locator('[data-world-map]').count(), 1); + assert.equal(await page.locator('[data-map-source]').count(), 0, 'overview must not repeat the source list'); + const tarasque = page.getByRole('link', {name: 'Tarasque (levels 200-200) - Camelot entrance - Avalon (505), X 2092.2 Z 3821.7', exact: true}).first(); const viewportRequest = page.waitForRequest(request => request.url().includes('admin/map-entities?view=world&')); @@ -117,7 +130,7 @@ try { await page.locator('[data-map-find]').selectOption('705'); await page.waitForFunction(() => document.querySelector('[data-map-view]').value === 'world'); assert.deepEqual(errors, []); - console.log('Possible-source links open outdoor shop entrances without a duplicate item map; shop maps and general map controls still work.'); + console.log('Item overviews deduplicate overworld locations; source links, shop maps and general map controls still work.'); } finally { await browser.close(); }