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

            return(json.GetHashCode());
        }
Esempio n. 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)));
        }
Esempio n. 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);
        }
Esempio n. 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);
     }
 }
Esempio n. 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)));
 }
Esempio n. 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)));
 }