mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Editor: Show pretty script field names
This commit is contained in:
@@ -852,7 +852,9 @@ internal class EntityEditor
|
||||
|
||||
IEnumerable<Attribute> attributes = field.GetCustomAttributes();
|
||||
|
||||
object? newValue = ShowFieldEditor(value, value?.GetType() ?? field.FieldType, field.Name, attributes);
|
||||
string prettyName = field.Name.ToPrettyName();
|
||||
|
||||
object? newValue = ShowFieldEditor(value, value?.GetType() ?? field.FieldType, prettyName, attributes);
|
||||
|
||||
if (newValue != DidNotChange)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
using System.Text;
|
||||
|
||||
namespace GlitchyEngine.Extensions;
|
||||
|
||||
public static class StringExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a variable name to a pretty name as good as reasonably possible.
|
||||
/// </summary>
|
||||
/// <param name="uglyName">The name of a variable to prettify.</param>
|
||||
/// <returns>The pretty string.</returns>
|
||||
public static string ToPrettyName(this string uglyName)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(uglyName.Length);
|
||||
|
||||
bool wasUpper = false;
|
||||
bool inWord = false;
|
||||
bool inNumber = false;
|
||||
|
||||
foreach (char c in uglyName)
|
||||
{
|
||||
if (char.IsLetter(c))
|
||||
{
|
||||
if (inNumber)
|
||||
{
|
||||
sb.Append(' ');
|
||||
inNumber = false;
|
||||
}
|
||||
|
||||
bool newWord = !inWord;
|
||||
|
||||
if (char.IsUpper(c) && !wasUpper)
|
||||
{
|
||||
newWord = true;
|
||||
wasUpper = true;
|
||||
|
||||
if (inWord)
|
||||
{
|
||||
sb.Append(' ');
|
||||
}
|
||||
}
|
||||
else if (char.IsLower(c))
|
||||
{
|
||||
wasUpper = false;
|
||||
}
|
||||
|
||||
sb.Append(newWord ? char.ToUpper(c) : char.ToLower(c));
|
||||
|
||||
inWord = true;
|
||||
}
|
||||
else if (char.IsDigit(c))
|
||||
{
|
||||
if (inWord)
|
||||
{
|
||||
sb.Append(' ');
|
||||
inWord = false;
|
||||
inNumber = true;
|
||||
}
|
||||
|
||||
sb.Append(c);
|
||||
}
|
||||
else if (inWord || inNumber)
|
||||
{
|
||||
sb.Append(' ');
|
||||
inWord = false;
|
||||
inNumber = false;
|
||||
wasUpper = false;
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user