public static List <MethodGenerationData> GenerateGetterMethods(PlayerDataEditorData data)
        {
            var methods = new List <MethodGenerationData>();

            if (!data.shouldGenerateGetter)
            {
                return(methods);
            }

            methods.Add(PlayerDataGetterMethodGenerator.GenerateGetReactivePropertyMethod(data));

            bool isVariableCollection = VariableTypeCheckerUtility.IsVariableCollection(data.baseDataType);
            bool IsVariableDictionary = VariableTypeCheckerUtility.IsVariableDictionary(data.baseDataType);
            bool isVariableNumeric    = VariableTypeCheckerUtility.IsVariableNumeric(data.baseDataType);

            if (!isVariableCollection && !IsVariableDictionary)
            {
                methods.Add(PlayerDataGetterMethodGenerator.GenerateGetValueMethod(data));
            }

            if (isVariableCollection)
            {
                methods.AddRange(PlayerDataGetterMethodGenerator.GenerateListGetterMethods(data));
            }

            if (IsVariableDictionary)
            {
                methods.AddRange(PlayerDataGetterMethodGenerator.GenerateDictionaryGetterMethods(data));
            }

            return(methods);
        }
        public static string EvaluatePlayerDataEditorKey(PlayerDataEditorData data)
        {
            if (data == null)
            {
                return(string.Empty);
            }

            data.key = GetRawPlayerDataEditorKey(data.key);

            List <string> typeStrings = new List <string>()
            {
                GetKeyPrefix(data.baseDataType),
                GetKeyPrefix(data.keyDataType),
                GetKeyPrefix(data.valueDataType)
            }.FindAll(x => !string.IsNullOrEmpty(x));

            if (typeStrings.Count == 0)
            {
                return(string.Empty);
            }

            string finalType = string.Join(PlayerDataEditorStaticData.KEY_DATA_TYPE_SEPARATOR, typeStrings);

            if (data.isLocalOnly)
            {
                finalType = string.Join(PlayerDataEditorStaticData.KEY_DATA_TYPE_SEPARATOR, finalType, PlayerDataEditorStaticData.KEY_DATA_LOCAL_PREFIX);
            }
            string finalKeyName = string.Join(PlayerDataEditorStaticData.KEY_DATA_TYPE_SEPARATOR, finalType, data.key);

            return(finalKeyName);
        }
Exemple #3
0
 public static string CreateReactivePropertyType(PlayerDataEditorData data)
 {
     return(VariableTypeCheckerUtility.IsVariableCollection(data.baseDataType)
         ? CreateReactiveCollectionPropertyType(data.valueDataType) : VariableTypeCheckerUtility.IsVariableDictionary(data.baseDataType)
         ? CreateReactiveDictionaryPropertyType(data.keyDataType, data.valueDataType)
         : CreateStandardReactivePropertyType(data.baseDataType));
 }
Exemple #4
0
 public static List <MethodGenerationData> GenerateNumericMutatorMethods(PlayerDataEditorData data)
 {
     return(new List <MethodGenerationData>
     {
         GenerateAddMethod(data),
         GenerateUseMethod(data)
     });
 }
 public static List <MethodGenerationData> GenerateDictionaryGetterMethods(PlayerDataEditorData data)
 {
     return(new List <MethodGenerationData>
     {
         GenerateGetByKeyMethod(data),
         GenerateContainsKeyMethod(data),
     });
 }
 public static List <MethodGenerationData> GenerateListGetterMethods(PlayerDataEditorData data)
 {
     return(new List <MethodGenerationData>
     {
         // GenerateFindByPredicateMethod(data),
         GenerateGetAtIndexMethod(data),
         GenerateContainsMethod(data)
     });
 }
 public static FieldGenerationData GeneratePlayerDataField(PlayerDataEditorData data)
 {
     return(new FieldGenerationData
     {
         m_VariableName = data.key.ToCamelCase(false),
         m_VariableType = ReactivePropertyEditorUtility.CreateReactivePropertyType(data),
         m_ProtectionLevel = ProtectionLevel.Public
     });
 }
Exemple #8
0
 public static List <MethodGenerationData> GenerateListMutatorMethods(PlayerDataEditorData data)
 {
     return(new List <MethodGenerationData>
     {
         GenerateAddToListMethod(data),
         GenerateAddRangeToListMethod(data),
         GenerateRemoveMethod(data),
         // GenerateRemoveWithPredicateMethod(data)
     });
 }
Exemple #9
0
 public static List <MethodGenerationData> GenerateDictionaryMutatorMethods(PlayerDataEditorData data)
 {
     return(new List <MethodGenerationData>
     {
         GenerateSetOrAddKvpMethod(data),
         GenerateAddKvpMethod(data),
         GenerateAddRangeToDictionaryMethod(data),
         GenerateRemoveKeyMethod(data)
     });
 }
 public static FieldGenerationData GeneratePlayerDataKeyField(PlayerDataEditorData data)
 {
     return(new FieldGenerationData
     {
         m_VariableName = data.key,
         m_VariableType = "string",
         m_InitializerValue = data.key,
         m_ProtectionLevel = ProtectionLevel.Public,
         m_StaticModifier = StaticFieldType.Const
     });
 }
 public static MethodGenerationData GenerateGetValueMethod(PlayerDataEditorData data)
 {
     return(new MethodGenerationData
     {
         m_MethodName = PlayerDataCodeGeneratorConstants.GETTER_GET_VALUE_METHOD_NAME + data.key.ToCamelCase(true),
         m_MethodReturnType = PlayerDataCodeGeneratorUtility.CreateValueReturnType(data),
         m_MethodBodyStatements = new List <string>
         {
             $"return {PlayerDataCodeGeneratorConstants.GETTER_GET_REACTIVE_PROPERTY_METHOD_NAME}{data.key.ToCamelCase(true)}().Value;"
         }
     });
 }
 public static MethodGenerationData GenerateGetReactivePropertyMethod(PlayerDataEditorData data)
 {
     return(new MethodGenerationData
     {
         m_MethodName = PlayerDataCodeGeneratorConstants.GETTER_GET_REACTIVE_PROPERTY_METHOD_NAME + data.key.ToCamelCase(true),
         m_MethodReturnType = ReactivePropertyEditorUtility.CreateReactivePropertyType(data),
         m_MethodBodyStatements = new List <string>
         {
             $"return {PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME}.{data.key.ToCamelCase(false)};"
         }
     });
 }
Exemple #13
0
        public static string CreateValueReturnType(PlayerDataEditorData data)
        {
            if (VariableTypeCheckerUtility.IsVariableCollection(data.baseDataType))
            {
                return($"List<{data.valueDataType}>");
            }

            if (VariableTypeCheckerUtility.IsVariableDictionary(data.baseDataType))
            {
                return($"Dictionary<{data.keyDataType}, {data.valueDataType}>");
            }

            return(data.baseDataType);
        }
        private void DrawPlayerEditorDataValueType(PlayerDataEditorData data, bool useLabel, Rect rect = default(Rect))
        {
            string labelValueDataType = (useLabel) ? "Value Data Type" : string.Empty;

            if (PlayerDataEditorStaticData.LIST_DATA_TYPE.Equals(data.baseDataType) ||
                PlayerDataEditorStaticData.DICTIONARY_DATA_TYPE.Equals(data.baseDataType))
            {
                EditorGUI.BeginChangeCheck();
                data.valueDataType = EditorUtilities.DrawStringPopup(labelValueDataType, data.valueDataType, PlayerDataEditorStaticData.valueSupportedDataType, rect);
                {
                    data.key = PlayerDataEditorUtilities.EvaluatePlayerDataEditorKey(data);
                }
            }
        }
Exemple #15
0
        public static string GetPlayerDataVariableReferenceForSaver(PlayerDataEditorData data)
        {
            if (VariableTypeCheckerUtility.IsVariableCollection(data.baseDataType))
            {
                return($"{PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME}.{data.key.ToCamelCase(false)}.ToList()");
            }

            if (VariableTypeCheckerUtility.IsVariableDictionary(data.baseDataType))
            {
                return($"{PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME}.{data.key.ToCamelCase(false)}.ToDictionary(t => t.Key, t => t.Value)");
            }

            return($"{PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME}.{data.key.ToCamelCase(false)}.Value");
        }
