mirror of
https://github.com/evennia/evennia.git
synced 2026-03-19 22:36:31 +01:00
Fixed a bug in is_typeclass and cleaned up some other things in the player/object typeclass. Resolves #722.
This commit is contained in:
parent
f007de3a5e
commit
78ca2819b2
3 changed files with 26 additions and 69 deletions
|
|
@ -767,6 +767,23 @@ class DefaultObject(ObjectDB):
|
|||
super(ObjectDB, self).delete()
|
||||
return True
|
||||
|
||||
def access(self, accessing_obj, access_type='read', default=False, **kwargs):
|
||||
"""
|
||||
Determines if another object has permission to access this object
|
||||
in whatever way.
|
||||
|
||||
Args:
|
||||
accessing_obj (Object): Object trying to access this one
|
||||
access_type (str): Type of access sought
|
||||
default (bool): What to return if no lock of access_type was found
|
||||
|
||||
Kwargs:
|
||||
Passed to the at_access hook along with the result.
|
||||
|
||||
"""
|
||||
result = super(DefaultObject, self).access(accessing_obj, access_type=access_type, default=default)
|
||||
self.at_access(result, accessing_obj, access_type, **kwargs)
|
||||
return result
|
||||
|
||||
def __eq__(self, other):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -429,84 +429,24 @@ class DefaultPlayer(PlayerDB):
|
|||
return None
|
||||
return matches
|
||||
|
||||
def is_typeclass(self, typeclass, exact=False):
|
||||
"""
|
||||
Returns true if this object has this type
|
||||
OR has a typeclass which is an subclass of
|
||||
the given typeclass.
|
||||
|
||||
typeclass - can be a class object or the
|
||||
python path to such an object to match against.
|
||||
|
||||
exact - returns true only if the object's
|
||||
type is exactly this typeclass, ignoring
|
||||
parents.
|
||||
|
||||
Returns: Boolean
|
||||
"""
|
||||
return super(DefaultPlayer, self).is_typeclass(typeclass, exact=exact)
|
||||
|
||||
def swap_typeclass(self, new_typeclass, clean_attributes=False, no_default=True):
|
||||
"""
|
||||
This performs an in-situ swap of the typeclass. This means
|
||||
that in-game, this object will suddenly be something else.
|
||||
Player will not be affected. To 'move' a player to a different
|
||||
object entirely (while retaining this object's type), use
|
||||
self.player.swap_object().
|
||||
|
||||
Note that this might be an error prone operation if the
|
||||
old/new typeclass was heavily customized - your code
|
||||
might expect one and not the other, so be careful to
|
||||
bug test your code if using this feature! Often its easiest
|
||||
to create a new object and just swap the player over to
|
||||
that one instead.
|
||||
|
||||
Arguments:
|
||||
new_typeclass (path/classobj) - type to switch to
|
||||
clean_attributes (bool/list) - will delete all attributes
|
||||
stored on this object (but not any
|
||||
of the database fields such as name or
|
||||
location). You can't get attributes back,
|
||||
but this is often the safest bet to make
|
||||
sure nothing in the new typeclass clashes
|
||||
with the old one. If you supply a list,
|
||||
only those named attributes will be cleared.
|
||||
no_default - if this is active, the swapper will not allow for
|
||||
swapping to a default typeclass in case the given
|
||||
one fails for some reason. Instead the old one
|
||||
will be preserved.
|
||||
Returns:
|
||||
boolean True/False depending on if the swap worked or not.
|
||||
|
||||
"""
|
||||
super(DefaultPlayer, self).swap_typeclass(new_typeclass,
|
||||
clean_attributes=clean_attributes, no_default=no_default)
|
||||
|
||||
def access(self, accessing_obj, access_type='read', default=False, **kwargs):
|
||||
"""
|
||||
Determines if another object has permission to access this object
|
||||
in whatever way.
|
||||
|
||||
accessing_obj (Object)- object trying to access this one
|
||||
access_type (string) - type of access sought
|
||||
default (bool) - what to return if no lock of access_type was found
|
||||
**kwargs - passed to the at_access hook along with the result.
|
||||
Args:
|
||||
accessing_obj (Object): Object trying to access this one
|
||||
access_type (str): Type of access sought
|
||||
default (bool): What to return if no lock of access_type was found
|
||||
|
||||
Kwargs:
|
||||
Passed to the at_access hook along with the result.
|
||||
|
||||
"""
|
||||
result = super(DefaultPlayer, self).access(accessing_obj, access_type=access_type, default=default)
|
||||
self.at_access(result, accessing_obj, access_type, **kwargs)
|
||||
return result
|
||||
|
||||
def check_permstring(self, permstring):
|
||||
"""
|
||||
This explicitly checks the given string against this object's
|
||||
'permissions' property without involving any locks.
|
||||
|
||||
permstring (string) - permission string that need to match a permission
|
||||
on the object. (example: 'Builders')
|
||||
Note that this method does -not- call the at_access hook.
|
||||
"""
|
||||
return super(DefaultPlayer, self).check_permstring(permstring)
|
||||
|
||||
## player hooks
|
||||
|
||||
def basetype_setup(self):
|
||||
|
|
|
|||
|
|
@ -401,7 +401,7 @@ class TypedObject(SharedMemoryModel):
|
|||
return selfpath in typeclass
|
||||
else:
|
||||
# check parent chain
|
||||
return any(cls.path in typeclass for cls in self.__class__.mro())
|
||||
return any(hasattr(cls, "path") and cls.path in typeclass for cls in self.__class__.mro())
|
||||
|
||||
def swap_typeclass(self, new_typeclass, clean_attributes=False,
|
||||
run_start_hooks=True, no_default=True):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue