def testExpressList(self): self.assertEquals( self.format( language.ExpressList([ language.ExpressString(u"foo"), u" ", language.ExpressString(u"bar") ])), u"foo bar")
def test_components(self): """ A L{Description.plaintext} includes any extra components. """ a = language.ExpressString(u"first part") b = language.ExpressString(u"last part") self.assertEquals( self.format( _description(title=self.thing.name, description=self.thing.description, components=[a, b])), u'[ fake thing ]\n' u'Fake Thing Description\n' + a.original + u"\n" + b.original)
def test_descriptionContributors(self): """ A L{Description.vt102} includes any extra components. """ a = language.ExpressString(u"first part") b = language.ExpressString(u"last part") self._assertECMA48Equality( self.format( _description(title=self.thing.name, description=self.thing.description, components=[a, b])), self.flatten([[[ T.bold, T.fg.green, u'[ ', [T.fg.normal, "fake thing"], u' ]\n' ], T.fg.green, u'Fake Thing Description\n'], a.original + u"\n" + b.original]))
def do(self, player, line, typeName, name, description=None, article=None): """ Create an item, and notify everyone present that it now exists. """ if not description: description = u'an undescribed object' for plug in getPlugins(IThingType, imaginary.plugins): if plug.type == typeName: proper = (article == "the") o = plug.getType()(store=player.store, name=name, description=description, proper=proper) break else: raise ActionFailure( events.ThatDoesntMakeSense( actor=player.thing, actorMessage=language.ExpressString(u"Can't find " + typeName + u"."))) creationSuccess(player.thing, o).broadcast() try: o.moveTo(player.thing) except DoesntFit: raise insufficientSpace(player.thing)
def testCapitalization(self): self.assertEquals( self.format(language.ExpressString(u"foo").capitalizeConcept()), u"Foo") self.assertEquals( self.format( language.ExpressList([[[[u"hi"]]]]).capitalizeConcept()), u"Hi") self.assertEquals( self.format( language.ItemizedList([u"foo", u"bar", u"baz"]).capitalizeConcept()), u"Foo, bar, and baz")
def do(self, player, line): from imaginary import garments equipment = list( player.store.query( objects.Thing, AND(garments.Garment.thing == objects.Thing.storeID, garments.Garment.wearer == player), sort=objects.Thing.name.ascending)) if equipment: evt = events.Success(actor=player.thing, actorMessage=[ u"You are wearing ", language.ItemizedList(equipment), u"." ]) else: evt = events.Success(actor=player.thing, actorMessage=language.ExpressString( u"You aren't wearing any equipment.")) evt.broadcast()
def do(self, player, line, direction): location = player.location evt = events.Success( location=location, actor=player, otherMessage=(player, " leaves ", direction.name, ".")) evt.broadcast() try: direction.traverse(player) except eimaginary.DoesntFit: raise eimaginary.ActionFailure(events.ThatDoesntWork( actor=player, actorMessage=language.ExpressString( u"There's no room for you there."))) # This is subtly incorrect: see http://divmod.org/trac/ticket/2917 lookAroundActor = iimaginary.IActor(player) LookAround().do(lookAroundActor, "look")
def do(self, player, line, direction): try: exit = iimaginary.IContainer( player.thing.location).getExitNamed(direction) except KeyError: raise eimaginary.ActionFailure( events.ThatDoesntWork(actor=player.thing, actorMessage=u"You can't go that way.")) dest = exit.toLocation location = player.thing.location evt = events.Success(location=location, actor=player.thing, otherMessage=(player.thing, " leaves ", direction, ".")) evt.broadcast() if exit.sibling is not None: arriveDirection = exit.sibling.name else: arriveDirection = object.OPPOSITE_DIRECTIONS[exit.name] try: player.thing.moveTo( dest, arrivalEventFactory=lambda player: events.MovementArrivalEvent( thing=player, origin=None, direction=arriveDirection)) except eimaginary.DoesntFit: raise eimaginary.ActionFailure( events.ThatDoesntWork(actor=player.thing, actorMessage=language.ExpressString( u"There's no room for you there."))) # XXX A convention for programmatically invoked actions? # None as the line? LookAround().do(player, "look")
def testExpressString(self): self.assertEquals(self.format(language.ExpressString(u"foo bar")), u"foo bar")
def conceptualize(self): return language.ExpressString(self.descr)
def contributeDescriptionFrom(self, paths): return language.ExpressString(u'This can be worn.')
def conceptualize(self): return language.ExpressString(u'This can be worn.')