Class StageAccess

java.lang.Object
org.openpatch.scratch.internal.StageAccess

public abstract class StageAccess extends Object
How an extension package reaches something on Stage that is not part of its public face.

TiledMap has to put a map's tiles into the stage's stamp queues, and it lives in its own package. Without this, the queue-taking stamp method would have to be public on Stage, where it would sit in every learner's autocomplete while taking a type - Stamp - that they have no way to build. The same trick as StageHooks, in the other direction: that one lets the render loop into a stage, this one lets an extension in.

Stage installs an implementation when the class is loaded, which has always happened by the time anything can call get() - reaching it requires a stage to pass in.

  • Constructor Details

    • StageAccess

      public StageAccess()
  • Method Details

    • install

      public static void install(StageAccess access)
      Installs the implementation. Called by Stage; the first one wins, so this cannot be swapped out from outside the library.
      Parameters:
      access - the implementation to install
    • get

      public static StageAccess get()
      Returns the installed accessor.
      Returns:
      the accessor
      Throws:
      IllegalStateException - if no stage has been loaded, which should be impossible from anywhere that has a stage to hand
    • stamp

      public abstract void stamp(Stage stage, Queue<Stamp> stamps, Layer layer)
      Stamps images permanently onto one of a stage's layers.
      Parameters:
      stage - the stage to stamp onto
      stamps - the images to stamp
      layer - which layer to stamp them onto