Interface GuideReveal

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface GuideReveal
How a page's content shows once the page is turned to: everything drawn on it (text, pictures, items, scenes, whatever a page type draws) asks the effect how it looks at this point of the reveal, by where it is on the page. Register one with GuideReveals.register(Identifier, GuideReveal); a book chooses it in book.json and an entry may choose its own:
"reveal": "mymod:shimmer"                                  // an effect, for its default length
"reveal": {"effect": "folios:rise", "seconds": 0.6}    // and how long it takes
"reveal": {"effect": "folios:ink", "once": true}       // only the first time each spread is seen this game
"reveal": {"effect": "folios:ink", "unread": true}     // only on spreads the reader hasn't been shown before
"reveal": "none"                                           // shown at once
An effect is asked once for each thing drawn each frame while it plays, so it should be cheap: arithmetic, no allocation beyond the GuideReveal.Look it returns (or one of the constants).
// Each line slides in from the left, the higher ones first.
GuideReveals.register(MyMod.id("slide"), (progress, x, y) -> {
    float local = GuideReveal.stagger(progress, y / GuideLayout.PAGE_HEIGHT, 0.5F);
    return new GuideReveal.Look(local, -(1 - GuideReveal.easeOut(local)) * 12, 0);
});
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
    How a thing looks: how much it shows (0 not at all, 1 fully; items and scenes, which can't fade, show once past a half), how far it is moved from its place in page pixels, a colour it is tinted towards (tint's alpha is how far: 0 not at all), and what share of its letters, if it is text, show as runes (0 none, 1 all).
    static final record 
    A reveal: an effect, how long it takes in seconds, whether it plays only the first time each spread is seen this game (once; pages of entries read in an earlier game count as seen), and whether it plays only on spreads the reader has never been shown in full (unread; kept with the player, or with the copy of a book that keeps its own, so it doesn't play again after a restart or on another computer).
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    around(GuidePainter painter, float progress, float seconds, float x, float y, float width, float height, float spreadX, float spreadY)
    Draws about one thing on the page just after it is drawn while the reveal plays: flames on a letter catching fire, a glow round an item.
    static float
    easeOut(float t)
    Eases 0 to 1 quickly at first and gently into its end.
    look(float progress, float x, float y)
    How something drawn at (x, y) looks at this point of the reveal.
    static float
    noise(int seed)
    A steady pseudo-random number from 0 to 1 for a seed: for where sparks start, which letters flicker.
    default void
    overlay(GuidePainter painter, float progress, float seconds, float pageX)
    Draws over a page while the reveal plays (progress under 1), after its content: fire along a burning edge, smoke, sparks, floating symbols.
    static float
    smooth(float t)
    Eases 0 to 1 gently at both ends.
    static float
    stagger(float progress, float place, float spread)
    A part's own progress when parts start one after another: place (0 to 1) is where it is in the order, and spread how much of the reveal the starts are spread over (0 all together, nearly 1 one at a time).
  • Method Details

    • look

      GuideReveal.Look look(float progress, float x, float y)
      How something drawn at (x, y) looks at this point of the reveal.
      Parameters:
      progress - how far the reveal has gone, 0 as the page lands to 1 when it is done (and 1 from then on)
      x - where it is drawn across the open spread, in page pixels: 0 at the left page's outer edge, GuideLayout.PAGE_WIDTH at the fold, twice that at the right page's outer edge; so an effect runs on over the fold
      y - where it is drawn down the page, in page pixels (0 to GuideLayout.PAGE_HEIGHT)
    • overlay

      default void overlay(GuidePainter painter, float progress, float seconds, float pageX)
      Draws over a page while the reveal plays (progress under 1), after its content: fire along a burning edge, smoke, sparks, floating symbols. In the page's own pixels, through its painter; pageX is where the page starts across the spread (0 or GuideLayout.PAGE_WIDTH), for drawing what runs on over the fold. Nothing by default. Each thing drawn here is drawn every frame, so a few hundred fills at most.
      Parameters:
      seconds - a clock for what flickers or drifts (the book's)
    • around

      default void around(GuidePainter painter, float progress, float seconds, float x, float y, float width, float height, float spreadX, float spreadY)
      Draws about one thing on the page just after it is drawn while the reveal plays: flames on a letter catching fire, a glow round an item. x, y, width and height are where it is in the painter's own pixels, for drawing; spreadX and spreadY where its middle is across the spread, as look(float, float, float) is given it. Called for letters, items and pictures (not for plain fills), so keep it to a few fills, and only where it shows. Nothing by default.
    • stagger

      static float stagger(float progress, float place, float spread)
      A part's own progress when parts start one after another: place (0 to 1) is where it is in the order, and spread how much of the reveal the starts are spread over (0 all together, nearly 1 one at a time).
    • easeOut

      static float easeOut(float t)
      Eases 0 to 1 quickly at first and gently into its end.
    • noise

      static float noise(int seed)
      A steady pseudo-random number from 0 to 1 for a seed: for where sparks start, which letters flicker.
    • smooth

      static float smooth(float t)
      Eases 0 to 1 gently at both ends.