Class MacroRunner

java.lang.Object
com.j3d.engine.interact.macros.MacroRunner
All Implemented Interfaces:
EventListener

public class MacroRunner extends Object implements EventListener
A single-instantiated class with the purpose of running a single Macro with many responsibilities

A typical flow is:

  1. Read one macro off the queue
  2. Execute it
  3. Repeat
However, in the case of Macro with an instruction type of InstructionType.COMMAND_EXEC, the executed command might be stateful (implement SemiStatefulCommand), meaning it may have not finished synchronously. In that case the order is as follows:
  1. Read one macro off the queue
  2. Execute it
  3. Check if it was a command and it is stateful

This class can be accessed via MacroUtils however should only be sued by MacroCmd (specifically its recording subcommand RunCmd)

See Also:
  • Field Details

    • macro

      private Macro macro
      The current macro
    • logLabel

      private SafeJLabel logLabel
      The loglabel for RunCmd callback errors
    • deque

      private ArrayDeque<MacroLine> deque
      The queue of instructions
    • running

      private boolean running
      Whether this macro is running or not
    • expectEvent

      private boolean expectEvent
      Whether the macro should expect a EventType.STATEFUL_COMMAND_COMPLETED event to proceed execution.
  • Constructor Details

    • MacroRunner

      MacroRunner()
      Package-private default constructor (Only MacroUtils can instantiate it)
  • Method Details

    • run

      public boolean run(SafeJLabel logLabel, String name)
      Attempts to run a given macro by name. This serves as the start of running a macro and will run ther entire macro to completion.
      Parameters:
      logLabel - The log label for error purposes
      name - The name of the macro to run
      Returns:
      boolean indicating whether the macro started running successfully.
    • clean

      public void clean()
      Cleans up all state to ensure run(SafeJLabel, String) can be called for a new macro.
    • poll

      private void poll()
      Retrieves the head of the instruction set and attempts to execute it.
    • onEvent

      public <K> void onEvent(EventType event, EventPayload<K> properties)
      Handles the event stuff of the macro. Specifically handles EventType.STATEFUL_COMMAND_COMPLETED only if expectEvent is true
      Specified by:
      onEvent in interface EventListener
      Type Parameters:
      K - The event emitter. In this case it would be Commands
      Parameters:
      event - The type of event
      properties - The given event payload
    • commandLine

      private boolean commandLine(String line)
      Execute a given command-line by stealing what the command parser itself thinks the parsed arguments would be.
      Parameters:
      line - The input line
      Returns:
      true indicating that the next macro instruction invocation can be polled via poll() otherwise false indicating that expectEvent is now true hence the next invocation will only happen once the event has been emitted.
      See Also:
    • selectLine

      private void selectLine(String line)
      Parses and applies the selection
      Parameters:
      line - The line input
      See Also:
    • cameraLine

      private void cameraLine(String line)
      Parses and applies the camera movement. both position and rotation
      Parameters:
      line - the line
      See Also:
    • isRunning

      public boolean isRunning()
      Whether the macro runner is itself running a macro or not
      Returns:
      true if it's running, false otherwise