Exemple #1
0
        static void AppendShallowCloneMethod(StringBuilder sb, string schemaKey, Dictionary <string, object> schemaData)
        {
            sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel2));
            sb.AppendFormat(GDECodeGenConstants.ShallowCloneMethodStart, schemaKey);
            sb.Append("\n\n");

            bool shouldAppendSpace        = false;
            bool didAppendSpaceForSection = false;
            bool isFirstSection           = true;
            bool didGetDict       = false;
            bool isUnityType      = false;
            bool didBasePathVar   = false;
            bool didListPathVar   = false;
            bool did2dListPathVar = false;

            // Base Types
            foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes)
            {
                List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, fieldType.ToString(), 0);
                foreach (string fieldKey in fieldKeys)
                {
                    isUnityType = GDEItemManager.IsUnityType(fieldType);
                    if (isUnityType)
                    {
                        if (!didGetDict)
                        {
                            sb.Append("\n");
                            sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                            sb.Append(GDECodeGenConstants.GetDict);
                            sb.Append("\n\n");
                            didGetDict = true;
                        }
                        else
                        {
                            sb.Append("\n");
                        }

                        if (!didBasePathVar)
                        {
                            sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                            sb.Append(GDECodeGenConstants.BasePathVar);
                            sb.Append("\n");
                            didBasePathVar = true;
                        }

                        sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                        sb.AppendFormat(GDECodeGenConstants.SaveGOPathFormat, fieldKey);
                        sb.Append("\n");
                    }

                    sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                    sb.AppendFormat(GDECodeGenConstants.BaseTypeCloneFormat, fieldKey);
                    sb.Append("\n");

                    shouldAppendSpace = true;
                    isFirstSection    = false;
                }
            }
            didAppendSpaceForSection = false;

            // Custom Types
            foreach (string fieldKey in GDEItemManager.SchemaCustomFieldKeys(schemaKey, 0))
            {
                if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection)
                {
                    sb.Append("\n");
                }

                sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                sb.AppendFormat(GDECodeGenConstants.CustomTypeShallowFormat, fieldKey);
                sb.Append("\n");

                shouldAppendSpace        = true;
                didAppendSpaceForSection = true;
                isFirstSection           = false;
            }
            didAppendSpaceForSection = false;

            // Basic List Types
            string variableType;

            foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes)
            {
                List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, fieldType.ToString(), 1);
                foreach (string fieldKey in fieldKeys)
                {
                    if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection)
                    {
                        sb.Append("\n");
                    }

                    isUnityType = GDEItemManager.IsUnityType(fieldType);
                    if (isUnityType)
                    {
                        if (!didGetDict)
                        {
                            sb.Append("\n");
                            sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                            sb.Append(GDECodeGenConstants.GetDict);
                            sb.Append("\n\n");
                            didGetDict = true;
                        }
                        else
                        {
                            sb.Append("\n");
                        }

                        if (!didListPathVar)
                        {
                            sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                            sb.Append(GDECodeGenConstants.ListPathVar);
                            sb.Append("\n");
                            didListPathVar = true;
                        }

                        sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                        sb.AppendFormat(GDECodeGenConstants.SaveGOListPathFormat, fieldKey);
                        sb.Append("\n");
                    }

                    variableType = GDEItemManager.GetVariableTypeFor(fieldType);

                    sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                    sb.AppendFormat(GDECodeGenConstants.ListTypeCloneFormat, fieldKey, variableType);
                    sb.Append("\n");

                    shouldAppendSpace        = true;
                    didAppendSpaceForSection = true;
                    isFirstSection           = false;
                }
            }
            didAppendSpaceForSection = false;

            // Custom List Types
            foreach (string fieldKey in GDEItemManager.SchemaCustomFieldKeys(schemaKey, 1))
            {
                if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection)
                {
                    sb.Append("\n");
                }

                schemaData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out variableType);

                sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                sb.AppendFormat(GDECodeGenConstants.ListTypeCloneFormat, fieldKey, "GDE" + variableType + "Data");
                sb.Append("\n");

                shouldAppendSpace        = true;
                didAppendSpaceForSection = true;
                isFirstSection           = false;
            }
            didAppendSpaceForSection = false;

            // Basic 2D List Types
            foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes)
            {
                List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, fieldType.ToString(), 2);
                foreach (string fieldKey in fieldKeys)
                {
                    if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection)
                    {
                        sb.Append("\n");
                    }

                    isUnityType = GDEItemManager.IsUnityType(fieldType);
                    if (isUnityType)
                    {
                        if (!didGetDict)
                        {
                            sb.Append("\n");
                            sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                            sb.Append(GDECodeGenConstants.GetDict);
                            sb.Append("\n\n");
                            didGetDict = true;
                        }
                        else
                        {
                            sb.Append("\n");
                        }

                        if (!did2dListPathVar)
                        {
                            sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                            sb.Append(GDECodeGenConstants.TwoDListPathVar);
                            sb.Append("\n");
                            did2dListPathVar = true;
                        }

                        sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                        sb.AppendFormat(GDECodeGenConstants.SaveGO2DListPathFormat, fieldKey);
                        sb.Append("\n");
                    }

                    variableType = GDEItemManager.GetVariableTypeFor(fieldType);

                    sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                    sb.AppendFormat(GDECodeGenConstants.TwoDListTypeCloneFormat, fieldKey, variableType);
                    sb.Append("\n");

                    shouldAppendSpace        = true;
                    didAppendSpaceForSection = true;
                    isFirstSection           = false;
                }
            }
            didAppendSpaceForSection = false;

            // Custom 2D List Types
            foreach (string fieldKey in GDEItemManager.SchemaCustomFieldKeys(schemaKey, 2))
            {
                if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection)
                {
                    sb.Append("\n");
                }

                schemaData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out variableType);

                sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
                sb.AppendFormat(GDECodeGenConstants.TwoDListTypeCloneFormat, fieldKey, "GDE" + variableType + "Data");
                sb.Append("\n");

                shouldAppendSpace        = true;
                didAppendSpaceForSection = true;
                isFirstSection           = false;
            }

            sb.Append("\n");
            sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));
            sb.Append(GDECodeGenConstants.CloneMethodEnd);
            sb.Append("\n");
        }
Exemple #2
0
        static void AppendVariableDeclarations(StringBuilder sb, string schemaKey, Dictionary <string, object> schemaData)
        {
            bool didAppendSpaceForSection = false;
            bool shouldAppendSpace        = false;
            bool isFirstSection           = true;

            string variableType;

            // Append all the single variables first
            foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes)
            {
                variableType = GDEItemManager.GetVariableTypeFor(fieldType);

                List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, fieldType.ToString(), 0);
                foreach (string fieldKey in fieldKeys)
                {
                    if (shouldAppendSpace)
                    {
                        sb.Append("\n");
                    }

                    AppendVariable(sb, variableType, fieldKey);
                    shouldAppendSpace = true;
                    isFirstSection    = false;
                }
            }

            // Append the custom types
            foreach (string fieldKey in GDEItemManager.SchemaCustomFieldKeys(schemaKey, 0))
            {
                if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection)
                {
                    sb.Append("\n");
                }

                schemaData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out variableType);
                variableType = string.Format(GDECodeGenConstants.DataClassNameFormat, variableType);
                AppendCustomVariable(sb, variableType, fieldKey);

                shouldAppendSpace        = true;
                isFirstSection           = false;
                didAppendSpaceForSection = true;
            }
            didAppendSpaceForSection = false;

            // Append the basic lists
            for (int dimension = 1; dimension <= 2; dimension++)
            {
                foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes)
                {
                    List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, fieldType.ToString(), dimension);
                    variableType = GDEItemManager.GetVariableTypeFor(fieldType);

                    foreach (string fieldKey in fieldKeys)
                    {
                        if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection)
                        {
                            sb.Append("\n");
                        }

                        AppendListVariable(sb, variableType, fieldKey, dimension);

                        shouldAppendSpace        = true;
                        didAppendSpaceForSection = true;
                        isFirstSection           = false;
                    }
                }
                didAppendSpaceForSection = false;
            }

            // Append the custom lists
            for (int dimension = 1; dimension <= 2; dimension++)
            {
                foreach (string fieldKey in GDEItemManager.SchemaCustomFieldKeys(schemaKey, dimension))
                {
                    if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection)
                    {
                        sb.Append("\n");
                    }

                    schemaData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out variableType);
                    variableType = string.Format(GDECodeGenConstants.DataClassNameFormat, variableType);
                    AppendCustomListVariable(sb, variableType, fieldKey, dimension);

                    shouldAppendSpace        = true;
                    isFirstSection           = false;
                    didAppendSpaceForSection = true;
                }
            }
        }