Fix for PEP8 and resolve a traceback.
This commit is contained in:
parent
afaadf77cc
commit
4f93bc7ee5
2 changed files with 153 additions and 146 deletions
|
|
@ -87,9 +87,10 @@
|
||||||
|
|
||||||
### Contribs
|
### Contribs
|
||||||
|
|
||||||
|
- `Build Menu` (vincent-lg): New @edit command to edit object properties in a menu.
|
||||||
|
- `Field Fill` (Tim Ashley Jenkins): Wraps EvMenu for creating submittable forms.
|
||||||
- `Health Bar` (Tim Ashley Jenkins): Easily create colorful bars/meters.
|
- `Health Bar` (Tim Ashley Jenkins): Easily create colorful bars/meters.
|
||||||
- `Tree select` (Fluttersprite): Wrapper around EvMenu to easier create
|
- `Tree select` (Fluttersprite): Wrap EvMenu to create a common type of menu from a string.
|
||||||
a common form of menu from a string.
|
|
||||||
- `Turnbattle suite` (Tim Ashley Jenkins)- the old `turnbattle.py` was moved into its own
|
- `Turnbattle suite` (Tim Ashley Jenkins)- the old `turnbattle.py` was moved into its own
|
||||||
`turnbattle/` package and reworked with many different flavors of combat systems:
|
`turnbattle/` package and reworked with many different flavors of combat systems:
|
||||||
- `tb_basic` - The basic turnbattle system, with initiative/turn order attack/defense/damage.
|
- `tb_basic` - The basic turnbattle system, with initiative/turn order attack/defense/damage.
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ is submitted, the form's data is submitted as a dictionary to any callable of
|
||||||
your choice.
|
your choice.
|
||||||
|
|
||||||
The function that initializes the fillable form menu is fairly simple, and
|
The function that initializes the fillable form menu is fairly simple, and
|
||||||
includes the caller, the template for the form, and the callback which the form
|
includes the caller, the template for the form, and the callback(caller, result) to which the form
|
||||||
data will be sent to upon submission:
|
data will be sent to upon submission.
|
||||||
|
|
||||||
init_fill_field(formtemplate, caller, formcallback)
|
init_fill_field(formtemplate, caller, formcallback)
|
||||||
|
|
||||||
|
|
@ -139,10 +139,11 @@ Optional:
|
||||||
the field to False or True.
|
the field to False or True.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from evennia.utils import evmenu, evtable, delay, list_to_string
|
from evennia.utils import evmenu, evtable, delay, list_to_string, logger
|
||||||
from evennia import Command
|
from evennia import Command
|
||||||
from evennia.server.sessionhandler import SESSIONS
|
from evennia.server.sessionhandler import SESSIONS
|
||||||
|
|
||||||
|
|
||||||
class FieldEvMenu(evmenu.EvMenu):
|
class FieldEvMenu(evmenu.EvMenu):
|
||||||
"""
|
"""
|
||||||
Custom EvMenu type with its own node formatter - removes extraneous lines
|
Custom EvMenu type with its own node formatter - removes extraneous lines
|
||||||
|
|
@ -198,8 +199,9 @@ def init_fill_field(formtemplate, caller, formcallback, pretext="", posttext="",
|
||||||
formdata = initial_formdata
|
formdata = initial_formdata
|
||||||
|
|
||||||
# Provide default help text if none given
|
# Provide default help text if none given
|
||||||
if formhelptext == None:
|
if formhelptext is None:
|
||||||
formhelptext = ("Available commands:|/"
|
formhelptext = (
|
||||||
|
"Available commands:|/"
|
||||||
"|w<field> = <new value>:|n Set given field to new value, replacing the old value|/"
|
"|w<field> = <new value>:|n Set given field to new value, replacing the old value|/"
|
||||||
"|wclear <field>:|n Clear the value in the given field, making it blank|/"
|
"|wclear <field>:|n Clear the value in the given field, making it blank|/"
|
||||||
"|wlook|n: Show the form's current values|/"
|
"|wlook|n: Show the form's current values|/"
|
||||||
|
|
@ -209,7 +211,7 @@ def init_fill_field(formtemplate, caller, formcallback, pretext="", posttext="",
|
||||||
|
|
||||||
# Pass kwargs to store data needed in the menu
|
# Pass kwargs to store data needed in the menu
|
||||||
kwargs = {
|
kwargs = {
|
||||||
"formdata":formdata,
|
"formdata": formdata,
|
||||||
"formtemplate": formtemplate,
|
"formtemplate": formtemplate,
|
||||||
"formcallback": formcallback,
|
"formcallback": formcallback,
|
||||||
"pretext": pretext,
|
"pretext": pretext,
|
||||||
|
|
@ -258,7 +260,7 @@ def menunode_fieldfill(caller, raw_string, **kwargs):
|
||||||
text = (display_formdata(formtemplate, formdata, pretext=pretext,
|
text = (display_formdata(formtemplate, formdata, pretext=pretext,
|
||||||
posttext=posttext, borderstyle=borderstyle), formhelptext)
|
posttext=posttext, borderstyle=borderstyle), formhelptext)
|
||||||
options = ({"key": "_default",
|
options = ({"key": "_default",
|
||||||
"goto":"menunode_fieldfill"})
|
"goto": "menunode_fieldfill"})
|
||||||
|
|
||||||
if raw_string:
|
if raw_string:
|
||||||
# Test for given 'submit' command
|
# Test for given 'submit' command
|
||||||
|
|
@ -281,7 +283,7 @@ def menunode_fieldfill(caller, raw_string, **kwargs):
|
||||||
try:
|
try:
|
||||||
formcallback(caller, formdata)
|
formcallback(caller, formdata)
|
||||||
except Exception:
|
except Exception:
|
||||||
log_trace("Error in fillable form callback.")
|
logger.log_trace("Error in fillable form callback.")
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
# Test for 'look' command
|
# Test for 'look' command
|
||||||
|
|
@ -315,7 +317,7 @@ def menunode_fieldfill(caller, raw_string, **kwargs):
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
# Clear the field
|
# Clear the field
|
||||||
formdata.update({matched_field:None})
|
formdata.update({matched_field: None})
|
||||||
caller.ndb._menutree.formdata = formdata
|
caller.ndb._menutree.formdata = formdata
|
||||||
caller.msg("Field '%s' cleared." % matched_field)
|
caller.msg("Field '%s' cleared." % matched_field)
|
||||||
return text, options
|
return text, options
|
||||||
|
|
@ -343,7 +345,7 @@ def menunode_fieldfill(caller, raw_string, **kwargs):
|
||||||
matched_field = key
|
matched_field = key
|
||||||
|
|
||||||
# No matched field
|
# No matched field
|
||||||
if matched_field == None:
|
if matched_field is None:
|
||||||
caller.msg("Field '%s' does not exist!" % fieldname)
|
caller.msg("Field '%s' does not exist!" % fieldname)
|
||||||
text = (None, formhelptext)
|
text = (None, formhelptext)
|
||||||
return text, options
|
return text, options
|
||||||
|
|
@ -373,12 +375,12 @@ def menunode_fieldfill(caller, raw_string, **kwargs):
|
||||||
# Field type text verification
|
# Field type text verification
|
||||||
if fieldtype == "text":
|
if fieldtype == "text":
|
||||||
# Test for max/min
|
# Test for max/min
|
||||||
if max_value != None:
|
if max_value is not None:
|
||||||
if len(newvalue) > max_value:
|
if len(newvalue) > max_value:
|
||||||
caller.msg("Field '%s' has a maximum length of %i characters." % (matched_field, max_value))
|
caller.msg("Field '%s' has a maximum length of %i characters." % (matched_field, max_value))
|
||||||
text = (None, formhelptext)
|
text = (None, formhelptext)
|
||||||
return text, options
|
return text, options
|
||||||
if min_value != None:
|
if min_value is not None:
|
||||||
if len(newvalue) < min_value:
|
if len(newvalue) < min_value:
|
||||||
caller.msg("Field '%s' reqiures a minimum length of %i characters." % (matched_field, min_value))
|
caller.msg("Field '%s' reqiures a minimum length of %i characters." % (matched_field, min_value))
|
||||||
text = (None, formhelptext)
|
text = (None, formhelptext)
|
||||||
|
|
@ -393,12 +395,12 @@ def menunode_fieldfill(caller, raw_string, **kwargs):
|
||||||
text = (None, formhelptext)
|
text = (None, formhelptext)
|
||||||
return text, options
|
return text, options
|
||||||
# Test for max/min
|
# Test for max/min
|
||||||
if max_value != None:
|
if max_value is not None:
|
||||||
if newvalue > max_value:
|
if newvalue > max_value:
|
||||||
caller.msg("Field '%s' has a maximum value of %i." % (matched_field, max_value))
|
caller.msg("Field '%s' has a maximum value of %i." % (matched_field, max_value))
|
||||||
text = (None, formhelptext)
|
text = (None, formhelptext)
|
||||||
return text, options
|
return text, options
|
||||||
if min_value != None:
|
if min_value is not None:
|
||||||
if newvalue < min_value:
|
if newvalue < min_value:
|
||||||
caller.msg("Field '%s' reqiures a minimum value of %i." % (matched_field, min_value))
|
caller.msg("Field '%s' reqiures a minimum value of %i." % (matched_field, min_value))
|
||||||
text = (None, formhelptext)
|
text = (None, formhelptext)
|
||||||
|
|
@ -431,7 +433,7 @@ def menunode_fieldfill(caller, raw_string, **kwargs):
|
||||||
newvalue = True
|
newvalue = True
|
||||||
|
|
||||||
# If everything checks out, update form!!
|
# If everything checks out, update form!!
|
||||||
formdata.update({matched_field:newvalue})
|
formdata.update({matched_field: newvalue})
|
||||||
caller.ndb._menutree.formdata = formdata
|
caller.ndb._menutree.formdata = formdata
|
||||||
|
|
||||||
# Account for truestr and falsestr when updating a boolean form
|
# Account for truestr and falsestr when updating a boolean form
|
||||||
|
|
@ -447,6 +449,7 @@ def menunode_fieldfill(caller, raw_string, **kwargs):
|
||||||
|
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
|
|
||||||
def form_template_to_dict(formtemplate):
|
def form_template_to_dict(formtemplate):
|
||||||
"""
|
"""
|
||||||
Initializes a dictionary of form data from the given list-of-dictionaries
|
Initializes a dictionary of form data from the given list-of-dictionaries
|
||||||
|
|
@ -466,10 +469,11 @@ def form_template_to_dict(formtemplate):
|
||||||
if "default" in field:
|
if "default" in field:
|
||||||
# Add in default value if present
|
# Add in default value if present
|
||||||
fieldvalue = field["default"]
|
fieldvalue = field["default"]
|
||||||
formdata.update({field["fieldname"]:fieldvalue})
|
formdata.update({field["fieldname"]: fieldvalue})
|
||||||
|
|
||||||
return formdata
|
return formdata
|
||||||
|
|
||||||
|
|
||||||
def display_formdata(formtemplate, formdata,
|
def display_formdata(formtemplate, formdata,
|
||||||
pretext="", posttext="", borderstyle="cells"):
|
pretext="", posttext="", borderstyle="cells"):
|
||||||
"""
|
"""
|
||||||
|
|
@ -496,12 +500,12 @@ def display_formdata(formtemplate, formdata,
|
||||||
if len(field["fieldname"]) + 5 > field_name_width:
|
if len(field["fieldname"]) + 5 > field_name_width:
|
||||||
field_name_width = len(field["fieldname"]) + 5
|
field_name_width = len(field["fieldname"]) + 5
|
||||||
# Get field value
|
# Get field value
|
||||||
if formdata[field["fieldname"]] != None:
|
if formdata[field["fieldname"]] is not None:
|
||||||
new_fieldvalue = str(formdata[field["fieldname"]])
|
new_fieldvalue = str(formdata[field["fieldname"]])
|
||||||
# Use blank message if field is blank and once is present
|
# Use blank message if field is blank and once is present
|
||||||
if new_fieldvalue == None and "blankmsg" in field:
|
if new_fieldvalue is None and "blankmsg" in field:
|
||||||
new_fieldvalue = "|x" + str(field["blankmsg"]) + "|n"
|
new_fieldvalue = "|x" + str(field["blankmsg"]) + "|n"
|
||||||
elif new_fieldvalue == None:
|
elif new_fieldvalue is None:
|
||||||
new_fieldvalue = " "
|
new_fieldvalue = " "
|
||||||
# Replace True and False values with truestr and falsestr from template
|
# Replace True and False values with truestr and falsestr from template
|
||||||
if formdata[field["fieldname"]] is True and "truestr" in field:
|
if formdata[field["fieldname"]] is True and "truestr" in field:
|
||||||
|
|
@ -515,9 +519,9 @@ def display_formdata(formtemplate, formdata,
|
||||||
|
|
||||||
return pretext + "|/" + str(formtable) + "|/" + posttext
|
return pretext + "|/" + str(formtable) + "|/" + posttext
|
||||||
|
|
||||||
"""
|
|
||||||
EXAMPLE FUNCTIONS / COMMAND STARTS HERE
|
# EXAMPLE FUNCTIONS / COMMAND STARTS HERE
|
||||||
"""
|
|
||||||
|
|
||||||
def verify_online_player(caller, value):
|
def verify_online_player(caller, value):
|
||||||
"""
|
"""
|
||||||
|
|
@ -559,40 +563,41 @@ def verify_online_player(caller, value):
|
||||||
# Returning False indicates the new value is not valid
|
# Returning False indicates the new value is not valid
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Returning anything besides True or False will replace the player's input with the returned value
|
# Returning anything besides True or False will replace the player's input with the returned
|
||||||
# In this case, the value becomes a reference to the character object
|
# value. In this case, the value becomes a reference to the character object. You can store data
|
||||||
# You can store data besides strings and integers in the 'formdata' dictionary this way!
|
# besides strings and integers in the 'formdata' dictionary this way!
|
||||||
return matched_character
|
return matched_character
|
||||||
|
|
||||||
# Form template for the example 'delayed message' form
|
# Form template for the example 'delayed message' form
|
||||||
SAMPLE_FORM = [
|
SAMPLE_FORM = [
|
||||||
{"fieldname":"Character",
|
{"fieldname": "Character",
|
||||||
"fieldtype":"text",
|
"fieldtype": "text",
|
||||||
"max":30,
|
"max": 30,
|
||||||
"blankmsg":"(Name of an online player)",
|
"blankmsg": "(Name of an online player)",
|
||||||
"required":True,
|
"required": True,
|
||||||
"verifyfunc":verify_online_player
|
"verifyfunc": verify_online_player
|
||||||
},
|
},
|
||||||
{"fieldname":"Delay",
|
{"fieldname": "Delay",
|
||||||
"fieldtype":"number",
|
"fieldtype": "number",
|
||||||
"min":3,
|
"min": 3,
|
||||||
"max":30,
|
"max": 30,
|
||||||
"default":10,
|
"default": 10,
|
||||||
"cantclear":True
|
"cantclear": True
|
||||||
},
|
},
|
||||||
{"fieldname":"Message",
|
{"fieldname": "Message",
|
||||||
"fieldtype":"text",
|
"fieldtype": "text",
|
||||||
"min":3,
|
"min": 3,
|
||||||
"max":200,
|
"max": 200,
|
||||||
"blankmsg":"(Message up to 200 characters)"
|
"blankmsg": "(Message up to 200 characters)"
|
||||||
},
|
},
|
||||||
{"fieldname":"Anonymous",
|
{"fieldname": "Anonymous",
|
||||||
"fieldtype":"bool",
|
"fieldtype": "bool",
|
||||||
"truestr":"Yes",
|
"truestr": "Yes",
|
||||||
"falsestr":"No",
|
"falsestr": "No",
|
||||||
"default":False
|
"default": False
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class CmdTestMenu(Command):
|
class CmdTestMenu(Command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -626,6 +631,7 @@ class CmdTestMenu(Command):
|
||||||
pretext=pretext, posttext=posttext,
|
pretext=pretext, posttext=posttext,
|
||||||
submitcmd="send", borderstyle="none")
|
submitcmd="send", borderstyle="none")
|
||||||
|
|
||||||
|
|
||||||
def sendmessage(obj, text):
|
def sendmessage(obj, text):
|
||||||
"""
|
"""
|
||||||
Callback to send a message to a player.
|
Callback to send a message to a player.
|
||||||
|
|
@ -636,6 +642,7 @@ def sendmessage(obj, text):
|
||||||
"""
|
"""
|
||||||
obj.msg(text)
|
obj.msg(text)
|
||||||
|
|
||||||
|
|
||||||
def init_delayed_message(caller, formdata):
|
def init_delayed_message(caller, formdata):
|
||||||
"""
|
"""
|
||||||
Initializes a delayed message, using data from the example form.
|
Initializes a delayed message, using data from the example form.
|
||||||
|
|
@ -656,6 +663,5 @@ def init_delayed_message(caller, formdata):
|
||||||
|
|
||||||
caller.msg("Message sent to %s!" % player_to_message)
|
caller.msg("Message sent to %s!" % player_to_message)
|
||||||
# Make a deferred call to 'sendmessage' above.
|
# Make a deferred call to 'sendmessage' above.
|
||||||
deferred = delay(message_delay, sendmessage, player_to_message, message)
|
delay(message_delay, sendmessage, player_to_message, message)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue