Exemplo n.º 1
0
        public void ChangeIdentifier(DataSheet dataSheet, SheetPage sheetPage, string newIdentifier)
        {
            foreach (SheetPage datasheetPage in dataSheet.datasheetPages)
            {
                for (int i = 0; i < datasheetPage.columns.Count; i++)
                {
                    SheetColumn datasheetColumn = datasheetPage.columns[i];

                    if (datasheetColumn.dataType != SheetDataType.Reference)
                    {
                        continue;
                    }

                    if (datasheetColumn.referenceSheet != sheetPage.sheetName)
                    {
                        continue;
                    }

                    if (datasheetColumn.isCollection)
                    {
                        for (int j = 0; j < datasheetPage.rows.Count; j++)
                        {
                            SheetRow  datasheetRow  = datasheetPage.rows[j];
                            SheetCell datasheetCell = datasheetRow.cells[i];
                            string[]  dataArray     = datasheetCell.data as string[];
                            for (int h = 0; h < dataArray.Length; h++)
                            {
                                if (dataArray[h] == identifier)
                                {
                                    dataArray[h] = newIdentifier;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < datasheetPage.rows.Count; j++)
                        {
                            SheetRow  datasheetRow  = datasheetPage.rows[j];
                            SheetCell datasheetCell = datasheetRow.cells[i];
                            if ((string)datasheetCell.data == identifier)
                            {
                                datasheetCell.data = newIdentifier;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Initialize(DataSheet dataSheet, Action <SheetPage> callback)
        {
            this.dataSheet = dataSheet;
            this.callback  = callback;

            sheetPage = new SheetPage();

            int highest = 0;

            if (dataSheet.datasheetPages.Length > 0)
            {
                highest = dataSheet.datasheetPages.Max(i => i.index);
            }
            sheetPage.index     = highest + 1;
            sheetPage.sheetName = string.Empty;
        }
Exemplo n.º 3
0
        public static LoadedPageData Initialize(DataSheet dataSheet, DatasheetType dataSheetType)
        {
            string         dataString = dataSheetType.GetIdentifier();
            SheetPage      sheetPage  = Array.Find(dataSheet.datasheetPages, i => i.sheetName == dataString);
            LoadedPageData pageData   = new LoadedPageData();

            pageData.dataSheetIdentifier = dataString;
            pageData.sheetPage           = sheetPage;

            if (!pageData.TryLoadStoredDimensions())
            {
                pageData.CalculateDimensions();
            }

            pageData.RecalculateTotalHeight();
            pageData.RecalculateTotalWidth();
            return(pageData);
        }
Exemplo n.º 4
0
        public void Initialize(DataSheet dataSheet, SheetPage sheetPage, SheetColumn sheetColumn, Action onColumnEdited)
        {
            this.dataSheet      = dataSheet;
            this.sheetPage      = sheetPage;
            this.sheetColumn    = sheetColumn;
            this.onColumnEdited = onColumnEdited;
            serializationName   = sheetColumn.serializationName;
            propertyName        = sheetColumn.propertyName;
            isCollection        = sheetColumn.isCollection;
            dataType            = sheetColumn.dataType;

            if (dataType != SheetDataType.Reference)
            {
                string[] options = dataSheet.datasheetPages.Select(i => i.sheetName).ToArray();
                referenceSheet = options[0];
            }
            else
            {
                referenceSheet = sheetColumn.referenceSheet;
            }
        }
Exemplo n.º 5
0
        public static void UpdateModelCode(SheetPage[] updatedPages)
        {
            List <SheetPage> deletedSheetPages = new List <SheetPage>();
            List <SheetPage> newSheetPages     = new List <SheetPage>();
            List <SheetPage> changedPages      = new List <SheetPage>();

            DataSheet dataSheet = new DataSheet();

            foreach (SheetPage sheetPage in updatedPages)
            {
                SheetPage originalPage = Array.Find(dataSheet.datasheetPages, i => i.sheetName == sheetPage.sheetName);
                if (originalPage == null)
                {
                    newSheetPages.Add(sheetPage);
                    continue;
                }

                if (originalPage.CheckIfSameCodebase(sheetPage))
                {
                    continue;
                }

                changedPages.Add(sheetPage);
            }

            foreach (SheetPage sheetPage in dataSheet.datasheetPages)
            {
                if (updatedPages.Any(i => i.sheetName == sheetPage.sheetName))
                {
                    continue;
                }

                deletedSheetPages.Add(sheetPage);
            }

            int totalChanges = newSheetPages.Count + deletedSheetPages.Count + changedPages.Count;

            if (totalChanges > 0)
            {
                foreach (SheetPage sheetPage in newSheetPages)
                {
                    Directory.CreateDirectory(sheetPage.sheetDirectoryLocation);
                    GenerateCode_Model(sheetPage);
                    GenerateCode_Record(dataSheet, newSheetPages, sheetPage);
                    GenerateCode_Identifier(sheetPage);
                }

                foreach (SheetPage sheetPage in changedPages)
                {
                    GenerateCode_Record(dataSheet, newSheetPages, sheetPage);
                    GenerateCode_Identifier(sheetPage);
                }

                foreach (SheetPage sheetPage in deletedSheetPages)
                {
                    string directory = SheetStringDefinitions.MODEL_DIRECTORY + sheetPage.sheetEnumCase;
                    Directory.Delete(directory, true);
                    File.Delete(directory + SheetStringDefinitions.META_FILE_EXTENSION);
                    File.Delete(SheetStringDefinitions.SCRIPTABLEOBJECT_DIRECTORY + sheetPage.sheetEnumCase + SheetStringDefinitions.SCRIPTABLEOBJECT_FILE_EXTENSION);
                    File.Delete(SheetStringDefinitions.SCRIPTABLEOBJECT_DIRECTORY + sheetPage.sheetEnumCase + SheetStringDefinitions.SCRIPTABLEOBJECT_FILE_EXTENSION + SheetStringDefinitions.META_FILE_EXTENSION);
                }

                GenerateCode_ModelManager(updatedPages);
                GenerateCode_DataSheetType(updatedPages);

                string[] updatedPagesJson = new string[updatedPages.Length];
                for (int i = 0; i < updatedPages.Length; i++)
                {
                    updatedPagesJson[i] = JsonUtility.ToJson(new SheetPageJsonable(updatedPages[i]));
                }

                string json = SheetDataType.String.GetStringValue(updatedPagesJson, true);
                File.WriteAllText(SheetStringDefinitions.FILE_LOCATION_TARGET_DATASHEET, json);
            }
            else
            {
                foreach (SheetPage sheetPage in updatedPages)
                {
                    CreateModelInstance(sheetPage);
                }
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Exemplo n.º 6
0
        private static void GenerateCode_Record(DataSheet dataSheet, List <SheetPage> newPages, SheetPage sheetPage)
        {
            List <string> recordTemplate = new List <string>(File.ReadAllLines(SheetStringDefinitions.TEMPLATE_DIRECTORY + SheetStringDefinitions.TEMPLATE_FILE_RECORD));

            for (int i = 0; i < recordTemplate.Count; i++)
            {
                string line = recordTemplate[i];
                recordTemplate[i] = line.Replace(SheetStringDefinitions.TEMPLATE_REPLACE_MODEL_NAME, sheetPage.sheetNameTrimmedUpperCase);
            }

            string[] propertyTemplate           = File.ReadAllLines(SheetStringDefinitions.TEMPLATE_DIRECTORY + SheetStringDefinitions.TEMPLATE_FILE_RECORD_PROPERTY);
            string[] propertyCollectionTemplate = File.ReadAllLines(SheetStringDefinitions.TEMPLATE_DIRECTORY + SheetStringDefinitions.TEMPLATE_FILE_RECORD_PROPERTY_COLLECTION);

            string[] referenceTemplate           = File.ReadAllLines(SheetStringDefinitions.TEMPLATE_DIRECTORY + SheetStringDefinitions.TEMPLATE_FILE_RECORD_REFERENCE);
            string[] referenceCollectionTemplate = File.ReadAllLines(SheetStringDefinitions.TEMPLATE_DIRECTORY + SheetStringDefinitions.TEMPLATE_FILE_RECORD_REFERENCE_COLLECTION);

            List <string> recordProperties = new List <string>();

            foreach (SheetColumn sheetColumn in sheetPage.columns)
            {
                if (recordProperties.Count > 0)
                {
                    recordProperties.Add(string.Empty);
                }

                string[] matchingTemplate;
                if (sheetColumn.dataType == SheetDataType.Reference)
                {
                    matchingTemplate = sheetColumn.isCollection ? referenceCollectionTemplate : referenceTemplate;
                }
                else
                {
                    matchingTemplate = sheetColumn.isCollection ? propertyCollectionTemplate : propertyTemplate;
                }

                foreach (string templateLine in matchingTemplate)
                {
                    if (sheetColumn.dataType == SheetDataType.Reference)
                    {
                        string      referenceSheet;
                        SheetPage[] sheetPages = dataSheet.datasheetPages.Where(i => i.sheetName == sheetColumn.referenceSheet).ToArray();
                        if (sheetPages.Length > 0)
                        {
                            referenceSheet = sheetPages[0].sheetEnumCase;
                        }
                        else
                        {
                            referenceSheet = newPages.Find(i => i.sheetName == sheetColumn.referenceSheet).sheetEnumCase;
                        }

                        recordProperties.Add(templateLine.Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_IDENTIFIER, sheetColumn.serializationName)
                                             .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_NAME_UPPER, sheetColumn.propertyName)
                                             .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_NAME_LOWER, sheetColumn.propertyName.FirstLetterToLower())
                                             .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_REFERENCE_MODEL_NAME, referenceSheet));
                    }
                    else
                    {
                        recordProperties.Add(templateLine.Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_IDENTIFIER, sheetColumn.serializationName)
                                             .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_NAME_UPPER, sheetColumn.propertyName)
                                             .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_NAME_LOWER, sheetColumn.propertyName.FirstLetterToLower())
                                             .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_TYPE, sheetColumn.dataType.GetIdentifier()));
                    }
                }
            }

            int replaceIndex = recordTemplate.FindIndex(i => i.Contains(SheetStringDefinitions.TEMPLATE_INSERT_PROPERTIES));

            recordTemplate.InsertRange(replaceIndex, recordProperties);

            File.WriteAllLines(sheetPage.sheetRecordFileLocation, recordTemplate);
        }