texture loader and option support
This commit is contained in:
@@ -27,6 +27,7 @@ defaultLib["BackgroundMusic"] = CreateStatic("Barotrauma.BackgroundMusic", true)
|
||||
defaultLib["GUISound"] = CreateStatic("Barotrauma.GUISound", true)
|
||||
defaultLib["DamageSound"] = CreateStatic("Barotrauma.DamageSound", true)
|
||||
|
||||
defaultLib["TextureLoader"] = CreateStatic("Barotrauma.TextureLoader")
|
||||
defaultLib["Sprite"] = CreateStatic("Barotrauma.Sprite", true)
|
||||
defaultLib["PlayerInput"] = CreateStatic("Barotrauma.PlayerInput", true)
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ Register("EventInput.KeyEventArgs")
|
||||
Register("Microsoft.Xna.Framework.Input.Keys")
|
||||
Register("Microsoft.Xna.Framework.Input.KeyboardState")
|
||||
|
||||
RegisterBarotrauma("TextureLoader")
|
||||
RegisterBarotrauma("Sprite")
|
||||
RegisterBarotrauma("GUI")
|
||||
RegisterBarotrauma("GUIStyle")
|
||||
|
||||
@@ -186,6 +186,31 @@ namespace Barotrauma
|
||||
converter: luaValue => luaValue.UserData.Object is LuaDouble v
|
||||
? (double)v
|
||||
: throw new ScriptRuntimeException("use Double(value) to pass primitive type 'double' to C#"));
|
||||
|
||||
RegisterOption<Character>();
|
||||
RegisterOption<Barotrauma.Networking.AccountId>();
|
||||
RegisterOption<int>();
|
||||
}
|
||||
|
||||
private void RegisterOption<T>()
|
||||
{
|
||||
Script.GlobalOptions.CustomConverters.SetClrToScriptCustomConversion(typeof(Option<T>), (Script v, object obj) =>
|
||||
{
|
||||
if (obj is Option<T> option)
|
||||
{
|
||||
if (option.TryUnwrap(out T outValue))
|
||||
{
|
||||
return UserData.Create(outValue);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.UserData, typeof(Option<T>), v =>
|
||||
{
|
||||
return Option<T>.Some(v.ToObject<T>());
|
||||
});
|
||||
}
|
||||
|
||||
private void RegisterAction<T>()
|
||||
|
||||
Reference in New Issue
Block a user