static void AppendSaveToDictMethod(StringBuilder sb, string schemaKey, Dictionary <string, object> schemaData) { sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel2)); sb.AppendFormat(GDECodeGenConstants.SaveToDictMethod, schemaKey); sb.Append("\n"); bool shouldAppendSpace = false; bool didAppendSpaceForSection = false; bool isFirstSection = true; // Append the basic types for (int dimension = 0; dimension <= 2; dimension++) { foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes) { List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, fieldType.ToString(), dimension); foreach (string fieldKey in fieldKeys) { if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection) { sb.Append("\n"); } AppendSaveToDictVariable(sb, fieldKey); shouldAppendSpace = true; didAppendSpaceForSection = true; isFirstSection = false; } } didAppendSpaceForSection = false; } // Append the custom lists for (int dimension = 0; dimension <= 2; dimension++) { foreach (string fieldKey in GDEItemManager.SchemaCustomFieldKeys(schemaKey, dimension)) { if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection) { sb.Append("\n"); } AppendSaveToDictVariable(sb, fieldKey); shouldAppendSpace = true; isFirstSection = false; didAppendSpaceForSection = true; } } sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3)); sb.Append(GDECodeGenConstants.SaveToDictEnd); sb.Append("\n"); }
static void AppendResetVariableMethods(StringBuilder sb, string schemaKey, Dictionary <string, object> schemaData) { bool shouldAppendSpace = false; bool didAppendSpaceForSection = false; bool isFirstSection = true; string variableType; // Append all the single variables first foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes) { variableType = fieldType.ToString(); List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, fieldType.ToString(), 0); foreach (string fieldKey in fieldKeys) { if (shouldAppendSpace) { sb.Append("\n"); } AppendResetVariableMethod(sb, fieldKey, variableType); shouldAppendSpace = true; isFirstSection = false; } } // Append all list variables for (int dimension = 1; dimension <= 2; dimension++) { foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes) { variableType = fieldType.ToString(); List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, variableType, dimension); foreach (string fieldKey in fieldKeys) { if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection) { sb.Append("\n"); } AppendResetListVariableMethod(sb, fieldKey, variableType, dimension); shouldAppendSpace = true; didAppendSpaceForSection = true; isFirstSection = false; } } didAppendSpaceForSection = false; } // Append all custom variables for (int dimension = 0; dimension <= 2; dimension++) { List <string> fieldKeys = GDEItemManager.SchemaCustomFieldKeys(schemaKey, dimension); foreach (string fieldKey in fieldKeys) { if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection) { sb.Append("\n"); } schemaData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out variableType); variableType = string.Format(GDECodeGenConstants.DataClassNameFormat, variableType); AppendResetCustomVariableMethod(sb, fieldKey, variableType, dimension); shouldAppendSpace = true; didAppendSpaceForSection = true; isFirstSection = false; } didAppendSpaceForSection = false; } }
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"); }
static void AppendLoadFromSavedMethod(StringBuilder sb, string schemaKey, Dictionary <string, object> schemaData) { sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel2)); sb.Append(GDECodeGenConstants.LoadFromSavedMethod); sb.Append("\n"); bool shouldAppendSpace = false; bool didAppendSpaceForSection = false; bool isFirstSection = true; string variableType; // Append all the single variables first foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes) { variableType = fieldType.ToString(); List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, fieldType.ToString(), 0); foreach (string fieldKey in fieldKeys) { AppendLoadFromSavedVariable(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 = "Custom"; AppendLoadFromSavedCustomVariable(sb, variableType, fieldKey); shouldAppendSpace = true; didAppendSpaceForSection = true; isFirstSection = false; } 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 = fieldType.ToString(); foreach (string fieldKey in fieldKeys) { if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection) { sb.Append("\n"); } AppendLoadSavedListVariable(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 = "Custom"; AppendLoadSavedListVariable(sb, variableType, fieldKey, dimension); shouldAppendSpace = true; isFirstSection = false; didAppendSpaceForSection = true; } } sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel2)); sb.Append(GDECodeGenConstants.LoadFromSavedMethodEnd); sb.Append("\n"); }
static void AppendLoadDictMethod(StringBuilder sb, string schemaKey, Dictionary <string, object> schemaData) { sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel2)); sb.Append(GDECodeGenConstants.LoadDictMethod); sb.Append("\n"); bool shouldAppendSpace = false; bool didAppendSpaceForSection = false; bool isFirstSection = true; string variableType; // Append all the single variables first foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes) { variableType = fieldType.ToString(); List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, fieldType.ToString()); foreach (string fieldKey in fieldKeys) { AppendLoadVariable(sb, variableType, fieldKey); shouldAppendSpace = true; isFirstSection = false; } } // Append the custom types bool appendTempKeyDeclaration = true; foreach (string fieldKey in GDEItemManager.SchemaCustomFieldKeys(schemaKey)) { if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection) { sb.Append("\n"); } schemaData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out variableType); variableType = string.Format(GDECodeGenConstants.DataClassNameFormat, variableType); if (appendTempKeyDeclaration) { sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel4)); sb.Append(GDECodeGenConstants.TempStringKeyDeclaration); sb.Append("\n"); appendTempKeyDeclaration = false; } AppendLoadCustomVariable(sb, variableType, fieldKey); shouldAppendSpace = true; didAppendSpaceForSection = true; isFirstSection = false; } didAppendSpaceForSection = false; // Append the basic lists foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes) { List <string> fieldKeys = GDEItemManager.SchemaListFieldKeysOfType(schemaKey, fieldType.ToString()); variableType = fieldType.ToString(); foreach (string fieldKey in fieldKeys) { if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection) { sb.Append("\n"); } AppendLoadListVariable(sb, variableType, fieldKey); shouldAppendSpace = true; didAppendSpaceForSection = true; isFirstSection = false; } } didAppendSpaceForSection = false; // Append the custom lists foreach (string fieldKey in GDEItemManager.SchemaCustomListFields(schemaKey)) { if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection) { sb.Append("\n"); } schemaData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out variableType); variableType = "Custom"; AppendLoadListVariable(sb, variableType, fieldKey); shouldAppendSpace = true; isFirstSection = false; didAppendSpaceForSection = true; } sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3)); sb.Append(GDECodeGenConstants.LoadDictMethodEnd); sb.Append("\n"); }
protected override void DrawEntry(string schemaKey, Dictionary <string, object> schemaData) { float beginningHeight = CurrentHeight(); // Start drawing below if (DrawFoldout(GDEConstants.SchemaLbl + " ", schemaKey, schemaKey, schemaKey, RenameSchema)) { bool shouldDrawSpace = false; bool didDrawSpaceForSection = false; // Draw the basic types foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes) { List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, fieldType.ToString()); foreach (string fieldKey in fieldKeys) { currentLinePosition += GDEConstants.Indent; DrawSingleField(schemaKey, fieldKey, schemaData); shouldDrawSpace = true; } } // Draw the custom types foreach (string fieldKey in GDEItemManager.SchemaCustomFieldKeys(schemaKey)) { if (shouldDrawSpace && !didDrawSpaceForSection) { NewLine(0.5f); didDrawSpaceForSection = true; } currentLinePosition += GDEConstants.Indent; DrawSingleField(schemaKey, fieldKey, schemaData); shouldDrawSpace = true; } didDrawSpaceForSection = false; // Draw the lists foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes) { List <string> fieldKeys = GDEItemManager.SchemaListFieldKeysOfType(schemaKey, fieldType.ToString()); foreach (string fieldKey in fieldKeys) { if (shouldDrawSpace && !didDrawSpaceForSection) { NewLine(0.5f); didDrawSpaceForSection = true; } currentLinePosition += GDEConstants.Indent; DrawListField(schemaKey, schemaData, fieldKey); shouldDrawSpace = true; } } didDrawSpaceForSection = false; // Draw the custom lists foreach (string fieldKey in GDEItemManager.SchemaCustomListFields(schemaKey)) { if (shouldDrawSpace && !didDrawSpaceForSection) { NewLine(0.5f); didDrawSpaceForSection = true; } currentLinePosition += GDEConstants.Indent; DrawListField(schemaKey, schemaData, fieldKey); shouldDrawSpace = true; } // Remove any fields that were deleted above foreach (string deletedKey in deletedFields) { RemoveField(schemaKey, schemaData, deletedKey); } deletedFields.Clear(); // Rename any fields that were renamed string error; string oldFieldKey; string newFieldKey; foreach (KeyValuePair <List <string>, Dictionary <string, object> > pair in renamedFields) { oldFieldKey = pair.Key[0]; newFieldKey = pair.Key[1]; if (!GDEItemManager.RenameSchemaField(oldFieldKey, newFieldKey, schemaKey, pair.Value, out error)) { EditorUtility.DisplayDialog(GDEConstants.ErrorLbl, string.Format("Couldn't rename {0} to {1}: {2}", oldFieldKey, newFieldKey, error), GDEConstants.OkLbl); } } renamedFields.Clear(); NewLine(); DrawAddFieldSection(schemaKey, schemaData); NewLine(2f); GUIContent content = new GUIContent(GDEConstants.DeleteBtn); float width = GUI.skin.button.CalcSize(content).x; if (GUI.Button(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), content)) { deletedSchemas.Add(schemaKey); } NewLine(); DrawSectionSeparator(); NewLine(0.25f); } float groupHeight = CurrentHeight() - beginningHeight; SetGroupHeight(schemaKey, groupHeight); }