Add hub zone with portal connections
This commit is contained in:
parent
56c82700b0
commit
b123d55fbd
2 changed files with 114 additions and 0 deletions
47
content/zones/hub.toml
Normal file
47
content/zones/hub.toml
Normal file
|
|
@ -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"
|
||||||
67
tests/test_hub_zone.py
Normal file
67
tests/test_hub_zone.py
Normal file
|
|
@ -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
|
||||||
Loading…
Reference in a new issue