moving useful bits of MiniYamlExts into OpenRa.FileFormats
This commit is contained in:
@@ -6,6 +6,8 @@ using System.IO;
|
|||||||
|
|
||||||
namespace OpenRa.FileFormats
|
namespace OpenRa.FileFormats
|
||||||
{
|
{
|
||||||
|
using MiniYamlNodes = Dictionary<string, MiniYaml>;
|
||||||
|
|
||||||
public class MiniYaml
|
public class MiniYaml
|
||||||
{
|
{
|
||||||
public string Value;
|
public string Value;
|
||||||
@@ -97,5 +99,32 @@ namespace OpenRa.FileFormats
|
|||||||
|
|
||||||
return new MiniYaml( a.Value ?? b.Value, Merge( a.Nodes, b.Nodes ) );
|
return new MiniYaml( a.Value ?? b.Value, Merge( a.Nodes, b.Nodes ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> ToLines(string name)
|
||||||
|
{
|
||||||
|
yield return name + ": " + Value;
|
||||||
|
if (Nodes != null)
|
||||||
|
foreach (var line in Nodes.ToLines(false))
|
||||||
|
yield return "\t" + line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MiniYamlExts
|
||||||
|
{
|
||||||
|
public static void WriteToFile(this MiniYamlNodes y, string filename)
|
||||||
|
{
|
||||||
|
File.WriteAllLines(filename, y.ToLines(true).Select(x => x.TrimEnd()).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<string> ToLines(this MiniYamlNodes y, bool lowest)
|
||||||
|
{
|
||||||
|
foreach (var kv in y)
|
||||||
|
{
|
||||||
|
foreach (var line in kv.Value.ToLines(kv.Key))
|
||||||
|
yield return line;
|
||||||
|
if (lowest)
|
||||||
|
yield return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
|
|
||||||
namespace RulesConverter
|
namespace RulesConverter
|
||||||
{
|
{
|
||||||
using MiniYamlNodes = Dictionary<string, MiniYaml>;
|
using MiniYamlNodes = Dictionary<string, MiniYaml>;
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
static class MiniYamlExts
|
static class MiniYamlExts
|
||||||
{
|
{
|
||||||
public static void WriteToFile( this MiniYamlNodes y, string filename )
|
|
||||||
{
|
|
||||||
File.WriteAllLines( filename, y.ToLines( true ).Select( x => x.TrimEnd() ).ToArray() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<string> ToLines( this MiniYamlNodes y, bool lowest )
|
|
||||||
{
|
|
||||||
foreach( var kv in y )
|
|
||||||
{
|
|
||||||
foreach( var line in kv.Value.ToLines( kv.Key ) )
|
|
||||||
yield return line;
|
|
||||||
if( lowest )
|
|
||||||
yield return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<string> ToLines( this MiniYaml y, string name )
|
|
||||||
{
|
|
||||||
yield return name + ": " + y.Value;
|
|
||||||
if( y.Nodes != null )
|
|
||||||
foreach( var line in y.Nodes.ToLines( false ) )
|
|
||||||
yield return "\t" + line;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void OptimizeInherits( this MiniYamlNodes y, MiniYamlNodes baseYaml )
|
public static void OptimizeInherits( this MiniYamlNodes y, MiniYamlNodes baseYaml )
|
||||||
{
|
{
|
||||||
foreach( var key in y.Keys.ToList() )
|
foreach( var key in y.Keys.ToList() )
|
||||||
@@ -66,7 +40,7 @@ namespace RulesConverter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MiniYamlNodes Diff( MiniYamlNodes a, MiniYamlNodes b )
|
static MiniYamlNodes Diff( MiniYamlNodes a, MiniYamlNodes b )
|
||||||
{
|
{
|
||||||
if( a.Count == 0 && b.Count == 0 )
|
if( a.Count == 0 && b.Count == 0 )
|
||||||
return null;
|
return null;
|
||||||
@@ -97,7 +71,7 @@ namespace RulesConverter
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MiniYaml Diff( MiniYaml a, MiniYaml b, out bool remove )
|
static MiniYaml Diff( MiniYaml a, MiniYaml b, out bool remove )
|
||||||
{
|
{
|
||||||
remove = false;
|
remove = false;
|
||||||
if( a == null && b == null )
|
if( a == null && b == null )
|
||||||
|
|||||||
Reference in New Issue
Block a user