/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package scriptbuilder.structures.events;

import scriptbuilder.structures.ELEMENT;
import scriptbuilder.structures.I_XML_Writable;
import scriptbuilder.structures.ScriptEvent;
import scriptbuilder.structures.XMLBuilder;

/**
 * Data model for an audio event. Audio events have a filepath leading to an
 * audio file to be played, and a length in seconds of that file.
 *
 * @author Bryan McGuffin
 */
public class AudioEvent extends ScriptEvent implements I_XML_Writable
{

    /**
     * Constructor.
     */
    public AudioEvent()
    {
        super(ScriptEventType.AUDIO_EVENT);
    }
    
    /**
     * Constructor with ID
     * @param id AudioEvent ID
     */
    public AudioEvent(String id)
    {
        super(ScriptEventType.AUDIO_EVENT);
        this.id = id;
    }

    /**
     * Length of the audio to be played, in seconds.
     */
    public Integer audioLength = 0;

    /**
     * File path for the audio file. Perhaps should only be generated on save?
     */
    public String audioPath = "";
    
    /**
     * id represents the audio file name that corresponds with the event
     */
     public String id = "";
     
    /**
     * sets the audio path relative to the running directory.
     * @param f filename
     */
    
   
    
    public void setAudioFilePathRelative(String f)
    {
        audioPath = "audio/" + f + ".mp3";
    }
    /**
     * sets audio path relative to the working directory using the id value.
     */
    public void setAudioFilePathRelative()
    {
        audioPath = "audio/" + id + ".mp3";
    }
    
    @Override
    public String toXML()
    {
        return XMLBuilder.emptyTag(ELEMENT.AUDIO.tag + " Length=\"" + audioLength + "\" Path=\"" + audioPath + "\"");
    }
}
