Exemplo n.º 1
0
        /// <summary>
        /// Take the supplied data and transform to the required array format required by the builder
        /// CSV file data should be comma separated for each map cell and a newline for each row, e.g.
        ///     1,1,2,3
        ///     4,2,1,3
        ///
        ///  CSV string data supplied should be comma separated as CSV file but each row separated by pipe ('|')
        ///  The map may be 0 or 1 indexed for the first item so ensure the start index value is set
        /// </summary>
        /// <param name="csvData">Tilemap data in string format. More for debugging but may be useful.</param>
        /// <param name="csvFile">Tilemap data as a file</param>
        /// <returns></returns>
        private static int[,] GetInputData(TileMapBuilder tb, string csvData, string csvFile)
        {
            string[] rowData;
            if (csvData == null && csvFile == null)
            {
                return(null);
            }
            if (csvData != null)
            {
                rowData = csvData.Split('|');
            }
            else if (csvFile != null)
            {
                rowData = File.ReadAllLines(csvFile);
            }
            else
            {
                return(null);
            }

            int[,] data;
            try
            {
                data = tb.TransformInputData(rowData);
            }
            catch (Exception e)
            {
                throw e;
            }
            return(data);
        }
        private void GenerateSceneFile()
        {
            string[]       rowData;
            TileMapBuilder tb = new TileMapBuilder();

            if (CSVString.Text.Trim() != "")
            {
                rowData = CSVString.Text.Trim().Split('|');
            }
            else if (CSVImport.Text.Trim() != "")
            {
                rowData = File.ReadAllLines(CSVImport.Text.Trim());
            }
            else
            {
                rowData = null;
            }

            try
            {
                tb.SetMapData(tb.TransformInputData(rowData));
            }
            catch (Exception e)
            {
                MessageBox.Show($"Failed: {e.Message}");
            }

            string sceneFile = tb
                               .SetCellSizePixels(uint.Parse(CellWidth.Text), uint.Parse(CellHeight.Text))
                               .SetTileSheetSizeUnits(uint.Parse(UnitWidth.Text), uint.Parse(UnitHeight.Text))
                               .SetTileSheetStartIndex(uint.Parse(StartCellIndex.Text))
                               .SetTileSheet(ImportSheet.Text)
                               .SetFormat(int.Parse(InternalFormat.Text))
                               .SetLoadSteps(int.Parse(InternalSteps.Text))
                               .SetNodeType(InternalMapClass.Text)
                               .SetTileSetType(InternalTileClass.Text)
                               .SetGodotTileWidth(uint.Parse(InternalMapWidth.Text))
                               .SetMapDataEmptyCellIndex(int.Parse(MapIgnoreCell.Text))
                               .SetNodeName(NodeName.Text)
                               .Build();

            try
            {
                File.WriteAllText(OutFile.Text, sceneFile);
                MessageBox.Show($"File written to:\n {OutFile.Text}");
            }
            catch (Exception e)
            {
                MessageBox.Show($"Failed to write output file: {OutFile.Text}\n\n{e.Message}");
            }
        }