Base module for managing storage and synchronization of all resources
Found in Chapter 4, page 134 of the textbook
Example: 4.3 Resource Map and Shader Loader- Source:
Methods
(inner) get(path)
Returns the data of the resource
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string | the path to the resource file |
- Source:
Returns:
the data of the resource
(inner) has(path) → {boolean}
Returns if the resource is in the resource map
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string | path to resource file |
- Source:
Returns:
true if the resource is in the resource map
- Type
- boolean
(inner) incRef(path)
Increment the number of references to a resource
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string | the resource to increment |
- Source:
(inner) loadDecodeParse(path, decodeResource, parseResource) → {Promise}
Generic loading function,
Step 1: fetch from server
Step 2: decodeResource on the loaded package
Step 3: parseResource on the decodedResource
Step 4: store result into the map
Push the promised operation into an arrayParameters:
| Name | Type | Description |
|---|---|---|
path |
string | the path to the resource file |
decodeResource |
function | function to decode resource, specific to the type of resource |
parseResource |
function | function to parse resource, specific to the type of resource |
- Source:
Returns:
promise to fetch the resource, null if the resource already exists in the map
- Type
- Promise
(inner) loadRequested(path)
Clears the MapEntry for the resource to be loaded
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string | the path to resource file |
- Source:
(inner) pushPromise(p)
Add a new promise to outstanding promise list
Parameters:
| Name | Type | Description |
|---|---|---|
p |
Promise | the new promise |
- Source:
(inner) set(key, value)
Sets the data of the MapEntry object for the resource key.
The path must already exist in the map
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | path to the resource file |
value |
the data of the resource |
- Source:
(inner) unload(path) → {boolean}
Decrements the number of references to a resource, removing it
from the resource map if there are no remaining references
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string | the path to the resource file to be unloaded |
- Source:
Returns:
true if unloading is successful
- Type
- boolean
(async, inner) waitOnPromises()
Halt until all outstanding promises are fulfilled
- Source: