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); }
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); }
public static int ConvertFormat(ConvertFormatOptions options) { CheckFileList(options.files, ALLOWED_EXTENSIONS); if (options.convertToJSON) { return(ConvertToJSON(options)); } if (options.convertToYarn) { return(ConvertToYarn(options)); } // var processName = System.IO.Path.GetFileName(Environment.GetCommandLineArgs()[0]); // YarnSpinnerConsole.Error(string.Format("You must specify a destination format. Run '{0} help convert' to learn more.", processName)); return(1); }
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); } }