Skip to content

Commit

Permalink
Support properties for UIComponent and UIObject
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoco007 committed Sep 20, 2024
1 parent 45773fd commit a001d3b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions BeatSaberMarkupLanguage/BSMLParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ private void HandleTagNode(XElement element, GameObject parent, BSMLParserParams

object host = parserParams.Host;
XAttribute id = element.Attribute("id");

// TODO: iterating over fields/properties for every tag is very inefficient
if (host != null && id != null)
{
foreach (FieldInfo fieldInfo in host.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
Expand All @@ -394,6 +396,19 @@ private void HandleTagNode(XElement element, GameObject parent, BSMLParserParams
fieldInfo.SetValue(host, currentNode);
}
}

foreach (PropertyInfo fieldInfo in host.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
{
if (fieldInfo.GetCustomAttribute<UIComponent>(true)?.Id == id.Value)
{
fieldInfo.SetValue(host, GetExternalComponent(currentNode, fieldInfo.PropertyType));
}

if (fieldInfo.GetCustomAttribute<UIObject>(true)?.Id == id.Value)
{
fieldInfo.SetValue(host, currentNode);
}
}
}

XAttribute tags = element.Attribute("tags");
Expand Down

0 comments on commit a001d3b

Please sign in to comment.