SaveSession
One player’s save in a world: the record as it stands, restored onto the world, her player entity and each saved entity, and read back from them.
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
loaded |
readonly |
SaveLoad | null |
The last load, or the refusal of a restore after it; null until a record, or none for a new game, has loaded. |
owners |
readonly |
readonly SaveOwner[] |
The owners of the record, in the order they restore. |
player |
readonly |
Entity | undefined |
Her player entity, once attachPlayer named it. |
Methods
Section titled “Methods”attachPlayer()
Section titled “attachPlayer()”attachPlayer(
player):void
Restores the player-scope saves onto her player entity, after every
onPlayerJoin, reads them from her from then on, and makes this the
session setSavedEntity restores her saved entities from. A restore
that throws refuses the load, as load does.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
player |
Entity |
Returns
Section titled “Returns”void
captureEntity()
Section titled “captureEntity()”captureEntity(
entity,key):SaveRead
Reads entity’s entity-scope saves into the record under key, as
it goes: a copy, since the entity is about to change or be destroyed.
Where one owner’s read fails, keeps the key’s record as it was and
hands out the problem.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
entity |
Entity |
key |
string |
Returns
Section titled “Returns”capturePlayer()
Section titled “capturePlayer()”capturePlayer():
SaveRead
Reads her player-scope saves and each of her saved entities into the
record, as her player goes: copies, as captureEntity makes. Where
one owner’s read fails, keeps the record as it was and hands out the
problem.
Returns
Section titled “Returns”load()
Section titled “load()”load(
value):SaveLoad
Loads a stored record, or none for a new game: each owner’s key is migrated and checked, in each saved entity’s record too, and the world-scope saves are restored. A record that fails, or a restore that throws, refuses the load: nothing more is restored, and nothing is written from then on.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
unknown |
Returns
Section titled “Returns”read()
Section titled “read()”read():
SaveRead|null
Reads every owner into the record and hands it out, each key no
owner claims kept, and each saved-entity key with no live saved
entity kept as it was last captured or loaded. Where one owner’s
read fails, hands out its problem and keeps the record as the last
good read left it. Null before a load and after a refused one, since
nothing may be written then. The record holds what each read
returned, not a copy: turn it into JSON before the game changes
again.
Returns
Section titled “Returns”SaveRead | null
restoreEntity()
Section titled “restoreEntity()”restoreEntity(
entity,key):boolean
Restores the record kept under key onto entity, the entity-scope
saves in order, over what its spawn set up. Answers false where a
restore threw, which refuses the load; a session with no load, or
one refused before, restores nothing and answers true.
setSavedEntity calls it.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
entity |
Entity |
key |
string |
Returns
Section titled “Returns”boolean