new rlDataManager()
Instantiate an object for loading multiple files(and .metadata files if available) sequentially into dataEntry objects. The loaded files can then be referenced by their key.
If a file named "X" is loaded and a file name "X.metadata" exists and no metadata was set manually, an attempt will be made to JSON.parse the contents of that file and upon success the resulting object will be set as the metadata property of the dataEntry.
zip file contents can be integrated directly into a datamanager as described here.
example: 02-loading-assets
Members
-
onloadfinished :rlDataManager~callbackOnLoading
-
Type:
-
onloadprogress :rlDataManager~callbackOnLoading
-
Type:
Methods
-
getEntry(key) → {rlDataManager.dataEntry|undefined}
-
Get the data entry with the given key (if the key does not exist the result is undefined).
Parameters:
Name Type Description keystring the key which uniquely identifies the entry to get
Returns:
- Type
- rlDataManager.dataEntry | undefined
-
getKeys() → {Array.<string>}
-
Get all known keys (sorted alphanumerically).
Returns:
- Type
- Array.<string>
-
hasFinished() → {boolean}
-
Returns:
true if the current batch of files finished loading
- Type
- boolean
-
startload(sources)
-
Start asynchronous, sequential loading of a batch of files. Make sure to set
onloadprogressandonloadfinishedbefore calling this. Can be called again to load another batch of files after the previous batch finished loading (do not call it again before the batch finished loading).Parameters:
Name Type Description sourcesArray.<rlDataManager.sourceDesc> an array of objects describing the files to load
-
unzipAndCollectItems(zipKey, keyPrefix, keepMetadataEntriesopt)
-
Unzip the contents of a loaded zip file entry and add the contained files directly as
dataEntryobjects to the data manager, key'ed as their (prefixed) full name as it appears inside the zip.For every filename "X" within the zip, if there is also a file named "X.metadata" (e.g. "myimage.png" and "myimage.png.metadata") in it, an attempt will be made to create an object from that files content via JSON.parse and on success, that object will be set as the metadata property in the
dataEntry.The entry for the zip file itself is removed from the data manager afterwards.
Utilizes JSZip, so the zip file must conform to the JSZip limitations.Parameters:
Name Type Attributes Default Description zipKeystring the key under which the zip file was loaded
keyPrefixstring followed by a slash will be put as the beginning of each full name from the file in the zip to form a new key (or an empty string to just use the file name inside the zip as key)
keepMetadataEntriesboolean <optional>
false set to true, if the metadata files themselves should be kept as entries as well
Type Definitions
-
dataEntry
-
(not an actual type, use object literals with these properties)
Properties:
Name Type Description itemrlData the
rlDatainstance assigned to this entrymetadataobject | null only set if defined in
rlDataManager.sourceDescor if loaded from a .metadata filefailInfoobject | null only set if loading of the file within the
rlDatainstance failed -
sourceDesc
-
(not an actual type, use object literals with these properties)
used bystartloadto define sourcesProperties:
Name Type Attributes Default Description keystring unique id to associate with the file within the
rlDataManagersrcURLstring relative or absolute URL to the file
overrideResponseTypestring <optional>
arraybuffer optional responseType to pass on to
rlData#startloadmetadataobject <optional>
null anything you want (e.g. for extensions or additional metadata)
if omitted,startloadwill attempt to get it from a file named "srcURL.metadata" by running JSON.parse on that files contents (if such file exists) -
callbackOnLoading(itemsLoaded, itemsFailed, itemsTotal)
-
Function signature for callbacks to use with
onloadprogressandonloadsuccessParameters:
Name Type Description itemsLoadednumber number of files which were successfully loaded
itemsFailednumber number of files which failed to load
itemsTotalnumber total number of files to load