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
|
|
@ -264,27 +264,50 @@ GLOBAL_CMD_TABLE.add_command("@find", cmd_find,
|
||||||
|
|
||||||
def cmd_create(command):
|
def cmd_create(command):
|
||||||
"""
|
"""
|
||||||
Creates a new object of type 'THING'.
|
@create
|
||||||
|
|
||||||
|
Usage: @create objname [=parent]
|
||||||
|
|
||||||
|
Creates a new object. If parent is given, the object is created as a child of this
|
||||||
|
parent. The parent script is assumed to be located under game/gamesrc/parents
|
||||||
|
and any further directory structure is given in Python notation. So if you
|
||||||
|
have a correct parent object defined in parents/examples/red_button.py, you could
|
||||||
|
load create a new object inheriting from this parent like this:
|
||||||
|
@create button=example.red_button
|
||||||
"""
|
"""
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
source_object.emit_to("You must supply a name!")
|
source_object.emit_to("You must supply a name!")
|
||||||
else:
|
return
|
||||||
|
|
||||||
|
eq_args = command.command_argument.split('=', 1)
|
||||||
|
target_name = eq_args[0]
|
||||||
|
|
||||||
# Create and set the object up.
|
# Create and set the object up.
|
||||||
# TODO: This dictionary stuff is silly. Feex.
|
# TODO: This dictionary stuff is silly. Feex.
|
||||||
odat = {"name": command.command_argument,
|
odat = {"name": target_name,
|
||||||
"type": 3,
|
"type": 3,
|
||||||
"location": source_object,
|
"location": source_object,
|
||||||
"owner": source_object}
|
"owner": source_object}
|
||||||
new_object = Object.objects.create_object(odat)
|
new_object = Object.objects.create_object(odat)
|
||||||
|
|
||||||
|
if len(eq_args)>1:
|
||||||
|
parent_str = eq_args[1]
|
||||||
|
if parent_str and new_object.set_script_parent(parent_str):
|
||||||
|
source_object.emit_to("You create %s as a child of %s." %
|
||||||
|
(new_object, parent_str))
|
||||||
|
else:
|
||||||
|
source_object.emit_to("'%s' is not a valid parent. Using default." %
|
||||||
|
parent_str)
|
||||||
|
else:
|
||||||
source_object.emit_to("You create a new thing: %s" % (new_object,))
|
source_object.emit_to("You create a new thing: %s" % (new_object,))
|
||||||
|
|
||||||
# Trigger stuff to happen after said object is created.
|
# Trigger stuff to happen after said object is created.
|
||||||
new_object.scriptlink.at_object_creation()
|
new_object.scriptlink.at_object_creation()
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("@create", cmd_create,
|
GLOBAL_CMD_TABLE.add_command("@create", cmd_create,
|
||||||
priv_tuple=("genperms.builder"))
|
priv_tuple=("genperms.builder"),auto_help=True)
|
||||||
|
|
||||||
def cmd_cpattr(command):
|
def cmd_cpattr(command):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -27,40 +27,54 @@ def cmd_parent(command):
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
|
|
||||||
if not command.command_argument:
|
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
|
return
|
||||||
|
|
||||||
eq_args = command.command_argument.split('=', 1)
|
eq_args = command.command_argument.split('=', 1)
|
||||||
target_name = eq_args[0]
|
target_name = eq_args[0]
|
||||||
parent_name = eq_args[1]
|
|
||||||
|
|
||||||
if len(target_name) == 0:
|
|
||||||
source_object.emit_to("Change the parent of what?")
|
|
||||||
return
|
|
||||||
|
|
||||||
if len(eq_args) > 1:
|
|
||||||
target_obj = source_object.search_for_object(target_name)
|
target_obj = source_object.search_for_object(target_name)
|
||||||
# Use search_for_object to handle duplicate/nonexistant results.
|
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if len(eq_args) > 1:
|
||||||
|
#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):
|
if not source_object.controls_other(target_obj):
|
||||||
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Allow the clearing of a zone
|
# Clear parent if command was @parent obj= or obj=none
|
||||||
if parent_name.lower() == "none":
|
if not parent_name or parent_name.lower() == "none":
|
||||||
target_obj.set_script_parent(None)
|
target_obj.set_script_parent(None)
|
||||||
source_object.emit_to("%s reverted to default parent." % (target_obj))
|
new_parent = target_obj.scriptlink()
|
||||||
|
source_object.emit_to("%s reverted to its default parent (%s)." %
|
||||||
|
(target_obj, new_parent))
|
||||||
return
|
return
|
||||||
|
|
||||||
target_obj.set_script_parent(parent_name)
|
# If we reach this point, attempt to change parent.
|
||||||
source_object.emit_to("%s is now a child of %s." % (target_obj, parent_name))
|
|
||||||
|
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:
|
else:
|
||||||
# We haven't provided a target zone.
|
# We haven't provided a target; list the current parent
|
||||||
source_object.emit_to("What should the object's parent be set to?")
|
current_parent = target_obj.get_scriptlink()
|
||||||
return
|
source_object.emit_to("Current parent of %s is %s." %
|
||||||
|
(target_obj,current_parent))
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("@parent", cmd_parent,
|
GLOBAL_CMD_TABLE.add_command("@parent", cmd_parent,
|
||||||
priv_tuple=("genperms.builder"))
|
priv_tuple=("genperms.builder"))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue