Пример #1
0
        public static int ConvertToYarn(ConvertFormatOptions options)
        {
            foreach (var file in options.files)
            {
                if (YarnSpinnerLoader.GetFormatFromFileName(file) == NodeFormat.Text)
                {
                    MerinoDebug.LogFormat(LoggingLevel.Warning, "Not converting file {0}, because its name implies it's already in Yarn format", file);
                    continue;
                }

                ConvertNodesInFile(options, file, "yarn.txt", ConvertNodesToYarnText);
            }
            return(0);
        }
Пример #2
0
        public static int ConvertToJSON(ConvertFormatOptions options)
        {
            foreach (var file in options.files)
            {
                if (YarnSpinnerLoader.GetFormatFromFileName(file) == NodeFormat.JSON)
                {
                    MerinoDebug.LogFormat(LoggingLevel.Warning, "Not converting file {0}, because its name implies it's already in JSON format", file);
                    continue;
                }

                ConvertNodesInFile(options, file, "json", (IEnumerable <YarnSpinnerLoader.NodeInfo> nodes) => JsonConvert.SerializeObject(nodes, Formatting.Indented));
            }
            return(0);
        }
Пример #3
0
        public static void ConvertNodesInFile(ConvertFormatOptions options, string file, string fileExtension, ConvertNodesToText convert)
        {
            //	var d = new Dialogue(null);

            var text = File.ReadAllText(file);

            IEnumerable <YarnSpinnerLoader.NodeInfo> nodes;

            try {
                nodes = YarnSpinnerLoader.GetNodesFromText(text, YarnSpinnerLoader.GetFormatFromFileName(file));
            } catch (FormatException e) {
                MerinoDebug.Log(LoggingLevel.Error, e.Message);
                return;
            }

            var serialisedText = convert(nodes);

            var destinationDirectory = options.outputDirectory;

            if (destinationDirectory == null)
            {
                destinationDirectory = Path.GetDirectoryName(file);
            }

            var fileName = Path.GetFileName(file);

            // ChangeExtension thinks that the file "Foo.yarn.txt" has the extension "txt", so
            // to simplify things, just lop that extension off right away if it's there
            fileName = fileName.Replace(".yarn.txt", "");

            // change the filename's extension
            fileName = Path.ChangeExtension(fileName, fileExtension);

            // figure out where we're writing this file
            var destinationFilePath = Path.Combine(destinationDirectory, fileName);

            File.WriteAllText(destinationFilePath, serialisedText);

            if (options.verbose)
            {
                MerinoDebug.Log(LoggingLevel.Verbose, "Wrote " + destinationFilePath);
            }
        }