Updated the is_typeclass method to be more general. Fixed an inconsistency with typeclass path prefixes.
This commit is contained in:
parent
e77d86a8f7
commit
de579df367
2 changed files with 11 additions and 7 deletions
|
|
@ -291,6 +291,7 @@ OBJECT_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tut
|
||||||
SCRIPT_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]
|
SCRIPT_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]
|
||||||
PLAYER_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]
|
PLAYER_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]
|
||||||
CHANNEL_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]
|
CHANNEL_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]
|
||||||
|
TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]
|
||||||
|
|
||||||
# Typeclass for player objects (linked to a character) (fallback)
|
# Typeclass for player objects (linked to a character) (fallback)
|
||||||
BASE_PLAYER_TYPECLASS = "typeclasses.players.Player"
|
BASE_PLAYER_TYPECLASS = "typeclasses.players.Player"
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,7 @@ class TypedObject(SharedMemoryModel):
|
||||||
super(TypedObject, self).__init__(*args, **kwargs)
|
super(TypedObject, self).__init__(*args, **kwargs)
|
||||||
if typeclass_path:
|
if typeclass_path:
|
||||||
try:
|
try:
|
||||||
self.__class__ = class_from_module(typeclass_path)
|
self.__class__ = class_from_module(typeclass_path, defaultpaths=settings.TYPECLASS_PATHS)
|
||||||
except Exception:
|
except Exception:
|
||||||
log_trace()
|
log_trace()
|
||||||
try:
|
try:
|
||||||
|
|
@ -390,15 +390,18 @@ class TypedObject(SharedMemoryModel):
|
||||||
if the object's type is exactly this typeclass, ignoring
|
if the object's type is exactly this typeclass, ignoring
|
||||||
parents.
|
parents.
|
||||||
"""
|
"""
|
||||||
if not isinstance(typeclass, basestring):
|
if isinstance(typeclass, basestring):
|
||||||
typeclass = typeclass.path
|
typeclass = [typeclass] + ["%s.%s" % (prefix, typeclass) for prefix in settings.TYPECLASS_PATHS]
|
||||||
|
else:
|
||||||
|
typeclass = [typeclass.path]
|
||||||
|
|
||||||
|
selfpath = self.path
|
||||||
if exact:
|
if exact:
|
||||||
return typeclass == self.path
|
# check only exact match
|
||||||
|
return selfpath in typeclass
|
||||||
else:
|
else:
|
||||||
# check parent chain
|
# check parent chain
|
||||||
selfpath = self.path
|
return any(cls.path in typeclass for cls in self.__class__.mro())
|
||||||
return any(cls for cls in self.__class__.mro() if cls.path == selfpath)
|
|
||||||
|
|
||||||
def swap_typeclass(self, new_typeclass, clean_attributes=False,
|
def swap_typeclass(self, new_typeclass, clean_attributes=False,
|
||||||
run_start_hooks=True, no_default=True):
|
run_start_hooks=True, no_default=True):
|
||||||
|
|
@ -439,7 +442,7 @@ class TypedObject(SharedMemoryModel):
|
||||||
|
|
||||||
if not callable(new_typeclass):
|
if not callable(new_typeclass):
|
||||||
# this is an actual class object - build the path
|
# this is an actual class object - build the path
|
||||||
new_typeclass = class_from_module(new_typeclass)
|
new_typeclass = class_from_module(new_typeclass, defaultpaths=settings.TYPECLASS_PATHS)
|
||||||
|
|
||||||
# if we get to this point, the class is ok.
|
# if we get to this point, the class is ok.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue