dungeon.dat: assemble magic-map images per level #409

Closed
opened 2026-10-29 21:26:59 +01:00 by jqueuniet · 2 comments
Owner

Follow-up to #402. dm2 extract --gdat writes one magic-map image per map stored in dungeon.dat. In-game, a level is several maps placed side by side.

Goal

Assemble each level's maps into one image. Each map goes at its shift_x / shift_y in level coordinates, the same layout as the DMDC2 "World Atlas".

Known facts

  • Per-map images draw a map exit with the level's border tileset. Where a map exit overlaps another map of the same level, the engine draws that map's cell instead; the assembled view should do the same.
  • Animation, creatures (--creatures) and --scale should behave as for per-map images.
  • Reference for checking: the DMDC2 atlas on DMWeb (DOS, levels 1-8 and 10), labelled in level coordinates.
Follow-up to #402. `dm2 extract --gdat` writes one magic-map image per map stored in `dungeon.dat`. In-game, a level is several maps placed side by side. ## Goal Assemble each level's maps into one image. Each map goes at its `shift_x` / `shift_y` in level coordinates, the same layout as the DMDC2 "World Atlas". ## Known facts - Per-map images draw a map exit with the level's border tileset. Where a map exit overlaps another map of the same level, the engine draws that map's cell instead; the assembled view should do the same. - Animation, creatures (`--creatures`) and `--scale` should behave as for per-map images. - Reference for checking: the DMDC2 atlas on DMWeb (DOS, levels 1-8 and 10), labelled in level coordinates.
Author
Owner

Design

dungeon.dat: magic-map images per level

Follow-up to #402 (per-map magic-map images, dm2-magicmap).

Intent

In-game, a level is made of several maps placed side by side. The per-map images from #402 show each piece alone, with border chips where the map ends. A level image puts the pieces together the way the game does, so a whole level can be looked over at a glance.

Goals

  • dm2 extract dungeon.dat -o out/ --gdat graphics.dat also writes one level_NN.png per level, alongside the existing map_NN.png / map_NN.json. It is written on every --gdat run, with no extra flag. NN is the maps' level field (DOS-EN uses 0-10).

  • Only magic-map chips are drawn: no coordinate rulers or labels.

  • Each map sits at its shift_x / shift_y in level coordinates. The canvas is the smallest rectangle holding all the level's maps. Cells no map covers are opaque black, like the gaps between cells.

  • Seam rule, the decided priority for a cell several maps claim:

    1. A map exit, or a connector teleporter (Teleporter::blocks_passage, which neighbouring maps treat as a map exit, #392), gives way to another map's real tile.
    2. Between real tiles that still conflict, a tile inside its map wins over one on another map's outer edge.
    3. Otherwise the map first in dungeon.dat order wins. No warning: overlap on seams is normal.

    In DOS-EN, 2275 cells overlap:

    • 1582 are a map exit on one map and a real tile on another (rule 1);
    • 399 are map exits on every map (they keep the border chip);
    • 229 are real tiles of the same type;
    • 65 are real tiles that differ. 64 of those are connector teleporters over floor (rule 1); the last is a wall on one map's edge against an inner floor (rule 2).
  • The winning cell is drawn with everything the per-map renderer draws for it on its own map: tileset, ornaments, creatures and animation.

  • Creatures are on by default, for per-map and level images and in the bindings. This reverses #402's default. The CLI flag becomes --no-creatures. --scale applies to level images as to map images.

  • Animation loops over the whole level image (the least common multiple of the cells' periods, capped at 64 ticks) at dm2_graphics::GAME_TICK_MS. A level with nothing animated is a plain PNG. The 4096 px per side limit applies.

  • A level with a map that cannot render (missing tileset) is skipped with a warning. The per-map images that do render are still written.

  • Bindings parity: dungeon_level_png(dungeon, gdat, level, scale, creatures) through dm2-convert, wasm dungeonLevelPng, FFI dm2_dungeon_level_png, Python dungeon_level_png(dungeon, gdat, level, scale=1, creatures=True). The per-map dungeon_map_png Python default becomes creatures=True.

Non-goals

  • Coordinate rulers, labels or a legend.
  • Console-family archives (#410). They keep today's "not supported yet" message.
  • Assembling several levels into one image.

Anti-goals

  • Seams that show border chips where the game shows the neighbouring map's floor.
  • Level images whose cells differ from the per-map images apart from the seam rule.
  • Noise: no warning per overlapping cell.

Constraints

  • Layering: CLI and dm2-convert call dm2-magicmap; dm2-magicmap calls dm2-dungeon / dm2-graphics.
  • Reuse the per-map chip selection: terrain_chips / creature_chips per owning map and its local coordinates. Don't duplicate rules.
  • dm2-magicmap and the creatures option are unreleased, so their API may change without a deprecation path.
  • Validation: the DMDC2 "World Atlas" (DOS, levels 1-8 and 10) is per level and labelled in level coordinates. #402 found it draws with the game's own chips, so walls, floors, pits, doors and stairs should match on levels 1-3. Its own conventions differ elsewhere (see the "Magic map" section of docs/formats/dungeon-dat.md).

Left to the builder

  • The library API: e.g. render_level_png(d, gdat, level, opts) beside render_map_png, sharing the compositor; and how RenderOptions expresses the creatures default (a Default impl with creatures: true is fine).
  • How the CLI groups maps by level and orders map and level output, and how it reports a skipped level.
  • Whether border-chip cells (map exits that no other map covers) keep the owning map's border tileset. They should, as in per-map images.
  • Error variants for a level that doesn't exist, and for an empty level.
  • Docs: the "Magic map" section and CHANGELOG (Added: level images, dungeon_level_png everywhere; Changed: creatures on by default, --no-creatures).
## Design # dungeon.dat: magic-map images per level Follow-up to #402 (per-map magic-map images, `dm2-magicmap`). ## Intent In-game, a level is made of several maps placed side by side. The per-map images from #402 show each piece alone, with border chips where the map ends. A level image puts the pieces together the way the game does, so a whole level can be looked over at a glance. ## Goals - `dm2 extract dungeon.dat -o out/ --gdat graphics.dat` also writes one `level_NN.png` per level, alongside the existing `map_NN.png` / `map_NN.json`. It is written on every `--gdat` run, with no extra flag. `NN` is the maps' `level` field (DOS-EN uses 0-10). - Only magic-map chips are drawn: no coordinate rulers or labels. - Each map sits at its `shift_x` / `shift_y` in level coordinates. The canvas is the smallest rectangle holding all the level's maps. Cells no map covers are opaque black, like the gaps between cells. - Seam rule, the decided priority for a cell several maps claim: 1. A map exit, or a connector teleporter (`Teleporter::blocks_passage`, which neighbouring maps treat as a map exit, #392), gives way to another map's real tile. 2. Between real tiles that still conflict, a tile inside its map wins over one on another map's outer edge. 3. Otherwise the map first in `dungeon.dat` order wins. No warning: overlap on seams is normal. In DOS-EN, 2275 cells overlap: - 1582 are a map exit on one map and a real tile on another (rule 1); - 399 are map exits on every map (they keep the border chip); - 229 are real tiles of the same type; - 65 are real tiles that differ. 64 of those are connector teleporters over floor (rule 1); the last is a wall on one map's edge against an inner floor (rule 2). - The winning cell is drawn with everything the per-map renderer draws for it on its own map: tileset, ornaments, creatures and animation. - Creatures are on by default, for per-map and level images and in the bindings. This reverses #402's default. The CLI flag becomes `--no-creatures`. `--scale` applies to level images as to map images. - Animation loops over the whole level image (the least common multiple of the cells' periods, capped at 64 ticks) at `dm2_graphics::GAME_TICK_MS`. A level with nothing animated is a plain PNG. The 4096 px per side limit applies. - A level with a map that cannot render (missing tileset) is skipped with a warning. The per-map images that do render are still written. - Bindings parity: `dungeon_level_png(dungeon, gdat, level, scale, creatures)` through `dm2-convert`, wasm `dungeonLevelPng`, FFI `dm2_dungeon_level_png`, Python `dungeon_level_png(dungeon, gdat, level, scale=1, creatures=True)`. The per-map `dungeon_map_png` Python default becomes `creatures=True`. ## Non-goals - Coordinate rulers, labels or a legend. - Console-family archives (#410). They keep today's "not supported yet" message. - Assembling several levels into one image. ## Anti-goals - Seams that show border chips where the game shows the neighbouring map's floor. - Level images whose cells differ from the per-map images apart from the seam rule. - Noise: no warning per overlapping cell. ## Constraints - Layering: CLI and `dm2-convert` call `dm2-magicmap`; `dm2-magicmap` calls `dm2-dungeon` / `dm2-graphics`. - Reuse the per-map chip selection: `terrain_chips` / `creature_chips` per owning map and its local coordinates. Don't duplicate rules. - `dm2-magicmap` and the `creatures` option are unreleased, so their API may change without a deprecation path. - Validation: the DMDC2 "World Atlas" (DOS, levels 1-8 and 10) is per level and labelled in level coordinates. #402 found it draws with the game's own chips, so walls, floors, pits, doors and stairs should match on levels 1-3. Its own conventions differ elsewhere (see the "Magic map" section of `docs/formats/dungeon-dat.md`). ## Left to the builder - The library API: e.g. `render_level_png(d, gdat, level, opts)` beside `render_map_png`, sharing the compositor; and how `RenderOptions` expresses the creatures default (a `Default` impl with `creatures: true` is fine). - How the CLI groups maps by level and orders map and level output, and how it reports a skipped level. - Whether border-chip cells (map exits that no other map covers) keep the owning map's border tileset. They should, as in per-map images. - Error variants for a level that doesn't exist, and for an empty level. - Docs: the "Magic map" section and CHANGELOG (Added: level images, `dungeon_level_png` everywhere; Changed: creatures on by default, `--no-creatures`).
Author
Owner

Level Magic-Map Images Implementation Plan

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.

Goal: dm2 extract --gdat also writes one level_NN.png per level, assembling the level's maps as the game places them; creatures become on by default.

Architecture: dm2-magicmap gains a level layout (which map and local cell owns each level cell, by the seam rule) and renders any layout through the existing compositor; a per-map image is the one-map layout. The CLI and the bindings call render_level_png beside render_map_png.

Tech Stack: Rust 2024; existing dm2-magicmap / dm2-dungeon / dm2-graphics.

Spec: issue #409 (draft: scratch/level-assembly-design.md).

Global Constraints

  • level_NN.png beside map_NN.png, written on every --gdat run; NN = the maps' level field (two digits).
  • Only chips; cells no map covers are opaque black.
  • Seam rule for a cell several maps claim: (1) a map exit or a connector teleporter (Teleporter::blocks_passage) gives way to another map's real tile; (2) between remaining real tiles, one inside its map beats one on another map's outer edge; (3) otherwise the map first in dungeon.dat order wins. No warning.
  • The winning cell is drawn exactly as the per-map renderer draws it on its own map (its tileset, ornaments, creatures, animation).
  • Creatures on by default everywhere: CLI --no-creatures replaces --creatures; Python defaults creatures=True for dungeon_map_png and dungeon_level_png.
  • Animation over the whole level, LCM of periods capped at 64 ticks, dm2_graphics::GAME_TICK_MS; 4096 px per side limit.
  • A level containing a map that can't render is skipped with a warning; its renderable per-map images are still written.
  • Layering: CLI and dm2-convert -> dm2-magicmap -> dm2-dungeon / dm2-graphics. Reuse terrain_chips / creature_chips; no duplicated rules.
  • dm2-magicmap and the creatures option are unreleased: API may change freely.

Review Focus

  1. A level whose maps use different tilesets: each cell keeps its owning map's base strip (Task 3 test).
  2. A cell where every claimant is a map exit: border chip of the first map in order (Task 2 test).
  3. level value with no maps: a typed error, not a panic or empty PNG (Task 3 test).
  4. A level spanning more than 4096 px at the requested scale: TooLarge before allocating (Task 3 test).
  5. A level containing an unrenderable map in the CLI: one warning naming the level, other levels and all renderable maps written (Task 4 test).

Task 1: Creatures on by default

Files: crates/dm2-magicmap/src/render.rs (RenderOptions), crates/dm2-cli/src/main.rs (Extract args), crates/dm2-cli/src/commands/extract.rs, crates/dm2-cli/tests/extract_magic_map.rs, bindings/python/dm2_tools/__init__.py, bindings/python/README.md, crates/dm2-wasm/README.md, docs/formats/dungeon-dat.md (Creatures paragraph), CHANGELOG.md.

Interfaces:

  • Produces: impl Default for RenderOptions = { scale: 1, creatures: true }; CLI flag --no-creatures (requires --gdat); Python dungeon_map_png(dungeon, gdat, map, scale=1, creatures=True).

  • Step 1: Failing tests: RenderOptions::default() == RenderOptions { scale: 1, creatures: true }; CLI: DOS-EN map 4 PNG differs between a plain --gdat run and --gdat --no-creatures; --creatures is rejected as an unknown flag; Python: dungeon_map_png(...) without creatures equals creatures=True.

  • Step 2: Implement; wasm/FFI keep an explicit creatures bool (no defaults in those ABIs).

  • Step 3: Docs + CHANGELOG (Changed: creatures on by default, --no-creatures). Gates; commit feat(magicmap): draw creatures by default.

Task 2: Level layout and the seam rule

Files: Create crates/dm2-magicmap/src/level.rs; modify crates/dm2-magicmap/src/lib.rs (module + exports).

Interfaces:

  • Produces:

    • pub struct LevelLayout { pub origin: (u16, u16), pub width: u16, pub height: u16, cells: Vec<Option<(usize, u8, u8)>> } — level-coordinate bounding box of the level's maps; each cell's owner (map index, local x, local y) or None when no map covers it.
    • impl LevelLayout { pub fn owner(&self, x: u16, y: u16) -> Option<(usize, u8, u8)> } (canvas-relative coordinates).
    • pub fn level_layout(d: &Dungeon, level: u8) -> Option<LevelLayout> (None when no map has that level).
    • pub fn levels(d: &Dungeon) -> Vec<u8> (distinct level values, ascending).
  • Step 1: Failing tests (synthetic two-map dungeons via test_util::Fixture extended to several maps if needed): rule 1 — map exit on A over floor on B → B owns; connector teleporter (blocks_passage) on A over floor on B → B owns; rule 2 — wall on A's outer edge vs floor inside B → B owns; rule 3 — floor inside A vs wall inside B, A first → A owns; all map exits → the first map owns; uncovered cell → None; bounding box = min shift .. max(shift + size).

  • Step 2: DOS-EN fixture test: for every level, every cell of every map has an owner, and the number of cells with more than one claimant across all levels is 2275 (the count measured for the design).

  • Step 3: Implement. A connector is a teleporter tile whose record (first teleporter on the tile's chain) has blocks_passage().

  • Step 4: Tests pass; gates; commit feat(magicmap): resolve level layouts with the seam rule.

Task 3: Render any layout; render_level_png

Files: crates/dm2-magicmap/src/render.rs, crates/dm2-magicmap/src/lib.rs.

Interfaces:

  • Consumes: level_layout, LevelLayout::owner.

  • Produces:

    • pub fn render_level_png(d: &Dungeon, gdat: &Archive, level: u8, opts: &RenderOptions) -> Result<Vec<u8>, MagicMapError>
    • MagicMapError::LevelOutOfRange(u8) (no map has that level).
    • A level containing a map whose base strip is missing returns NoTileset { map, tileset } for the first such map.
    • render_map_png unchanged in signature and output bytes.
  • Step 1: Failing tests: a one-map level (synthetic) renders byte-identical to render_map_png of that map; DOS-EN: each level's PNG is 8 * width * scale by 8 * height * scale of its layout; a seam cell owned by map B in level L has the same pixels as that cell in B's own map image (compare the 8x8 block, tick 0); two maps with different map_graphics_style keep their own base strips; render_level_png(.., 99, ..) -> LevelOutOfRange(99); scale making a side over 4096 -> TooLarge; uncovered cells are opaque black.

  • Step 2: Implement: the renderer iterates placed cells (canvas x, y, map, local x, local y) with one MapView per map (built once, all sharing one Strips cache); per-map rendering builds the identity placement of one map. Canvas coordinates become u16. Loop detection and APNG writing stay shared.

  • Step 3: Tests pass (existing render tests unchanged); gates; commit feat(magicmap): render level images.

Task 4: extract writes level images

Files: crates/dm2-cli/src/commands/extract.rs, crates/dm2-cli/tests/extract_magic_map.rs.

Interfaces:

  • Consumes: levels, render_level_png.

  • Step 1: Failing tests: DOS-EN --gdat run writes level_00.png .. level_10.png for exactly the levels levels() returns, beside the map images; --no-creatures applies to level images too (DOS-EN level holding map 4 differs with and without); with one map patched to tileset 15 (as the existing NoTileset test), the level holding it is skipped with one warning warning: level NN: ... and every other level and map image is written; console-family still writes JSON only.

  • Step 2: Implement inside the existing render-everything-before-writing step; whole-file errors still abort before anything is written.

  • Step 3: Tests pass; gates; commit feat(cli): write level magic-map images.

Task 5: Bindings

Files: crates/dm2-convert/src/convert.rs, crates/dm2-wasm/src/wasm.rs + README.md, crates/dm2-ffi/src/lib.rs + include/dm2_tools.h, bindings/python/dm2_tools/__init__.py + README.md, tests in crates/dm2-convert/tests/reads.rs, crates/dm2-ffi/tests/abi.rs, bindings/python/tests/test_reads.py.

Interfaces:

  • Produces: dm2_convert::dungeon_level_png(dungeon: &[u8], gdat: &[u8], level: u8, scale: u8, creatures: bool) -> Result<Vec<u8>, ConvertError>; wasm dungeonLevelPng; FFI dm2_dungeon_level_png; Python dungeon_level_png(dungeon, gdat, level, scale=1, creatures=True) -> bytes.

  • Step 1: Failing tests: DOS-EN level 1 returns PNG bytes in convert, FFI and Python; level 99 errors; scale 0 errors (ZeroScale).

  • Step 2: Implement following dungeon_map_png through each layer; keep the C header in sync.

  • Step 3: Tests pass (Python as in the #402 work: cargo build --release -p dm2-ffi, then PYTHONPATH=bindings/python UV_CACHE_DIR=scratch/uv-cache uv run --no-project --with pytest -- python -m pytest bindings/python/tests -q); cargo check -p dm2-wasm --target wasm32-unknown-unknown; commit feat(bindings): expose level magic-map rendering.

Task 6: Validation and docs

Files: docs/formats/dungeon-dat.md ("Magic map" section), CHANGELOG.md, crates/dm2-magicmap/README.md.

  • Step 1: Render DOS-EN levels 1-3 at --scale 2 and compare each with the DMDC2 atlas level image (http://dmweb.free.fr/files/Game,Dungeon_Master_II,DMDC2,Dungeon,Level_0N,Map.png; the atlas adds a coordinate border). Check seams especially: walls, floors, pits, doors and stairs should match; trace any other difference to the engine or to the atlas's documented conventions before changing code. Fix real defects with a test each, in their own commit.
  • Step 2: Docs: level images, the seam rule (with the DOS-EN overlap counts), creatures default; CHANGELOG Added (level images, render_level_png, dungeon_level_png in every binding); commit docs(magicmap): document level images.

PR split: Tasks 1-3 (library); Tasks 4-6 (CLI, bindings, docs).

# Level Magic-Map Images Implementation Plan > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. **Goal:** `dm2 extract --gdat` also writes one `level_NN.png` per level, assembling the level's maps as the game places them; creatures become on by default. **Architecture:** `dm2-magicmap` gains a level layout (which map and local cell owns each level cell, by the seam rule) and renders any layout through the existing compositor; a per-map image is the one-map layout. The CLI and the bindings call `render_level_png` beside `render_map_png`. **Tech Stack:** Rust 2024; existing `dm2-magicmap` / `dm2-dungeon` / `dm2-graphics`. **Spec:** issue #409 (draft: `scratch/level-assembly-design.md`). ## Global Constraints - `level_NN.png` beside `map_NN.png`, written on every `--gdat` run; `NN` = the maps' `level` field (two digits). - Only chips; cells no map covers are opaque black. - Seam rule for a cell several maps claim: (1) a map exit or a connector teleporter (`Teleporter::blocks_passage`) gives way to another map's real tile; (2) between remaining real tiles, one inside its map beats one on another map's outer edge; (3) otherwise the map first in `dungeon.dat` order wins. No warning. - The winning cell is drawn exactly as the per-map renderer draws it on its own map (its tileset, ornaments, creatures, animation). - Creatures on by default everywhere: CLI `--no-creatures` replaces `--creatures`; Python defaults `creatures=True` for `dungeon_map_png` and `dungeon_level_png`. - Animation over the whole level, LCM of periods capped at 64 ticks, `dm2_graphics::GAME_TICK_MS`; 4096 px per side limit. - A level containing a map that can't render is skipped with a warning; its renderable per-map images are still written. - Layering: CLI and `dm2-convert` -> `dm2-magicmap` -> `dm2-dungeon` / `dm2-graphics`. Reuse `terrain_chips` / `creature_chips`; no duplicated rules. - `dm2-magicmap` and the creatures option are unreleased: API may change freely. ## Review Focus 1. A level whose maps use different tilesets: each cell keeps its owning map's base strip (Task 3 test). 2. A cell where every claimant is a map exit: border chip of the first map in order (Task 2 test). 3. `level` value with no maps: a typed error, not a panic or empty PNG (Task 3 test). 4. A level spanning more than 4096 px at the requested scale: `TooLarge` before allocating (Task 3 test). 5. A level containing an unrenderable map in the CLI: one warning naming the level, other levels and all renderable maps written (Task 4 test). --- ### Task 1: Creatures on by default **Files:** `crates/dm2-magicmap/src/render.rs` (`RenderOptions`), `crates/dm2-cli/src/main.rs` (Extract args), `crates/dm2-cli/src/commands/extract.rs`, `crates/dm2-cli/tests/extract_magic_map.rs`, `bindings/python/dm2_tools/__init__.py`, `bindings/python/README.md`, `crates/dm2-wasm/README.md`, `docs/formats/dungeon-dat.md` (Creatures paragraph), `CHANGELOG.md`. **Interfaces:** - Produces: `impl Default for RenderOptions` = `{ scale: 1, creatures: true }`; CLI flag `--no-creatures` (requires `--gdat`); Python `dungeon_map_png(dungeon, gdat, map, scale=1, creatures=True)`. - [ ] **Step 1: Failing tests:** `RenderOptions::default() == RenderOptions { scale: 1, creatures: true }`; CLI: DOS-EN map 4 PNG differs between a plain `--gdat` run and `--gdat --no-creatures`; `--creatures` is rejected as an unknown flag; Python: `dungeon_map_png(...)` without `creatures` equals `creatures=True`. - [ ] **Step 2:** Implement; wasm/FFI keep an explicit `creatures` bool (no defaults in those ABIs). - [ ] **Step 3:** Docs + CHANGELOG (Changed: creatures on by default, `--no-creatures`). Gates; commit `feat(magicmap): draw creatures by default`. ### Task 2: Level layout and the seam rule **Files:** Create `crates/dm2-magicmap/src/level.rs`; modify `crates/dm2-magicmap/src/lib.rs` (module + exports). **Interfaces:** - Produces: - `pub struct LevelLayout { pub origin: (u16, u16), pub width: u16, pub height: u16, cells: Vec<Option<(usize, u8, u8)>> }` — level-coordinate bounding box of the level's maps; each cell's owner `(map index, local x, local y)` or `None` when no map covers it. - `impl LevelLayout { pub fn owner(&self, x: u16, y: u16) -> Option<(usize, u8, u8)> }` (canvas-relative coordinates). - `pub fn level_layout(d: &Dungeon, level: u8) -> Option<LevelLayout>` (`None` when no map has that level). - `pub fn levels(d: &Dungeon) -> Vec<u8>` (distinct `level` values, ascending). - [ ] **Step 1: Failing tests** (synthetic two-map dungeons via `test_util::Fixture` extended to several maps if needed): rule 1 — map exit on A over floor on B → B owns; connector teleporter (`blocks_passage`) on A over floor on B → B owns; rule 2 — wall on A's outer edge vs floor inside B → B owns; rule 3 — floor inside A vs wall inside B, A first → A owns; all map exits → the first map owns; uncovered cell → `None`; bounding box = min shift .. max(shift + size). - [ ] **Step 2:** DOS-EN fixture test: for every level, every cell of every map has an owner, and the number of cells with more than one claimant across all levels is 2275 (the count measured for the design). - [ ] **Step 3:** Implement. A connector is a teleporter tile whose record (first teleporter on the tile's chain) has `blocks_passage()`. - [ ] **Step 4:** Tests pass; gates; commit `feat(magicmap): resolve level layouts with the seam rule`. ### Task 3: Render any layout; `render_level_png` **Files:** `crates/dm2-magicmap/src/render.rs`, `crates/dm2-magicmap/src/lib.rs`. **Interfaces:** - Consumes: `level_layout`, `LevelLayout::owner`. - Produces: - `pub fn render_level_png(d: &Dungeon, gdat: &Archive, level: u8, opts: &RenderOptions) -> Result<Vec<u8>, MagicMapError>` - `MagicMapError::LevelOutOfRange(u8)` (no map has that level). - A level containing a map whose base strip is missing returns `NoTileset { map, tileset }` for the first such map. - `render_map_png` unchanged in signature and output bytes. - [ ] **Step 1: Failing tests:** a one-map level (synthetic) renders byte-identical to `render_map_png` of that map; DOS-EN: each level's PNG is `8 * width * scale` by `8 * height * scale` of its layout; a seam cell owned by map B in level L has the same pixels as that cell in B's own map image (compare the 8x8 block, tick 0); two maps with different `map_graphics_style` keep their own base strips; `render_level_png(.., 99, ..)` -> `LevelOutOfRange(99)`; scale making a side over 4096 -> `TooLarge`; uncovered cells are opaque black. - [ ] **Step 2:** Implement: the renderer iterates placed cells `(canvas x, y, map, local x, local y)` with one `MapView` per map (built once, all sharing one `Strips` cache); per-map rendering builds the identity placement of one map. Canvas coordinates become `u16`. Loop detection and APNG writing stay shared. - [ ] **Step 3:** Tests pass (existing render tests unchanged); gates; commit `feat(magicmap): render level images`. ### Task 4: `extract` writes level images **Files:** `crates/dm2-cli/src/commands/extract.rs`, `crates/dm2-cli/tests/extract_magic_map.rs`. **Interfaces:** - Consumes: `levels`, `render_level_png`. - [ ] **Step 1: Failing tests:** DOS-EN `--gdat` run writes `level_00.png` .. `level_10.png` for exactly the levels `levels()` returns, beside the map images; `--no-creatures` applies to level images too (DOS-EN level holding map 4 differs with and without); with one map patched to tileset 15 (as the existing NoTileset test), the level holding it is skipped with one warning `warning: level NN: ...` and every other level and map image is written; console-family still writes JSON only. - [ ] **Step 2:** Implement inside the existing render-everything-before-writing step; whole-file errors still abort before anything is written. - [ ] **Step 3:** Tests pass; gates; commit `feat(cli): write level magic-map images`. ### Task 5: Bindings **Files:** `crates/dm2-convert/src/convert.rs`, `crates/dm2-wasm/src/wasm.rs` + `README.md`, `crates/dm2-ffi/src/lib.rs` + `include/dm2_tools.h`, `bindings/python/dm2_tools/__init__.py` + `README.md`, tests in `crates/dm2-convert/tests/reads.rs`, `crates/dm2-ffi/tests/abi.rs`, `bindings/python/tests/test_reads.py`. **Interfaces:** - Produces: `dm2_convert::dungeon_level_png(dungeon: &[u8], gdat: &[u8], level: u8, scale: u8, creatures: bool) -> Result<Vec<u8>, ConvertError>`; wasm `dungeonLevelPng`; FFI `dm2_dungeon_level_png`; Python `dungeon_level_png(dungeon, gdat, level, scale=1, creatures=True) -> bytes`. - [ ] **Step 1: Failing tests:** DOS-EN level 1 returns PNG bytes in convert, FFI and Python; level 99 errors; scale 0 errors (`ZeroScale`). - [ ] **Step 2:** Implement following `dungeon_map_png` through each layer; keep the C header in sync. - [ ] **Step 3:** Tests pass (Python as in the #402 work: `cargo build --release -p dm2-ffi`, then `PYTHONPATH=bindings/python UV_CACHE_DIR=scratch/uv-cache uv run --no-project --with pytest -- python -m pytest bindings/python/tests -q`); `cargo check -p dm2-wasm --target wasm32-unknown-unknown`; commit `feat(bindings): expose level magic-map rendering`. ### Task 6: Validation and docs **Files:** `docs/formats/dungeon-dat.md` ("Magic map" section), `CHANGELOG.md`, `crates/dm2-magicmap/README.md`. - [ ] **Step 1:** Render DOS-EN levels 1-3 at `--scale 2` and compare each with the DMDC2 atlas level image (http://dmweb.free.fr/files/Game,Dungeon_Master_II,DMDC2,Dungeon,Level_0N,Map.png; the atlas adds a coordinate border). Check seams especially: walls, floors, pits, doors and stairs should match; trace any other difference to the engine or to the atlas's documented conventions before changing code. Fix real defects with a test each, in their own commit. - [ ] **Step 2:** Docs: level images, the seam rule (with the DOS-EN overlap counts), creatures default; CHANGELOG Added (level images, `render_level_png`, `dungeon_level_png` in every binding); commit `docs(magicmap): document level images`. **PR split:** Tasks 1-3 (library); Tasks 4-6 (CLI, bindings, docs).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jqueuniet/dm2-tools#409
No description provided.