Added info about creating the tutorial world to the Limbo desc. Also refactored some of the lock functions a bit for efficiency.

This commit is contained in:
Griatch 2012-02-06 21:48:50 +01:00
parent 42d502bfc6
commit 8b5f3628ab
3 changed files with 36 additions and 29 deletions

View file

@ -240,6 +240,7 @@ class CmdBatchCommands(MuxCommand):
show_curr(caller) show_curr(caller)
else: else:
caller.msg("Running Batch-command processor - Automatic mode for %s ..." % python_path) caller.msg("Running Batch-command processor - Automatic mode for %s ..." % python_path)
# add the 'safety' cmdset in case the batch processing adds cmdsets to us # add the 'safety' cmdset in case the batch processing adds cmdsets to us
for inum in range(len(commands)): for inum in range(len(commands)):
# loop through the batch file # loop through the batch file

View file

@ -120,18 +120,20 @@ def perm(accessing_obj, accessed_obj, *args, **kwargs):
is part of PERMISSION_HIERARCHY, permission is also granted is part of PERMISSION_HIERARCHY, permission is also granted
to all ranks higher up in the hierarchy. to all ranks higher up in the hierarchy.
""" """
if not args: try:
perm = args[0].lower()
permissions = [p.lower() for p in accessing_obj.permissions]
except AttributeError, IndexError:
return False return False
perm = args[0].lower()
if hasattr(accessing_obj, 'permissions'): if perm in permissions:
if perm in [p.lower() for p in accessing_obj.permissions]: # simplest case - we have a direct match
# simplest case - we have a direct match return True
return True if perm in PERMISSION_HIERARCHY:
if perm in PERMISSION_HIERARCHY: # check if we have a higher hierarchy position
# check if we have a higher hierarchy position ppos = PERMISSION_HIERARCHY.index(perm)
ppos = PERMISSION_HIERARCHY.index(perm) return any(1 for hpos, hperm in enumerate(PERMISSION_HIERARCHY)
return any(True for hpos, hperm in enumerate(PERMISSION_HIERARCHY) if hperm in permissions and hpos > ppos)
if hperm in [p.lower() for p in accessing_obj.permissions] and hpos > ppos)
return False return False
def perm_above(accessing_obj, accessed_obj, *args, **kwargs): def perm_above(accessing_obj, accessed_obj, *args, **kwargs):
@ -141,10 +143,16 @@ def perm_above(accessing_obj, accessed_obj, *args, **kwargs):
it's assumed we refer to superuser. If no hierarchy is defined, it's assumed we refer to superuser. If no hierarchy is defined,
this function has no meaning and returns False. this function has no meaning and returns False.
""" """
if args and args[0].lower() in PERMISSION_HIERARCHY: try:
ppos = PERMISSION_HIERARCHY.index(args[0].lower()) perm = args[0].lower()
return any(True for hpos, hperm in enumerate(PERMISSION_HIERARCHY) except IndexError:
return False
if perm in PERMISSION_HIERARCHY:
ppos = PERMISSION_HIERARCHY.index(perm)
return any(1 for hpos, hperm in enumerate(PERMISSION_HIERARCHY)
if hperm in [p.lower() for p in accessing_obj.permissions] and hpos > ppos) if hperm in [p.lower() for p in accessing_obj.permissions] and hpos > ppos)
return False
def pperm(accessing_obj, accessed_obj, *args, **kwargs): def pperm(accessing_obj, accessed_obj, *args, **kwargs):
""" """
@ -204,6 +212,15 @@ def pid(accessing_obj, accessed_obj, *args, **kwargs):
return dbref(_to_player(accessing_obj), accessed_obj, *args, **kwargs) return dbref(_to_player(accessing_obj), accessed_obj, *args, **kwargs)
# this is more efficient than multiple if ... elif statments
CF_MAPPING = {'eq': lambda val1, val2: val1 == val2 or int(val1) == int(val2),
'gt': lambda val1, val2: int(val1) > int(val2),
'lt': lambda val1, val2: int(val1) < int(val2),
'ge': lambda val1, val2: int(val1) >= int(val2),
'le': lambda val1, val2: int(val1) <= int(val2),
'ne': lambda val1, val2: int(val1) != int(val2),
'default': lambda val1, val2: False}
def attr(accessing_obj, accessed_obj, *args, **kwargs): def attr(accessing_obj, accessed_obj, *args, **kwargs):
""" """
Usage: Usage:
@ -237,20 +254,7 @@ def attr(accessing_obj, accessed_obj, *args, **kwargs):
def valcompare(val1, val2, typ='eq'): def valcompare(val1, val2, typ='eq'):
"compare based on type" "compare based on type"
try: try:
if typ == 'eq': return CF_MAPPING.get(typ, 'default')(val1, val2)
return val1 == val2 or int(val1) == int(val2)
elif typ == 'gt':
return int(val1) > int(val2)
elif typ == 'lt':
return int(val1) < int(val2)
elif typ == 'ge':
return int(val1) >= int(val2)
elif typ == 'le':
return int(val1) <= int(val2)
elif typ == 'ne':
return int(val1) != int(val2)
else:
return False
except Exception, e: except Exception, e:
#print e #print e
# this might happen if we try to compare two things that cannot be compared # this might happen if we try to compare two things that cannot be compared

View file

@ -76,6 +76,8 @@ def create_objects():
string += " From here you are ready to begin development." string += " From here you are ready to begin development."
string += " If you should need help or would like to participate" string += " If you should need help or would like to participate"
string += " in community discussions, visit http://evennia.com." string += " in community discussions, visit http://evennia.com."
string += " If you are logged in as User #1 you can create a"
string += " demo/tutorial area with '@batchcommand contrib.tutorial_world.build'."
string = _(string) string = _(string)
limbo_obj.db.desc = string limbo_obj.db.desc = string
limbo_obj.save() limbo_obj.save()