Most enums are now just tables, no need for registration

This commit is contained in:
Evil Factory
2022-04-02 16:55:43 -03:00
parent 4113b1ca2d
commit 2520fe7268
3 changed files with 47 additions and 60 deletions
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using MoonSharp.Interpreter;
@@ -87,6 +88,28 @@ namespace Barotrauma
return generic.Invoke(null, null);
}
public static object CreateEnumTable(string typeName)
{
Type type = GetType(typeName);
if (type == null)
{
GameMain.Lua.HandleLuaException(new Exception($"Tried to create an enum table with a type that doesn't exist:: {typeName}."));
return null;
}
Dictionary<string, object> result = new Dictionary<string, object>();
foreach (var value in Enum.GetValues(type))
{
string name = Enum.GetName(type, value);
result[name] = value;
}
return result;
}
public static void MakeFieldAccessible(IUserDataDescriptor IUUD, string fieldName)
{
if (IUUD == null)