Beispiel #1
0
        def addChildren(menu, childList):
            for child in childList:
                emote = None
                if type(child) == type({}):
                    item = child.keys()[0]
                    emote = child[item]
                    child = item
                if type(child) == type(0):
                    terminal = SCStaticTextTerminal(child)
                    if emote is not None:
                        terminal.setLinkedEmote(emote)
                    menu.append(terminal)
                elif type(child) == type([]):
                    if type(child[0]) == type(''):
                        holderTitle = child[0]
                        subMenu = SCMenu()
                        subMenuChildren = child[1:]
                    else:
                        menuType, holderTitle = child[0], child[1]
                        subMenu = menuType()
                        subMenuChildren = child[2:]
                    if emote:
                        print 'warning: tried to link emote %s to a menu holder' % emote
                    holder = SCMenuHolder(holderTitle, menu=subMenu)
                    menu.append(holder)
                    addChildren(subMenu, subMenuChildren)
                elif type(child) == type('') and child[:2] == 'gm':
                    terminal = SCGMTextTerminal(child)
                    menu.append(terminal)
                else:
                    raise 'error parsing speedchat structure. invalid child: %s' % child

            return
Beispiel #2
0
        def addChildren(menu, childList):
            """ this recursive function adds children to an SCMenu
            according to the specification in 'childList'. See above
            for the format of childList (it matches the format of
            'structure'). """
            for child in childList:
                # if it's a dictionary, there's an emote attached
                emote = None
                if type(child) == type({}):
                    assert len(child.keys()) == 1
                    item = child.keys()[0]
                    emote = child[item]
                    child = item

                # use this func to add terminal nodes;
                # takes care of linking emotes
                # def addTerminal(terminal, menu=menu, emote=emote):
                #    if emote is not None:
                #        terminal.setLinkedEmote(emote)
                #    menu.append(terminal)

                if type(child) == type(0):
                    # it's a static text ID
                    assert child in OTPLocalizer.SpeedChatStaticText
                    terminal = SCStaticTextTerminal(child)
                    if emote is not None:
                        terminal.setLinkedEmote(emote)
                    menu.append(terminal)
                    # addTerminal(SCStaticTextTerminal(child))
                elif type(child) == type([]):
                    # we've got a menu holder and a menu to be held
                    # if first element of list is string, it's a plain SCMenu
                    if type(child[0]) == type(''):
                        holderTitle = child[0]
                        subMenu = SCMenu()
                        subMenuChildren = child[1:]
                    else:
                        # otherwise, first element of list is class
                        menuType, holderTitle = child[0], child[1]
                        subMenu = menuType()
                        subMenuChildren = child[2:]
                    if emote:
                        print ('warning: tried to link emote %s '
                               'to a menu holder' % emote)
                    holder = SCMenuHolder(holderTitle, menu=subMenu)
                    menu.append(holder)
                    addChildren(subMenu, subMenuChildren)
                elif type(child) == type('') and child[:2] == 'gm':
                    terminal = SCGMTextTerminal(child)
                    menu.append(terminal)
                else:
                    raise ('error parsing speedchat structure. '
                           'invalid child: %s' % child)