package de.rico.adventure.actions.custom;

import javax.media.opengl.GL;

import de.rico.adventure.actions.AbstractAction;
import de.rico.adventure.actions.ActionScheduler;
import de.rico.adventure.script.ScriptInterpreter;

/**
 * This class is a game action that can be used to queue the call
 * of a scripted method into the game action scheduler.
 * @author Frank Bruns
 *
 */
public class CallScriptedMethod extends AbstractAction
{
	private ScriptInterpreter interpreter = null;
	private String methodName = null;

	/**
	 * Creates a new game action to call a scripted method in a
	 * queued way.
	 * @param interpreter script interpreter that can invoke the method
	 * @param methodName name of the method to invoke
	 */
	public CallScriptedMethod(ScriptInterpreter interpreter, String methodName)
	{
		this.interpreter = interpreter;
		this.methodName = methodName;
	}

	/* (non-Javadoc)
	 * @see de.rico.adventure.actions.AbstractAction#update(long)
	 */
	@Override
	public void update(long elapsedTime)
	{
		this.interpreter.invokeMethod(this.methodName);

		// remove this action from the scheduler
		ActionScheduler.getInstance().removeFirst();
	}

	/* (non-Javadoc)
	 * @see de.rico.adventure.actions.AbstractAction#forceFinish()
	 */
	@Override
	public void finishUp()
	{
		// do nothing at the moment
	}

	/* (non-Javadoc)
	 * @see de.rico.adventure.actions.AbstractAction#draw(javax.media.opengl.GL)
	 */
	@Override
	public void draw(GL gl)
	{
		// do nothing
	}

}
