View Source Ecspanse.Snapshot (ECSpanse v0.10.0)
Provides functions to export and restore Entities and Resources. Those can be used to implement custom save/load functionality.
All functions in this module must be executed from synchronous Systems.
The 'export filter' or 'unfiltered' terms in the functions documentation refers to the :export_filter
option, available for Ecspanse.Component
and Ecspanse.Resource
. This option can filter
out components and resources from the export process.
Attention
All restore functions are overwriting any existing entity components or resources.
Some examples are available in the documentation.
Summary
Export
Exports a list of custom entities and their unfiltered components.
Exports all entities and their components without export filters.
Exports a specific entity and its unfiltered components.
Exports a specific entity with it's descendants and their unfiltered components.
Exports all resources without export filters.
Restore
Restores entities and their components from a list of entity IDs and component specs.
Restores entities and components from a list of entity snapshot structs.
Restores an entity and components from an entity ID and a list of component specs.
Restores a resource from a resource spec.
Restores resources from a list of resource specs.
Restores resources from a list of resource snapshot structs.
Relationships
Removes the invalid relationships between entities.
See Ecspanse.Snapshot.show_invalid_relationships/0
for more details.
Shows invalid relationships between entities.
Export
@spec export_custom_entities!([Ecspanse.Entity.t()]) :: [ Ecspanse.Snapshot.EntitySnapshot.t() ]
Exports a list of custom entities and their unfiltered components.
Returns a list of entity snapshots.
@spec export_entities!() :: [Ecspanse.Snapshot.EntitySnapshot.t()]
Exports all entities and their components without export filters.
Returns a list of entity snapshots.
@spec export_entity!(Ecspanse.Entity.t()) :: Ecspanse.Snapshot.EntitySnapshot.t() | nil
Exports a specific entity and its unfiltered components.
Returns the entity snapshot, or nil
if the entity does not exist.
@spec export_entity_with_descendants!(Ecspanse.Entity.t()) :: [ Ecspanse.Snapshot.EntitySnapshot.t() ]
Exports a specific entity with it's descendants and their unfiltered components.
Returns a list of entity snapshots.
@spec export_resources!() :: [Ecspanse.Snapshot.ResourceSnapshot.t()]
Exports all resources without export filters.
Returns a list of resource snapshots.
Restore
@spec restore_entities!([ {Ecspanse.Entity.id(), [Ecspanse.Component.component_spec()]} ]) :: :ok
Restores entities and their components from a list of entity IDs and component specs.
@spec restore_entities_from_snapshots!([Ecspanse.Snapshot.EntitySnapshot.t()]) :: :ok
Restores entities and components from a list of entity snapshot structs.
@spec restore_entity!(Ecspanse.Entity.id(), [Ecspanse.Component.component_spec()]) :: :ok
Restores an entity and components from an entity ID and a list of component specs.
@spec restore_resource!(Ecspanse.Resource.resource_spec()) :: :ok
Restores a resource from a resource spec.
@spec restore_resources!([Ecspanse.Resource.resource_spec()]) :: :ok
Restores resources from a list of resource specs.
@spec restore_resources_from_snapshots!([Ecspanse.Snapshot.ResourceSnapshot.t()]) :: :ok
Restores resources from a list of resource snapshot structs.
Relationships
@spec remove_invalid_relationships!() :: :ok
Removes the invalid relationships between entities.
See Ecspanse.Snapshot.show_invalid_relationships/0
for more details.
@spec show_invalid_relationships() :: %{ invalid_child_relationships: [{Ecspanse.Entity.t(), [Ecspanse.Entity.t()]}], invalid_parent_relationships: [{Ecspanse.Entity.t(), [Ecspanse.Entity.t()]}] }
Shows invalid relationships between entities.
The result is a map with two keys: :invalid_parent_relationships
and :invalid_child_relationships
.
Each key contains a list of tuples with the current entity and the list of invalid entities.