Example #1
0
        ///Append prety json to yaml file as comments for version control diff purposes
        static void AppendPrettyJSONComments(Graph graph, string path)
        {
            var systemPath = EditorUtils.AssetToSystemPath(path);
            var lines      = File.ReadAllLines(systemPath);

            //not a yaml? bail out.
            if (lines.Length == 0 || !lines[0].StartsWith(IS_YAML))
            {
                return;
            }

            var result = new List <string>(lines.Length);

            //clear previous. Unity actually does not keep any changes made to the file, but I don't trust this will always be the case.
            var skip = false;

            for (var i = 0; i < lines.Length; i++)
            {
                var line = lines[i];
                if (line.StartsWith(SERIALIZATION_START))
                {
                    skip = true;
                }
                if (skip)
                {
                    continue;
                }
                if (line.StartsWith(SERIALIZATION_END))
                {
                    skip = false;
                    continue;
                }
                result.Add(line);
            }

            //add new
            result.Add(SERIALIZATION_START);
            result.Add("#The pretty formatted json serialization bellow is only a reference to help in version control diff. Other than that it is not used at all.");
            var pretyJson = ParadoxNotion.Serialization.JSONSerializer.PrettifyJson(graph.GetSerializedJsonData());
            var split     = pretyJson.Split(new string[] { System.Environment.NewLine }, System.StringSplitOptions.None);

            for (var i = 0; i < split.Length; i++)
            {
                var newLine = '#' + split[i];
                result.Add(newLine);
            }
            result.Add(SERIALIZATION_END);

            File.WriteAllLines(systemPath, result);
        }