Module persistence_entity
Helper functions and utilities for persisting entity data.
Functions
persistence.entity.defineField(name, key, get, set, getDefaultM, addArgs) | Define a persistable entity field. |
persistence.entity.save(e, fields) | Save entity data to a table. |
persistence.entity.load(e, fields, data) | Load entity data from a table. |
persistence.entity.saveCpuShip(e) | Save typical CpuShip data to a table. |
persistence.entity.loadCpuShip(e, data) | Load typical CpuShip data from a table. |
Persistable fields
template | Template. |
callsign | Callsign. |
hull | Current hull. |
hullMax | Max hull. |
energy | Energy. |
energyMax | Max energy. |
coolant | Total available coolant. |
hvli | HVLI ammunition. |
homing | Homing ammunition. |
emp | EMP ammunition. |
nuke | Nuke ammunition. |
mine | Mine ammunition. |
shield | Current shields. |
shieldMax | Max shields. |
position | Position. |
velocity | Velocity. |
sysHealthMax | System max health. |
sysHealth | System current health. |
sysHacked | System hacked level. |
sysHeat | System heat level. |
sysPowerReq | System power request. |
sysPower | System power level. |
sysCoolantReq | System coolant request. |
sysCoolant | System coolant level. |
cargo | Ship cargo. |
Functions
- persistence.entity.defineField(name, key, get, set, getDefaultM, addArgs)
-
Define a persistable entity field.
Parameters:
- name The name of the field. Must be unique.
- key The storage key of the field. Must be unique. Should be short.
- get
Either the name of an entity method or a
function(e, ...)
to get the stored data from an entity. If a function, a second return value defines the default value. - set
Either the name of an entity method or a
function(e, ..., val)
to set the stored data on an entity. - getDefaultM
If
get
is the name of an entity method, then the name of an entity method to get the default value, ornil
. - addArgs
The value(s) to pass in place of
...
inget
,set
, andgetDefaultM
.
- persistence.entity.save(e, fields)
-
Save entity data to a table.
Parameters:
- e The entity to save data from.
- fields The list of fields to save.
Returns:
-
A table containing the entity data.
- persistence.entity.load(e, fields, data)
-
Load entity data from a table.
Parameters:
- e The entity to apply loaded data to.
- fields The list of fields to load.
- data A table containing the entity data.
- persistence.entity.saveCpuShip(e)
-
Save typical CpuShip data to a table.
Equivalent to persistence.entity.save with a preset list of fields.
Parameters:
- e The CpuShip to save data from.
Returns:
-
A table containing the entity data.
- persistence.entity.loadCpuShip(e, data)
-
Load typical CpuShip data from a table.
Equivalent to persistence.entity.load with a preset list of fields.
Parameters:
- e The CpuShip to apply loaded data to.
- data A table containing the entity data.
Persistable fields
- template
- Template.
- callsign
- Callsign.
- hull
- Current hull.
- hullMax
- Max hull.
- energy
- Energy.
- energyMax
- Max energy.
- coolant
- Total available coolant.
- hvli
- HVLI ammunition.
- homing
- Homing ammunition.
- emp
- EMP ammunition.
- nuke
- Nuke ammunition.
- mine
- Mine ammunition.
- shield
- Current shields.
- shieldMax
- Max shields.
- position
- Position.
- velocity
- Velocity.
- sysHealthMax
- System max health.
- sysHealth
- System current health.
- sysHacked
- System hacked level.
- sysHeat
- System heat level.
- sysPowerReq
- System power request.
- sysPower
- System power level.
- sysCoolantReq
- System coolant request.
- sysCoolant
- System coolant level.
- cargo
- Ship cargo.