package speiger.src.coreengine.rendering.utils.states;

import speiger.src.collections.floats.functions.FloatConsumer;

public class FloatState implements IGLState {
	protected final float defaultValue;
	protected float value;
	FloatConsumer setter;
	
	public FloatState(float defaultValue, FloatConsumer setter) {
		this.defaultValue = this.value = defaultValue;
		this.setter = setter;
	}
	
	public FloatState set(float value) {
		if(equalsNot(this.value, value)) {
			this.value = value;
			setter.accept(value);
		}
		return this;
	}
	
	public float get() {
		return value;
	}
	
	@Override
	public void setDefault() {
		set(defaultValue);
	}
	
	@Override
	public void reapply() {
		setter.accept(defaultValue);
	}
	
	protected boolean equalsNot(float key, float value) {
		return Float.floatToIntBits(key) != Float.floatToIntBits(value);
	}
}
