Example #1
0
 protected override void OnRenderGUI(int layer)
 {
     if (GetDictState(out CorruptionState keyState, out string infoKey, out CorruptionState valueState, out string infoValue))
     {
         foreach (DictItem item in _dictValue.Value.Items)
         {
             GUILayout.BeginVertical(GUI.skin.box);
             DrawTypeItemLabel(string.Concat("Key: ", item.KeySection.ValueString), GetTypeString(item.KeySection.GetSafeValueType(), item.KeySection.ValueType), infoKey, keyState);
             DrawTypeItemLabel(string.Concat("Value: ", item.ValueSection.ValueString), GetTypeString(item.ValueSection.GetSafeValueType(), item.ValueSection.ValueType), infoValue, valueState);
             GUILayout.EndVertical();
         }
     }
     else if (GetArrayState(out CorruptionState arrayState, out string arrayInfo))
     {
         for (int i = 0; i < _arrayValue.Value.Items.Length; i++)
         {
             SaveableValueSection entry = _arrayValue.Value.Items[i];
             GUILayout.BeginVertical(GUI.skin.box);
             DrawTypeItemLabel(string.Concat(i, ": ", entry.ValueString), GetTypeString(entry.GetSafeValueType(), entry.ValueType), arrayInfo, arrayState);
             GUILayout.EndVertical();
         }
     }
     else
     {
         GetCorruptStateWithInfo(out CorruptionState state, out string info);
         DrawTypeItemLabel(_valueSection.ValueString, GetTypeString(_valueSection.GetSafeValueType(), _valueSection.ValueType), info, state);
     }
 }
Example #2
0
            private bool GetArrayState(out CorruptionState arrayState, out string info)
            {
                info       = string.Empty;
                arrayState = CorruptionState.None;

                if (IsArray)
                {
                    if (_arrayValue.Value.Items.Length > 0)
                    {
                        if (_keyEntry.TryGetExpectedArrayType(out Type expectedArrayType))
                        {
                            SaveableValueSection item = _arrayValue.Value.Items[0];
                            arrayState = item.GetSafeValueType() != null && expectedArrayType.IsAssignableFrom(item.GetSafeValueType()) ? CorruptionState.None : CorruptionState.Error;

                            if (arrayState == CorruptionState.Error)
                            {
                                if (item.GetSafeValueType() == null)
                                {
                                    info = TYPE_NOT_FOUND_INFO_MESSAGE;
                                }
                                else
                                {
                                    info = string.Format(EXPECTED_TYPE_INFO_MESSAGE_F, expectedArrayType.Name, item.GetSafeValueType().Name);
                                }
                            }
                        }
                    }
                    return(true);
                }

                return(false);
            }
Example #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);
             }
         }
     }
 }
Example #4
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);
             }
         }
     }
 }
Example #5
0
 public static SaveDataItem CreateFrom(string key, SaveableValueSection saveableValue)
 {
     return(new SaveDataItem()
     {
         SectionKey = key,
         ValueSection = saveableValue,
     });
 }
Example #6
0
 public static SaveableArray <T> From(T[] array)
 {
     SaveableValueSection[] items = new SaveableValueSection[array.Length];
     for (int i = 0; i < array.Length; i++)
     {
         items[i] = new SaveableValueSection(array[i], typeof(T));
     }
     return(new SaveableArray <T>(items));
 }
        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))));
            }
        }
Example #8
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))));
            }
        }
        public void SetValue(string key, object value)
        {
            if (_keyToNormalValue.ContainsKey(key))
            {
                _keyToNormalValue[key] = new SaveableValueSection(value, value.GetType());
            }
            else
            {
                _keyToNormalValue.Add(key, new SaveableValueSection(value, value.GetType()));
            }

            SetValueSection(key, new SaveableValueSection(value, value.GetType()));
        }
Example #10
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();
     }
 }
Example #11
0
 public DictItem(object key, object value)
 {
     KeySection   = new SaveableValueSection(key);
     ValueSection = new SaveableValueSection(value);
 }
Example #12
0
 public ValKeyItem(StorageKeyEntry keyEntry, SaveableValueSection value) : base(keyEntry.StorageKey)
 {
     ValItem = new ValItem(keyEntry, value);
 }
Example #13
0
 public SaveDataItem(string key, object value)
 {
     SectionKey   = key;
     ValueSection = new SaveableValueSection(value);
 }