Modify example menu to allow for species selection

This commit is contained in:
Hazel Nova 2024-01-13 11:09:14 +08:00
parent bdc519048a
commit 151db69595
2 changed files with 39 additions and 41 deletions

View File

@ -52,14 +52,10 @@ class AccountCmdSet(default_cmds.AccountCmdSet):
key = "DefaultAccount"
def at_cmdset_creation(self):
"""
Populates the cmdset
"""
super().at_cmdset_creation()
#
# any commands you add below will overload the default ones.
#
# Char creation
self.add(ContribCmdCharCreate)
class UnloggedinCmdSet(default_cmds.UnloggedinCmdSet):
"""
@ -100,8 +96,3 @@ class SessionCmdSet(default_cmds.SessionCmdSet):
# any commands you add below will overload the default ones.
#
# Char creation
class AccountCmdSet(default_cmds.AccountCmdSet):
def at_cmdset_creation(self):
super().at_cmdset_creation()
self.add(ContribCmdCharCreate)

View File

@ -100,26 +100,33 @@ def menunode_welcome(caller):
# Storing your information in a dictionary like this makes the menu nodes much cleaner,
# as well as making info easier to update. You can even import it from a different module,
# e.g. wherever you have the classes actually defined, so later updates only happen in one place.
_CLASS_INFO_DICT = {
# The keys here are the different options you can choose, and the values are the info pages
"warrior": dedent(
_SPECIES_INFO_DICT = {
"Human": dedent(
"""\
Most warriors specialize in melee weapons, although ranged combat
is not unheard of.
The most common species in the adventurers guild, at least for new recruits.
Warriors like to compete by beating each other up for fun.
Humans are well-rounded and very adaptable.
While they may not have claws or fangs or any fancy adaptations,
they don't have any drawbacks or glaring weaknesses either.
"""
),
"mage": dedent(
"Catkin": dedent(
"""\
Mages prefer less combative lines of work, such as showmanship or
selling enchanted charms. Those who choose to be a battle mage are
highly sought after by adventuring parties.
Relatively common, compared to more obscure Monsterkin types.
Mage schools, being led by the most academic-minded of mages, are
notorious for intellectual snobbery.
A variant of human descended from feline heritage,
Catkin keep some traits of their ancestors, including ears, tails, and claws.
"""
),
"Dogkin": dedent(
"""\
Relatively common, compared to more obscure Monsterkin types.
A variant of human descended from canine heritage,
Dogkin keep some traits of their ancestors, including ears, tails, and fangs.
"""
)
# Descriptions and species still very much WIP
}
@ -139,66 +146,66 @@ def menunode_info_base(caller):
help = "A link to your wiki for more information on classes could be useful here."
options = []
# Build your options from your info dict so you don't need to update this to add new options
for pclass in _CLASS_INFO_DICT.keys():
for species in _SPECIES_INFO_DICT.keys():
options.append(
{
"desc": f"Learn about the |c{pclass}|n class",
"goto": ("menunode_info_class", {"selected_class": pclass}),
"desc": f"Learn about the |c{species}|n species",
"goto": ("menunode_info_species", {"selected_species": species}),
}
)
return (text, help), options
# putting your kwarg in the menu declaration helps keep track of what variables the node needs
def menunode_info_class(caller, raw_string, selected_class=None, **kwargs):
"""Informational overview of a particular class"""
def menunode_info_species(caller, raw_string, selected_species=None, **kwargs):
"""Informational overview of a particular species"""
# sometimes weird bugs happen - it's best to check for them rather than let the game break
if not selected_class:
if not selected_species:
# reset back to the previous step
caller.new_char.db.chargen_step = "menunode_welcome"
# print error to player and quit the menu
return "Something went wrong. Please try again."
# Since you have all the info in a nice dict, you can just grab it to display here
text = _CLASS_INFO_DICT[selected_class]
text = _SPECIES_INFO_DICT[selected_species]
help = "If you want option-specific help, you can define it in your info dict and reference it."
options = []
# set an option for players to choose this class
options.append(
{
"desc": f"Become {_INFLECT.an(selected_class)}",
"goto": (_set_class, {"selected_class": selected_class}),
"desc": f"Become {_INFLECT.an(selected_species)}",
"goto": (_set_species, {"selected_species": selected_species}),
}
)
# once again build your options from the same info dict
for pclass in _CLASS_INFO_DICT.keys():
for species in _SPECIES_INFO_DICT.keys():
# make sure you don't print the currently displayed page as an option
if pclass != selected_class:
if species != selected_species:
options.append(
{
"desc": f"Learn about the |c{pclass}|n class",
"goto": ("menunode_info_class", {"selected_class": pclass}),
"desc": f"Learn about the |c{species}|n species",
"goto": ("menunode_info_species", {"selected_species": species}),
}
)
return (text, help), options
def _set_class(caller, raw_string, selected_class=None, **kwargs):
# a class should always be selected here
if not selected_class:
def _set_species(caller, raw_string, selected_species=None, **kwargs):
# a species should always be selected here
if not selected_species:
# go back to the base node for this decision
return "menunode_info_base"
char = caller.new_char
# any special code for setting this option would go here!
# but we'll just set an attribute
char.db.player_class = selected_class
char.db.species = list(_SPECIES_INFO_DICT.keys()).index(selected_species)
# move on to the next step!
return "menunode_categories"
return "menunode_multi_choice"
#########################################################