Package com.pocolifo.robobase.control
Class Toggleable
- java.lang.Object
-
- com.pocolifo.robobase.control.Toggleable
-
public class Toggleable extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Toggleable(BoolSupplier currentState)
Creates aToggleable
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
get()
Get the current toggled state.Toggleable
onToggleOff(java.lang.Runnable runnable)
Run code when thisToggleable
is toggled OFF.Toggleable
onToggleOn(java.lang.Runnable runnable)
Run code when thisToggleable
is toggled ON.Toggleable
processUpdates()
Updates this Toggleable.
-
-
-
Constructor Detail
-
Toggleable
public Toggleable(BoolSupplier currentState)
Creates aToggleable
.- Parameters:
currentState
- A method to get the current state of something (like whether a gamepad button is pressed)
-
-
Method Detail
-
get
public boolean get()
Get the current toggled state.- Returns:
- The toggled state of this
Toggleable
-
processUpdates
public Toggleable processUpdates()
Updates this Toggleable. Should be called ONCE as frequent as possible or in the main loop!- Returns:
- This
Toggleable
instance.
-
onToggleOn
public Toggleable onToggleOn(java.lang.Runnable runnable)
Run code when thisToggleable
is toggled ON.- Parameters:
runnable
- ARunnable
that is executed when this toggleable is toggled ON.- Returns:
- This
Toggleable
instance.
-
onToggleOff
public Toggleable onToggleOff(java.lang.Runnable runnable)
Run code when thisToggleable
is toggled OFF.- Parameters:
runnable
- ARunnable
that is executed when this toggleable is toggled OFF.- Returns:
- This
Toggleable
instance.
-
-