package turgen.plugin.plturbo;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import turgen.generator.PulseCrate;
import turgen.playlist.AbstractPlayListItem;

/**Playlist item for PL Turbo ROM*/
public class PlHardTurboPlaylistItem extends AbstractPlayListItem {

    public String fname=null;
    public int binaryLoader=0;
    public static final int CV_BINARY_HT=0;
    private static final String[] methodStrings = {"[HT]","[HT+]"};

    /** Create new instance*/
    public PlHardTurboPlaylistItem(String inF,String outF,PulseCrate speed,String fname,int binaryLoader,int[] silenceList) {
        this.inFile=inF;
        this.outFile=outF;
        this.pulses=speed;
        this.fname=fname;
        this.binaryLoader=binaryLoader;
        this.silenceList=silenceList;
    }

    /**Get string representation*/
    public String toString() {
        return methodStrings[binaryLoader]+fname;
    }

    /** Create blank instance*/
    public PlHardTurboPlaylistItem() {

    }

    /** Validate item*/
    public boolean validate() {
        if (this.inFile==null) return false;
        if (this.outFile==null) this.outFile="";
        if (this.fname==null) this.fname="NONAME";
        if (this.pulses==null) return false;
        return true;
    }

    
    public AbstractPlayListItem getClonedCopy() {
        int[] silenceListCopy = (int[])this.silenceList.clone();
        PulseCrate pulsesCopy = pulses.getCopy();
        PlHardTurboPlaylistItem item = new PlHardTurboPlaylistItem(inFile, outFile, pulsesCopy, fname, binaryLoader, silenceListCopy);
        copyBasics(item);
        return item;
    }

    
    public void saveToStream(DataOutputStream dos) throws Exception {
        saveBasics(dos);
        dos.writeUTF(fname);
        dos.writeInt(binaryLoader);
    }

    
    public void loadFromStream(DataInputStream dis, int version) throws Exception {
        loadBasics(dis);
        fname=dis.readUTF();
        binaryLoader=dis.readInt();
    }

}
