Package org.openpatch.scratch.internal
Class BuiltinAssets
java.lang.Object
org.openpatch.scratch.internal.BuiltinAssets
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classWhere a single bundled sprite lives on its sheet. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks whether a bundled sprite with this name exists.static BuiltinAssets.EntryLooks up a bundled sprite.static List<BuiltinAssets.Entry>Returns every bundled sprite, including the ones whose bare name is taken by an earlier sheet, in sheet order.getNames()Returns every bundled sprite name, without the sheet qualifier and without duplicates, in sheet order.static StringReturns the name to write in code for a sprite.Returns the bundled sheets, in lookup order.static booleanisBuiltinName(String name) Checks whether a string looks like a bundled sprite name rather than a file path.Finds bundled sprite names close to what was typed, so a wrong name can be answered with "did you mean ...?".
-
Method Details
-
isBuiltinName
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
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
Checks whether a bundled sprite with this name exists.- Parameters:
name- a bare or sheet-qualified name- Returns:
- true if it exists
-
getNames
Returns every bundled sprite name, without the sheet qualifier and without duplicates, in sheet order.- Returns:
- all available names
-
getSheets
Returns the bundled sheets, in lookup order.- Returns:
- the sheet names
-
getEntries
Returns every bundled sprite, including the ones whose bare name is taken by an earlier sheet, in sheet order.- Returns:
- all sprites
-
getReferenceName
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
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 foundlimit- how many suggestions to return at most- Returns:
- the closest matching names, best first
-