From 9cdc1c48e48396b950ad12b90a686c3c46abf7c8 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Sat, 7 Feb 2026 13:38:32 -0500 Subject: [PATCH] Add a map renderer --- .gitignore | 1 + justfile | 3 ++ scripts/render_map.py | 96 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 scripts/render_map.py diff --git a/.gitignore b/.gitignore index 8d3b990..aefbfe8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__ repos +build diff --git a/justfile b/justfile index 17c400a..2a629cb 100644 --- a/justfile +++ b/justfile @@ -15,3 +15,6 @@ run: debug: uv run python -m mudlib --debug + +render: + uv run python scripts/render_map.py diff --git a/scripts/render_map.py b/scripts/render_map.py new file mode 100644 index 0000000..1b1d115 --- /dev/null +++ b/scripts/render_map.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python +"""Render the full world map as an HTML page.""" + +import sys +import tomllib +import webbrowser +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).parent.parent / "src")) + +from mudlib.world.terrain import World + +ROOT = Path(__file__).parent.parent + + +def main(): + config_path = ROOT / "worlds" / "earth" / "config.toml" + with open(config_path, "rb") as f: + config = tomllib.load(f) + + seed = config["world"]["seed"] + width = config["world"]["width"] + height = config["world"]["height"] + name = config["world"]["name"] + + print(f"generating {name} ({width}x{height}, seed={seed})...") + world = World(seed=seed, width=width, height=height) + + # encode terrain as compact string, one char per tile + rows = ["".join(row) for row in world.terrain] + terrain_data = "\\n".join(rows) + + html = f""" + + +{name} + + + + + + +""" + + out_path = ROOT / "build" / "map.html" + out_path.parent.mkdir(exist_ok=True) + out_path.write_text(html) + print(f"wrote {out_path}") + webbrowser.open(f"file://{out_path.resolve()}") + + +if __name__ == "__main__": + main()