divmod-dev team mailing list archive
-
divmod-dev team
-
Mailing list archive
-
Message #00521
[Merge] lp:~jerith/divmod.org/short-directions-1215929 into lp:divmod.org
Jeremy Thurgood has proposed merging lp:~jerith/divmod.org/short-directions-1215929 into lp:divmod.org.
Requested reviews:
Divmod-dev (divmod-dev)
Related bugs:
Bug #1215929 in Divmod Imaginary: "Short aliases for standard directions would be handy"
https://bugs.launchpad.net/imaginary/+bug/1215929
For more details, see:
https://code.launchpad.net/~jerith/divmod.org/short-directions-1215929/+merge/181830
Adds some short aliases for standard directions.
--
https://code.launchpad.net/~jerith/divmod.org/short-directions-1215929/+merge/181830
Your team Divmod-dev is requested to review the proposed merge of lp:~jerith/divmod.org/short-directions-1215929 into lp:divmod.org.
=== modified file 'Imaginary/imaginary/action.py'
--- Imaginary/imaginary/action.py 2013-06-09 16:07:17 +0000
+++ Imaginary/imaginary/action.py 2013-08-23 13:51:21 +0000
@@ -788,11 +788,21 @@
+_direction_names = objects.OPPOSITE_DIRECTIONS.keys()
+_direction_names.extend(objects.DIRECTION_ALIASES.keys())
+
DIRECTION_LITERAL = reduce(
operator.xor, [
pyparsing.Literal(d)
- for d
- in objects.OPPOSITE_DIRECTIONS]).setResultsName("direction")
+ for d in _direction_names]).setResultsName("direction")
+
+
+
+def expandDirection(direction):
+ """
+ Expand direction aliases into the names of the directions they refer to.
+ """
+ return objects.DIRECTION_ALIASES.get(direction, direction)
@@ -804,6 +814,7 @@
pyparsing.restOfLine.setResultsName("name"))
def do(self, player, line, direction, name):
+ direction = expandDirection(direction)
if iimaginary.IContainer(player.thing.location).getExitNamed(direction, None) is not None:
raise eimaginary.ActionFailure(events.ThatDoesntMakeSense(
actor=player.thing,
@@ -831,6 +842,7 @@
DIRECTION_LITERAL)
def do(self, player, line, direction):
+ direction = expandDirection(direction)
for exit in iimaginary.IContainer(player.thing.location).getExits():
if exit.name == direction:
if exit.sibling is not None:
@@ -858,7 +870,7 @@
class Go(Action):
expr = (
- DIRECTION_LITERAL |
+ (DIRECTION_LITERAL + pyparsing.LineEnd()) |
(pyparsing.Literal("go") + pyparsing.White() +
targetString("direction")) |
(pyparsing.Literal("enter") + pyparsing.White() +
@@ -873,6 +885,7 @@
Identify a direction by having the player search for L{IExit}
providers that they can see and reach.
"""
+ directionName = expandDirection(directionName)
return player.obtainOrReportWhyNot(
Proximity(
3.0,
=== modified file 'Imaginary/imaginary/objects.py'
--- Imaginary/imaginary/objects.py 2013-07-24 22:20:29 +0000
+++ Imaginary/imaginary/objects.py 2013-08-23 13:51:21 +0000
@@ -433,6 +433,18 @@
+DIRECTION_ALIASES = {
+ u"n": u"north",
+ u"s": u"south",
+ u"w": u"west",
+ u"e": u"east",
+ u"nw": u"northwest",
+ u"se": u"southeast",
+ u"ne": u"northeast",
+ u"sw": u"southwest"}
+
+
+
class Exit(item.Item):
"""
An L{Exit} is an oriented pathway between two L{Thing}s which each
=== modified file 'Imaginary/imaginary/test/test_actions.py'
--- Imaginary/imaginary/test/test_actions.py 2013-07-26 00:20:17 +0000
+++ Imaginary/imaginary/test/test_actions.py 2013-08-23 13:51:21 +0000
@@ -447,6 +447,32 @@
"dig west boring tunnel",
["There is already an exit in that direction."])
+
+ def testDigDirectionAliases(self):
+ self._test(
+ "dig w dark tunnel",
+ ["You create an exit."],
+ ["Test Player created an exit to the west."])
+ room = iimaginary.IContainer(self.location).getExitNamed(u'west').toLocation
+ self.assertEquals(room.name, u"dark tunnel")
+ self.assertEquals(room.description, u'')
+ self.assertIdentical(iimaginary.IContainer(room).getExitNamed(u'east').toLocation,
+ self.location)
+
+ self._test(
+ "dig e bright tunnel",
+ ["You create an exit."],
+ ["Test Player created an exit to the east."])
+ room = iimaginary.IContainer(self.location).getExitNamed(u'east').toLocation
+ self.assertEquals(room.name, u"bright tunnel")
+ self.assertEquals(room.description, u'')
+ self.assertIdentical(iimaginary.IContainer(room).getExitNamed(u'west').toLocation, self.location)
+
+ self._test(
+ "dig w boring tunnel",
+ ["There is already an exit in that direction."])
+
+
def testBury(self):
self._test(
"bury south",
@@ -485,6 +511,44 @@
[])
+ def testBuryDirectionAliases(self):
+ self._test(
+ "bury s",
+ ["There isn't an exit in that direction."])
+ self.assertEquals(list(iimaginary.IContainer(self.location).getExits()), [])
+
+ room = objects.Thing(store=self.store, name=u"destination", proper=True)
+ objects.Container.createFor(room, capacity=1000)
+ objects.Exit.link(room, self.location, u'north')
+
+ self._test(
+ "bury s",
+ ["It's gone."],
+ ["Test Player destroyed the exit to destination."])
+
+ self.assertEquals(
+ list(iimaginary.IContainer(self.location).getExits()),
+ [])
+
+ self.assertEquals(
+ list(iimaginary.IContainer(room).getExits()),
+ [])
+
+ objects.Exit.link(self.location, room, u'south')
+ self.observer.moveTo(room)
+
+ self._test(
+ "bury s",
+ ["It's gone."],
+ ["The exit to Test Location crumbles and disappears."])
+ self.assertEquals(
+ list(iimaginary.IContainer(self.location).getExits()),
+ [])
+ self.assertEquals(
+ list(iimaginary.IContainer(room).getExits()),
+ [])
+
+
def testGo(self):
self._test(
"go west",
@@ -516,6 +580,37 @@
["Test Player arrives from the west."])
+ def testGoDirectionAliases(self):
+ self._test(
+ "go w",
+ ["You can't go that way."])
+ self._test(
+ "w",
+ ["You can't go that way."])
+
+ room = objects.Thing(store=self.store, name=u"destination")
+ objects.Container.createFor(room, capacity=1000)
+ objects.Exit.link(self.location, room, u"west")
+
+ self._test(
+ "w",
+ [E("[ destination ]"),
+ E("( east )"),
+ ""],
+ ["Test Player leaves west."])
+
+ self._test(
+ "n",
+ ["You can't go that way."])
+ self._test(
+ "go e",
+ [E("[ Test Location ]"),
+ E("( west )"),
+ "Location for testing.",
+ "Here, you see Observer Player."],
+ ["Test Player arrives from the west."])
+
+
def test_goThroughOneWayExit(self):
"""
Going through a one-way exit with a known direction will announce that
@@ -579,6 +674,13 @@
[E("[ ") + ".*" + E(" ]"), # Not testing room description
E("( ") + ".*" + E(" )"), # Just do enough to make sure it was not an error.
""])
+ shortDirections = ["nw", "n", "ne", "e", "w", "sw", "s", "se"]
+ for d, rd in zip(shortDirections, reversed(shortDirections)):
+ self._test(
+ d,
+ [E("[ ") + ".*" + E(" ]"), # Not testing room description
+ E("( ") + ".*" + E(" )"), # Just do enough to make sure it was not an error.
+ ""])
def test_scrutinize(self):
Follow ups