HammeriteAssetLibrary
Core: files, names and extension. Inherits RefCounted
Where a NAME becomes a model, a sound - a resource of one kind (#87).
A map records names, and the game says where names are found: directories to search, and sources of its own (add_source()) for whatever does not live under res:// at all - a mod's folder of raw files loaded at runtime. Sources are asked first, in the order they were added, so a mod can stand in for something the game ships under the same name. What is found is remembered. A name found to be nothing is searched for again from the next frame on, so a file that arrives later - a download, a mod installed while the game runs - is found without anyone clearing anything.
Properties
| Type | Name | Default |
|---|---|---|
String[] | search_paths | [] |
Methods
| Returns | Method |
|---|---|
void | add_search_path(directory: String) |
void | add_source(find: Callable, list: Callable = Callable()) |
void | clear_sources() |
Resource | resolve(name: StringName) |
bool | has(name: StringName) |
StringName | name_of(resource: Resource) |
PackedStringArray | list_names() |
void | clear_cache() |
PackedStringArray | files_in(directory: String, extensions: PackedStringArray) static |
Property descriptions
search_paths
var search_paths: String[] = []
Directories searched after the sources, in order: the first hit wins. Assigned or edited in place, the next lookup searches afresh.
Method descriptions
add_search_path()
func add_search_path(directory: String) -> void
Search directory after the search paths there are, as search_paths does.
add_source()
func add_source(find: Callable, list: Callable = Callable()) -> void
find takes a name, as a String, and returns the resource, or null when this source has no such thing. list returns the names it has, for whoever offers a choice of them.
clear_sources()
func clear_sources() -> void
Drop every source add_source() registered and forget every remembered answer. A game that added sources calls it on exit; the Hammerite autoload does so for HammeriteModelLibrary.library.
resolve()
func resolve(name: StringName) -> Resource
The resource called name, or null when neither a source nor a search path has one. A res:// or uid:// path, as an inspector's file picker writes, is taken as the file it names when no source answers for it.
has()
func has(name: StringName) -> bool
Whether name resolves to something. Resolves it, and remembers the answer, as resolve() does.
name_of()
func name_of(resource: Resource) -> StringName
What resource was found as, or empty for one this library did not find.
list_names()
func list_names() -> PackedStringArray
Every name the sources and search paths hold, each once, in the order they are asked.
clear_cache()
func clear_cache() -> void
Forget every remembered answer, so names are looked up afresh. Changing search_paths and adding or clearing sources do this already, and a name found to be nothing is looked for again on the next frame; what is left is a file found once that has since changed on disk.
files_in()
static func files_in(directory: String, extensions: PackedStringArray) -> PackedStringArray
The files in directory with one of extensions, by the names they were authored under. An exported game has no foo.png, only the foo.png.import pointing at what it was imported to - and a text resource leaves foo.tres.remap - so a listing that took the directory at its word found nothing to offer at all.