A base type for a Registry, which is an object which handles loading scriptable objects.

Parameters:

T

The type to construct. Must implement IRegistryEntry.

J

The type of the JSON data used when constructing.

P

The type of the parameters used for fetchEntry().

Constructor

new(registryId:String, dataFilePath:String, ?versionRule:VersionRule)

Parameters:

registryId

A readable ID for this registry, used when logging.

dataFilePath

The path (relative to assets/data) to search for JSON files.

Variables

finalregistryId:String

The ID of the registry. Used when logging.

Methods

countEntries():Int

Count the number of entries in this registry.

Returns:

The number of entries.

fetchEntry(id:String, ?params:P):Null<T>

Fetch an entry by its ID.

Parameters:

id

The ID of the entry to fetch.

Returns:

The entry, or null if it does not exist.

fetchEntryVersion(id:String):Null<Version>

Retrieve the data for an entry and parse its Semantic Version.

Parameters:

id

The ID of the entry.

Returns:

The entry's version, or null if it does not exist or is invalid.

getScriptedEntryClassName(id:String, ?params:P):Null<String>

Return the class name of the scripted entry with the given ID, if it exists.

Parameters:

id

The ID of the entry.

Returns:

The class name, or null if it does not exist.

hasEntry(id:String):Bool

Return whether the registry has successfully parsed an entry with the given ID.

Parameters:

id

The ID of the entry.

Returns:

true if the entry exists, false otherwise.

isScriptedEntry(id:String, ?params:P):Bool

Return whether the entry ID is known to have an attached script.

Parameters:

id

The ID of the entry.

Returns:

true if the entry has an attached script, false otherwise.

listEntryIds():Array<String>

Retrieve a list of all entry IDs in this registry.

Returns:

The list of entry IDs.

loadEntries():Void

TODO: Create a loadEntriesAsync(onProgress, onComplete) function.

parseEntryData(id:String):Null<J>

Read, parse, and validate the JSON data and produce the corresponding data object.

NOTE: Must be implemented on the implementation class.

Parameters:

id

The ID of the entry.

Returns:

The created entry.

parseEntryDataRaw(contents:String, ?fileName:String):Null<J>

Parse and validate the JSON data and produce the corresponding data object.

NOTE: Must be implemented on the implementation class.

Parameters:

contents

The JSON as a string.

fileName

An optional file name for error reporting.

Returns:

The created entry.

parseEntryDataWithMigration(id:String, version:Null<Version>):Null<J>

Read, parse, and validate the JSON data and produce the corresponding data object, accounting for old versions of the data.

NOTE: Extend this function to handle migration.

Parameters:

id

The ID of the entry.

version

The entry's version (use fetchEntryVersion(id)).

Returns:

The created entry.

toString():String

A list of all entries that are not included in the base game.

Returns:

Array