Exemple #16
0
 private static MethodGenerationData GenerateAddToListMethod(PlayerDataEditorData data)
 {
     return(new MethodGenerationData
     {
         m_MethodName = PlayerDataCodeGeneratorConstants.MUTATOR_COLLECTION_ADD_TO_LIST_METHOD_NAME + data.key.ToCamelCase(true),
         m_MethodReturnType = "void",
         m_MethodParams = new List <MethodParameterData>
         {
             new MethodParameterData(data.valueDataType, "value")
         },
         m_MethodBodyStatements = new List <string>
         {
             $"{PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME}.{data.key.ToCamelCase(false)}.Add(value);"
         }
     });
 }
 private static MethodGenerationData GenerateContainsMethod(PlayerDataEditorData data)
 {
     return(new MethodGenerationData
     {
         m_MethodName = PlayerDataCodeGeneratorConstants.GETTER_COLLECTION_CONTAINS_METHOD_NAME + data.key.ToCamelCase(true),
         m_MethodReturnType = "bool",
         m_MethodParams = new List <MethodParameterData>
         {
             new MethodParameterData(data.valueDataType, "value")
         },
         m_MethodBodyStatements = new List <string>
         {
             $"return {PlayerDataCodeGeneratorConstants.GETTER_GET_REACTIVE_PROPERTY_METHOD_NAME}{data.key.ToCamelCase(true)}().Contains(value);"
         }
     });
 }
Exemple #18
0
 private static MethodGenerationData GenerateRemoveMethod(PlayerDataEditorData data)
 {
     return(new MethodGenerationData
     {
         m_MethodName = "Remove_" + data.key.ToCamelCase(true),
         m_MethodReturnType = "void",
         m_MethodParams = new List <MethodParameterData>
         {
             new MethodParameterData(data.valueDataType, "value")
         },
         m_MethodBodyStatements = new List <string>
         {
             $"{PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME}.{data.key.ToCamelCase(false)}.Remove(value);"
         }
     });
 }
 // dictionary
 private static MethodGenerationData GenerateGetByKeyMethod(PlayerDataEditorData data)
 {
     return(new MethodGenerationData
     {
         m_MethodName = PlayerDataCodeGeneratorConstants.GETTER_DICTIONARY_GET_VALUE_BY_KEY_METHOD_NAME + data.key.ToCamelCase(true),
         m_MethodReturnType = data.valueDataType,
         m_MethodParams = new List <MethodParameterData>
         {
             new MethodParameterData(data.keyDataType, "key")
         },
         m_MethodBodyStatements = new List <string>
         {
             $"if (!{PlayerDataCodeGeneratorConstants.GETTER_DICTIONARY_CONTAINS_KEY_METHOD_NAME}{data.key.ToCamelCase(true)}(key))\r\nreturn default;",
             $"return {PlayerDataCodeGeneratorConstants.GETTER_GET_REACTIVE_PROPERTY_METHOD_NAME}{data.key.ToCamelCase(true)}()[key];"
         }
     });
 }
        private void DrawPlayerEditorDataKey(PlayerDataEditorData data, bool useLabel, Rect rect = default(Rect))
        {
            string labelKey = (useLabel) ? "Save Key" : string.Empty;

            if (rect == default(Rect))
            {
                data.key = EditorGUILayout.TextField(labelKey, data.key);
            }
            else
            {
                data.key = EditorGUI.TextField(rect, labelKey, data.key);
            }
            if (!string.IsNullOrEmpty(data.key))
            {
                data.key = data.key.ToUpper();
            }
        }
Exemple #21
0
 private static MethodGenerationData GenerateUseMethod(PlayerDataEditorData data)
 {
     return(new MethodGenerationData
     {
         m_MethodName = PlayerDataCodeGeneratorConstants.MUTATOR_USE_METHOD_NAME + data.key.ToCamelCase(true),
         m_MethodReturnType = "void",
         m_MethodParams = new List <MethodParameterData>
         {
             new MethodParameterData(data.baseDataType, "value")
         },
         m_MethodBodyStatements = new List <string>
         {
             $"{PlayerDataCodeGeneratorConstants.MUTATOR_SET_METHOD_NAME}{data.key.ToCamelCase(true)}" +
             $"({PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME}.{data.key.ToCamelCase(false)}.Value - value);"
         }
     });
 }
 private static MethodGenerationData GenerateGetAtIndexMethod(PlayerDataEditorData data)
 {
     return(new MethodGenerationData
     {
         m_MethodName = PlayerDataCodeGeneratorConstants.GETTER_COLLECTION_GET_VALUE_AT_INDEX_METHOD_NAME + data.key.ToCamelCase(true),
         m_MethodReturnType = data.valueDataType,
         m_MethodParams = new List <MethodParameterData>
         {
             new MethodParameterData("int", "index")
         },
         m_MethodBodyStatements = new List <string>
         {
             $"if ({PlayerDataCodeGeneratorConstants.GETTER_GET_REACTIVE_PROPERTY_METHOD_NAME}{data.key.ToCamelCase(true)}().Count >= index || index < 0)\n\rreturn default;",
             $"return {PlayerDataCodeGeneratorConstants.GETTER_GET_REACTIVE_PROPERTY_METHOD_NAME}{data.key.ToCamelCase(true)}()[index];"
         }
     });
 }
Exemple #23
0
        private static MethodGenerationData GenerateAddRangeToListMethod(PlayerDataEditorData data)
        {
            return(new MethodGenerationData
            {
                m_MethodName = "AddRange_" + data.key.ToCamelCase(true),
                m_MethodReturnType = "void",
                m_MethodParams = new List <MethodParameterData>
                {
                    new MethodParameterData(PlayerDataCodeGeneratorUtility.CreateValueReturnType(data), "values")
                },

                m_MethodBodyStatements = new List <string>
                {
                    $"foreach (var value in values)\n\r{PlayerDataCodeGeneratorConstants.MUTATOR_COLLECTION_ADD_TO_LIST_METHOD_NAME}{data.key.ToCamelCase(true)}(value);",
                }
            });
        }
Exemple #24
0
        private static MethodGenerationData GenerateAddRangeToDictionaryMethod(PlayerDataEditorData data)
        {
            return(new MethodGenerationData
            {
                m_MethodName = "AddRange_" + data.key.ToCamelCase(true),
                m_MethodReturnType = "void",
                m_MethodParams = new List <MethodParameterData>
                {
                    new MethodParameterData(PlayerDataCodeGeneratorUtility.CreateValueReturnType(data), "dictionary")
                },

                m_MethodBodyStatements = new List <string>
                {
                    "foreach (var kvp in dictionary)",
                    $"\n\r{PlayerDataCodeGeneratorConstants.MUTATOR_DICTIONARY_ADD_KVP_METHOD_NAME + data.key.ToCamelCase(true)}(kvp.Key, kvp.Value);"
                }
            });
        }
Exemple #25
0
 private static MethodGenerationData GenerateDictionaryNumericUseMethod(PlayerDataEditorData data)
 {
     return(new MethodGenerationData
     {
         m_MethodName = PlayerDataCodeGeneratorConstants.MUTATOR_USE_DICTIONARY_VALUE_METHOD_NAME + data.key.ToCamelCase(true),
         m_MethodReturnType = "void",
         m_MethodParams = new List <MethodParameterData>
         {
             new MethodParameterData(data.keyDataType, "key"),
             new MethodParameterData(data.valueDataType, "value")
         },
         m_MethodBodyStatements = new List <string>
         {
             string.Format("{0}{1}(key, 0);", PlayerDataCodeGeneratorConstants.MUTATOR_DICTIONARY_ADD_KVP_METHOD_NAME, data.key.ToCamelCase(true)),
             string.Format("{0}.{1}[key] -= value;", PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME, data.key.ToCamelCase(false))
         }
     });
 }
Exemple #26
0
        private static MethodGenerationData GenerateRemoveKeyMethod(PlayerDataEditorData data)
        {
            return(new MethodGenerationData
            {
                m_MethodName = "RemoveKey_" + data.key.ToCamelCase(true),
                m_MethodReturnType = "void",
                m_MethodParams = new List <MethodParameterData>
                {
                    new MethodParameterData(data.keyDataType, "key")
                },

                m_MethodBodyStatements = new List <string>
                {
                    $"var dictionary = {PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME}.{data.key.ToCamelCase(false)};",
                    "if (!dictionary.ContainsKey(key))\n\rreturn;",
                    "dictionary.Remove(key);"
                }
            });
        }
