예제 #1
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);
                }
            }
        }
예제 #2
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);
            });
        }
예제 #3
0
        private Task ProcessJson(ISheetConnector pConnector, Action <string> OnPrintWorkProcess, TypeData pSheet,
                                 TypeDataList pTypeDataList)
        {
            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>();
            int iColumnStartIndex = -1;

            return(pSheet.ParsingSheet_UseTask(pConnector,
                                               ((listRow, strText, iRowIndex, 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) == false)
                    {
                        continue;
                    }

                    if (mapFieldData.TryGetValue(mapMemberName[i], out FieldTypeData pFieldTypeData) == false)
                    {
                        OnPrintWorkProcess?.Invoke($"{pSheet.strSheetName}({pSheet.strSheetID}) - mapFieldData.ContainsKey({mapMemberName[i]}) Fail");
                        continue;
                    }

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

                pArray.Add(pObject);
            })).ContinueWith((pTask) =>
            {
                pJson_Instance.Add("array", pArray);

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

                var pAlreadyExist = pTypeDataList.listTypeData.FirstOrDefault(p => p.strSheetID == pSheet.strSheetID);
                if (pAlreadyExist != null)
                {
                    pTypeDataList.listTypeData.Remove(pAlreadyExist);
                }

                pTypeDataList.listTypeData.Add(pSheet);
            }));
        }
