Exemplo n.º 1
0
        static void AppendListVariable(StringBuilder sb, string type, string name, int dimension)
        {
            string formattedType = type;

            if (GDEItemManager.IsUnityType(type))
            {
                formattedType = "UnityObject";
            }
            else
            {
                formattedType = type.UppercaseFirst();
            }

            sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel2));

            if (dimension == 1)
            {
                sb.AppendFormat(GDECodeGenConstants.OneDListVariableFormat, type, name, formattedType);
            }
            else
            {
                sb.AppendFormat(GDECodeGenConstants.TwoDListVariableFormat, type, name, formattedType + GDECodeGenConstants.TwoDListSuffix);
            }

            sb.Append("\n");
        }
Exemplo n.º 2
0
        string Convert2DListToSheetFormat(BasicFieldType type, object value)
        {
            string result = string.Empty;

            if (GDEItemManager.IsUnityType(type))
            {
                var   pathList = new List <List <string> >();
                IList goList   = value as IList;
                foreach (var sublist in goList)
                {
                    IList list        = sublist as IList;
                    var   pathSubList = new List <string>();
                    foreach (var go in list)
                    {
                        pathSubList.Add(GDEItemManager.GetJsonRepresentation(go as UnityEngine.Object));
                    }
                    pathList.Add(pathSubList);
                }

                // Now convert the path 2d list to json
                result = Json.Serialize(pathList);
            }
            else
            {
                result = Json.Serialize(value);
            }

            return(result);
        }
Exemplo n.º 3
0
        static void AppendVariable(StringBuilder sb, string type, string name)
        {
            string formattedType = type;

            if (GDEItemManager.IsUnityType(type))
            {
                formattedType = "UnityObject";
            }
            else
            {
                formattedType = type.UppercaseFirst();
            }

            sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel2));
            sb.AppendFormat(GDECodeGenConstants.VariableFormat, type, name, formattedType);
            sb.Append("\n");
        }
Exemplo n.º 4
0
        static void AppendLoadSavedListVariable(StringBuilder sb, string type, string name, int dimension)
        {
            string formattedType = type;

            if (GDEItemManager.IsUnityType(type))
            {
                formattedType = "UnityObject";
            }

            sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3));

            if (dimension == 1)
            {
                sb.AppendFormat(GDECodeGenConstants.LoadSavedVariableListFormat, formattedType, name);
            }
            else
            {
                sb.AppendFormat(GDECodeGenConstants.LoadSavedVariableListFormat, formattedType + GDECodeGenConstants.TwoDListSuffix, name);
            }

            sb.Append("\n");
        }
Exemplo n.º 5
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");
        }
Exemplo n.º 6
0
        void CreateItems(string schemaName, List <FieldInfo> fields, ExcelRange sheetCells)
        {
            Dictionary <string, object> schemaData = null;

            GDEItemManager.AllSchemas.TryGetValue(schemaName, out schemaData);

            // If schema failed to parse (schema data is null), we can't parse any items
            if (schemaData == null)
            {
                return;
            }

            string itemName;
            string error;
            Dictionary <string, object> itemData;

            var itemKeysColumn = (from cell in sheetCells["a:a"]
                                  where cell != null &&
                                  !string.IsNullOrEmpty(cell.Text) &&
                                  !cell.Text.Trim().ToLower().Equals(GDEExcelDataHelper.IgnoreToken) &&
                                  !cell.Text.Trim().ToLower().Equals(GDEExcelDataHelper.FieldNameToken) &&
                                  !cell.Text.Trim().ToLower().Equals(GDEExcelDataHelper.FieldTypeToken)
                                  select cell);

            // Add to the total item count
            totalItems += itemKeysColumn.Count();

            foreach (var keyCell in itemKeysColumn)
            {
                itemName = keyCell.Text.Trim();
                itemData = schemaData.DeepCopy();
                itemData.Add(GDMConstants.SchemaKey, schemaName);

                for (int x = 0; x < fields.Count; x++)
                {
                    try
                    {
                        string        cellText = sheetCells[fields[x].cellCol + keyCell.End.Row].Text;
                        List <object> matches;
                        if (fields[x].skip)
                        {
                            continue;
                        }
                        else if (fields[x].isList)
                        {
                            if (fields[x].type.Equals(BasicFieldType.String) ||
                                fields[x].type.Equals(BasicFieldType.Vector2) ||
                                fields[x].type.Equals(BasicFieldType.Vector3) ||
                                fields[x].type.Equals(BasicFieldType.Vector4) ||
                                fields[x].type.Equals(BasicFieldType.Color) ||
                                GDEItemManager.IsUnityType(fields[x].type) ||
                                fields[x].isCustom)
                            {
                                matches = GDEParser.Parse(cellText);
                            }
                            else
                            {
                                matches = new List <object>(cellText.Split(','));
                            }

                            itemData[fields[x].name] = ConvertListValueToType(fields[x].type, matches);
                        }
                        else if (fields[x].is2DList)
                        {
                            if (fields[x].type.Equals(BasicFieldType.GameObject))
                            {
                                itemData[fields[x].name] = LoadUnityType2DList <GameObject>(cellText);
                            }
                            else if (fields[x].type.Equals(BasicFieldType.Texture2D))
                            {
                                itemData[fields[x].name] = LoadUnityType2DList <Texture2D>(cellText);
                            }
                            else if (fields[x].type.Equals(BasicFieldType.Material))
                            {
                                itemData[fields[x].name] = LoadUnityType2DList <Material>(cellText);
                            }
                            else if (fields[x].type.Equals(BasicFieldType.AudioClip))
                            {
                                itemData[fields[x].name] = LoadUnityType2DList <AudioClip>(cellText);
                            }
                            else
                            {
                                itemData[fields[x].name] = Json.Deserialize(cellText);
                            }
                        }
                        else
                        {
                            if (fields[x].type.Equals(BasicFieldType.Vector2) ||
                                fields[x].type.Equals(BasicFieldType.Vector3) ||
                                fields[x].type.Equals(BasicFieldType.Vector4) ||
                                fields[x].type.Equals(BasicFieldType.Color))
                            {
                                matches = new List <object>(cellText.Split(','));
                                matches.ForEach(obj => obj = obj.ToString().Trim());
                                itemData[fields[x].name]   = ConvertValueToType(fields[x].type, matches);
                            }
                            else
                            {
                                itemData[fields[x].name] = ConvertValueToType(fields[x].type, cellText);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError(ex);
                        Debug.LogError(string.Format(GDEConstants.ErrorParsingCellFormat, schemaName, fields[x].cellCol + keyCell.End.Row));
                        object defaultValue = GDEItemManager.GetDefaultValueForType(fields[x].type);
                        if (fields[x].isList || fields[x].is2DList)
                        {
                            itemData[fields[x].name] = new List <object>();
                        }
                        else
                        {
                            itemData[fields[x].name] = defaultValue;
                        }
                    }
                    processedItems++;

                    if (OnUpdateProgress != null)
                    {
                        OnUpdateProgress(GDEConstants.ImportingGameDataLbl, progressMessage, processedItems / totalItems);
                    }
                }

                GDEItemManager.AddItem(itemName, itemData, out error);
            }
        }