Class Trigger

  • Direct Known Subclasses:
    TriggerControl

    public abstract class Trigger
    extends Object
    A field type for triggers (actions) - see @T. The Trigger type provides a Linkable.Int for listening for triggers, and maintains a count of each time the trigger has been called (useful for sequencing). It is also possible to connect Runnable functions to be called on each trigger.
    • Constructor Detail

      • Trigger

        protected Trigger()
    • Method Detail

      • clearLinks

        public Trigger clearLinks()
        Clear all Linkables from this Trigger.
        Returns:
        this
      • link

        public Trigger link​(Runnable runnable)
        Run the provided Runnable each time this Trigger is triggered. This method is shorthand for on().link(i -> runnable.run());.
        Parameters:
        runnable - function to run on trigger
        Returns:
        this
      • on

        public Linkable.Int on()
        Returns a new Linkable.Int for listening to each trigger. The int passed to the created linkable will be the same as index, incrementing each time, wrapping at maxIndex.
        Returns:
        new Linkable.Int for reacting to triggers
      • index

        public Trigger index​(int idx)
        Set the current index. Must not be negative.
        Parameters:
        idx - new index
        Returns:
        this
      • maxIndex

        public Trigger maxIndex​(int max)
        Set the maximum index, at which the index will wrap back to zero.
        Parameters:
        max - maximum index
        Returns:
        this
      • index

        public int index()
        Get the current index.
        Returns:
        current index
      • maxIndex

        public int maxIndex()
        Get the current maximum index.
        Returns:
        maximum index
      • trigger

        public Trigger trigger()
        Manually trigger this Trigger. Useful for chaining this trigger to other sources of input. Otherwise behaves as if externally called, incrementing index and calling linkables.
        Returns:
        this
      • trigger

        protected void trigger​(long time)
      • hasLinks

        protected boolean hasLinks()
      • triggerLinks

        protected void triggerLinks()
      • incrementIndex

        protected void incrementIndex()