Interface IScyllaPersistable
Contract between a system that owns in-memory game state and the Scylla Persistence module that writes and restores it. A system implements this interface and registers itself with ScyllaPersistenceRegistry to contribute one partition to every save, without referencing the Persistence module at compile time.
Namespace: Scylla.Core.Persistence
Assembly: ScyllaCore.dll
Syntax
public interface IScyllaPersistable
Remarks
This contract lives in Core, deliberately sized like the existing
IStatsHost pattern in the Data module, so that any Tier 1 module can
implement it and call Register(IScyllaPersistable) without a
reference to the Persistence module. That keeps the same-tier no-reference rule
intact even though save partitions are contributed by modules that initialize
before Persistence exists as a concept in their own assemblies.
Unlike IStatsHost, which is wired through simple property injection on a
single consumer, an unknown, open set of modules can implement this interface, so
discovery goes through the static ScyllaPersistenceRegistry instead
of a point-to-point reference.
Fields
Empty
Singleton no-op fallback. PartitionID is empty, CaptureState()
returns null, and RestoreState(object, int) is a silent no-op. Used where a
default value is needed instead of a null reference.
Declaration
public static readonly IScyllaPersistable Empty
Field Value
| Type | Description |
|---|---|
| IScyllaPersistable |
Properties
PartitionID
The stable identifier for the partition this implementor contributes to a save. Must be unique across every registered IScyllaPersistable and must not change across versions, since it is the key a save file uses to route a partition's payload back to the system that owns it on load.
Declaration
string PartitionID { get; }
Property Value
| Type | Description |
|---|---|
| string |
SchemaVersion
The current schema version of the state returned by CaptureState(). Recorded alongside the partition so a future version of this type can detect and migrate an older payload on load.
Declaration
int SchemaVersion { get; }
Property Value
| Type | Description |
|---|---|
| int |
StateType
The concrete type of the object returned by CaptureState() and expected by RestoreState(object, int). Used by the serializer to resolve the correct type without relying on runtime type information embedded in the payload.
Declaration
Type StateType { get; }
Property Value
| Type | Description |
|---|---|
| Type |
Methods
CaptureState()
Captures a snapshot of this system's current state for inclusion in a save. Called on the main thread within a single frame; implementations should copy references and small values rather than performing expensive work here.
Declaration
object CaptureState()
Returns
| Type | Description |
|---|---|
| object | A plain state object of the type described by StateType, ready to be
serialized. Must not be |
RestoreState(object, int)
Restores this system's state from a previously captured and deserialized snapshot. Called on the main thread after the payload has been decoded and, if needed, migrated to the type's current schema version.
Declaration
void RestoreState(object state, int savedSchemaVersion)
Parameters
| Type | Name | Description |
|---|---|---|
| object | state | The deserialized state object, of the type described by StateType. |
| int | savedSchemaVersion | The schema version the state was saved under, which may be lower than the current SchemaVersion if the save predates a schema change already handled by migration before this call. |