Exemple #27
0
 // dictionary only
 private static MethodGenerationData GenerateAddKvpMethod(PlayerDataEditorData data)
 {
     return(new MethodGenerationData
     {
         m_MethodName = PlayerDataCodeGeneratorConstants.MUTATOR_DICTIONARY_ADD_KVP_METHOD_NAME + data.key.ToCamelCase(true),
         m_MethodReturnType = "void",
         m_MethodParams = new List <MethodParameterData>
         {
             new MethodParameterData(data.keyDataType, "key"),
             new MethodParameterData(data.valueDataType, "value")
         },
         m_MethodBodyStatements = new List <string>
         {
             $"var dictionary = {PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME}.{data.key.ToCamelCase(false)};",
             "if (dictionary.ContainsKey(key))\n\rreturn;",
             $"{PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME}.{data.key.ToCamelCase(false)}.Add(key, value);"
         }
     });
 }
        private void DrawPlayerEditorData(PlayerDataEditorData data, bool useLabel)
        {
            if (data == null)
            {
                data = new PlayerDataEditorData();
            }

            DrawPlayerEditorDataKey(data, useLabel);
            DrawPlayerEditorDataBaseType(data, useLabel);

            EditorGUI.indentLevel++;
            DrawPlayerEditorDataKeyType(data, useLabel);
            DrawPlayerEditorDataValueType(data, useLabel);
            EditorGUI.indentLevel--;

            DrawPlayerEditorIsLocalOnly(data, useLabel, EditorStyles.toggle);
            DrawPlayerEditorShouldGenerateGetter(data, useLabel, EditorStyles.toggle);
            DrawPlayerEditorShouldGenerateMutator(data, useLabel, EditorStyles.toggle);
            DrawPlayerEditorShouldGenerateSubscribe(data, useLabel, EditorStyles.toggle);
        }
Exemple #29
0
 public static MethodGenerationData GenerateSetMethod(PlayerDataEditorData data)
 {
     return(new MethodGenerationData
     {
         m_MethodName = PlayerDataCodeGeneratorConstants.MUTATOR_SET_METHOD_NAME + data.key.ToCamelCase(true),
         m_MethodReturnType = "void",
         m_MethodParams = new List <MethodParameterData>
         {
             new MethodParameterData(PlayerDataCodeGeneratorUtility.CreateValueReturnType(data), "value")
         },
         m_MethodBodyStatements = new List <string>
         {
             VariableTypeCheckerUtility.IsVariableCollection(data.baseDataType)
             ? $"{PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME}.{data.key.ToCamelCase(false)} = value.ToReactiveCollection();"
             : VariableTypeCheckerUtility.IsVariableDictionary(data.baseDataType)
             ? $"{PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME}.{data.key.ToCamelCase(false)} = value.ToReactiveDictionary();"
             : $"{PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME}.{data.key.ToCamelCase(false)}.Value = value;"
         }
     });
 }
        // for lists only
        private static MethodGenerationData GenerateFindByPredicateMethod(PlayerDataEditorData data)
        {
            // List<string> test = new List<string>();
            // System.Predicate<string> predicate = x => x.Equals("test");
            // test.FindAll(predicate);

            return(new MethodGenerationData
            {
                m_MethodName = PlayerDataCodeGeneratorConstants.GETTER_COLLECTION_GET_VALUES_BY_PREDICATE_METHOD_NAME + data.key.ToCamelCase(true),
                m_MethodReturnType = PlayerDataCodeGeneratorUtility.CreateValueReturnType(data),
                m_MethodParams = new List <MethodParameterData>
                {
                    new MethodParameterData($"Predicate<{data.valueDataType}>", "predicate")
                },
                m_MethodBodyStatements = new List <string>
                {
                    $"return {PlayerDataCodeGeneratorConstants.GETTER_GET_REACTIVE_PROPERTY_METHOD_NAME}{data.key.ToCamelCase(true)}().FindAll(predicate);"
                }
            });
        }