All primitive number types have validation, which:
- Controls the number type: bytes stay bytes etc.
- Define a minimum and maximum value.
- Control secondary attributes like which widget the user will see in-GUI when modifying the setting.
ValidatedNumber
Number validation is defined using one of the six subclasses of ValidatedNumber
. By default, the allowable min and max will be the entire range of the type (Integer.MIN_VALUE to Integer.MAX_VALUE, for example).
public float myValidatedFloat = 0.5f; // this value is backed by automatic validation, with no max or min boundpublic ValidatedFloat myValidatedFloat = new ValidatedFloat(0.5f,1f,0f); // default value, max value, min value
Annotations
Validated Numbers each have their own partnered Annotation you can use to annotate a plain field.
@ValidatedFloat.Restrict(min = 0f, max = 1f) // the previously unbounded simple float now has automatic validation with bounds between 0 and 1.public float myValidatedFloat = 0.5f;@ValidatedInt.Restrict(min = 0, type = ValidatedNumber.WidgetType.TEXTBOX_WITH_BUTTONS) //Restrict can also set the widget type used in the config GUIpublic int myWidgetTypeInt = 1;
Shorthands
Fzzy Config has shorthand constructors for validated numbers. These are generally used to provide validators for other validation like Lists or Maps, where you may not have any need for restrictions.
public ValidatedFloat myValidatedFloat = new ValidatedFloat();
Heads up!
See the documentation pages for Integer 🗗, Float 🗗, Double 🗗, Long 🗗, Short 🗗, Byte 🗗