public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        TxtToXml myScript = (TxtToXml)target;

        if (GUILayout.Button("TxtToXml"))
        {
            myScript.Convert();
        }
    }
示例#2
0
        /// <summary>
        /// Creates an XDocument with a set of documents from the given <paramref name="inputFolderPath"/> and saves it to the <paramref name="outputPath"/>.
        /// </summary>
        public static void ConvertDocumentsToXml(string extension, string inputFolderPath, string outputPath)
        {
            if (!extension.StartsWith("."))
            {
                extension = $".{extension}";
            }

            XElement rootElement;
            ToXml    converter;

            switch (extension)
            {
            case ".txt":
                rootElement = new XElement("DocumentSet");
                converter   = new TxtToXml();
                break;

            case ".csv":
                rootElement = new XElement("SheetSet");
                converter   = new CsvToXml();
                break;

            case ".xml":
                rootElement = new XElement("XmlSet");
                converter   = new ToXmlViaXslt(_xsltPath);
                break;

            default:
                throw new NotSupportedException($"{extension} is not a supported file format\r\n" +
                                                $"Supported formats: {supportedConversionFormats.ShowElements()}.");
            }

            string[] files = Directory.GetFiles(inputFolderPath);
            if (files
                .Where(file => Path.HasExtension(file))
                .All(file => Path.GetExtension(file) == extension))
            {
                var aggregator = new FileAggregator(inputFolderPath);

                foreach (string file in files)
                {
                    var doc = new XDocument();
                    doc.Add(aggregator.ConvertFilesToXml(rootElement, converter));
                    doc.Save(outputPath);
                }
            }
            else
            {
                throw new NotSupportedException($"{inputFolderPath} must only contain files with this extension: {extension} and subfolders");
            }
        }
示例#3
0
        /// <summary>
        /// The main entry of the command.
        /// </summary>
        /// <param name="args">The arguments of the command.</param>
        public static void Main(string[] args)
        {
            // Creates a configuration from 3 arguments:
            Func <CommandMode, string, string, Config> createConfig3 =
                (CommandMode mode, string inputFileName, string outputFileName) => {
                if (File.Exists(inputFileName))
                {
                    return(new Config(mode, inputFileName, outputFileName));
                }
                return(new Config(CommandMode.None));
            };

            // Creates a configuration from 2 arguments:
            Func <CommandMode, string, Config> createConfig2 =
                (CommandMode mode, string inputFileName) => {
                string extension = "txt";
                switch (mode)
                {
                case CommandMode.TMX: extension = "xml"; break;

                case CommandMode.TXT: extension = "xml"; break;

                case CommandMode.TXT2TMX: extension = "tmx"; break;
                }
                string outputFileName = Path.GetFileNameWithoutExtension(inputFileName) + "." + extension;
                return(createConfig3(mode, inputFileName, outputFileName));
            };

            try {
                // Get the configuration of the command:
                Config cfg = new Config(CommandMode.None);
                if (args.Length == 3)
                {
                    if (args[0] == "-tmx")
                    {
                        cfg = createConfig3(CommandMode.TMX, args[1], args[2]);
                    }
                    else if (args[0] == "-txt")
                    {
                        cfg = createConfig3(CommandMode.TXT, args[1], args[2]);
                    }
                    else if (args[0] == "-txt2tmx")
                    {
                        cfg = createConfig3(CommandMode.TXT2TMX, args[1], args[2]);
                    }
                }
                else if (args.Length == 2)
                {
                    if (args[0] == "-tmx")
                    {
                        cfg = createConfig2(CommandMode.TMX, args[1]);
                    }
                    else if (args[0] == "-txt")
                    {
                        cfg = createConfig2(CommandMode.TXT, args[1]);
                    }
                    else if (args[0] == "-txt2tmx")
                    {
                        cfg = createConfig2(CommandMode.TXT2TMX, args[1]);
                    }
                }
                // Check the selected mode:
                switch (cfg.Mode)
                {
                case CommandMode.TMX:
                    // Initiates the TMX to XML conversion:
                    TmxToXml.Convert(cfg.InputFileName, cfg.OutputFileName);
                    break;

                case CommandMode.TXT:
                    // Initiates the TXT to XML conversion:
                    TxtToXml.Convert(cfg.InputFileName, cfg.OutputFileName);
                    break;

                case CommandMode.TXT2TMX:
                    // Initiates the TXT to TMX conversion:
                    TxtToTmx.Convert(cfg.InputFileName, cfg.OutputFileName);
                    break;

                default:
                    // Shows the help of the command:
                    Console.WriteLine("Sokoban Tools Help:");
                    Console.WriteLine();
                    Console.WriteLine(AppDomain.CurrentDomain.FriendlyName + " -tmx input.tmx output.xml");
                    Console.WriteLine(AppDomain.CurrentDomain.FriendlyName + " -txt input output.xml");
                    Console.WriteLine(AppDomain.CurrentDomain.FriendlyName + " -txt2tmx input output.tmx");
                    Console.WriteLine();
                    Console.WriteLine("-tmx = Converts a Tiled file format to the game level format.");
                    Console.WriteLine("-txt = Converts a classic file format to the game level format.");
                    Console.WriteLine("-txt2tmx = Converts a classic file format to the Tiled file format.");
                    Console.WriteLine();
                    Console.WriteLine("Classic format: http://www.sokobano.de/wiki/index.php?title=Level_format");
                    Console.WriteLine();
                    break;
                }
            } catch (Exception e) {
                Debug.Log(e);
            }
        }