From dc3b9c3f13b06b80db5c9f9a4c15804dfd60af4a Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Mon, 13 May 2019 19:28:30 +0000 Subject: [PATCH] Support abbreviating portal names when moving Allow users to abbreviate portal names provided to the move command for convenience. --- mudpy/command.py | 10 ++++++---- mudpy/tests/selftest.py | 4 ++-- share/command.yaml | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/mudpy/command.py b/mudpy/command.py index 39e0a83..20b448c 100644 --- a/mudpy/command.py +++ b/mudpy/command.py @@ -263,10 +263,12 @@ def look(actor, parameters): def move(actor, parameters): """Move the avatar in a given direction.""" - if parameters in actor.universe.contents[actor.get("location")].portals(): - actor.move_direction(parameters) - else: - actor.send("You cannot go that way.") + for portal in sorted( + actor.universe.contents[actor.get("location")].portals()): + if portal.startswith(parameters): + actor.move_direction(portal) + return(portal) + actor.send("You cannot go that way.") def preferences(actor, parameters): diff --git a/mudpy/tests/selftest.py b/mudpy/tests/selftest.py index 1b2de6a..6755195 100644 --- a/mudpy/tests/selftest.py +++ b/mudpy/tests/selftest.py @@ -223,8 +223,8 @@ test_help = ( test_abbrev = ( (0, "> ", "h"), (0, r"h\[elp\].*m\[ove\].*> ", "he mo"), - (0, r"Move in a specific direction\..*> ", "mov north"), - (0, r"You exit to the north\..*> ", "m south"), + (0, r"Move in a specific direction\..*> ", "mov nor"), + (0, r"You exit to the north\..*> ", "m s"), (0, r"You exit to the south\..*> ", ""), ) diff --git a/share/command.yaml b/share/command.yaml index 7fe1d16..10a0cdf 100644 --- a/share/command.yaml +++ b/share/command.yaml @@ -44,8 +44,9 @@ command.look.description: Look around. command.look.help: With the look command, you can see where you are. command.move.description: Move in a specific direction. -command.move.help: You move in a direction by entering:$(eol)$(eol) move - north +command.move.help: Move to another place by supplying the name of a + portal/direction or a suitable abbreviation for one, + like:$(eol)$(eol) move north$(eol) move s command.preferences.description: View or change your preferences. command.preferences.help: If invoked with no parameters, all your current -- 2.11.0