Exemplo n.º 1
0
 def init_content(self):
     # Fit text to width. Split into lines and reform into target height
     text = utils.wrap(self.db.text, width=self.db.screen_width,
                       indent=2).split("\n")
     self.db.pages = [
         "\n".join(text[i:i + self.db.screen_height])
         for i in range(0, len(text), self.db.screen_height)
     ]
     self.db.current_page = 0
Exemplo n.º 2
0
def wrap(text, *args, **kwargs):
    "Wrap/Fill text to width. fill(text, width=78, indent=0)"
    width = _DEFAULT_WIDTH
    indent = 0
    for iarg, arg in enumerate(args):
        if iarg == 0:
            width = int(arg) if arg.isdigit() else width
        elif iarg == 1:
            indent = int(arg) if arg.isdigit() else indent
    return utils.wrap(text, width=width, indent=indent)
Exemplo n.º 3
0
def wrap(text, *args, **kwargs):
    "Wrap/Fill text to width. fill(text, width=78, indent=0)"
    width = _DEFAULT_WIDTH
    indent = 0
    for iarg, arg in enumerate(args):
        if iarg == 0:
            width = int(arg) if arg.isdigit() else width
        elif iarg == 1:
            indent = int(arg) if arg.isdigit() else indent
    return utils.wrap(text, width=width, indent=indent)
Exemplo n.º 4
0
    def get_help(self, caller):
        """
        Get help about this object. By default we return a
        listing of all actions you can do on this object.

        """
        # custom-created signatures. We don't sort these
        command_signatures, helpstr = self.get_cmd_signatures()

        callsigns = list_to_string(["*" + sig for sig in command_signatures], endsep="or")

        # parse for *thing markers (use these as items)
        options = caller.attributes.get("options", category=self.room.tagcategory, default={})
        style = options.get("things_style", 2)

        helpstr = helpstr.format(callsigns=callsigns)
        helpstr = parse_for_things(helpstr, style, clr="|w")
        return wrap(helpstr, width=80)
Exemplo n.º 5
0
def verify_desc(caller, raw_input):
    "Sets the special desc and asks the player to verify it."
    specialdesc = utils.wrap(raw_input, width=80)
    if len(specialdesc) > 300:
        specialdesc = specialdesc[:299]
    if specialdesc == "":
        specialdesc = "A special move called %s" % callder.ndb.special_name
    caller.ndb.special_desc = specialdesc
    effectlist = [caller.ndb.special_effect_1]
    if caller.ndb.special_effect_2:
        effectlist.append(caller.ndb.special_effect_2)
    effectstring = utils.list_to_string(effectlist, endsep="|255and|455", addquote=False)
    effectstringlength = len(effectstring)
    if "|255and|455" in effectstring:
        effectstringlength -= 8
    paddinglength = max((80 - effectstringlength - len(caller.ndb.special_name) - 9), 0)
    padding = ('{:-^%i}' % paddinglength).format('')
    text = "Your special move:\n\n|455%s |255[|455%s|255] %s |455%i|255 SP|n\n%s\n\nIs this all right?" % (caller.ndb.special_name, effectstring, padding, rules.special_cost(effectlist), caller.ndb.special_desc)
    options = ({"key": "Yes", "desc":"Finalize special move", "goto": "finalize_special"},
               {"key": "No", "desc":"Enter a new description", "goto": "desc_special"}
               )
    return text, options
Exemplo n.º 6
0
    def func(self):
        ch = self.caller
        args = self.args.strip().split()
        obj = ch.ndb._redit.obj

        if has_zone(ch) != obj['zone']:
            ch.msg("You do not have permission to edit this zones room")
            return
        if not args:
            attrs = self.valid_room_attributes.copy()
            attrs[attrs.index('type')] = 'sector'
            keywords = "|n\n*|c".join(attrs)
            ch.msg(
                f'You must provide one of the valid keywords.\n*|c{keywords}')
            return

        keyword = args[0].lower()
        set_str = f"{keyword} set"
        if match_string(keyword, 'name'):
            if len(args) == 1:
                ch.msg("Must supply name for room")
                return
            obj['name'] = " ".join(args[1:]).strip()
            ch.msg(set_str)
            return

        elif match_string(keyword, 'desc'):
            if len(args) > 1:
                obj['desc'] = " ".join(args[1:]).strip()
                ch.msg(set_str)
            else:

                def save_func(_caller, buffer):
                    obj['desc'] = buffer
                    ch.msg(set_str)

                _ = EvEditor(ch,
                             loadfunc=(lambda _: obj['desc']),
                             savefunc=save_func)
            return
        elif match_string(keyword, 'sector'):
            if len(args) > 1:
                sector = args[1].strip()
                if sector not in VALID_ROOM_SECTORS.keys():
                    ch.msg("not a valid room sector")
                    return
                obj['type'] = sector
                return
            else:
                # show all sectors
                sectors = ", ".join(VALID_ROOM_SECTORS.keys())
                msg = f"Sectors:\n{wrap(sectors)}"
                ch.msg(msg)
                return
        elif match_string(keyword, 'edesc'):
            if len(args) > 1:
                ch.msg("set `edesc` without any arguments.")
            else:

                def save_func(_caller, buffer):
                    split = [
                        x.strip() for x in re.split("<(.*)>", buffer.strip())
                        if x
                    ]

                    if len(split) == 1:
                        # key not found
                        ch.msg("Keys must have <..> syntax.")
                        return

                    # uneven key/contents
                    if len(split) % 2 != 0:
                        # last elemet is key without content
                        split.append("n/a")

                    # create dictionary from keys/contents
                    edesc = dict([(k, v)
                                  for k, v in zip(split[::2], split[1::2])])

                    obj['edesc'] = edesc
                    ch.msg(set_str)

                if obj['edesc']:
                    edesc = ""
                    for key, contents in obj['edesc'].items():
                        edesc += f"<{key}>\n{contents}\n"
                else:
                    edesc = "<keyword> contents"
                _ = EvEditor(ch,
                             loadfunc=(lambda _: edesc),
                             savefunc=save_func)
        elif keyword == 'zone':
            ch.msg("You can't set zone this way")
            return
        elif keyword == 'flags':
            if len(args) > 1:
                flag = args[1].strip()
                if flag == 'clear':
                    obj['flags'].clear()

                if flag not in VALID_ROOM_FLAGS:
                    ch.msg("Not a valid room flag")
                    return

                if flag in obj['flags']:
                    obj['flags'].remove(flag)
                    ch.msg(f"{flag} flag removed")
                else:
                    obj['flags'].append(flag)
                    ch.msg(f"{flag} flag applied")

            else:
                # show all foom flags
                flags = wrap(", ".join(VALID_ROOM_FLAGS))
                msg = f"Room Flags:\n{flags}"
                ch.msg(msg)
                return
        elif match_string(keyword, 'exits'):
            if len(args) > 1:
                exit_name = args[1]
                if args[2] == 'clear':
                    exit_vnum = 'clear'
                else:
                    try:
                        exit_vnum = int(args[2])
                    except:
                        ch.msg("That is not a valid vnum")
                        return

                if exit_vnum == 'clear':
                    obj['exits'][exit_name] = -1
                else:
                    # check to see if exit_vnum is a valid vnum
                    if not room_exists(exit_vnum):
                        ch.msg("That room vnum does not exist")
                        return
                    obj['exits'][exit_name] = exit_vnum
                    ch.msg(set_str)

            else:
                ch.msg("Must provide a vnum to the exit")
                return
        else:
            ch.msg("That isn't a valid keyword")
            return