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
|
||||
|
||||
- `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.
|
||||
- `Tree select` (Fluttersprite): Wrapper around EvMenu to easier create
|
||||
a common form of menu from a string.
|
||||
- `Tree select` (Fluttersprite): Wrap EvMenu to create a common type of menu from a string.
|
||||
- `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:
|
||||
- `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.
|
||||
|
||||
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
|
||||
data will be sent to upon submission:
|
||||
includes the caller, the template for the form, and the callback(caller, result) to which the form
|
||||
data will be sent to upon submission.
|
||||
|
||||
init_fill_field(formtemplate, caller, formcallback)
|
||||
|
||||
|
|
@ -139,10 +139,11 @@ Optional:
|
|||
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.server.sessionhandler import SESSIONS
|
||||
|
||||
|
||||
class FieldEvMenu(evmenu.EvMenu):
|
||||
"""
|
||||
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
|
||||
|
||||
# Provide default help text if none given
|
||||
if formhelptext == None:
|
||||
formhelptext = ("Available commands:|/"
|
||||
if formhelptext is None:
|
||||
formhelptext = (
|
||||
"Available commands:|/"
|
||||
"|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|/"
|
||||
"|wlook|n: Show the form's current values|/"
|
||||
|
|
@ -281,7 +283,7 @@ def menunode_fieldfill(caller, raw_string, **kwargs):
|
|||
try:
|
||||
formcallback(caller, formdata)
|
||||
except Exception:
|
||||
log_trace("Error in fillable form callback.")
|
||||
logger.log_trace("Error in fillable form callback.")
|
||||
return None, None
|
||||
|
||||
# Test for 'look' command
|
||||
|
|
@ -343,7 +345,7 @@ def menunode_fieldfill(caller, raw_string, **kwargs):
|
|||
matched_field = key
|
||||
|
||||
# No matched field
|
||||
if matched_field == None:
|
||||
if matched_field is None:
|
||||
caller.msg("Field '%s' does not exist!" % fieldname)
|
||||
text = (None, formhelptext)
|
||||
return text, options
|
||||
|
|
@ -373,12 +375,12 @@ def menunode_fieldfill(caller, raw_string, **kwargs):
|
|||
# Field type text verification
|
||||
if fieldtype == "text":
|
||||
# Test for max/min
|
||||
if max_value != None:
|
||||
if max_value is not None:
|
||||
if len(newvalue) > max_value:
|
||||
caller.msg("Field '%s' has a maximum length of %i characters." % (matched_field, max_value))
|
||||
text = (None, formhelptext)
|
||||
return text, options
|
||||
if min_value != None:
|
||||
if min_value is not None:
|
||||
if len(newvalue) < min_value:
|
||||
caller.msg("Field '%s' reqiures a minimum length of %i characters." % (matched_field, min_value))
|
||||
text = (None, formhelptext)
|
||||
|
|
@ -393,12 +395,12 @@ def menunode_fieldfill(caller, raw_string, **kwargs):
|
|||
text = (None, formhelptext)
|
||||
return text, options
|
||||
# Test for max/min
|
||||
if max_value != None:
|
||||
if max_value is not None:
|
||||
if newvalue > max_value:
|
||||
caller.msg("Field '%s' has a maximum value of %i." % (matched_field, max_value))
|
||||
text = (None, formhelptext)
|
||||
return text, options
|
||||
if min_value != None:
|
||||
if min_value is not None:
|
||||
if newvalue < min_value:
|
||||
caller.msg("Field '%s' reqiures a minimum value of %i." % (matched_field, min_value))
|
||||
text = (None, formhelptext)
|
||||
|
|
@ -447,6 +449,7 @@ def menunode_fieldfill(caller, raw_string, **kwargs):
|
|||
|
||||
return text, options
|
||||
|
||||
|
||||
def form_template_to_dict(formtemplate):
|
||||
"""
|
||||
Initializes a dictionary of form data from the given list-of-dictionaries
|
||||
|
|
@ -470,6 +473,7 @@ def form_template_to_dict(formtemplate):
|
|||
|
||||
return formdata
|
||||
|
||||
|
||||
def display_formdata(formtemplate, formdata,
|
||||
pretext="", posttext="", borderstyle="cells"):
|
||||
"""
|
||||
|
|
@ -496,12 +500,12 @@ def display_formdata(formtemplate, formdata,
|
|||
if len(field["fieldname"]) + 5 > field_name_width:
|
||||
field_name_width = len(field["fieldname"]) + 5
|
||||
# Get field value
|
||||
if formdata[field["fieldname"]] != None:
|
||||
if formdata[field["fieldname"]] is not None:
|
||||
new_fieldvalue = str(formdata[field["fieldname"]])
|
||||
# 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"
|
||||
elif new_fieldvalue == None:
|
||||
elif new_fieldvalue is None:
|
||||
new_fieldvalue = " "
|
||||
# Replace True and False values with truestr and falsestr from template
|
||||
if formdata[field["fieldname"]] is True and "truestr" in field:
|
||||
|
|
@ -515,9 +519,9 @@ def display_formdata(formtemplate, formdata,
|
|||
|
||||
return pretext + "|/" + str(formtable) + "|/" + posttext
|
||||
|
||||
"""
|
||||
EXAMPLE FUNCTIONS / COMMAND STARTS HERE
|
||||
"""
|
||||
|
||||
# EXAMPLE FUNCTIONS / COMMAND STARTS HERE
|
||||
|
||||
|
||||
def verify_online_player(caller, value):
|
||||
"""
|
||||
|
|
@ -559,9 +563,9 @@ def verify_online_player(caller, value):
|
|||
# Returning False indicates the new value is not valid
|
||||
return False
|
||||
|
||||
# Returning anything besides True or False will replace the player's input with the returned value
|
||||
# In this case, the value becomes a reference to the character object
|
||||
# You can store data besides strings and integers in the 'formdata' dictionary this way!
|
||||
# Returning anything besides True or False will replace the player's input with the returned
|
||||
# value. In this case, the value becomes a reference to the character object. You can store data
|
||||
# besides strings and integers in the 'formdata' dictionary this way!
|
||||
return matched_character
|
||||
|
||||
# Form template for the example 'delayed message' form
|
||||
|
|
@ -594,6 +598,7 @@ SAMPLE_FORM = [
|
|||
}
|
||||
]
|
||||
|
||||
|
||||
class CmdTestMenu(Command):
|
||||
"""
|
||||
This test command will initialize a menu that presents you with a form.
|
||||
|
|
@ -626,6 +631,7 @@ class CmdTestMenu(Command):
|
|||
pretext=pretext, posttext=posttext,
|
||||
submitcmd="send", borderstyle="none")
|
||||
|
||||
|
||||
def sendmessage(obj, text):
|
||||
"""
|
||||
Callback to send a message to a player.
|
||||
|
|
@ -636,6 +642,7 @@ def sendmessage(obj, text):
|
|||
"""
|
||||
obj.msg(text)
|
||||
|
||||
|
||||
def init_delayed_message(caller, formdata):
|
||||
"""
|
||||
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)
|
||||
# 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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue