# `play_video file`
#
# Plays the specified video blocking the currently running event .
#
# **Parameters**
#
# - *file*: Video file to play
#
# @ESC
extends ESCBaseCommand
class_name PlayVideoCommand

# Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor:
	return ESCCommandArgumentDescriptor.new(
		1,
		[TYPE_STRING, TYPE_STRING]
	)


# Validate whether the given arguments match the command descriptor
func validate(arguments: Array):
	if not .validate(arguments):
		return false

	if not ResourceLoader.exists(arguments[0]):
		escoria.logger.error(
			self,
			"[%s]: invalid parameter. File %s not found."
					% [get_command_name(), arguments[0]]
		)
		return false
	return true


# Run the command
func run(command_params: Array) -> int:
	escoria.game_scene.play_video(command_params[0])
	#We wait for the video to emit "finished" fignal with yield
	yield(escoria.game_scene.get_video_player(),"finished")
	return ESCExecution.RC_OK
