Ejemplo n.º 1
0
        /// <summary>
        /// Serializes every registered data store and store to disk
        /// based on the encryption method an other persistence settings
        /// </summary>
        public void Save()
        {
            JObject saveFileResult = new JObject();

            m_jsonEncrypter.EncryptionMode = m_settings.m_encryptionMode;

            foreach (var dataStore in m_dataStoreHash)
            {
                saveFileResult.Add(DataStoreRegistry.TypeToString(dataStore.Value.GetType()), dataStore.Value.SerializeStoredData());
            }

            m_jsonEncrypter.SaveToDisk(saveFileResult, m_settings);
        }
Ejemplo n.º 2
0
        private void SetupRegisteredStores()
        {
            var registeredStores = DataStoreRegistry.GetRegisteredStores();

            if (registeredStores.Count == 0)
            {
                Debug.LogWarning("There are no registered data stores in Save Manager. Nothing will be saved");
            }

            foreach (var dataStore in registeredStores)
            {
                RegisterType(dataStore.Value);
            }
        }
Ejemplo n.º 3
0
        private void RegisterType(Type type)
        {
            string key = DataStoreRegistry.TypeToString(type);

            if (!m_dataStoreHash.ContainsKey(key))
            {
                object[] args          = { this };
                var      packageObject = (DataStore)Activator.CreateInstance(type, args);
                m_dataStoreHash.Add(key, packageObject);
            }
            else
            {
                Debug.LogWarning("There Are Duplicate Stores on Settings!!");
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Retrieves the Registered Data Store
 /// </summary>
 /// <param name="considerSubTypes">If should consider child types on the search</param>
 /// <typeparam name="T">The type of the data store</typeparam>
 /// <returns>The DataStore of Type T. Null if the store is not registered</returns>
 public T GetDataStoreFor <T>(bool considerSubTypes = false) where T : DataStore
 {
     if (!considerSubTypes)
     {
         string key = DataStoreRegistry.TypeToString(typeof(T));
         if (m_dataStoreHash.ContainsKey(key))
         {
             return((T)m_dataStoreHash[key]);
         }
     }
     else
     {
         foreach (var dataStore in m_dataStoreHash)
         {
             if (dataStore.Value.GetType().IsSubclassOf(typeof(T)) || typeof(T) == dataStore.Value.GetType())
             {
                 return((T)dataStore.Value);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads a single Data Store from the save file
        /// </summary>
        /// <param name="deserializeAfter">Whether the DataStore should be immediately loaded from the save file</param>
        /// <typeparam name="T">The Data Store to be loaded</typeparam>
        /// <returns>True if Loaded. False otherwise or if the data store hasn't been registered</returns>
        public bool LoadSingleStoreCacheFromSaveFile <T>(bool deserializeAfter = false) where T : DataStore
        {
            string key = DataStoreRegistry.TypeToString(typeof(T));

            m_jsonEncrypter.EncryptionMode = m_settings.m_encryptionMode;
            JObject saveFileObject = m_jsonEncrypter.ReadFromDisk(m_settings);

            if (saveFileObject == null)
            {
                return(false);
            }

            if (saveFileObject.ContainsKey(key))
            {
                m_dataStoreHash[key].SetCache(saveFileObject[key] as JObject);
            }

            if (deserializeAfter)
            {
                m_dataStoreHash[key].DeserializeStoredObjectsFromCache();
            }

            return(true);
        }