package vermilion;

/**
 * A parameter meant to represent a continuous slider. This is stored as
 * a value between 0000 and 9999.
 */
public class ParameterSlider extends ParameterBase
{
    public int value;

    /**
     * The constructor creates a parameter, accepting an initial value.
     * @param name A name for this parameter.
     * @param isTrack Indicates whether the parameter is global.
     * @param initVal A single precision floating point initial value.
     */
    public ParameterSlider(String name, boolean isTrack, int initVal)
    {
        super(name, PARAMETER_TYPE_SLIDER, isTrack);
        value = initVal;
    }

    /**
     * The serialisation type for this object is 'SLIDER'.
     */
    @Override
    public String getType() { return "SLIDER"; }

    /**
     * The current serialisation version for this object is 1.
     */
    @Override
    public int getVersion() { return 1; }

    @Override
    public String saveImpl()
    {
        return String.valueOf(value);
    }

    @Override
    public UsefulFileObject loadImpl(String str, int version)
    {
        if (version == 1)
        {
            return new ParameterSlider(null, false, Integer.parseInt(str));
        }

        return null;
    }

    @Override
    public void copyValue(ParameterBase source)
    {
        value = ((ParameterSlider) source).value;
    }
}
