Add Persistence documentation

This commit is contained in:
NGnius (Graham) 2020-04-28 22:59:36 -04:00
parent 07ba6f2dc4
commit 36516ec185
4 changed files with 49 additions and 0 deletions

View file

@ -7,12 +7,32 @@ using GamecraftModdingAPI.Utility;
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
{
/// <summary>
/// The entity factory used for creating entities and entity components.
/// </summary>
/// <value>The entity factory.</value>
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);
/// <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);
}
}

View file

@ -9,6 +9,11 @@ using GamecraftModdingAPI.Utility;
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
{
private static Dictionary<string, IEntitySerializer> _serializers = new Dictionary<string, IEntitySerializer>();

View file

@ -7,8 +7,14 @@ using RobocraftX.Common;
namespace GamecraftModdingAPI.Persistence
{
/// <summary>
/// Simple entity serializer sufficient for simple entity components.
/// </summary>
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);
private GetEntitiesToSerialize getEntitiesToSerialize;
@ -54,6 +60,10 @@ namespace GamecraftModdingAPI.Persistence
return true;
}
/// <summary>
/// Construct the entity serializer.
/// </summary>
/// <param name="getEntitiesToSerialize">Provider of entity IDs to serialize.</param>
public SimpleEntitySerializer(GetEntitiesToSerialize getEntitiesToSerialize)
{
this.getEntitiesToSerialize = getEntitiesToSerialize;

View file

@ -10,24 +10,38 @@ using GamecraftModdingAPI.Events;
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
{
private static readonly VersionTrackingEngine versionEngine = new VersionTrackingEngine();
private static bool isEnabled = false;
/// <summary>
/// Gets the API version saved in the current game.
/// </summary>
/// <returns>The version.</returns>
public static uint GetVersion()
{
if (!isEnabled) return 0u;
return versionEngine.GetGameVersion();
}
/// <summary>
/// Enable API version tracking.
/// </summary>
public static void Enable()
{
EventManager.AddEventEmitter(versionEngine);
isEnabled = true;
}
/// <summary>
/// Disable API version tracking.
/// </summary>
public static void Disable()
{
EventManager.AddEventEmitter(versionEngine);