-
Notifications
You must be signed in to change notification settings - Fork 3
EmuBitfieldOption
This class represents a specific bit in a bitfield (or an action which may be applied to multiple bits). Most of the time these will be automatically taken care of by the bitfield they belong to, although in some situations you may want to take control.
Note: I recommend having a strong understanding of binary numbers and bit fields ("flags") before manually creating and manipulating Emu's bitfield-related elements.
Inheritance: EmuCore / EmuCallback
EmuBitfieldOption(text, value, callback, eval)
Parameter | Type | Description |
---|---|---|
text | string | The text shown to label the option |
value | real | The value contained in the option |
callback | function | The function invoked when the option is toggled |
eval | function | The function that determines whether or not the option is "on" |
Notably, EmuBitfieldOptions require a callback and evaluator function. The callback is invoked when the option is clicked on, and the evaluator function is invoked every frame to determine if the option should be drawn as "on" or "off."
var option = new EmuBitfieldOption("None", 0, function() {
root.value = 0;
root.callback();
},
function() {
return root.value == 0;
}
);
bitfield.AddOptions(option);
This will create an EmuBitfieldOption element with a specialized callback and evaluator, and add it to a previously defined EmuBitfield. The callback will set the entire bitfield value to zero, and the evaluator will only return true if the bitfield value is exactly equal to zero.
There are several helper functions to go with EmuBitfieldOptions, which should cover most situations where you would want to create them manually.
This may be used in place of a callback. It will set the value of the bitfield to exactly the value of the option rather than toggling it. This can be useful when trying to add an "All" or "None" option to a bitfield.
This may be used in place of an evaluator function. It will only return true if the value of the bitfield is exactly equal to the value of the option, rather than containing a specific bit. This can be useful when trying to add an "All" or "None" option to a bitfield.