From b123d55fbd8d8066b751cd34ebea7978c34ec52f Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Wed, 11 Feb 2026 22:10:14 -0500 Subject: [PATCH] Add hub zone with portal connections --- content/zones/hub.toml | 47 +++++++++++++++++++++++++++++ tests/test_hub_zone.py | 67 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 content/zones/hub.toml create mode 100644 tests/test_hub_zone.py diff --git a/content/zones/hub.toml b/content/zones/hub.toml new file mode 100644 index 0000000..051cc59 --- /dev/null +++ b/content/zones/hub.toml @@ -0,0 +1,47 @@ +name = "hub" +description = "a crossroads where paths converge beneath a weathered signpost" +width = 15 +height = 15 +toroidal = false +spawn_x = 7 +spawn_y = 7 + +[terrain] +rows = [ + "#######.#######", + "#######.#######", + "#######.#######", + "#######.#######", + "#......+......#", + "#......+......#", + "#......+......#", + "..............+", + "#......+......#", + "#......+......#", + "#......+......#", + "#######.#######", + "#######.#######", + "#######.#######", + "#######.#######", +] + +[terrain.impassable] +tiles = ["#"] + +[[portals]] +x = 7 +y = 0 +target = "overworld:500,500" +label = "a wide dirt path" + +[[portals]] +x = 14 +y = 7 +target = "tavern:4,5" +label = "a weathered oak door" + +[[portals]] +x = 7 +y = 14 +target = "treehouse:0,7" +label = "a mossy forest trail" diff --git a/tests/test_hub_zone.py b/tests/test_hub_zone.py new file mode 100644 index 0000000..1c804d4 --- /dev/null +++ b/tests/test_hub_zone.py @@ -0,0 +1,67 @@ +"""Tests for the hub zone.""" + +import pathlib + +from mudlib.zones import load_zone + + +def test_load_hub_zone(): + """Load the hub zone from TOML file.""" + project_root = pathlib.Path(__file__).resolve().parents[1] + hub_path = project_root / "content" / "zones" / "hub.toml" + + zone = load_zone(hub_path) + + assert zone.name == "hub" + assert zone.width == 15 + assert zone.height == 15 + assert zone.toroidal is False + assert zone.spawn_x == 7 + assert zone.spawn_y == 7 + + +def test_hub_zone_has_portals(): + """Hub zone has portals to overworld, tavern, and treehouse.""" + project_root = pathlib.Path(__file__).resolve().parents[1] + hub_path = project_root / "content" / "zones" / "hub.toml" + + zone = load_zone(hub_path) + + # Find portals in zone contents + portals = [obj for obj in zone._contents if obj.__class__.__name__ == "Portal"] + assert len(portals) == 3 + + # Check that we have portals to each target zone + target_zones = {p.target_zone for p in portals} + assert target_zones == {"overworld", "tavern", "treehouse"} + + +def test_hub_zone_portals_at_correct_positions(): + """Portals are at expected coordinates on the map.""" + project_root = pathlib.Path(__file__).resolve().parents[1] + hub_path = project_root / "content" / "zones" / "hub.toml" + + zone = load_zone(hub_path) + + portals = [obj for obj in zone._contents if obj.__class__.__name__ == "Portal"] + + # North portal to overworld at (7, 0) + overworld_portal = [p for p in portals if p.target_zone == "overworld"][0] + assert overworld_portal.x == 7 + assert overworld_portal.y == 0 + assert overworld_portal.target_x == 500 + assert overworld_portal.target_y == 500 + + # East portal to tavern at (14, 7) + tavern_portal = [p for p in portals if p.target_zone == "tavern"][0] + assert tavern_portal.x == 14 + assert tavern_portal.y == 7 + assert tavern_portal.target_x == 4 + assert tavern_portal.target_y == 5 + + # South portal to treehouse at (7, 14) + treehouse_portal = [p for p in portals if p.target_zone == "treehouse"][0] + assert treehouse_portal.x == 7 + assert treehouse_portal.y == 14 + assert treehouse_portal.target_x == 0 + assert treehouse_portal.target_y == 7