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)
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)
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
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)
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)
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
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)
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)
def reset_aliases(self): """ Reset the aliases list just to defaults. """ self.aliases.clear() self.aliases.append(misc.normalize(self.name.split()[0]))
def add_alias(self, alias): """ Add an alias for the PC. """ self.aliases.append(misc.normalize(alias))