def vt102(self, observer): title = [T.bold, T.fg.green, u'[ ', [T.fg.normal, IConcept(self.title).vt102(observer)], u' ]\n'] yield title exits = list( IConcept(exit.name).vt102(observer) for exit in (self.exits or ()) if exit.shouldEvenAttemptTraversalFrom(self.target, observer)) if exits: yield [ T.bold, T.fg.green, u'( ', [ T.fg.normal, T.fg.yellow, iterutils.interlace( u' ', exits)], u' )', u'\n'] if self.description: yield (T.fg.green, self.description, u'\n') if self.components: yield iterutils.interlace( u"\n", filter(None, (component.vt102(observer) for component in self.components)))
def testInterlace(self): self.assertEquals(list(iterutils.interlace('x', ())), []) self.assertEquals(list(iterutils.interlace('x', [1])), [1]) self.assertEquals(list(iterutils.interlace('x', [1, 2])), [1, 'x', 2]) self.assertEquals(list(iterutils.interlace('x', [1, 2, 3])), [1, 'x', 2, 'x', 3])
def do(self, player, line): cmds = dict.fromkeys( getattr(cmd, 'actionName', cmd.__name__.lower()) for cmd in self.__class__.actions).keys() cmds.sort() player.send((iterutils.interlace(" ", cmds), "\n"))
def testInterlace(self): self.assertEquals( list(iterutils.interlace('x', ())), []) self.assertEquals( list(iterutils.interlace('x', [1])), [1]) self.assertEquals( list(iterutils.interlace('x', [1, 2])), [1, 'x', 2]) self.assertEquals( list(iterutils.interlace('x', [1, 2, 3])), [1, 'x', 2, 'x', 3])
def do(self, player, line, name): srch = player.thing.search(2, iimaginary.IVisible, name) evt = events.Success( actor=player.thing, actorMessage=language.ExpressList( list(iterutils.interlace('\n', (o.visualize() for o in srch))))) evt.broadcast()
def vt102(self, observer): exits = u'' if self.exits: exits = [T.bold, T.fg.green, u'( ', [T.fg.normal, T.fg.yellow, iterutils.interlace(u' ', (exit.name for exit in self.exits))], u' )', u'\n'] description = self.description or u"" if description: description = (T.fg.green, self.description, u'\n') descriptionConcepts = [] for pup in self.others: descriptionConcepts.append(pup.conceptualize()) def index(c): try: return self.preferredOrder.index(c.__class__.__name__) except ValueError: # Anything unrecognized goes after anything recognized. return len(self.preferredOrder) descriptionConcepts.sort(key=index) descriptionComponents = [] for c in descriptionConcepts: s = c.vt102(observer) if s: descriptionComponents.extend([s, u'\n']) if descriptionComponents: descriptionComponents.pop() return [ [T.bold, T.fg.green, u'[ ', [T.fg.normal, self.name], u' ]\n'], exits, description, descriptionComponents]
def vt102(self, observer): exits = u'' if self.exits: exits = [ T.bold, T.fg.green, u'( ', [ T.fg.normal, T.fg.yellow, iterutils.interlace(u' ', (exit.name for exit in self.exits)) ], u' )', u'\n' ] description = self.description or u"" if description: description = (T.fg.green, self.description, u'\n') descriptionConcepts = [] for pup in self.others: descriptionConcepts.append(pup.conceptualize()) def index(c): try: return self.preferredOrder.index(c.__class__.__name__) except ValueError: # Anything unrecognized goes after anything recognized. return len(self.preferredOrder) descriptionConcepts.sort(key=index) descriptionComponents = [] for c in descriptionConcepts: s = c.vt102(observer) if s: descriptionComponents.extend([s, u'\n']) if descriptionComponents: descriptionComponents.pop() return [[T.bold, T.fg.green, u'[ ', [T.fg.normal, self.name], u' ]\n'], exits, description, descriptionComponents]