Exemple #1
0
        public int GetVerificationHash()
        {
            string json = SerializationHelpers.Serialize(GetRawSnapshot(),
                                                         RequiredConverters.GetConverters(),
                                                         RequiredConverters.GetContextObjects(Maybe <GameEngine> .Empty));

            return(json.GetHashCode());
        }
Exemple #2
0
        /// <summary>
        /// Restores a GameSnapshot using the given GameSnapshot JSON and the given TemplateGroup
        /// JSON.
        /// </summary>
        public static GameSnapshotRestorer Restore(string snapshotJson, string templateJson,
                                                   Maybe <GameEngine> gameEngine)
        {
            string json = CombineJson(snapshotJson, templateJson);

            return(SerializationHelpers.Deserialize <GameSnapshotRestorer>(json,
                                                                           RequiredConverters.GetConverters(),
                                                                           RequiredConverters.GetContextObjects(gameEngine)));
        }
Exemple #3
0
        public IGameSnapshot TakeSnapshot()
        {
            string snapshotJson = SerializationHelpers.Serialize(GetRawSnapshot(),
                                                                 RequiredConverters.GetConverters(),
                                                                 RequiredConverters.GetContextObjects(Maybe <GameEngine> .Empty));

            var restored = GameSnapshotRestorer.Restore(snapshotJson, _templateJson,
                                                        Maybe <GameEngine> .Empty);

            return(restored.GameSnapshot);
        }
Exemple #4
0
 /// <summary>
 /// Loads an ITemplateGroup from the given JSON. The JSON should have been generated by
 /// calling SaveTemplates.
 /// </summary>
 /// <exception cref="DeserializationException">An error loading the group
 /// occurred.</exception>
 public static ITemplateGroup LoadTemplateGroup(string json)
 {
     try {
         ITemplateGroup group = SerializationHelpers.Deserialize <TemplateGroup>(json,
                                                                                 RequiredConverters.GetConverters(),
                                                                                 RequiredConverters.GetContextObjects(Maybe <GameEngine> .Empty,
                                                                                                                      new TemplateConversionContext()));
         return(group);
     }
     catch (Exception e) {
         throw new DeserializationException(json, e);
     }
 }
Exemple #5
0
 /// <summary>
 /// Converts a template group to JSON that can be restored later.
 /// </summary>
 public static string SaveTemplateGroup(ITemplateGroup templates)
 {
     return(SerializationHelpers.Serialize <TemplateGroup>((TemplateGroup)templates,
                                                           RequiredConverters.GetConverters(),
                                                           RequiredConverters.GetContextObjects(Maybe <GameEngine> .Empty)));
 }
Exemple #6
0
 /// <summary>
 /// Converts a game snapshot to JSON that can be restored later.
 /// </summary>
 public static string SaveSnapshot(IGameSnapshot snapshot)
 {
     return(SerializationHelpers.Serialize <GameSnapshot>((GameSnapshot)snapshot,
                                                          RequiredConverters.GetConverters(),
                                                          RequiredConverters.GetContextObjects(Maybe <GameEngine> .Empty)));
 }