Migrate zones help from hardcoded to TOML
This commit is contained in:
parent
d7698ca830
commit
a24e0c03c3
4 changed files with 46 additions and 39 deletions
21
content/help/zones.toml
Normal file
21
content/help/zones.toml
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
name = "zones"
|
||||||
|
title = "zones"
|
||||||
|
admin = true
|
||||||
|
body = """
|
||||||
|
zones are spatial containers - rooms, dungeons, overworld areas.
|
||||||
|
each zone has a terrain grid, spawn point, and optional portals.
|
||||||
|
|
||||||
|
listing zones
|
||||||
|
@zones list all registered zones
|
||||||
|
|
||||||
|
navigating
|
||||||
|
@goto <zone> teleport to a zone's spawn point
|
||||||
|
enter <portal> step through a portal to another zone
|
||||||
|
|
||||||
|
building
|
||||||
|
@dig <name> <w> <h> create a new blank zone
|
||||||
|
@paint toggle paint mode for terrain editing
|
||||||
|
@save save current zone to file
|
||||||
|
|
||||||
|
see: @zones, @goto, @dig, @paint, @save
|
||||||
|
"""
|
||||||
|
|
@ -357,30 +357,6 @@ async def cmd_client(player: Player, args: str) -> None:
|
||||||
await player.send("\r\n".join(lines) + "\r\n")
|
await player.send("\r\n".join(lines) + "\r\n")
|
||||||
|
|
||||||
|
|
||||||
async def cmd_zones_help(player: Player, args: str) -> None:
|
|
||||||
"""Show the zones guide."""
|
|
||||||
lines = [
|
|
||||||
"zones",
|
|
||||||
" zones are spatial containers - rooms, dungeons, overworld areas.",
|
|
||||||
" each zone has a terrain grid, spawn point, and optional portals.",
|
|
||||||
"",
|
|
||||||
" listing zones",
|
|
||||||
" @zones list all registered zones",
|
|
||||||
"",
|
|
||||||
" navigating",
|
|
||||||
" @goto <zone> teleport to a zone's spawn point",
|
|
||||||
" enter <portal> step through a portal to another zone",
|
|
||||||
"",
|
|
||||||
" building",
|
|
||||||
" @dig <name> <w> <h> create a new blank zone",
|
|
||||||
" @paint toggle paint mode for terrain editing",
|
|
||||||
" @save save current zone to file",
|
|
||||||
"",
|
|
||||||
" see: @zones, @goto, @dig, @paint, @save",
|
|
||||||
]
|
|
||||||
await player.send("\r\n".join(lines) + "\r\n")
|
|
||||||
|
|
||||||
|
|
||||||
# Register the commands command
|
# Register the commands command
|
||||||
register(
|
register(
|
||||||
CommandDefinition(
|
CommandDefinition(
|
||||||
|
|
@ -414,18 +390,6 @@ register(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Register the zones help topic
|
|
||||||
register(
|
|
||||||
CommandDefinition(
|
|
||||||
"zones",
|
|
||||||
cmd_zones_help,
|
|
||||||
mode="*",
|
|
||||||
hidden=True,
|
|
||||||
admin=True,
|
|
||||||
help="zone building guide",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def cmd_help(player: Player, args: str) -> None:
|
async def cmd_help(player: Player, args: str) -> None:
|
||||||
"""Show help for a command or skill.
|
"""Show help for a command or skill.
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ from mudlib.commands import (
|
||||||
look, # noqa: F401
|
look, # noqa: F401
|
||||||
movement, # noqa: F401
|
movement, # noqa: F401
|
||||||
)
|
)
|
||||||
|
from mudlib.commands.help import _help_topics
|
||||||
|
from mudlib.content import load_help_topics
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
@ -43,6 +45,19 @@ def admin_player(mock_reader, mock_writer):
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def _load_zones_topic():
|
||||||
|
"""Load the zones help topic for tests that need it."""
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
help_dir = Path(__file__).resolve().parents[1] / "content" / "help"
|
||||||
|
if help_dir.exists():
|
||||||
|
loaded = load_help_topics(help_dir)
|
||||||
|
_help_topics.update(loaded)
|
||||||
|
yield
|
||||||
|
_help_topics.clear()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_help_command_is_registered():
|
async def test_help_command_is_registered():
|
||||||
"""The help command should be registered in the command registry."""
|
"""The help command should be registered in the command registry."""
|
||||||
|
|
@ -117,9 +132,6 @@ async def test_help_zones_shows_see_also(admin_player):
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_help_zones_requires_admin(player):
|
async def test_help_zones_requires_admin(player):
|
||||||
"""Non-admin players cannot see admin help topics."""
|
"""Non-admin players cannot see admin help topics."""
|
||||||
# Import build to ensure @zones help topic is registered
|
|
||||||
from mudlib.commands import build # noqa: F401
|
|
||||||
|
|
||||||
await commands.dispatch(player, "help zones")
|
await commands.dispatch(player, "help zones")
|
||||||
output = "".join([call[0][0] for call in player.writer.write.call_args_list])
|
output = "".join([call[0][0] for call in player.writer.write.call_args_list])
|
||||||
assert "unknown" in output.lower()
|
assert "unknown" in output.lower()
|
||||||
|
|
|
||||||
|
|
@ -144,3 +144,13 @@ async def test_help_admin_topic_visible_to_admins(admin_player):
|
||||||
await commands.dispatch(admin_player, "help secret")
|
await commands.dispatch(admin_player, "help secret")
|
||||||
output = "".join(c[0][0] for c in admin_player.writer.write.call_args_list)
|
output = "".join(c[0][0] for c in admin_player.writer.write.call_args_list)
|
||||||
assert "hidden" in output
|
assert "hidden" in output
|
||||||
|
|
||||||
|
|
||||||
|
def test_zones_toml_loads_from_content():
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
help_dir = Path(__file__).resolve().parents[1] / "content" / "help"
|
||||||
|
topics = load_help_topics(help_dir)
|
||||||
|
assert "zones" in topics
|
||||||
|
assert topics["zones"].admin is True
|
||||||
|
assert "@zones" in topics["zones"].body
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue