package de.rico.adventure.conversation;

import de.rico.adventure.entity.character.AbstractCharacter;
import de.rico.engine.effect.sound.Mp3Sound;

/**
 * This class is a container for one ore more sentences of text
 * to be said by a character.
 * @author Frank Bruns
 */
public class Sentence
{
	private AbstractCharacter character = null;
	private String  text = "";
	private String scriptCode = null; // contains scripted code
	private Mp3Sound sound = null;
	private boolean running = true;

	/**
	 * Creates a new sentence object with the specified text, but
	 * without a sound file assigned.
	 * @param c character that sais the sentence
	 * @param text text for this sentence object
	 */
	public Sentence(AbstractCharacter c, String text)
	{
		this.character = c;
		this.text = text;
	}

	/**
	 * Creates a new sentence object with the specified text and
	 * the speciefied sound file.
	 * @param c character that sais the sentence
	 * @param text text for this sentence object
	 * @param pathSound path to mp3 sound file
	 */
	public Sentence(AbstractCharacter c, String text, String pathSound)
	{
		this(c,text);
		this.sound = new Mp3Sound(pathSound, false);
	}

	/**
	 * Assigns the specified scripted code to the sentence
	 * @param code scripted code that is connected to the sentence
	 */
	public void setScriptCode(String code)
	{
		this.scriptCode = code;
	}

	/**
	 * Returns the scripted code that is assigned to the sentence.
	 * If none is available the method returns <code>null</code>.
	 * @return scripted code that is connected to the sentence
	 */
	public String getScriptCode()
	{
		return this.scriptCode;
	}

	/**
	 * Returns the character that is assigned to this sentence.
	 * @return character of the sentence
	 */
	public AbstractCharacter getCharacter()
	{
		return this.character;
	}

	/**
	 * Returns the text assigned to this Sentence object.
	 * @return text of this Sentence object
	 */
	public String getText()
	{
		return this.text;
	}

	/**
	 * Returns the sound that is assigned to this Sentence object.
	 * @return sound of this Sentence object
	 */
	public Mp3Sound getSound()
	{
		return this.sound;
	}
	
	/**
	 * A method that reloads the sound file associated to this sentence.
	 *
	 */
	public void reloadSound()
	{
		if(this.sound != null)
			this.sound = new Mp3Sound(this.sound.getSoundPath(),this.sound.isLooped());
	}

	/**
	 * Determines whether or not this sentence is currently running.
	 * @return is running? --> true=yes, false=no
	 */
	public boolean isRunning()
	{
		return this.running;
	}
}
