Esempio n. 1
0
        private static void Parsing_OnCode(TypeData pSheetData, SpreadSheetConnector pConnector, CodeFileBuilder pCodeFileBuilder, List <CommandLineArg> listCommandLine)
        {
            var pCodeType = pCodeFileBuilder.AddCodeType(pSheetData.strFileName, pSheetData.eType);
            var mapFieldData_ConvertStringToEnum              = pSheetData.listFieldData.Where((pFieldData) => pFieldData.bConvertStringToEnum).ToDictionary(((pFieldData) => pFieldData.strFieldName));
            var listFieldData_DeleteThisField_OnCode          = pSheetData.listFieldData.Where((pFieldData) => pFieldData.bDeleteThisField_InCode).Select((pFieldData) => pFieldData.strFieldName);
            Dictionary <int, CodeTypeDeclaration> mapEnumType = new Dictionary <int, CodeTypeDeclaration>();


            int iDefinedTypeRow = -1;

            pSheetData.ParsingSheet(pConnector,
                                    (listRow, strText, iRow, iColumn) =>
            {
                // 변수 선언 형식인경우
                if (strText.Contains(":"))
                {
                    if (iDefinedTypeRow == -1)
                    {
                        iDefinedTypeRow = iRow;
                    }

                    if (iDefinedTypeRow != iRow)
                    {
                        return;
                    }

                    string[] arrText    = strText.Split(':');
                    string strFieldName = arrText[0];

                    if (mapFieldData_ConvertStringToEnum.ContainsKey(strFieldName))
                    {
                        FieldTypeData pFieldData = mapFieldData_ConvertStringToEnum[strFieldName];
                        mapEnumType.Add(iColumn, pCodeFileBuilder.AddCodeType(pFieldData.strEnumName, ESheetType.Enum));

                        if (pSheetData.listEnumName.Contains(pFieldData.strEnumName) == false)
                        {
                            pSheetData.listEnumName.Add(pFieldData.strEnumName);
                        }
                    }

                    // 삭제되는 코드인 경우
                    if (listFieldData_DeleteThisField_OnCode.Contains(strFieldName))
                    {
                        return;
                    }

                    pCodeType.AddField(new FieldTypeData(strFieldName, arrText[1]));
                    return;
                }

                // 이넘 Column인 경우 이넘 생성
                if (mapEnumType.ContainsKey(iColumn))
                {
                    mapEnumType[iColumn].AddEnumField(new EnumFieldData(strText));
                    return;
                }
            });

            Execute_CommandLine(pCodeType, listCommandLine);
        }
Esempio n. 2
0
        static public void DoCheck_IsValid_Table(this TypeData pSheetData, SpreadSheetConnector pConnector, Action <string> OnError)
        {
            bool bIsEnum = pSheetData.eType == ESheetType.Enum;

            pSheetData.ParsingSheet(pConnector,
                                    (listRow, strText, iRow, iColumn) =>
            {
                if (bIsEnum)
                {
                    Dictionary <int, EEnumHeaderType> mapEnumType = new Dictionary <int, EEnumHeaderType>();

                    EEnumHeaderType eType = EEnumHeaderType.EnumNone;
                    if (Enum.TryParse(strText, out eType))
                    {
                        // mapEnumType.Add(,eType)
                        if (eType == EEnumHeaderType.EnumType)
                        {
                            for (int i = iColumn; i < listRow.Count; i++)
                            {
                                string strTextOtherColumn = (string)listRow[i];
                                if (Enum.TryParse(strTextOtherColumn, out eType) == false)
                                {
                                    OnError?.Invoke($"테이블 유효성 체크 - 이넘 파싱 에러");
                                    return;
                                }

                                if (mapEnumType.ContainsKey(iColumn) == false)
                                {
                                    mapEnumType.Add(iColumn, eType);
                                }
                            }
                        }

                        return;
                    }

                    if (mapEnumType.ContainsKey(iColumn) == false)
                    {
                        return;
                    }

                    switch (mapEnumType[iColumn])
                    {
                    case EEnumHeaderType.EnumType:
                    case EEnumHeaderType.EnumValue:
                        if (string.IsNullOrEmpty(strText))
                        {
                            OnError?.Invoke($"테이블 유효성 체크 - 이넘 파싱 에러");
                            return;
                        }
                        break;
                    }
                }
                else
                {
                }
            });
        }
