Пример #1
0
        public static List <MethodGenerationData> GenerateSaverMethods(List <PlayerDataEditorData> datas, string category)
        {
            var           methods       = new List <MethodGenerationData>();
            List <string> bodyStatement = new List <string>();

            // Example: _playerDataManager.TrySave<int>(PlayerDataKeys.INT_TEST_INT, _playerData.matchThreeLevel.Value);
            for (int i = 0, count = datas.Count; i < count; i++)
            {
                methods.Add(new MethodGenerationData
                {
                    m_MethodName           = PlayerDataCodeGeneratorConstants.SAVER_METHOD_NAME + datas[i].key.ToCamelCase(true),
                    m_MethodReturnType     = "void",
                    m_MethodBodyStatements = new List <string>
                    {
                        string.Format("{0}.TrySave<{1}>({2}.{3}, {4});",
                                      PlayerDataCodeGeneratorConstants.PLAYER_DATA_MANAGER_REFERENCE_NAME,
                                      PlayerDataCodeGeneratorUtility.CreateValueReturnType(datas[i]),
                                      PlayerDataCodeGeneratorConstants.PLAYER_DATA_KEYS_CLASS_NAME,
                                      datas[i].key,
                                      PlayerDataCodeGeneratorUtility.GetPlayerDataVariableReferenceForSaver(datas[i]))
                    }
                });
            }

            return(methods);
        }
 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;"
         }
     });
 }
Пример #3
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);",
                }
            });
        }
Пример #4
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);"
                }
            });
        }
Пример #5
0
        public static MethodGenerationData GenerateLoadMethod(List <PlayerDataEditorData> datas, string category)
        {
            List <string> bodyStatement = new List <string>();

            for (int i = 0; i < datas.Count; i++)
            {
                bool usesReactiveProperty = PlayerDataCodeGeneratorUtility.UsesReactiveProperty(datas[i].baseDataType);
                // Example: _playerData.Set_TestInt(_playerDataManager.TryLoad<int>(PlayerDataKeys.INT_TEST_INT))
                string defaultValue         = "default";
                bool   isVariableCollection = VariableTypeCheckerUtility.IsVariableCollection(datas[i].baseDataType);
                bool   IsVariableDictionary = VariableTypeCheckerUtility.IsVariableDictionary(datas[i].baseDataType);

                string baseFormat = "{0}.{1} = {2}.TryLoad<{3}>({4}.{5}, {6}, {7});";
                string loadType   = datas[i].baseDataType;

                if (isVariableCollection)
                {
                    defaultValue = $"new {datas[i].baseDataType}<{datas[i].valueDataType}>()";
                    baseFormat   = "{0}.{1} = new " + ReactivePropertyEditorUtility.CreateReactivePropertyType(datas[i]) + "({2}.TryLoad<{3}>({4}.{5}, {6}, {7}));";
                    loadType     = $"{datas[i].baseDataType}<{datas[i].valueDataType}>";
                }
                else if (IsVariableDictionary)
                {
                    defaultValue = $"new {datas[i].baseDataType}<{datas[i].keyDataType}, {datas[i].valueDataType}>()";
                    baseFormat   = "{0}.{1} = new " + ReactivePropertyEditorUtility.CreateReactivePropertyType(datas[i]) + "({2}.TryLoad<{3}>({4}.{5}, {6}, {7}));";
                    loadType     = $"{datas[i].baseDataType}<{datas[i].keyDataType},{datas[i].valueDataType}>";
                }

                bodyStatement.Add(string.Format(baseFormat,
                                                PlayerDataCodeGeneratorConstants.PLAYER_DATA_REFERENCE_NAME,
                                                usesReactiveProperty ? datas[i].key.ToCamelCase(false) : datas[i].key.ToCamelCase(false) + ".Value",
                                                PlayerDataCodeGeneratorConstants.PLAYER_DATA_MANAGER_REFERENCE_NAME,
                                                loadType,
                                                PlayerDataCodeGeneratorConstants.PLAYER_DATA_KEYS_CLASS_NAME,
                                                datas[i].key, defaultValue, datas[i].isLocalOnly.ToString().ToLower()));
            }

            return(new MethodGenerationData
            {
                m_MethodName = PlayerDataCodeGeneratorConstants.LOADER_METHOD_NAME + category,
                m_MethodReturnType = "void",
                m_MethodBodyStatements = bodyStatement
            });
        }
        // 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);"
                }
            });
        }
Пример #7
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;"
         }
     });
 }
Пример #8
0
        public static MethodGenerationData GeneratePlayerDataKeyValueGetterMethod(List <PlayerDataEditorData> datas, string category)
        {
            List <string> statements = new List <string>();

            foreach (var data in datas)
            {
                bool useReactiveProperty = PlayerDataCodeGeneratorUtility.UsesReactiveProperty(data.baseDataType);
                // dictionary[PlayerDataKeys.INT_TEST_INT] = () => _playerDataGetter.GetValue_TestInt();
                statements.Add(string.Format("getterMap[{0}.{1}] = () => {2}.{3}{4}();",
                                             PlayerDataCodeGeneratorConstants.PLAYER_DATA_KEYS_CLASS_NAME,
                                             data.key,
                                             PlayerDataCodeGeneratorConstants.PLAYER_DATA_GETTER_REFERENCE_NAME,
                                             useReactiveProperty ? PlayerDataCodeGeneratorConstants.GETTER_GET_REACTIVE_PROPERTY_METHOD_NAME : PlayerDataCodeGeneratorConstants.GETTER_GET_VALUE_METHOD_NAME,
                                             data.key.ToCamelCase(true)));
            }

            return(new MethodGenerationData
            {
                m_MethodName = PlayerDataCodeGeneratorConstants.KEY_VALUE_GETTER_MAP_METHOD_NAME + category,
                m_MethodReturnType = "void",
                m_MethodBodyStatements = statements,
                m_ProtectionLevel = ProtectionLevel.Private
            });
        }