Make @typeclass/reset also purge cmdsets. Resolves #1000.

This commit is contained in:
Griatch 2016-08-19 22:48:44 +02:00
parent 89fbc44d15
commit 2d35c71cd1
2 changed files with 7 additions and 2 deletions

View file

@ -1641,7 +1641,7 @@ class CmdTypeclass(COMMAND_DEFAULT_CLASS):
old_typeclass_path = obj.typeclass_path
# we let this raise exception if needed
obj.swap_typeclass(new_typeclass, clean_attributes=reset)
obj.swap_typeclass(new_typeclass, clean_attributes=reset, clean_cmdsets=reset)
if is_same:
string = "%s updated its existing typeclass (%s).\n" % (obj.name, obj.path)

View file

@ -407,7 +407,7 @@ class TypedObject(SharedMemoryModel):
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):
run_start_hooks=True, no_default=True, clean_cmdsets=False):
"""
This performs an in-situ swap of the typeclass. This means
that in-game, this object will suddenly be something else.
@ -437,6 +437,7 @@ class TypedObject(SharedMemoryModel):
allow for swapping to a default typeclass in case the
given one fails for some reason. Instead the old one will
be preserved.
clean_cmdsets (bool, optional): Delete all cmdsets on the object.
Returns:
result (bool): True/False depending on if the swap worked
or not.
@ -470,6 +471,10 @@ class TypedObject(SharedMemoryModel):
else:
self.attributes.clear()
self.nattributes.clear()
if clean_cmdsets:
# purge all cmdsets
self.cmdset.clear()
self.cmdset.remove_default()
if run_start_hooks:
# fake this call to mimic the first save