Skip to content

Add create_image_pack for tagged PNG asset packs - #1

Open
arhidavid wants to merge 5 commits into
mainfrom
cursor/pack-builder-followup-8303
Open

arhidavid wants to merge 5 commits into
mainfrom
cursor/pack-builder-followup-8303

Conversation

@arhidavid

@arhidavid arhidavid commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Problem and behavior

Follow-up to thekannen/battlemap-mcp#17: import_image already shipped in upstream 1.4.2. This PR is the pack-builder half only, based on current upstream main / 1.4.2.

create_image_pack(filename, name, images, pack_id="", author="") builds a native .dungeondraft_pack of named, tagged PNG objects. The archive includes the root registration manifest and inner pack.json, plus native tags/sets. Existing files are never overwritten. Writes are limited to Dungeondraft’s configured asset folder.

Workflow after create: restart Dungeondraft (verified live) — or rescan packs in the Assets window (unverified without restart) → prepare_map_with_packs with the returned id → list_assets / search_pack_contents / place_object. search_pack_contents can already see the new archive on disk before a rescan/restart.

Design choice (tool count)

Adds one companion tool: create_image_pack.

  • Not merged into import_image (embed-in-map vs library pack are different jobs).
  • Not merged into prepare_map_with_packs (that tool rewrites map headers; packing PNGs does not belong there).
  • Does not add refresh_asset_packs (see note 3 below).

Addressing thekannen’s #17 notes

  1. No-clobber / portable publish. Replaced os.link with O_CREAT | O_EXCL open of the final destination, then write + fsync. That works on exFAT, FAT32, and network shares where hard links fail. A competing writer that claims the name first surfaces as “already exists”; this call only unlinks a file it created.

  2. Where packs may be written. filename is a bare name (same style as prepare_map_with_packs). The destination is resolved under pack_contents.assets_directory() only (config.ini custom_assets_directory or BATTLEMAP_MCP_ASSETS_DIR). Absolute/outside paths are refused.

  3. refresh_asset_packs / Assets.UpdateTree — deferred. The #17 live notes reported a native read error and editor exit when an invalid early test archive was moved during cleanup while Dungeondraft was running; that “do not move mounted packs” restriction remains documented. Neither our cloud environment nor our live pass isolated UpdateTree, and this PR does not expose refresh. Safe path: ask the user to restart Dungeondraft (or rescan in the Assets window), then call prepare_map_with_packs. If a later live session clearly shows refresh-only is safe, that can be a small follow-up.

  4. Fewer new tools. One new tool instead of three (import_image already upstream; refresh omitted).

Implementation

  • Extends server/battlemap_mcp/image_import.py with pack building (reuses PNG validation).
  • Registers create_image_pack as a companion tool in bridge_client.py.
  • Docs: docs/image-pack.md; PROTOCOL / docs README updated.
  • No bridge / GDScript changes; no re-add of import_image.

Validation

Offline CI/checks:

  • Full python server/tools/gate.py passed (format, lint, bridge/contract/lifecycle/engine, skills, agent docs, types, tests).
  • tools/release.py check passed.
  • New/extended offline coverage in server/tests/test_image_import.py: pack round-trip, root manifest, no-clobber race, asset-folder path limit, reserved Colorable tag, corrupt PNG refusal.

Live Windows + Dungeondraft check on a61209d (running the PR’s 1.4.2-matched bridge source hash):

  • python server/tools/gate.py passed on Windows with a fresh temporary folder.
  • create_image_pack refused an outside path (../…), wrote a two-PNG .dungeondraft_pack inside Dungeondraft’s configured asset folder, and refused to overwrite it (file hash stayed identical); search_pack_contents found both tags on disk immediately.
  • After restarting Dungeondraft, list_asset_packs saw the pack, prepare_map_with_packs added it to a scratch map copy, both tagged objects were discoverable and placeable, and both survived save and reopen; pixel checks confirmed transparent centers in the DD2VTT export.
  • Note: the manual Assets-window rescan path without restarting Dungeondraft was not tested live.
  • Dungeondraft exited cleanly before removing the temporary pack (do not move/remove mounted packs while the editor runs).

Documentation pages needing maintainer update

AI assistance

Code and PR text were written with AI assistance (Cursor / Codex).

Note for Mike

Opened on arhidavid/battlemap-mcp for your review first (currently private). Not opened against thekannen/battlemap-mcp; no upstream comments or pushes. When you are ready to submit upstream, make the fork public (or export the branch) and reuse this description against #17’s pack-builder follow-up request.

Open in Web Open in Cursor 

arhidavid and others added 5 commits November 8, 2026 12:34
On Windows, every map open ran two PowerShell checks on the bridge's
token, and each one flashed a console window and could pull focus away
from Dungeondraft. The token now lasts for the whole Dungeondraft
session, so the checks run once at startup and later map opens show
nothing.

import_image places a PNG from your computer as an object, the way
dragging it into Dungeondraft does. The image is stored inside the map
file, so it survives moving or deleting the original.

From battlemap-mcp#16 and #17.

Co-authored-by: thekannen <thekannengieser@gmail.com>
The console fix and image import are @arhidavid's work, from pull
requests #16 and #17: thank you, David.

- On Windows, opening a map no longer flashes a console window or
  steals focus; the token check runs once per Dungeondraft session.
- Place a PNG from your computer on the map, stored inside the map.
- With Moulk's Soft Shadows, your assistant can add, adjust and undo
  soft shadows on objects, walls and paths, and copies keep them.
- With Moulk's Sketch Tool, your sketch notes stay out of exports.
- Redo survives taking a screenshot or saving.
- Elements kept for undo are freed when another map opens.
- The README lists the mods the assistant supports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A narrated walk-through on YouTube installs battlemap-mcp from nothing
with the Claude desktop app: the extension, the Dungeondraft mod, a
connection check and a first room. It's linked beside the documentation
and in Get started.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Carry forward the pack-builder half of upstream #17 on top of 1.4.2.
Publish with O_CREAT|O_EXCL into Dungeondraft's configured asset folder
only, add one companion tool (no Assets.UpdateTree refresh), and cover
no-clobber and path limits in offline tests.

Co-authored-by: arhidavid <arhidavid@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants