Adds "name" parameter to ESC spawn command (#410)

Co-authored-by: StraToN <StraToN@users.noreply.github.com>
This commit is contained in:
Julian Murgia
2021-10-07 08:22:11 +02:00
committed by GitHub
parent 378f29283d
commit 41902b5791
11 changed files with 128 additions and 90 deletions

View File

@@ -71,8 +71,6 @@ func run(command_params: Array) -> int:
escoria.inputs_manager.clear_stack()
escoria.main_menu_instance.hide()
var res_room = escoria.resource_cache.get_resource(command_params[0])
# Load game scene

View File

@@ -1,4 +1,4 @@
# `spawn path [object2]`
# `spawn identifier path [is_active=true] [object2] `
#
# Instances a scene determined by "path", and places in the position of
# object2 (object2 is optional)
@@ -11,50 +11,71 @@ class_name SpawnCommand
# Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new(
1,
[TYPE_STRING, TYPE_STRING],
[null, null]
2,
[TYPE_STRING, TYPE_STRING, TYPE_BOOL, TYPE_STRING],
[null, null, true, null]
)
# Validate wether the given arguments match the command descriptor
func validate(arguments: Array):
if not ResourceLoader.exists(arguments[0]):
if arguments[0].empty() \
or arguments[0] in escoria.object_manager.RESERVED_OBJECTS:
escoria.logger.report_errors(
"spawn: invalid global_id",
[
"global_id %s is invalid" % arguments[0]
]
)
return false
if not ResourceLoader.exists(arguments[1]):
escoria.logger.report_errors(
"spawn: invalid scene path",
[
"Scene with path %s not found" % arguments[0]
"Scene with path %s not found" % arguments[1]
]
)
return false
if arguments[1] and not escoria.object_manager.objects.has(arguments[1]):
return false
if arguments[3] and not escoria.object_manager.objects.has(arguments[2]):
escoria.logger.report_errors(
"spawn: invalid object",
[
"Object with global id %s not found" % arguments[1]
"Object with global id %s not found" % arguments[2]
]
)
return false
return false
return .validate(arguments)
# Run the command
func run(command_params: Array) -> int:
var res_scene = escoria.resource_cache.get_resource(command_params[0])
var res_scene = escoria.resource_cache.get_resource(command_params[1])
# Load room scene
var scene = res_scene.instance()
if scene:
escoria.main.get_node("/root").add_child(scene)
if command_params[1]:
var obj = escoria.object_manager.get_object(command_params[1])
if command_params[3]:
var obj = escoria.object_manager.get_object(command_params[3])
scene.set_position(obj.get_global_position())
escoria.inputs_manager.hotspot_focused = ""
escoria.object_manager.register_object(
ESCObject.new(
command_params[0],
scene
),
true
)
escoria.object_manager.get_object(command_params[0]).active = \
command_params[2]
else:
escoria.logger.report_errors(
"spawn: Invalid scene",
[
"Failed loading scene %s" % command_params[0]
"Failed loading scene %s" % command_params[1]
]
)