Skip to content

osrforge.previews

The deterministic SVG level renderer and the previews index page.

Pure string assembly with no dependencies and no timestamps — previews are one of the three pure artifacts, so byte-stability across runs is a contract. The renderer supports the full osrlib Edge model: synthesis emits open and door edges, and geometry overrides can introduce anything the model allows.

Element emission order is pinned (ruler, cells, walls, doors, entrance, transitions, labels — each group in a deterministic sort) so identical specs render identical bytes.

CELL_PX module-attribute

CELL_PX = 24

The fixed cell size in pixels.

PreviewIndexLevel

Bases: NamedTuple

One level's row in the previews index: the caller supplies layout-relative hrefs.

heading instance-attribute

heading: str

The level's section heading (The Bone Barrow — level 1).

svg_href instance-attribute

svg_href: str

The level's preview SVG, relative to index.html.

map_pages instance-attribute

map_pages: tuple[tuple[int, str], ...]

The level's surveyed map pages as (page number, href) pairs, relative to index.html.

render_level_svg

render_level_svg(dungeon_id: str, level: LevelSpec) -> str

Render one level's grid map as an SVG document string.

Area cells are filled and labelled with the area id at each area's first cell; corridor cells (non-area cells with at least one non-wall edge) get a lighter fill; walls are solid strokes wherever the edge map says wall, including the implicit boundary; doors are ticks (outlined when secret); the entrance is circled; transitions carry their glyph (▲ stairs up, ▼ down). A coordinate ruler frames the grid — column numbers across the top, row numbers down the left — printing the exact 0-based x, y values a geometry override's cells and edge keys use.

Parameters:

Name Type Description Default
dungeon_id str

The dungeon id, for the title line.

required
level LevelSpec

The level spec to render.

required

Returns:

Type Description
str

The SVG document, ending in a newline.

render_previews_index

render_previews_index(title: str, levels: tuple[PreviewIndexLevel, ...]) -> str

Render previews/index.html: each level's synthesized map beside its surveyed map pages.

The page is the eyeballing surface the correction loop's first step asks for — the SVG preview and the module's own page renders side by side, no tab-flipping. Pure string assembly like the SVGs: no timestamps, no scripts, deterministic bytes.

Parameters:

Name Type Description Default
title str

The module title, as built.

required
levels tuple[PreviewIndexLevel, ...]

One entry per dungeon level, in survey order.

required

Returns:

Type Description
str

The HTML document, ending in a newline.