feat(rust): the live map (phase 14, protocol 11)
PLAN.md §30 as approved, plus D119/D120 from the build. Server: - rust_map_images (one row per server: picture as MEDIUMBLOB, geometry, monuments, DERIVATION_VERSION) and rust_map_overrides; purge.sql pair. - mapImages.js: D110. The board poll notices a new boot/wipe/seed/size and asks map.info; a new key or hash from the free Rust+ cache (or a render kept on disk) is fetched in slices, checked against its SHA-256 and stored in one statement. One fetch per server, a backoff on failure, `stale` abandons a fetch that straddles a map change. Render now (D109) is admin-only and watched to completion. - mapLive.js: D111. One map.live per server per 5 s whoever asks; positions are held in memory only. - model/map: four layers (world, events public; players, bases staff), a fleet default plus per-server override (D114), the players layer capped by presence (D113), own dot and online first-party clan mates for a linked viewer (D115, D117, D118). A layer the viewer may not see is absent from the answer, never sent and hidden. - Routes: public /servers/:id/map, /map/image (immutable under its hash), /map/live; admin /servers/:id/map/fetch and /render; the Map card on the visibility PUT. Swagger fragment and frozen manifest regenerated. Client: - A Map tab: Leaflet over the picture in CRS.Simple, the game's own grid (labels only when a cell is wide enough to hold one), a legend that lists hidden layers with who can see them, polled every 10 s while visible. - D120: Leaflet is a lazy split chunk beside entry.js, not in it. release.yml copies every dist/*.js; checkExternals and build.test.js hold both ends. - The Map card on Admin -> Rust visibility, with Fetch again and Render now. Capability `map` declared for the Android app (phase 15). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
This commit is contained in:
@@ -19,7 +19,7 @@ import { fileURLToPath } from 'node:url'
|
||||
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||
const CLIENT = path.resolve(HERE, '..')
|
||||
|
||||
const { bareImports, problemsWith } = await import('../scripts/checkExternals.js')
|
||||
const { bareImports, problemsWith, relativeImports } = await import('../scripts/checkExternals.js')
|
||||
const configModule = await import('../vite.config.js')
|
||||
const config = configModule.default
|
||||
const { SHARED, SHARED_PACKAGES: guardedPackages } = configModule
|
||||
@@ -152,3 +152,38 @@ test('an import inside a string is not an import — the check reads code, not t
|
||||
// string must not end it early and leave the tail looking like code.
|
||||
assert.deepStrictEqual(bareImports('const s="he said \\"import\\" loudly";'), [])
|
||||
})
|
||||
|
||||
// ── D120: Leaflet's split chunk ───────────────────────────────────────────
|
||||
|
||||
test('a split chunk is found by what entry.js imports, and a string is still not an import', () => {
|
||||
assert.deepStrictEqual(relativeImports('const m=await import("./leaflet-Ab12.js")'), ['leaflet-Ab12.js'])
|
||||
assert.deepStrictEqual(relativeImports('import"./other.js";import"react"'), ['other.js'])
|
||||
assert.deepStrictEqual(relativeImports('const s="import(\\"./fake.js\\")"'), [])
|
||||
})
|
||||
|
||||
test('every chunk entry.js imports is in dist/, and none of them bundles a shared dependency', () => {
|
||||
const dist = path.join(CLIENT, 'dist')
|
||||
const entry = path.join(dist, 'entry.js')
|
||||
if (!fs.existsSync(entry)) return
|
||||
const split = relativeImports(fs.readFileSync(entry, 'utf8'))
|
||||
assert.ok(split.length >= 1, 'the Map tab imports Leaflet from a chunk of its own (D120)')
|
||||
for (const name of split) {
|
||||
assert.ok(fs.existsSync(path.join(dist, name)), `entry.js imports ./${name}, which the build did not emit`)
|
||||
assert.deepStrictEqual(problemsWith(fs.readFileSync(path.join(dist, name), 'utf8')), [], name)
|
||||
}
|
||||
})
|
||||
|
||||
test('Leaflet is not in the entry chunk — every page of the site loads that one', () => {
|
||||
const entry = path.join(CLIENT, 'dist', 'entry.js')
|
||||
if (!fs.existsSync(entry)) return
|
||||
assert.doesNotMatch(fs.readFileSync(entry, 'utf8'), /Leaflet 1\.9/, 'Leaflet was bundled into entry.js')
|
||||
})
|
||||
|
||||
test('the release ships every chunk, not entry.js by name', () => {
|
||||
// The other half of D120. A release that copied `entry.js` alone would load on
|
||||
// every page and spin for ever on the Map tab, with every check above green.
|
||||
const release = fs.readFileSync(path.join(CLIENT, '..', '.gitea', 'workflows', 'release.yml'), 'utf8')
|
||||
assert.match(release, /cp client\/dist\/\*\.js "\$OUT\/client\/dist\/"/)
|
||||
assert.doesNotMatch(release, /cp client\/dist\/entry\.js /)
|
||||
})
|
||||
|
||||
|
||||
92
client/test/mapGeometry.test.js
Normal file
92
client/test/mapGeometry.test.js
Normal file
@@ -0,0 +1,92 @@
|
||||
// ── How a world position reaches a pixel (PLAN.md §30.3) ─────────────────
|
||||
//
|
||||
// The grid cases are the GAME's answers, not this file's: on 2026-09-25 a probe
|
||||
// on the Oxide rig (a 3000 map, seed 1234) asked `MapHelper.PositionToString`
|
||||
// for these positions and wrote down what it said. A label the page draws that
|
||||
// disagrees with the in-game map is a player walking to the wrong square — and
|
||||
// phase 3's plugin did exactly that for three weeks with a 146.3 m cell (D119).
|
||||
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import { boundsOf, column, countdown, grid, gridLabel, scaleOf, toLatLng } from '../src/lib/mapGeometry.js'
|
||||
|
||||
// The rig's map as `GET /map` describes it.
|
||||
const RIG = { worldSize: 3000, oceanMargin: 500, width: 2500, height: 2500, gridCells: 20, gridCellSize: 150 }
|
||||
|
||||
test('the grid label is the game’s, at every probed position', () => {
|
||||
const probed = [
|
||||
['ue_jungle_swamp_a', 764.7, 167.4, 'P8'],
|
||||
['ue_jungle_swamp_a', 733.7, -556.0, 'O13'],
|
||||
['harbor_2', 1122.7, 204.6, 'R8'],
|
||||
['harbor_1', 678.1, 1005.7, 'O3'],
|
||||
['ferry_terminal_1', 645.4, -1004.1, 'O16'],
|
||||
['fishing_village_a', -787.8, 224.1, 'E8'],
|
||||
['fishing_village_c', -203.0, -911.1, 'I16'],
|
||||
['fishing_village_b', 1142.1, -566.5, 'R13'],
|
||||
['desert_military_base_c', 94.0, -729.3, 'K14'],
|
||||
['arctic_research_base_a', -556.9, 840.0, 'G4'],
|
||||
['powerplant_1', -608.6, -346.4, 'F12'],
|
||||
['water_treatment_plant_1', 497.8, 84.9, 'N9'],
|
||||
['nw-corner', -1499, 1499, 'A0'],
|
||||
['se-corner', 1499, -1499, 'T19'],
|
||||
['origin', 0, 0, 'K10'],
|
||||
]
|
||||
for (const [name, x, z, game] of probed) assert.equal(gridLabel(RIG, x, z), game, name)
|
||||
})
|
||||
|
||||
test('a 146.3 m cell — phase 3’s constant — would have disagreed with the game', () => {
|
||||
// Kept as a test so the constant cannot come back in a refactor that "fixes"
|
||||
// the cell size to the number community tools quote.
|
||||
assert.notEqual(gridLabel({ ...RIG, gridCells: 21, gridCellSize: 146.3 }, 645.4, -1004.1), 'O16')
|
||||
})
|
||||
|
||||
test('columns past Z are spelled the way Rust spells them', () => {
|
||||
assert.equal(column(0), 'A')
|
||||
assert.equal(column(25), 'Z')
|
||||
assert.equal(column(26), 'AA')
|
||||
assert.equal(column(27), 'AB')
|
||||
})
|
||||
|
||||
test('the ocean margin is in pixels and is not scaled', () => {
|
||||
assert.equal(scaleOf(RIG), 0.5)
|
||||
// The world's corners sit exactly one margin inside the picture's.
|
||||
assert.deepEqual(toLatLng(RIG, -1500, -1500), [500, 500])
|
||||
assert.deepEqual(toLatLng(RIG, 1500, 1500), [2000, 2000])
|
||||
assert.deepEqual(toLatLng(RIG, 0, 0), [1250, 1250])
|
||||
})
|
||||
|
||||
test('north is up: a larger z is a larger latitude, and x is longitude', () => {
|
||||
const [lat1, lng1] = toLatLng(RIG, 100, 100)
|
||||
const [lat2, lng2] = toLatLng(RIG, 100, 400)
|
||||
assert.ok(lat2 > lat1)
|
||||
assert.equal(lng1, lng2)
|
||||
assert.deepEqual(boundsOf(RIG), [[0, 0], [2500, 2500]])
|
||||
})
|
||||
|
||||
test('something off the edge of the world is still placed, outside the picture', () => {
|
||||
// The rig's cargo ship, as the probe found it: past the world AND the margin.
|
||||
const [lat, lng] = toLatLng(RIG, 2691.6, -1453.1)
|
||||
assert.ok(lng > RIG.width)
|
||||
assert.ok(lat > 0 && lat < RIG.height)
|
||||
})
|
||||
|
||||
test('the grid has a line per edge and a label per cell, A0 at the north-west corner', () => {
|
||||
const g = grid(RIG)
|
||||
assert.equal(g.lines.length, 2 * (RIG.gridCells + 1))
|
||||
assert.equal(g.labels.length, RIG.gridCells * RIG.gridCells)
|
||||
const a0 = g.labels.find((l) => l.text === 'A0')
|
||||
assert.deepEqual([a0.x, a0.z], [-1500, 1500])
|
||||
assert.deepEqual(grid(null), { lines: [], labels: [] })
|
||||
})
|
||||
|
||||
test('a geometry that cannot place anything places nothing rather than NaN everywhere', () => {
|
||||
assert.equal(scaleOf({ worldSize: 0, width: 2500 }), 0)
|
||||
assert.equal(gridLabel({ worldSize: 3000 }, 0, 0), null)
|
||||
})
|
||||
|
||||
test('a hack timer reads as minutes and seconds', () => {
|
||||
assert.equal(countdown(540), '9:00')
|
||||
assert.equal(countdown(61.4), '1:01')
|
||||
assert.equal(countdown(-3), '0:00')
|
||||
})
|
||||
Reference in New Issue
Block a user