Exemple #1
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);
            }
Exemple #2
0
            protected void DrawItemLabel(string labelValue, string infoText, CorruptionState curruptionState)
            {
                GUIStyle labelStyle = new GUIStyle(GUI.skin.label);

                string icon  = GetCorruptionStateIcon(curruptionState);
                Color? color = GetCorruptionStateColor(curruptionState);

                if (color.HasValue)
                {
                    labelStyle.normal.textColor = color.Value;
                }

                GUIContent labelContent;

                if (string.IsNullOrEmpty(infoText))
                {
                    labelContent = new GUIContent(string.Concat(labelValue, " ", icon));
                }
                else
                {
                    labelContent = new GUIContent(string.Concat(labelValue, " ", icon), string.Concat(infoText, " ", icon));
                }

                EditorGUILayout.LabelField(labelContent, labelStyle);
            }
Exemple #3
0
        public static CorruptionState ValidateStorage(string storagePath, Storage.EncodingType encodingType, CorruptionState openOnState = CorruptionState.Warning | CorruptionState.Error)
        {
            CorruptionState worstCorruptionState = CorruptionState.None;

            IStorageCapsule[] capsuleInstances = GetStorageCapsuleInstances();
            CapsuleItem[]     capsuleItems     = LoadCapsuleItems(storagePath, encodingType, capsuleInstances);
            for (int i = 0; i < capsuleItems.Length; i++)
            {
                CapsuleItem capsuleItem = capsuleItems[i];

                if (capsuleItem.StorageItem.IsEmpty)
                {
                    continue;
                }

                if (worstCorruptionState < capsuleItem.CorruptionState)
                {
                    worstCorruptionState = capsuleItem.CorruptionState;
                }

                if (openOnState.HasFlag(worstCorruptionState))
                {
                    OpenWindow().LoadStorage(storagePath, encodingType);
                }
            }

            return(worstCorruptionState);
        }
Exemple #4
0
            private bool GetDictState(out CorruptionState keyState, out string infoKey, out CorruptionState valueState, out string infoValue)
            {
                infoKey    = string.Empty;
                infoValue  = string.Empty;
                keyState   = CorruptionState.None;
                valueState = CorruptionState.None;

                if (IsDict)
                {
                    if (_dictValue.Value.Items.Length > 0)
                    {
                        if (_keyEntry.TryGetExpectedDictTypes(out Type expectedKeyType, out Type expectedValueType))
                        {
                            DictItem item   = _dictValue.Value.Items[0];
                            Type     tKey   = item.KeySection.GetSafeValueType();
                            Type     tValue = item.ValueSection.GetSafeValueType();

                            keyState   = tKey != null && expectedKeyType.IsAssignableFrom(tKey) ? CorruptionState.None : CorruptionState.Error;
                            valueState = tValue != null && expectedValueType.IsAssignableFrom(tValue) ? CorruptionState.None : CorruptionState.Error;

                            if (keyState == CorruptionState.Error)
                            {
                                if (tKey == null)
                                {
                                    infoKey = TYPE_NOT_FOUND_INFO_MESSAGE;
                                }
                                else
                                {
                                    infoKey = string.Format(EXPECTED_TYPE_INFO_MESSAGE_F, expectedKeyType.Name, tKey.Name);
                                }
                            }

                            if (valueState == CorruptionState.Error)
                            {
                                if (tValue == null)
                                {
                                    infoValue = TYPE_NOT_FOUND_INFO_MESSAGE;
                                }
                                else
                                {
                                    infoValue = string.Format(EXPECTED_TYPE_INFO_MESSAGE_F, expectedValueType.Name, tValue.Name);
                                }
                            }
                        }
                    }

                    return(true);
                }

                return(false);
            }
Exemple #5
0
            protected Color?GetCorruptionStateColor(CorruptionState state)
            {
                switch (state)
                {
                case CorruptionState.Error:
                    return(Color.red);

                case CorruptionState.Warning:
                    return(new Color(1f, 0.65f, 0f));

                default:
                    return(null);
                }
            }
Exemple #6
0
            protected string GetCorruptionStateIcon(CorruptionState state)
            {
                switch (state)
                {
                case CorruptionState.Error:
                    return("[!]");

                case CorruptionState.Warning:
                    return("[?]");

                default:
                    return(string.Empty);
                }
            }
Exemple #7
0
            protected CorruptionState GetWorstState(params CorruptionState[] states)
            {
                CorruptionState state = CorruptionState.None;

                if (states == null || states.Length == 0)
                {
                    return(state);
                }

                for (int i = 0; i < states.Length; i++)
                {
                    if (states[i] > state)
                    {
                        state = states[i];
                    }
                }

                return(state);
            }
Exemple #8
0
            public void GetCorruptStateWithInfo(out CorruptionState state, out string info)
            {
                if (!_keyEntry.IsValid)
                {
                    state = CorruptionState.Warning;
                    info  = KEY_VALIDATION_CORRUPT_INFO_MESSAGE;
                    return;
                }

                if (_keyEntry.HasDuplicate)
                {
                    state = CorruptionState.Error;
                    info  = string.Format(KEY_HAS_DUPLICATE_F, _keyEntry.StorageKey);
                    return;
                }

                if (_valueSection.GetSafeValueType() == null || _keyEntry.GetExpectedType() == null)
                {
                    state = CorruptionState.Error;
                    info  = state == CorruptionState.None ? string.Empty : TYPE_NOT_FOUND_INFO_MESSAGE;
                    return;
                }

                if (GetDictState(out CorruptionState keyState, out string infoKey, out CorruptionState valueState, out string infoValue))
                {
                    state = GetWorstState(keyState, valueState);
                    info  = state == CorruptionState.None ? string.Empty : (infoKey.Length > infoValue.Length ? infoKey : infoValue);
                    return;
                }

                if (GetArrayState(out CorruptionState arrayState, out string arrayInfo))
                {
                    state = arrayState;
                    info  = arrayInfo;
                    return;
                }

                state = _keyEntry.IsOfExpectedType(_valueSection.GetSafeValueType()) ? CorruptionState.None : CorruptionState.Error;
                info  = state == CorruptionState.None ? string.Empty : string.Format(EXPECTED_TYPE_INFO_MESSAGE_F, _keyEntry.GetExpectedType().Name, _valueSection.GetSafeValueType().Name);
            }
Exemple #9
0
 protected void DrawTypeItemLabel(string labelValue, string typeValue, string infoText, CorruptionState curruptionState)
 {
     DrawItemLabel(string.Concat(labelValue, " << ", typeValue), infoText, curruptionState);
 }