Esempio n. 3
0
        static public void DoWork(this TypeData pSheetData, SpreadSheetConnector pConnector, CodeFileBuilder pCodeFileBuilder, Action <string> OnError)
        {
            List <CommandLineArg> listCommandLine = Parsing_CommandLine(pSheetData.strCommandLine, OnError);

            switch (pSheetData.eType)
            {
            case ESheetType.Class:
            case ESheetType.Struct:
                Parsing_OnCode(pSheetData, pConnector, pCodeFileBuilder, listCommandLine);
                break;

            case ESheetType.Enum:
                Parsing_OnEnum(pSheetData, pConnector, pCodeFileBuilder);
                break;

            case ESheetType.Global:
                Parsing_OnGlobal(pSheetData, pConnector, pCodeFileBuilder);
                break;
            }
        }
Esempio n. 4
0
 abstract public void DoWork(CodeFileBuilder pCodeFileBuilder, SpreadSheetConnector pConnector, IEnumerable <TypeData> listSheetData, Action <string> OnPrintWorkState);
Esempio n. 5
0
        public override void DoWork(CodeFileBuilder pCodeFileBuilder, SpreadSheetConnector pConnector, IEnumerable <TypeData> listSheetData, Action <string> OnPrintWorkProcess)
        {
            TypeDataList pTypeDataList = new TypeDataList(pConnector.strFileName);

            foreach (var pSheet in listSheetData)
            {
                if (pSheet.eType == ESheetType.Enum)
                {
                    continue;
                }

                JObject pJson_Instance = new JObject();
                JArray  pArray         = new JArray();

                Dictionary <string, FieldTypeData> mapFieldData  = pSheet.listFieldData.Where(p => p.bIsVirtualField == false).ToDictionary(p => p.strFieldName);
                Dictionary <int, string>           mapMemberName = new Dictionary <int, string>();
                Dictionary <int, string>           mapMemberType = new Dictionary <int, string>();
                int iColumnStartIndex = -1;

                pSheet.ParsingSheet(pConnector,
                                    ((IList <object> listRow, string strText, int iRowIndex, int iColumnIndex) =>
                {
                    if (strText.Contains(':')) // 변수 타입 파싱
                    {
                        if (mapMemberName.ContainsKey(iColumnIndex))
                        {
                            return;
                        }

                        string[] arrText = strText.Split(':');
                        mapMemberName.Add(iColumnIndex, arrText[0]);
                        mapMemberType.Add(iColumnIndex, arrText[1]);

                        if (iColumnStartIndex == -1)
                        {
                            iColumnStartIndex = iColumnIndex;
                        }

                        return;
                    }

                    if (iColumnIndex != iColumnStartIndex)
                    {
                        return;
                    }

                    JObject pObject = new JObject();

                    // 실제 변수값
                    for (int i = iColumnIndex; i < listRow.Count; i++)
                    {
                        if (mapMemberName.ContainsKey(i))
                        {
                            if (mapFieldData.TryGetValue(mapMemberName[i], out var pFieldTypeData) == false)
                            {
                                OnPrintWorkProcess?.Invoke($"{pSheet.strSheetName} - mapFieldData.ContainsKey({mapMemberName[i]}) Fail");
                                continue;
                            }

                            string strFieldName = pFieldTypeData.strFieldName;
                            string strValue = (string)listRow[i];
                            pObject.Add(strFieldName, strValue);
                        }
                    }

                    pArray.Add(pObject);
                }));

                if (pArray.Count == 0)
                {
                    continue;
                }

                pJson_Instance.Add("array", pArray);

                string strFileName = $"{pSheet.strFileName}.json";
                JsonSaveManager.SaveData(pJson_Instance, $"{GetRelative_To_AbsolutePath(strExportPath)}/{strFileName}");

                pTypeDataList.listTypeData.Add(pSheet);
            }

#if !UNITY_EDITOR
            JsonSaveManager.SaveData(pTypeDataList, $"{GetRelative_To_AbsolutePath(strExportPath)}/{nameof(TypeDataList)}.json");
#endif
        }
