Constructor
new Highscores(id, length, tables)
Creates a new object.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string | Unique application ID, matching Application.id. |
length |
number | The number of positions per highscore table. |
tables |
number | The number of highscore tables. |
- Source:
Throws:
-
If the application ID is missing or invalid.
- Type
- Error
Members
(readonly) key :string
A string value that uniquely identifies the highscore data in localstorage.
Useful when several applications are distributed via the same domain.
Type:
- string
- Source:
Methods
clear() → {undefined}
Removes all highscore data associated with the current application.
Note that this action cannot be undone.
- Source:
Returns:
- Type
- undefined
dispose() → {undefined}
Initiates deallocation of this object.
- Source:
Returns:
- Type
- undefined
export() → {Array.<Object>}
Returns an independent copy of all highscore tables.
- Source:
Returns:
Highscore tables.
- Type
- Array.<Object>
get(ranking, tableopt) → {Object}
Gets a specific high score based on ranking. Note that first places start
with index 0 and not 1.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
ranking |
number | Requested ranking. | ||
table |
number |
<optional> |
0 | Which table the data should be retrieved from. |
- Source:
Returns:
- Type
- Object
import(data) → {boolean}
Replaces and saves all tables when the data matches this configuration.
Entries must be sorted by score in descending order.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Array.<Object> | Highscore tables to import. |
- Source:
Returns:
True if the data was imported.
- Type
- boolean
reload() → {boolean}
Reloads highscore data from LocalStorage without replacing the current data
when storage is unavailable or contains invalid data.
- Source:
Returns:
True if valid data was loaded.
- Type
- boolean
send(score, nameopt, tableopt) → {number}
Sends data to the highscore list. The data is saved if it qualifies as a
highscore.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
score |
number | Score to save. | ||
name |
string |
<optional> |
Rune | Name of score holder. |
table |
number |
<optional> |
0 | Which table to use. |
- Source:
Returns:
Current ranking on the highscore list.
- Type
- number
sync(callbackopt) → {undefined}
Requests highscore synchronization from the host, if available. The callback
is always invoked asynchronously with success and updated boolean properties.
The local list remains available when synchronization cannot be performed.
Pending callbacks are cancelled when this object is disposed.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
callback |
function |
<optional> |
Called when synchronization finishes. |
- Source:
Returns:
- Type
- undefined
test(score, tableopt) → {number}
Tests whether a score can qualify as a high score. The method returns the
raking of the score in the form of an integer. The result -1 indicates that
the score is outside the scope of the current high score table and thus not
a high score. Note that a test does not affect the current high score list,
nothing is saved or deleted when a test is performed. Non-finite scores
cannot qualify and return -1.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
score |
number | Score to test. | ||
table |
number |
<optional> |
0 | Table to test against. |
- Source:
Returns:
Current ranking on the highscore list.
- Type
- number