Byaml : fix path index types with no paths
This commit is contained in:
parent
dc96965440
commit
b0edf476e9
@ -16,7 +16,7 @@ using Syroot.BinaryData;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class BYAML : IEditor<ByamlEditor>, IFileFormat, IConvertableTextFormat
|
||||
public class BYAML : IEditor<UserControl>, IFileFormat, IConvertableTextFormat
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Parameter;
|
||||
|
||||
@ -52,6 +52,8 @@ namespace FirstPlugin
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<uint, string> Hashes = new Dictionary<uint, string>();
|
||||
|
||||
#region Text Converter Interface
|
||||
public TextFileType TextFileType => TextFileType.Yaml;
|
||||
public bool CanConvertBack => true;
|
||||
@ -115,7 +117,6 @@ namespace FirstPlugin
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ConvertBEtoLE(object sender, EventArgs args)
|
||||
{
|
||||
var byamlF = new BYAML();
|
||||
@ -138,52 +139,52 @@ namespace FirstPlugin
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class EditableNode
|
||||
public static bool IsHash(string k)
|
||||
{
|
||||
public Type type { get { return Node[Index].GetType(); } }
|
||||
dynamic Node;
|
||||
dynamic Index;
|
||||
if (k == null) return false;
|
||||
|
||||
public dynamic Get() { return Node[Index]; }
|
||||
return IsHex(k.ToArray());
|
||||
}
|
||||
|
||||
public void Set(dynamic value) { Node[Index] = value; }
|
||||
public string GetTreeViewString()
|
||||
private static bool IsHex(IEnumerable<char> chars)
|
||||
{
|
||||
bool isHex;
|
||||
foreach (var c in chars)
|
||||
{
|
||||
if (Index is int)
|
||||
return Node[Index].ToString();
|
||||
else
|
||||
return Index + " : " + Node[Index].ToString();
|
||||
}
|
||||
isHex = ((c >= '0' && c <= '9') ||
|
||||
(c >= 'a' && c <= 'f') ||
|
||||
(c >= 'A' && c <= 'F'));
|
||||
|
||||
public EditableNode(dynamic _node, dynamic _index)
|
||||
{
|
||||
Node = _node;
|
||||
Index = _index;
|
||||
if (!isHex)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsDialog = false;
|
||||
public BymlFileData BymlData;
|
||||
|
||||
public ByamlEditor OpenForm()
|
||||
public UserControl OpenForm()
|
||||
{
|
||||
ByamlEditor editor = new ByamlEditor();
|
||||
editor.FileFormat = this;
|
||||
editor.Text = FileName;
|
||||
editor.Dock = DockStyle.Fill;
|
||||
|
||||
/* if (FileName.Contains("_muunt"))
|
||||
if (FileName.Contains("_muunt"))
|
||||
{
|
||||
var muuntEditor = new MuuntEditor.MuuntEditor();
|
||||
muuntEditor.LoadByaml(data.RootNode, FileName);
|
||||
muuntEditor.Show();
|
||||
}*/
|
||||
var muuntEditor = new Turbo.TurboMuuntEditor();
|
||||
muuntEditor.LoadByaml(this, Path.GetDirectoryName(FilePath));
|
||||
return muuntEditor;
|
||||
}
|
||||
return editor;
|
||||
}
|
||||
|
||||
public void FillEditor(UserControl control)
|
||||
{
|
||||
if (control is Turbo.TurboMuuntEditor)
|
||||
return;
|
||||
|
||||
((ByamlEditor)control).UpdateByaml(
|
||||
BymlData.RootNode,
|
||||
BymlData.SupportPaths,
|
||||
|
@ -164,6 +164,8 @@ namespace FirstPlugin
|
||||
return UInt64.Parse(value, CultureInfo.InvariantCulture);
|
||||
else if (tag == "!ll")
|
||||
return Int64.Parse(value, CultureInfo.InvariantCulture);
|
||||
else if (tag == "!p")
|
||||
return new ByamlPathIndex() { Index = Int32.Parse(value, CultureInfo.InvariantCulture) };
|
||||
else
|
||||
{
|
||||
float floatValue = 0;
|
||||
@ -171,7 +173,15 @@ namespace FirstPlugin
|
||||
if (isFloat)
|
||||
return floatValue;
|
||||
else
|
||||
{
|
||||
if (BYAML.IsHash(value))
|
||||
{
|
||||
uint hash = Convert.ToUInt32(value, 16);
|
||||
if (BYAML.Hashes.ContainsKey(hash))
|
||||
return $"!h {BYAML.Hashes[hash]}";
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,7 +220,16 @@ namespace FirstPlugin
|
||||
yamlNode.Style = SharpYaml.YamlStyle.Flow;
|
||||
|
||||
foreach (var item in (IDictionary<string, dynamic>)node)
|
||||
yamlNode.Add(item.Key, SaveNode(item.Key, item.Value));
|
||||
{
|
||||
string key = item.Key;
|
||||
if (BYAML.IsHash(key))
|
||||
{
|
||||
uint hash = Convert.ToUInt32(key, 16);
|
||||
if (BYAML.Hashes.ContainsKey(hash))
|
||||
key = $"!h {BYAML.Hashes[hash]}";
|
||||
}
|
||||
yamlNode.Add(key, SaveNode(item.Key, item.Value));
|
||||
}
|
||||
return yamlNode;
|
||||
}
|
||||
else if (node is ByamlPathPoint)
|
||||
@ -231,6 +250,7 @@ namespace FirstPlugin
|
||||
else if (node is uint) tag = "!u";
|
||||
else if (node is Int64) tag = "!ul";
|
||||
else if (node is double) tag = "!d";
|
||||
else if (node is ByamlPathIndex) tag = "!p";
|
||||
|
||||
var yamlNode = new YamlScalarNode(ConvertValue(node));
|
||||
if (tag != null) yamlNode.Tag = tag;
|
||||
@ -288,6 +308,7 @@ namespace FirstPlugin
|
||||
private static string ConvertValue(dynamic node)
|
||||
{
|
||||
if (node is bool) return ((bool)node) ? "true" : "false";
|
||||
else if (node is ByamlPathIndex) return ((ByamlPathIndex)node).Index.ToString();
|
||||
else if (node is float) return string.Format("{0:0.000.00}", node);
|
||||
else return node.ToString();
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user