Beispiel #1
0
 public ValItem(StorageKeyEntry keyEntry, SaveableValueSection valueSection) : base(keyEntry.StorageKey)
 {
     _keyEntry     = keyEntry;
     _valueSection = valueSection;
     if (_valueSection.GetSafeValueType() == typeof(SaveableDict))
     {
         _dictValue = (SaveableDict)_valueSection.GetValue();
     }
     else if (_valueSection.GetSafeValueType() == typeof(SaveableArray))
     {
         _arrayValue = (SaveableArray)_valueSection.GetValue();
     }
 }
Beispiel #2
0
 public static void Do(Storage storage, Migration[] migrations)
 {
     foreach (var pair in GetMigrationsPerCapsule(migrations))
     {
         List <Migration> capsuleMigrations = pair.Value;
         if (storage.TryRead(pair.Key, out ReadStorageResult storageResult))
         {
             SaveableValueSection migratorLevelSection = storageResult.CapsuleStorage.GetValueSection(MIGRATOR_INDEX_KEY);
             int migratorLevelIndex = migratorLevelSection.IsValid ? (int)migratorLevelSection.GetValue() : 0;
             int preMigrationLevel  = migratorLevelIndex;
             for (int i = migratorLevelIndex; i < capsuleMigrations.Count; i++)
             {
                 Migration migration = capsuleMigrations[i];
                 migration.Do(storageResult);
                 // Migrator Level is the one coming after this one, may it be the next loop or in the future
                 migratorLevelIndex = i + 1;
                 Debug.Log(migration.GetType().FullName + ".Do();");
             }
             if (preMigrationLevel != migratorLevelIndex)
             {
                 storageResult.CapsuleStorage.SetValue(MIGRATOR_INDEX_KEY, migratorLevelIndex);
                 storage.Flush(pair.Key);
             }
         }
     }
 }
Beispiel #3
0
 public static void Undo(Storage storage, Migration[] migrations)
 {
     foreach (var pair in GetMigrationsPerCapsule(migrations))
     {
         List <Migration> capsuleMigrations = pair.Value;
         if (storage.TryRead(pair.Key, out ReadStorageResult storageResult))
         {
             SaveableValueSection migratorLevelSection = storageResult.CapsuleStorage.GetValueSection(MIGRATOR_INDEX_KEY);
             int migratorLevelIndex = migratorLevelSection.IsValid ? (int)migratorLevelSection.GetValue() : 0;
             int preMigrationLevel  = migratorLevelIndex;
             for (int i = migratorLevelIndex - 1; i >= 0; i--)
             {
                 Migration migration = capsuleMigrations[i];
                 migration.Undo(storageResult);
                 // Migrator Level is set to target the one last undone
                 migratorLevelIndex = i;
                 Debug.Log(migration.GetType().FullName + ".Undo();");
             }
             if (preMigrationLevel != migratorLevelIndex)
             {
                 storageResult.CapsuleStorage.SetValue(MIGRATOR_INDEX_KEY, migratorLevelIndex);
                 storage.Flush(pair.Key);
             }
         }
     }
 }
        public ValueStorageDictionary(string parentStorageCapsuleID, Dictionary <string, SaveableValueSection> loadedValues)
        {
            ParentStorageCapsuleID = parentStorageCapsuleID;
            _keyToNormalValue      = loadedValues;

            SaveableValueSection keysToKeepSection = GetValueSection(VALUE_KEYS_TO_KEEP_KEY);

            if (keysToKeepSection.IsValid)
            {
                _keysToKeep = new List <string>(SaveableArray.To <string>((SaveableArray)keysToKeepSection.GetValue(typeof(SaveableArray))));
            }
        }
Beispiel #5
0
        public StorageDictionary(string parentStorageCapsuleID, IStorageAccess storageAccess, Dictionary <string, SaveableValueSection> loadedValues, Dictionary <string, object> loadedRefs) : base(parentStorageCapsuleID, loadedValues)
        {
            _storageAccess    = storageAccess;
            _keyToReferenceID = loadedRefs;

            SaveableValueSection keysToKeepSection = GetValueSection(REF_KEYS_TO_KEEP_KEY);

            if (keysToKeepSection.IsValid)
            {
                _keysToKeep = new List <string>(SaveableArray.To <string>((SaveableArray)keysToKeepSection.GetValue(typeof(SaveableArray))));
            }
        }