Esempio n. 6
0
        private static void Parsing_OnEnum(TypeData pSheetData, SpreadSheetConnector pConnector, CodeFileBuilder pCodeFileBuilder)
        {
            Dictionary <int, EEnumHeaderType>        mapEnumType  = new Dictionary <int, EEnumHeaderType>();
            Dictionary <string, CodeTypeDeclaration> mapEnumValue = new Dictionary <string, CodeTypeDeclaration>();

            pSheetData.ParsingSheet(pConnector,
                                    (listRow, strText, iRow, iColumn) =>
            {
                EEnumHeaderType eType = EEnumHeaderType.EnumNone;
                if (Enum.TryParse(strText, out eType))
                {
                    if (eType == EEnumHeaderType.EnumType)
                    {
                        if (mapEnumType.ContainsKey(iColumn) == false)
                        {
                            mapEnumType.Add(iColumn, eType);
                        }

                        for (int i = iColumn; i < listRow.Count; i++)
                        {
                            string strTextOtherColumn = (string)listRow[i];
                            if (Enum.TryParse(strTextOtherColumn, out eType))
                            {
                                if (mapEnumType.ContainsKey(i) == false)
                                {
                                    mapEnumType.Add(i, eType);
                                }
                            }
                        }
                    }

                    return;
                }

                try
                {
                    eType = mapEnumType[iColumn];
                }
                catch
                {
                    eType = mapEnumType[iColumn];
                }

                if (eType != EEnumHeaderType.EnumType)
                {
                    return;
                }

                if (mapEnumValue.ContainsKey(strText) == false)
                {
                    mapEnumValue.Add(strText, pCodeFileBuilder.AddCodeType(strText, ESheetType.Enum));
                }

                EnumFieldData pFieldData = new EnumFieldData();
                for (int i = iColumn; i < listRow.Count; i++)
                {
                    if (mapEnumType.TryGetValue(i, out eType))
                    {
                        string strNextText = (string)listRow[i];
                        switch (eType)
                        {
                        case EEnumHeaderType.EnumValue:
                            pFieldData.strValue = strNextText;
                            break;

                        case EEnumHeaderType.NumberValue: pFieldData.iNumber = int.Parse(strNextText); break;

                        case EEnumHeaderType.Comment: pFieldData.strComment = strNextText; break;
                        }
                    }
                }

                if (string.IsNullOrEmpty(pFieldData.strValue))
                {
                    throw new Exception($"이넘인데 값이 없습니다 - 타입 : {mapEnumValue[strText].Name}");
                }

                mapEnumValue[strText].AddEnumField(pFieldData);
            });
        }
Esempio n. 7
0
        static public void ParsingSheet(this TypeData pSheet, SpreadSheetConnector pConnector, delOnParsingText OnParsingText)
        {
            const string const_strCommandString       = "#";
            const string const_strIgnoreString_Row    = "R";
            const string const_strIgnoreString_Column = "C";
            const string const_strStartString         = "Start";

            if (pConnector == null)
            {
                return;
            }

            IList <IList <Object> > pData = pConnector.GetExcelData(pSheet.strSheetName);

            if (pData == null)
            {
                return;
            }

            if (OnParsingText == null) // For Loop에서 Null Check 방지
            {
                OnParsingText = (a, b, c, d) => { }
            }
            ;

            HashSet <int> setIgnoreColumnIndex = new HashSet <int>();
            bool          bIsParsingStart      = false;

            for (int i = 0; i < pData.Count; i++)
            {
                bool           bIsIgnoreRow = false;
                IList <object> listRow      = pData[i];
                for (int j = 0; j < listRow.Count; j++)
                {
                    if (setIgnoreColumnIndex.Contains(j))
                    {
                        continue;
                    }

                    string strText = (string)listRow[j];
                    if (string.IsNullOrEmpty(strText))
                    {
                        continue;
                    }

                    if (strText.StartsWith(const_strCommandString))
                    {
                        bool bIsContinue = false;
                        if (strText.Contains(const_strIgnoreString_Column))
                        {
                            setIgnoreColumnIndex.Add(j);
                            bIsContinue = true;
                        }

                        if (bIsParsingStart == false)
                        {
                            if (strText.Contains(const_strStartString))
                            {
                                bIsParsingStart = true;
                                bIsContinue     = true;
                            }
                        }

                        if (bIsIgnoreRow == false && strText.Contains(const_strIgnoreString_Row))
                        {
                            bIsContinue  = true;
                            bIsIgnoreRow = true;
                        }

                        if (bIsContinue)
                        {
                            continue;
                        }
                    }

                    if (bIsIgnoreRow)
                    {
                        continue;
                    }

                    if (bIsParsingStart == false)
                    {
                        continue;
                    }

                    OnParsingText(listRow, strText, i, j);
                }
            }
        }
