Modifications to the @create and @parent commands, to safeguard against erroneous scriptlink names as well as allowing to define parent upon @creation. The @parent command calls at_object_creation(), seems that behaviour is the intuitive one.
This commit is contained in:
parent
9abde7b60f
commit
9d199032b0
2 changed files with 69 additions and 32 deletions
|
|
@ -27,40 +27,54 @@ def cmd_parent(command):
|
|||
source_object = command.source_object
|
||||
|
||||
if not command.command_argument:
|
||||
source_object.emit_to("Change the parent of what?")
|
||||
source_object.emit_to("Change/check the parent of what?")
|
||||
return
|
||||
|
||||
eq_args = command.command_argument.split('=', 1)
|
||||
target_name = eq_args[0]
|
||||
parent_name = eq_args[1]
|
||||
target_obj = source_object.search_for_object(target_name)
|
||||
|
||||
if len(target_name) == 0:
|
||||
source_object.emit_to("Change the parent of what?")
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
if len(eq_args) > 1:
|
||||
target_obj = source_object.search_for_object(target_name)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
#if we gave a command of the form @parent obj=something we want to
|
||||
#somehow affect the parent.
|
||||
|
||||
parent_name = eq_args[1]
|
||||
|
||||
#check permissions
|
||||
if not source_object.controls_other(target_obj):
|
||||
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
||||
return
|
||||
|
||||
# Allow the clearing of a zone
|
||||
if parent_name.lower() == "none":
|
||||
# Clear parent if command was @parent obj= or obj=none
|
||||
if not parent_name or parent_name.lower() == "none":
|
||||
target_obj.set_script_parent(None)
|
||||
source_object.emit_to("%s reverted to default parent." % (target_obj))
|
||||
return
|
||||
new_parent = target_obj.scriptlink()
|
||||
source_object.emit_to("%s reverted to its default parent (%s)." %
|
||||
(target_obj, new_parent))
|
||||
return
|
||||
|
||||
target_obj.set_script_parent(parent_name)
|
||||
source_object.emit_to("%s is now a child of %s." % (target_obj, parent_name))
|
||||
# If we reach this point, attempt to change parent.
|
||||
|
||||
former_parent = target_obj.get_scriptlink()
|
||||
if target_obj.set_script_parent(parent_name):
|
||||
#new script path added; initialize the parent
|
||||
target_obj.scriptlink.at_object_creation()
|
||||
s = "%s's parent is now %s (instead of %s).\n\r"
|
||||
s += "Note that the new parent type could have overwritten "
|
||||
s += "same-named attributes on the existing object."
|
||||
source_object.emit_to(s)
|
||||
else:
|
||||
source_object.emit_to("'%s' is not a valid parent path." % parent_name)
|
||||
|
||||
else:
|
||||
# We haven't provided a target zone.
|
||||
source_object.emit_to("What should the object's parent be set to?")
|
||||
return
|
||||
# We haven't provided a target; list the current parent
|
||||
current_parent = target_obj.get_scriptlink()
|
||||
source_object.emit_to("Current parent of %s is %s." %
|
||||
(target_obj,current_parent))
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("@parent", cmd_parent,
|
||||
priv_tuple=("genperms.builder"))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue