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.enums.State;
import de.rico.adventure.structure.StateManager;

/**
 * A game action that can be used to set the game to a specified
 * game state like State.CINEMATIC or State.NO_INPUT in a sequencial way.
 * @author Frank Bruns
 *
 */
public class SetToGameState extends AbstractAction
{
	private State gameState = null;

	/**
	 * Creates the game action with the specified state.
	 * @param state state to set the game to
	 */
	public SetToGameState(State state)
	{
		this.gameState = state;
	}

	/* (non-Javadoc)
	 * @see de.rico.adventure.actions.AbstractAction#update(long)
	 */
	@Override
	public void update(long elapsedTime)
	{
		StateManager.getInstance().setState(this.gameState);
		ActionScheduler.getInstance().removeFirst();
	}

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

	/* (non-Javadoc)
	 * @see de.rico.adventure.actions.AbstractAction#finishUp()
	 */
	@Override
	public void finishUp()
	{
		// Set the state in any way
		StateManager.getInstance().setState(this.gameState);
	}
}