Esempio n. 8
0
        private static void Parsing_OnGlobal(TypeData pSheetData, SpreadSheetConnector pConnector, CodeFileBuilder pCodeFileBuilder)
        {
            // 글로벌 테이블은 데이터를 담는 데이터컨테이너와 글로벌키 Enum타입 2개를 생성한다.
            var pCodeType_Class     = pCodeFileBuilder.AddCodeType(pSheetData.strFileName, pSheetData.eType);
            var pCodeType_GlobalKey = pCodeFileBuilder.AddCodeType(const_GlobalKey_EnumName, ESheetType.Enum);

            if (pSheetData.listEnumName.Contains(const_GlobalKey_EnumName) == false)
            {
                pSheetData.listEnumName.Add(const_GlobalKey_EnumName);
            }

            Dictionary <int, EGlobalColumnType> mapGlobalColumnType = new Dictionary <int, EGlobalColumnType>();
            HashSet <string> setGlobalTable_ByType = new HashSet <string>();

            string strTypeName          = "";
            int    iColumnIndex_Type    = -1;
            int    iColumnIndex_Comment = -1;

            pSheetData.ParsingSheet(pConnector,
                                    (listRow, strText, iRow, iColumn) =>
            {
                // 변수 선언 형식인경우
                if (strText.Contains(":"))
                {
                    string[] arrText          = strText.Split(':');
                    string strFieldName       = arrText[0];
                    string strFieldName_Lower = strFieldName.ToLower();

                    for (int i = 0; i < (int)EGlobalColumnType.MAX; i++)
                    {
                        EGlobalColumnType eCurrentColumnType = (EGlobalColumnType)i;
                        if (strFieldName_Lower.Contains(eCurrentColumnType.ToString().ToLower()))
                        {
                            mapGlobalColumnType.Add(iColumn, eCurrentColumnType);

                            switch (eCurrentColumnType)
                            {
                            case EGlobalColumnType.Key:
                                {
                                    FieldTypeData pFieldData = pSheetData.listFieldData.Where(p => p.strFieldName == strFieldName).FirstOrDefault();
                                    if (pFieldData != null)
                                    {
                                        pFieldData.bDeleteThisField_InCode = true;
                                    }

                                    FieldTypeData pFieldData_Enum = pSheetData.listFieldData.Where(p => p.strFieldName == const_GlobalKey_FieldName).FirstOrDefault();
                                    if (pFieldData_Enum == null)
                                    {
                                        pFieldData_Enum = new FieldTypeData(const_GlobalKey_FieldName, const_GlobalKey_EnumName);
                                        pFieldData_Enum.strDependencyFieldName = pFieldData.strFieldName;
                                        pFieldData_Enum.bIsVirtualField        = true;
                                        pSheetData.listFieldData.Add(pFieldData_Enum);
                                    }
                                }

                                break;

                            case EGlobalColumnType.Comment:
                                {
                                    FieldTypeData pFieldData = pSheetData.listFieldData.Where(p => p.strFieldName == strFieldName).FirstOrDefault();
                                    if (pFieldData != null)
                                    {
                                        pFieldData.bDeleteThisField_InCode = true;
                                    }
                                    iColumnIndex_Comment = iColumn;
                                }
                                break;

                            case EGlobalColumnType.Type:
                                iColumnIndex_Type = iColumn;
                                strTypeName       = strFieldName;
                                pCodeType_Class.AddField(new FieldTypeData(strFieldName, arrText[1]));

                                FieldTypeData pFieldData_Type = pSheetData.listFieldData.Where(p => p.strFieldName == strFieldName).FirstOrDefault();
                                if (pFieldData_Type == null)
                                {
                                    pSheetData.listFieldData.Add(new FieldTypeData(strFieldName, arrText[1]));
                                }

                                break;


                            default:
                                pCodeType_Class.AddField(new FieldTypeData(strFieldName, arrText[1]));
                                break;
                            }

                            return;
                        }
                    }
                }

                // 변수 선언이 아니라 값을 파싱하면 일단 타입부터 확인한다
                EGlobalColumnType eColumnType = EGlobalColumnType.None;
                if (mapGlobalColumnType.TryGetValue(iColumn, out eColumnType) == false)
                {
                    return;
                }

                switch (eColumnType)
                {
                case EGlobalColumnType.Key:

                    string strComment = "";
                    if (iColumnIndex_Comment != -1 && iColumnIndex_Comment < listRow.Count)
                    {
                        strComment = (string)listRow[iColumnIndex_Comment];
                    }

                    if (string.IsNullOrEmpty(strComment))
                    {
                        pCodeType_GlobalKey.AddEnumField(new EnumFieldData(strText));
                    }
                    else
                    {
                        pCodeType_GlobalKey.AddEnumField(new EnumFieldData(strText, strComment));
                    }

                    break;

                case EGlobalColumnType.Type:

                    if (setGlobalTable_ByType.Contains(strText))
                    {
                        return;
                    }
                    setGlobalTable_ByType.Add(strText);

                    string strFieldType      = (string)listRow[iColumnIndex_Type];
                    FieldTypeData pFieldData = pSheetData.listFieldData.Where(p => p.strFieldName == strTypeName && p.strFieldType == strFieldType).FirstOrDefault();
                    if (pFieldData == null)
                    {
                        pFieldData = new FieldTypeData(strTypeName, strFieldType);
                        pSheetData.listFieldData.Add(pFieldData);
                    }

                    pFieldData.bIsTemp = true;
                    pFieldData.bDeleteThisField_InCode = true;
                    pFieldData.bIsVirtualField         = strFieldType != "string";
                    pFieldData.bIsKeyField             = true;
                    pFieldData.bIsOverlapKey           = true;

                    break;
                }
            });
        }
        public override void DoWork(CodeFileBuilder pCodeFileBuilder, SpreadSheetConnector pConnector, IEnumerable <TypeData> listSheetData, Action <string> OnPrintWorkState)
        {
            CodeNamespace pNameSpace = new CodeNamespace();

            List <CodeNamespaceImport> listDefaultUsing = new List <CodeNamespaceImport>();

            listDefaultUsing.Add(new CodeNamespaceImport("UnityEngine"));

            List <CommandLineArg> listCommandLine = Parsing_CommandLine(strCommandLine, null);

            for (int i = 0; i < listCommandLine.Count; i++)
            {
                ECommandLine eCommandLine = (ECommandLine)Enum.Parse(typeof(ECommandLine), listCommandLine[i].strArgName);
                switch (eCommandLine)
                {
                case ECommandLine.addusing:
                    listDefaultUsing.Add(new CodeNamespaceImport(listCommandLine[i].strArgValue));
                    break;

                case ECommandLine.useusing:
                    pNameSpace.Name = listCommandLine[i].strArgValue;
                    break;
                }
            }
            CodeNamespaceImport[] arrDefaultUsing = listDefaultUsing.ToArray();
            pNameSpace.Imports.AddRange(arrDefaultUsing);

            CodeTypeDeclarationCollection arrTypes = pCodeFileBuilder.GetCodeTypeDeclarationCollection();
            List <CodeTypeDeclaration>    listType = new List <CodeTypeDeclaration>();

            foreach (CodeTypeDeclaration pType in arrTypes)
            {
                listType.Add(pType);
            }


            HashSet <CodeTypeDeclaration>     setExecutedType = new HashSet <CodeTypeDeclaration>();
            IEnumerable <CodeTypeDeclaration> listUnitySO     = listType.Where(p => string.IsNullOrEmpty(p.Name) == false && p.IsClass);

            foreach (CodeTypeDeclaration pType in listUnitySO)
            {
                TypeData pSaveData = listSheetData.Where((pSaveDataSheet) => pSaveDataSheet.strFileName == pType.Name).FirstOrDefault();
                if (pSaveData == null)
                {
                    continue;
                }

                Create_SO(pCodeFileBuilder, pNameSpace, pType, pSaveData);

                IEnumerable <CodeTypeDeclaration> arrEnumTypes = listType.Where(p => pSaveData.listEnumName.Contains(p.Name));
                foreach (var pEnumType in arrEnumTypes)
                {
                    setExecutedType.Add(pEnumType);
                }

                if (pSaveData.eType == ESheetType.Global)
                {
                    Create_GlobalSOContainer(pCodeFileBuilder, pNameSpace, arrDefaultUsing, pType, arrEnumTypes.ToArray(), pSaveData);
                }
                else
                {
                    Create_SOContainer(pCodeFileBuilder, pNameSpace, arrDefaultUsing, pType, arrEnumTypes.ToArray(), pSaveData);
                }

                OnPrintWorkState?.Invoke($"UnitySO - Working SO {pType.Name}");
                setExecutedType.Add(pType);
            }

            // Others
            pNameSpace.Types.Clear();
            IEnumerable <CodeTypeDeclaration> listOthers = listType.Where(p => string.IsNullOrEmpty(p.Name) == false && setExecutedType.Contains(p) == false);

            foreach (CodeTypeDeclaration pType in listOthers)
            {
                OnPrintWorkState?.Invoke($"UnitySO - Working Others {pType.Name}");
                pNameSpace.Types.Add(pType);
                setExecutedType.Add(pType);
            }

            if (pNameSpace.Types.Count != 0)
            {
                pCodeFileBuilder.Generate_CSharpCode(pNameSpace, $"{GetRelative_To_AbsolutePath(strExportPath)}/Others");
            }
        }