Exemple #1
0
 def variant(bg):
     """ Make a parser for the background. """
     fullname = epp.literal(misc.normalize(bg.name))
     shortname = epp.literal(misc.normalize(bg.shortname))
     eff = epp.effect(lambda val, st: val.update({Capture.BACKGROUND: bg}))
     return epp.chain(
         [epp.branch([fullname, shortname], save_iterator=False), eff],
         save_iterator=False)
Exemple #2
0
 def variant(species):
     """ Make a parser for the species. """
     fullname = epp.literal(misc.normalize(species.name))
     shortname = epp.literal(misc.normalize(species.shortname))
     eff = epp.effect(
         lambda val, st: val.update({Capture.SPECIES: species}))
     return epp.chain(
         [epp.branch([fullname, shortname], save_iterator=False), eff],
         save_iterator=False)
Exemple #3
0
 def set_name(self, name):
     """ Set the name of the character and add a default alias. """
     if self.name is not None:
         self.remove_alias(misc.normalize(self.name).split()[0])
     alias = name.split()[0]
     self.add_alias(alias)
     self.name = name
Exemple #4
0
 def read_name(self):
     """ Read and return the name of the party. """
     while True:
         name = self.io.ask(self.data.strings[cat.CHAR_CREATION][char.NAME_PROMPT])
         name = misc.normalize(name)
         if name == "":
             continue
         return misc.pretty_name(name)
Exemple #5
0
 def specific_pc_parser(pc):
     """ Make a parser for a specific PC. """
     name = epp.literal(misc.normalize(pc.name))
     aliases = epp.multi(pc.aliases)
     eff = epp.effect(lambda val, st: val.update({Capture.PC: pc}))
     return epp.chain(
         [epp.branch([name, aliases], save_iterator=False), eff],
         save_iterator=False)
Exemple #6
0
 def ask(self, prompt, do_normalize=False):
     """
     Request user input. Return the inputted string, optionally normalized.
     """
     self.flush()
     print()
     inp = input(f"{prompt.strip()} ")
     if do_normalize:
         inp = normalize(inp)
     return inp
Exemple #7
0
def _make_topic():
    """ Make a help/apropos topic parser. """
    output_parser = epp.chain([
        epp.greedy(epp.everything()),
        epp.effect(lambda val, st: val.update(
            {Capture.TOPIC: misc.normalize(st.parsed)}))
    ],
                              save_iterator=False)
    return epp.chain(
        [epp.literal("{topic}"),
         epp.effect(lambda val, st: output_parser)],
        save_iterator=False)
Exemple #8
0
def _make_name():
    """ Make a name parser. """
    output_parser = epp.chain([
        epp.greedy(epp.everything()),
        epp.effect(lambda val, st: val.update(
            {Capture.NAME: misc.normalize(st.parsed)}))
    ],
                              save_iterator=False)
    return epp.chain(
        [epp.literal("{name}"),
         epp.effect(lambda val, st: output_parser)],
        save_iterator=False)
Exemple #9
0
 def reset_aliases(self):
     """ Reset the aliases list just to defaults. """
     self.aliases.clear()
     self.aliases.append(misc.normalize(self.name.split()[0]))
Exemple #10
0
 def add_alias(self, alias):
     """ Add an alias for the PC. """
     self.aliases.append(misc.normalize(alias))