예제 #4
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;
                }
            });
        }
        private void OnFinishConnect(ISheetConnector pConnector, Exception pException_OnError)
        {
            if (pException_OnError != null)
            {
                WriteConsole("연결 실패 " + pException_OnError);
                return;
            }

            if (_mapSaveData.ContainsKey(pConnector.strSheetID))
            {
                pSpreadSheet_CurrentConnected       = _mapSaveData[pConnector.strSheetID];
                pSpreadSheet_CurrentConnected.eType = pConnector.eSheetType;
                List <TypeData> listSavedTable = pSpreadSheet_CurrentConnected.listTable;

                int iOrder = 0;
                foreach (KeyValuePair <string, SheetData> pSheet in pConnector.mapWorkSheetData_Key_Is_SheetID)
                {
                    TypeData pTypeDataFind = listSavedTable.FirstOrDefault(x => (x.strSheetID == pSheet.Key));
                    if (pTypeDataFind == null)
                    {
                        listSavedTable.Add(new TypeData(pSheet.Value.strSheetID, pSheet.Value.strSheetName, iOrder));
                    }
                    else
                    {
                        // 이미 저장되있는 Sheet의 경우
                        // 웹에 있는 SheetName과 로컬의 SheetName이 다를 수 있기 때문에 갱신
                        pTypeDataFind.strSheetName = pSheet.Value.strSheetName;
                        pTypeDataFind.iOrder       = iOrder;
                    }

                    iOrder++;
                }
            }
            else
            {
                pSpreadSheet_CurrentConnected = new SaveData_SpreadSheet(pConnector.strSheetID, pConnector.eSheetType);
                _mapSaveData[pSpreadSheet_CurrentConnected.strSheetID] = pSpreadSheet_CurrentConnected;

                int iOrder = 0;
                pSpreadSheet_CurrentConnected.listTable.Clear();
                foreach (KeyValuePair <string, SheetData> pSheet in pConnector.mapWorkSheetData_Key_Is_SheetID)
                {
                    pSpreadSheet_CurrentConnected.listTable.Add(new TypeData(pSheet.Value.strSheetID, pSheet.Value.strSheetName, iOrder++));
                }

                SaveDataManager.SaveSheet(pSpreadSheet_CurrentConnected);

                WriteConsole("새 파일을 만들었습니다.");
            }

            checkedListBox_SheetList.Items.Clear();
            List <TypeData> listSheetSaved = pSpreadSheet_CurrentConnected.listTable;

            listSheetSaved.Sort((x, y) => x.iOrder.CompareTo(y.iOrder));

            TypeData[] arrSheetDelete = listSheetSaved.Where((pSheet) =>
                                                             pConnector.mapWorkSheetData_Key_Is_SheetID.Values.Any(p => p.strSheetID == pSheet.strSheetID) == false).ToArray();

            if (arrSheetDelete.Length > 0)
            {
                for (int i = 0; i < arrSheetDelete.Length; i++)
                {
                    listSheetSaved.Remove(arrSheetDelete[i]);
                }

                AutoSaveAsync_CurrentSheet();
            }
            ClearFieldData(listSheetSaved);

            for (int i = 0; i < listSheetSaved.Count; i++)
            {
                checkedListBox_SheetList.Items.Add(listSheetSaved[i], listSheetSaved[i].bEnable);
            }

            checkedListBox_WorkList.Items.Clear();
            List <WorkBase> listWorkBase = pSpreadSheet_CurrentConnected.listSaveWork;

            listWorkBase.Sort((x, y) => x.iWorkOrder.CompareTo(y.iWorkOrder));
            for (int i = 0; i < listWorkBase.Count; i++)
            {
                checkedListBox_WorkList.Items.Add(listWorkBase[i], listWorkBase[i].bEnable);
            }

            SetState(EState.IsConnected);
            WriteConsole("연결 성공");
            _bIsConnecting = false;
        }
        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");
            }
        }
        private void Create_SOContainer(CodeFileBuilder pCodeFileBuilder, CodeNamespace pNameSpace, CodeNamespaceImport[] arrDefaultUsing, CodeTypeDeclaration pType, CodeTypeDeclaration[] arrEnumType, TypeData pSaveData)
        {
            Create_SOContainer(pNameSpace, arrDefaultUsing, pType, arrEnumType, out var pContainerType, out var pInitMethod);

            IEnumerable <FieldTypeData> listKeyField = pSaveData.listFieldData.Where(p => p.bIsKeyField);

            foreach (var pFieldData in listKeyField)
            {
                string strFieldName  = "";
                string strMemberType = "";
                if (pFieldData.bIsOverlapKey)
                {
                    strFieldName  = $"mapData_Key_Is_{pFieldData.strFieldName}";
                    strMemberType = $"Dictionary<{pFieldData.strFieldType}, List<{pType.Name}>>";
                }
                else
                {
                    strFieldName  = $"mapData_Key_Is_{pFieldData.strFieldName}";
                    strMemberType = $"Dictionary<{pFieldData.strFieldType}, {pType.Name}>";
                }

                pContainerType.AddField(new FieldTypeData(strFieldName, strMemberType));
                Generate_CacheMethod(pContainerType, pInitMethod, const_strListData, strFieldName, pFieldData.strFieldName, pFieldData.bIsOverlapKey);
            }

            pCodeFileBuilder.Generate_CSharpCode(pNameSpace, $"{GetRelative_To_AbsolutePath(strExportPath)}/{pContainerType.Name}");
        }
        private void Create_GlobalSOContainer(CodeFileBuilder pCodeFileBuilder, CodeNamespace pNameSpace, CodeNamespaceImport[] arrDefaultUsing, CodeTypeDeclaration pType, CodeTypeDeclaration[] arrEnumType, TypeData pSaveData)
        {
            Create_SOContainer(pNameSpace, arrDefaultUsing, pType, arrEnumType, out var pContainerType, out var pInitMethod);

            IEnumerable <FieldTypeData> listKeyField = pSaveData.listFieldData.Where(p => p.bIsKeyField);

            string strValueFieldName = "";
            IEnumerable <FieldTypeData> listRealField = pSaveData.listFieldData.Where(p => p.bIsKeyField == false);

            foreach (var pRealField in listRealField)
            {
                if (pRealField.strFieldName.ToLower().Contains(nameof(EGlobalColumnType.Value).ToLower()))
                {
                    strValueFieldName = pRealField.strFieldName;
                    break;
                }
            }

            HashSet <string> setAlreadyExecute = new HashSet <string>();

            foreach (var pFieldData in listKeyField)
            {
                if (setAlreadyExecute.Contains(pFieldData.strFieldType))
                {
                    continue;
                }
                setAlreadyExecute.Add(pFieldData.strFieldType);

                string strFieldName  = $"mapData_Type_Is_{pFieldData.strFieldType}";
                string strMemberType = $"Dictionary<{"EGlobalKey"}, {pFieldData.strFieldType}>";

                pContainerType.AddField(new FieldTypeData(strFieldName, strMemberType));
                Generate_CacheMethod_Global(pContainerType, pInitMethod, const_strListData, strFieldName, pFieldData.strFieldName, pFieldData.strFieldType, strValueFieldName);
            }

            pCodeFileBuilder.Generate_CSharpCode(pNameSpace, $"{GetRelative_To_AbsolutePath(strExportPath)}/{pContainerType.Name}");
        }
        private void Create_SO(CodeFileBuilder pCodeFileBuilder, CodeNamespace pNameSpace, CodeTypeDeclaration pType, TypeData pSaveData)
        {
            pType.AddBaseClass("UnityEngine.ScriptableObject");
            pNameSpace.Types.Clear();
            pNameSpace.Types.Add(pType);

            var listVirtualFieldOption = pSaveData.listFieldData.Where(pExportOption => pExportOption.bDeleteThisField_InCode == false && pExportOption.bIsVirtualField);

            foreach (var pVirtualField in listVirtualFieldOption)
            {
                pType.AddField(pVirtualField);
            }

            pCodeFileBuilder.Generate_CSharpCode(pNameSpace, $"{GetRelative_To_AbsolutePath(strExportPath)}/{pType.Name}");
        }