Class WorldSnapshot
- Namespace
- KeenEyes.Serialization
- Assembly
- KeenEyes.Core.dll
Represents a complete snapshot of a world's state.
public sealed record WorldSnapshot : IEquatable<WorldSnapshot>
- Inheritance
-
WorldSnapshot
- Implements
- Inherited Members
Examples
// Create a snapshot
var snapshot = SnapshotManager.CreateSnapshot(world);
// Serialize to JSON
var json = SnapshotManager.ToJson(snapshot);
// Later, deserialize and restore
var loadedSnapshot = SnapshotManager.FromJson(json);
SnapshotManager.RestoreSnapshot(world, loadedSnapshot);
Remarks
A snapshot captures all entities, their components, hierarchy relationships, and singleton data at a specific point in time. This can be serialized to JSON or binary format for persistence.
Snapshots are immutable once created. To modify world state, restore the snapshot to a world, make changes, and create a new snapshot.
Properties
Entities
Gets or sets the collection of all serialized entities in the snapshot.
public required IReadOnlyList<SerializedEntity> Entities { get; init; }
Property Value
Remarks
Entities are stored in creation order to facilitate predictable restoration. Parent entities should appear before their children to ensure hierarchy can be reconstructed in a single pass.
Metadata
Gets or sets optional metadata associated with this snapshot.
public IReadOnlyDictionary<string, object>? Metadata { get; init; }
Property Value
Remarks
This dictionary can be used to store application-specific metadata such as save slot name, player name, game progress, etc.
Metadata values must be JSON-serializable types (strings, numbers, booleans, or nested dictionaries/arrays of these types).
Singletons
Gets or sets the collection of all serialized singletons in the snapshot.
public required IReadOnlyList<SerializedSingleton> Singletons { get; init; }
Property Value
Remarks
Singletons are world-level data not tied to any entity.
Timestamp
Gets or sets the timestamp when this snapshot was created.
public required DateTimeOffset Timestamp { get; init; }
Property Value
Remarks
Stored as UTC time for consistency across time zones.
Version
Gets or sets the format version of this snapshot.
public int Version { get; init; }
Property Value
Remarks
Used for backwards compatibility when the snapshot format changes. Current version is 1.