Add Persistence documentation
This commit is contained in:
parent
07ba6f2dc4
commit
36516ec185
4 changed files with 49 additions and 0 deletions
|
@ -7,12 +7,32 @@ using GamecraftModdingAPI.Utility;
|
||||||
|
|
||||||
namespace GamecraftModdingAPI.Persistence
|
namespace GamecraftModdingAPI.Persistence
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Entity serializer and deserializer interface for storing and retrieving data in a Gamecraft save file (GameSave.GC).
|
||||||
|
/// </summary>
|
||||||
public interface IEntitySerializer : IDeserializationFactory, IQueryingEntitiesEngine
|
public interface IEntitySerializer : IDeserializationFactory, IQueryingEntitiesEngine
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The entity factory used for creating entities and entity components.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The entity factory.</value>
|
||||||
IEntityFactory EntityFactory { set; }
|
IEntityFactory EntityFactory { set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serialize the entities.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Whether serialization was successful.</returns>
|
||||||
|
/// <param name="serializationData">Serialized data to write to (writes to GameSave.GC).</param>
|
||||||
|
/// <param name="entitiesDB">Entities db for the game.</param>
|
||||||
|
/// <param name="entitySerializer">Entity serializer with support for single-entity serialization.</param>
|
||||||
bool Serialize(ref ISerializationData serializationData, EntitiesDB entitiesDB, IEntitySerialization entitySerializer);
|
bool Serialize(ref ISerializationData serializationData, EntitiesDB entitiesDB, IEntitySerialization entitySerializer);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserialize the entities.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Whether deserialization was successful.</returns>
|
||||||
|
/// <param name="serializationData">Serialized data to read from (read from GameSave.GC).</param>
|
||||||
|
/// <param name="entitySerializer">Entity serializer with support for single-entity deserialization.</param>
|
||||||
bool Deserialize(ref ISerializationData serializationData, IEntitySerialization entitySerializer);
|
bool Deserialize(ref ISerializationData serializationData, IEntitySerialization entitySerializer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,11 @@ using GamecraftModdingAPI.Utility;
|
||||||
|
|
||||||
namespace GamecraftModdingAPI.Persistence
|
namespace GamecraftModdingAPI.Persistence
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Keeps track of serializers.
|
||||||
|
/// This is used to add and retrieve serializers.
|
||||||
|
/// Added IEntitySerializations are used in serializing and deserializing Gamecraft save files (GameSave.GC).
|
||||||
|
/// </summary>
|
||||||
public static class SerializerManager
|
public static class SerializerManager
|
||||||
{
|
{
|
||||||
private static Dictionary<string, IEntitySerializer> _serializers = new Dictionary<string, IEntitySerializer>();
|
private static Dictionary<string, IEntitySerializer> _serializers = new Dictionary<string, IEntitySerializer>();
|
||||||
|
|
|
@ -7,8 +7,14 @@ using RobocraftX.Common;
|
||||||
|
|
||||||
namespace GamecraftModdingAPI.Persistence
|
namespace GamecraftModdingAPI.Persistence
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Simple entity serializer sufficient for simple entity components.
|
||||||
|
/// </summary>
|
||||||
public class SimpleEntitySerializer<Descriptor> : IEntitySerializer where Descriptor : ISerializableEntityDescriptor, new()
|
public class SimpleEntitySerializer<Descriptor> : IEntitySerializer where Descriptor : ISerializableEntityDescriptor, new()
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Delegate function called when the serializer needs to know what entities to serialize.
|
||||||
|
/// </summary>
|
||||||
public delegate EGID[] GetEntitiesToSerialize(EntitiesDB entitiesDB);
|
public delegate EGID[] GetEntitiesToSerialize(EntitiesDB entitiesDB);
|
||||||
|
|
||||||
private GetEntitiesToSerialize getEntitiesToSerialize;
|
private GetEntitiesToSerialize getEntitiesToSerialize;
|
||||||
|
@ -54,6 +60,10 @@ namespace GamecraftModdingAPI.Persistence
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Construct the entity serializer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="getEntitiesToSerialize">Provider of entity IDs to serialize.</param>
|
||||||
public SimpleEntitySerializer(GetEntitiesToSerialize getEntitiesToSerialize)
|
public SimpleEntitySerializer(GetEntitiesToSerialize getEntitiesToSerialize)
|
||||||
{
|
{
|
||||||
this.getEntitiesToSerialize = getEntitiesToSerialize;
|
this.getEntitiesToSerialize = getEntitiesToSerialize;
|
||||||
|
|
|
@ -10,24 +10,38 @@ using GamecraftModdingAPI.Events;
|
||||||
|
|
||||||
namespace GamecraftModdingAPI.Utility
|
namespace GamecraftModdingAPI.Utility
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tracks the API version the current game was built for.
|
||||||
|
/// For compatibility reasons, this must be enabled before it will work.
|
||||||
|
/// </summary>
|
||||||
public static class VersionTracking
|
public static class VersionTracking
|
||||||
{
|
{
|
||||||
private static readonly VersionTrackingEngine versionEngine = new VersionTrackingEngine();
|
private static readonly VersionTrackingEngine versionEngine = new VersionTrackingEngine();
|
||||||
|
|
||||||
private static bool isEnabled = false;
|
private static bool isEnabled = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the API version saved in the current game.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The version.</returns>
|
||||||
public static uint GetVersion()
|
public static uint GetVersion()
|
||||||
{
|
{
|
||||||
if (!isEnabled) return 0u;
|
if (!isEnabled) return 0u;
|
||||||
return versionEngine.GetGameVersion();
|
return versionEngine.GetGameVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enable API version tracking.
|
||||||
|
/// </summary>
|
||||||
public static void Enable()
|
public static void Enable()
|
||||||
{
|
{
|
||||||
EventManager.AddEventEmitter(versionEngine);
|
EventManager.AddEventEmitter(versionEngine);
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disable API version tracking.
|
||||||
|
/// </summary>
|
||||||
public static void Disable()
|
public static void Disable()
|
||||||
{
|
{
|
||||||
EventManager.AddEventEmitter(versionEngine);
|
EventManager.AddEventEmitter(versionEngine);
|
||||||
|
|
Loading…
Reference in a new issue