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 key
string 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
onloadprogress
andonloadfinished
before 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 sources
Array.<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
dataEntry
objects 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 zipKey
string the key under which the zip file was loaded
keyPrefix
string 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)
keepMetadataEntries
boolean <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 item
rlData the
rlData
instance assigned to this entrymetadata
object | null only set if defined in
rlDataManager.sourceDesc
or if loaded from a .metadata filefailInfo
object | null only set if loading of the file within the
rlData
instance failed -
sourceDesc
-
(not an actual type, use object literals with these properties)
used bystartload
to define sourcesProperties:
Name Type Attributes Default Description key
string unique id to associate with the file within the
rlDataManager
srcURL
string relative or absolute URL to the file
overrideResponseType
string <optional>
arraybuffer optional responseType to pass on to
rlData#startload
metadata
object <optional>
null anything you want (e.g. for extensions or additional metadata)
if omitted,startload
will 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
onloadprogress
andonloadsuccess
Parameters:
Name Type Description itemsLoaded
number number of files which were successfully loaded
itemsFailed
number number of files which failed to load
itemsTotal
number total number of files to load