Support abbreviating portal names when moving
authorJeremy Stanley <fungi@yuggoth.org>
Mon, 13 May 2019 19:28:30 +0000 (19:28 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Mon, 13 May 2019 19:42:27 +0000 (19:42 +0000)
Allow users to abbreviate portal names provided to the move command
for convenience.

mudpy/command.py
mudpy/tests/selftest.py
share/command.yaml

index 39e0a83..20b448c 100644 (file)
@@ -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):
index 1b2de6a..6755195 100644 (file)
@@ -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\..*> ", ""),
 )
 
index 7fe1d16..10a0cdf 100644 (file)
@@ -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