Class BuiltinAssets

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

public final class BuiltinAssets extends Object
Registry for the sprite sheets that ship inside the Scratch for Java jar.

The bundled artwork comes from kenney.nl and is released under CC0, so it can be used for any purpose without attribution. Each sheet has an XML atlas next to it describing where every single sprite sits on the sheet; this class reads those atlases and lets a sprite be addressed by plain name:


 sprite.addCostume("bunny1_jump");
 

A name may be given bare ("cactus") or qualified with its sheet ("jumper/cactus"). Three names - cactus, rock and spring - occur on more than one sheet; for those, the bare form resolves against the first sheet in SHEETS and the qualified form is needed to reach the others. Lookup ignores case.

  • Method Details

    • isBuiltinName

      public static boolean isBuiltinName(String name)
      Checks whether a string looks like a bundled sprite name rather than a file path. Anything containing a path separator or a file extension is treated as a path, so existing code that passes real paths keeps working.
      Parameters:
      name - the string to test
      Returns:
      true if the string could name a bundled sprite
    • get

      public static BuiltinAssets.Entry get(String name)
      Looks up a bundled sprite.
      Parameters:
      name - a bare ("grass") or sheet-qualified ("platformer/grass") name
      Returns:
      the entry, or null if no bundled sprite has that name
    • contains

      public static boolean contains(String name)
      Checks whether a bundled sprite with this name exists.
      Parameters:
      name - a bare or sheet-qualified name
      Returns:
      true if it exists
    • getNames

      public static List<String> getNames()
      Returns every bundled sprite name, without the sheet qualifier and without duplicates, in sheet order.
      Returns:
      all available names
    • getSheets

      public static List<String> getSheets()
      Returns the bundled sheets, in lookup order.
      Returns:
      the sheet names
    • getEntries

      public static List<BuiltinAssets.Entry> getEntries()
      Returns every bundled sprite, including the ones whose bare name is taken by an earlier sheet, in sheet order.
      Returns:
      all sprites
    • getReferenceName

      public static String getReferenceName(BuiltinAssets.Entry entry)
      Returns the name to write in code for a sprite. That is its bare name, unless an earlier sheet already claims it, in which case the sheet has to be given as well.
      Parameters:
      entry - a bundled sprite
      Returns:
      the name that resolves to exactly this sprite
    • suggest

      public static List<String> suggest(String name, int limit)
      Finds bundled sprite names close to what was typed, so a wrong name can be answered with "did you mean ...?".
      Parameters:
      name - the name that could not be found
      limit - how many suggestions to return at most
      Returns:
      the closest matching names, best first