Class ScriptSequence

All Implemented Interfaces:
Subscription, AutoCloseable

public final class ScriptSequence extends Object implements Subscription

A cancellable ordered sequence of delayed actions owned by a script context.

Build a sequence with then(Runnable) and waitFor(int), then call start(). Delays are accumulated until the next action. Closing the sequence cancels its pending scheduled action.

  • Method Details

    • then

      public ScriptSequence then(Runnable action)
      Appends an action after the currently accumulated delay.
      Parameters:
      action - The action to invoke.
      Returns:
      This sequence.
      Throws:
      IllegalStateException - if the sequence has started.
    • waitFor

      public ScriptSequence waitFor(int delay)
      Adds a delay before the next appended action.
      Parameters:
      delay - The non-negative delay in milliseconds.
      Returns:
      This sequence.
      Throws:
      IllegalStateException - if the sequence has started.
      IllegalArgumentException - if delay is negative.
      ArithmeticException - if the accumulated delay overflows.
    • cameraPanTo

      public ScriptSequence cameraPanTo(Point2D target, int durationTicks)
      Schedules a camera pan to a given map location.
      Parameters:
      target - The target in map coordinates.
      durationTicks - The transition duration in update ticks.
      Returns:
      This sequence.
    • cameraPanTo

      public ScriptSequence cameraPanTo(IEntity target, int durationTicks)
      Schedules a camera pan to center on a target entity.
      Parameters:
      target - The target entity.
      durationTicks - The transition duration in update ticks.
      Returns:
      This sequence.
    • cameraZoom

      public ScriptSequence cameraZoom(float targetZoom, int delayMs)
      Schedules a smooth camera zoom transition.
      Parameters:
      targetZoom - The target zoom factor.
      delayMs - The transition duration in milliseconds.
      Returns:
      This sequence.
    • screenShake

      public ScriptSequence screenShake(double intensity, int intervalMs, int durationMs)
      Schedules a screen shake effect.
      Parameters:
      intensity - The shake intensity.
      intervalMs - The minimum interval between generated shake offsets, in milliseconds.
      durationMs - The shake duration in milliseconds.
      Returns:
      This sequence.
    • playSound

      public ScriptSequence playSound(String soundName)

      Schedules playing a sound effect by resource name.

      Missing resources are silently skipped when the action runs.

      Parameters:
      soundName - The sound resource name.
      Returns:
      This sequence.
    • playSound

      public ScriptSequence playSound(Sound sound)
      Schedules playing a sound effect.
      Parameters:
      sound - The sound to play.
      Returns:
      This sequence.
    • start

      public Subscription start()
      Starts the sequence and transfers cancellation ownership to its context.
      Returns:
      This sequence as a cancellable subscription.
      Throws:
      IllegalStateException - if it has already started.
    • isRunning

      public boolean isRunning()
      Returns whether the sequence has pending actions.
      Returns:
      true while a started sequence has not completed or been closed.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Subscription