Add project files.
This commit is contained in:
25
AssetStudio/YAML/Utils/Extensions/ArrayYAMLExtensions.cs
Normal file
25
AssetStudio/YAML/Utils/Extensions/ArrayYAMLExtensions.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class ArrayYAMLExtensions
|
||||
{
|
||||
public static YAMLNode ExportYAML(this byte[] _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Length * 2);
|
||||
for (int i = 0; i < _this.Length; i++)
|
||||
{
|
||||
sb.AppendHex(_this[i]);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this T[][] _this)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
return ((IEnumerable<IEnumerable<T>>)_this).ExportYAML();
|
||||
}
|
||||
}
|
||||
}
|
||||
82
AssetStudio/YAML/Utils/Extensions/EmitterExtensions.cs
Normal file
82
AssetStudio/YAML/Utils/Extensions/EmitterExtensions.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
namespace AssetStudio
|
||||
{
|
||||
internal static class EmitterExtensions
|
||||
{
|
||||
public static Emitter WriteHex(this Emitter _this, byte value)
|
||||
{
|
||||
_this.Write(HexAlphabet[value >> 4]);
|
||||
_this.Write(HexAlphabet[value & 0xF]);
|
||||
return _this;
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, ushort value)
|
||||
{
|
||||
_this.Write(HexAlphabet[(value >> 4) & 0xF]);
|
||||
_this.Write(HexAlphabet[(value >> 0) & 0xF]);
|
||||
_this.Write(HexAlphabet[(value >> 12) & 0xF]);
|
||||
_this.Write(HexAlphabet[(value >> 8) & 0xF]);
|
||||
return _this;
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, short value)
|
||||
{
|
||||
return WriteHex(_this, unchecked((ushort)value));
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, uint value)
|
||||
{
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 4) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 0) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 12) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 8) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 20) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 16) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 28) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 24) & 0xF)]);
|
||||
return _this;
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, int value)
|
||||
{
|
||||
return WriteHex(_this, unchecked((uint)value));
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, ulong value)
|
||||
{
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 4) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 0) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 12) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 8) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 20) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 16) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 28) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 24) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 36) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 32) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 44) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 40) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 52) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 48) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 60) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 56) & 0xF)]);
|
||||
return _this;
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, long value)
|
||||
{
|
||||
return WriteHex(_this, unchecked((ulong)value));
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, float value)
|
||||
{
|
||||
return WriteHex(_this, BitConverterExtensions.ToUInt32(value));
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, double value)
|
||||
{
|
||||
return WriteHex(_this, BitConverterExtensions.ToUInt64(value));
|
||||
}
|
||||
|
||||
private static readonly string HexAlphabet = "0123456789ABCDEF";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class IDictionaryExportYAMLExtensions
|
||||
{
|
||||
public static YAMLNode ExportYAML<T>(this IReadOnlyDictionary<int, T> _this)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
map.Add(kvp.Key, kvp.Value.ExportYAML());
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IReadOnlyDictionary<string, T> _this)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
map.Add(kvp.Key, kvp.Value.ExportYAML());
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T1, T2>(this IReadOnlyDictionary<Tuple<T1, long>, T2> _this)
|
||||
where T1 : IYAMLExportable
|
||||
where T2 : IYAMLExportable
|
||||
{
|
||||
// TODO: test
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode kvpMap = new YAMLMappingNode();
|
||||
YAMLMappingNode keyMap = new YAMLMappingNode();
|
||||
keyMap.Add("first", kvp.Key.Item1.ExportYAML());
|
||||
keyMap.Add("second", kvp.Key.Item2);
|
||||
kvpMap.Add("first", keyMap);
|
||||
kvpMap.Add("second", kvp.Value.ExportYAML());
|
||||
node.Add(kvpMap);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IReadOnlyDictionary<T, int> _this)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
YAMLNode key = kvp.Key.ExportYAML();
|
||||
if (key.NodeType == YAMLNodeType.Scalar)
|
||||
{
|
||||
map.Add(key, kvp.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
map.Add("first", key);
|
||||
map.Add("second", kvp.Value);
|
||||
}
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IReadOnlyDictionary<T, float> _this)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
YAMLNode key = kvp.Key.ExportYAML();
|
||||
if (key.NodeType == YAMLNodeType.Scalar)
|
||||
{
|
||||
map.Add(key, kvp.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
map.Add("first", key);
|
||||
map.Add("second", kvp.Value);
|
||||
}
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T1, T2>(this IReadOnlyDictionary<T1, T2> _this)
|
||||
where T1 : IYAMLExportable
|
||||
where T2 : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
YAMLNode key = kvp.Key.ExportYAML();
|
||||
if (key.NodeType == YAMLNodeType.Scalar)
|
||||
{
|
||||
map.Add(key, kvp.Value.ExportYAML());
|
||||
}
|
||||
else
|
||||
{
|
||||
map.Add("first", key);
|
||||
map.Add("second", kvp.Value.ExportYAML());
|
||||
}
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T1, T2>(this IReadOnlyDictionary<T1, T2[]> _this)
|
||||
where T1 : IYAMLExportable
|
||||
where T2 : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
YAMLNode key = kvp.Key.ExportYAML();
|
||||
if (key.NodeType == YAMLNodeType.Scalar)
|
||||
{
|
||||
map.Add(key, kvp.Value.ExportYAML());
|
||||
}
|
||||
else
|
||||
{
|
||||
map.Add("first", key);
|
||||
map.Add("second", kvp.Value.ExportYAML());
|
||||
}
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
105
AssetStudio/YAML/Utils/Extensions/IDictionaryYAMLExtensions.cs
Normal file
105
AssetStudio/YAML/Utils/Extensions/IDictionaryYAMLExtensions.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class IDictionaryYAMLExtensions
|
||||
{
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<uint, string> _this)
|
||||
{
|
||||
YAMLMappingNode node = new YAMLMappingNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
node.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<long, string> _this)
|
||||
{
|
||||
YAMLMappingNode node = new YAMLMappingNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
node.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<string, string> _this)
|
||||
{
|
||||
YAMLMappingNode node = new YAMLMappingNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
node.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<string, int> _this)
|
||||
{
|
||||
YAMLMappingNode node = new YAMLMappingNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
node.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<string, float> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
map.Add(kvp.Key, kvp.Value);
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<Tuple<ushort, ushort>, float> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode keyNode = new YAMLMappingNode();
|
||||
keyNode.Add(kvp.Key.Item1, kvp.Key.Item2);
|
||||
YAMLMappingNode kvpMap = new YAMLMappingNode();
|
||||
kvpMap.Add("first", keyNode);
|
||||
kvpMap.Add("second", kvp.Value);
|
||||
node.Add(kvpMap);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<Tuple<int, long>, string> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode keyNode = new YAMLMappingNode();
|
||||
keyNode.Add(kvp.Key.Item1, kvp.Key.Item2);
|
||||
YAMLMappingNode kvpMap = new YAMLMappingNode();
|
||||
kvpMap.Add("first", keyNode);
|
||||
kvpMap.Add("second", kvp.Value);
|
||||
node.Add(kvpMap);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IReadOnlyDictionary<Tuple<T, long>, string> _this, Func<T, int> converter)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode keyNode = new YAMLMappingNode();
|
||||
keyNode.Add(converter(kvp.Key.Item1), kvp.Key.Item2);
|
||||
YAMLMappingNode kvpMap = new YAMLMappingNode();
|
||||
kvpMap.Add("first", keyNode);
|
||||
kvpMap.Add("second", kvp.Value);
|
||||
node.Add(kvpMap);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
273
AssetStudio/YAML/Utils/Extensions/IEnumerableYAMLExtensions.cs
Normal file
273
AssetStudio/YAML/Utils/Extensions/IEnumerableYAMLExtensions.cs
Normal file
@@ -0,0 +1,273 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class IEnumerableYAMLExtensions
|
||||
{
|
||||
public static YAMLNode ExportYAML(this IEnumerable<bool> _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (bool value in _this)
|
||||
{
|
||||
byte bvalue = unchecked((byte)(value ? 1 : 0));
|
||||
sb.AppendHex(bvalue);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<char> _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (char value in _this)
|
||||
{
|
||||
sb.AppendHex((ushort)value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<byte> _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (byte value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<ushort> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (ushort value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (ushort value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<short> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (short value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (short value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<uint> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (uint value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (uint value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<int> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (int value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (int value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<ulong> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (ulong value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (ulong value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<long> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (long value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (long value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<float> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (float value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<double> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (double value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<string> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (string value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<IEnumerable<string>> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (IEnumerable<string> export in _this)
|
||||
{
|
||||
node.Add(export.ExportYAML());
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IEnumerable<T> _this)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (T export in _this)
|
||||
{
|
||||
node.Add(export.ExportYAML());
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IEnumerable<IEnumerable<T>> _this)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (IEnumerable<T> export in _this)
|
||||
{
|
||||
node.Add(export.ExportYAML());
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IEnumerable<Tuple<string, T>> _this)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
map.Add(kvp.Item1, kvp.Item2.ExportYAML());
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T1, T2>(this IEnumerable<Tuple<T1, T2>> _this, Func<T1, int> converter)
|
||||
where T2 : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
map.Add(converter(kvp.Item1), kvp.Item2.ExportYAML());
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IEnumerable<KeyValuePair<string, T>> _this)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
map.Add(kvp.Key, kvp.Value.ExportYAML());
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
171
AssetStudio/YAML/Utils/Extensions/IListYAMLExtensions.cs
Normal file
171
AssetStudio/YAML/Utils/Extensions/IListYAMLExtensions.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class IListYAMLExtensions
|
||||
{
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<bool> _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 2);
|
||||
foreach (bool value in _this)
|
||||
{
|
||||
byte bvalue = unchecked((byte)(value ? 1 : 0));
|
||||
sb.AppendHex(bvalue);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<char> _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 4);
|
||||
foreach (char value in _this)
|
||||
{
|
||||
sb.AppendHex((ushort)value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<byte> _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 2);
|
||||
foreach (byte value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<ushort> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 4);
|
||||
foreach (ushort value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (ushort value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<short> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 4);
|
||||
foreach (short value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (short value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<uint> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 8);
|
||||
foreach (uint value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (uint value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<int> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 8);
|
||||
foreach (int value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (int value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<ulong> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 16);
|
||||
foreach (ulong value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (ulong value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<long> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 16);
|
||||
foreach (long value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (long value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class YAMLMappingNodeExtensions
|
||||
{
|
||||
public static void AddSerializedVersion(this YAMLMappingNode _this, int version)
|
||||
{
|
||||
if(version > 1)
|
||||
{
|
||||
_this.Add(SerializedVersionName, version);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ForceAddSerializedVersion(this YAMLMappingNode _this, int version)
|
||||
{
|
||||
if (version > 0)
|
||||
{
|
||||
_this.Add(SerializedVersionName, version);
|
||||
}
|
||||
}
|
||||
|
||||
public static void InsertSerializedVersion(this YAMLMappingNode _this, int version)
|
||||
{
|
||||
if(version > 1)
|
||||
{
|
||||
_this.InsertBegin(SerializedVersionName, version);
|
||||
}
|
||||
}
|
||||
|
||||
public const string SerializedVersionName = "serializedVersion";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user