fixed reloadlua breaking __call metamethods, fixed singleplayer crash, added fun things to client-side lua :)
This commit is contained in:
@@ -998,6 +998,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
SoundManager?.Update();
|
SoundManager?.Update();
|
||||||
|
|
||||||
|
GameMain.Lua.hook.Call("think", new object[] { });
|
||||||
|
|
||||||
Timing.Accumulator -= Timing.Step;
|
Timing.Accumulator -= Timing.Step;
|
||||||
|
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Barotrauma.Networking;
|
||||||
|
|
||||||
|
namespace Barotrauma
|
||||||
|
{
|
||||||
|
partial class LuaSetup
|
||||||
|
{
|
||||||
|
public class LuaGUI
|
||||||
|
{
|
||||||
|
LuaSetup env;
|
||||||
|
public LuaGUI(LuaSetup _env)
|
||||||
|
{
|
||||||
|
env = _env;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatBox ChatBox
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return GameMain.Client.ChatBox;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2805,6 +2805,10 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
public override void AddChatMessage(ChatMessage message)
|
public override void AddChatMessage(ChatMessage message)
|
||||||
{
|
{
|
||||||
|
var should = new LuaResult(GameMain.Lua.hook.Call("chatMessage", new object[] { message.Text, message.SenderClient, message.Type, message }));
|
||||||
|
|
||||||
|
if (should.Bool()) return;
|
||||||
|
|
||||||
base.AddChatMessage(message);
|
base.AddChatMessage(message);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(message.Text)) { return; }
|
if (string.IsNullOrEmpty(message.Text)) { return; }
|
||||||
|
|||||||
@@ -365,7 +365,7 @@ namespace Barotrauma
|
|||||||
TaskPool.Update();
|
TaskPool.Update();
|
||||||
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
|
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
|
||||||
|
|
||||||
GameMain.Lua.hook.Call("think", new object[] { elapsedTime, Timing.TotalTime });
|
GameMain.Lua.hook.Call("think", new object[] { });
|
||||||
|
|
||||||
Timing.Accumulator -= Timing.Step;
|
Timing.Accumulator -= Timing.Step;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -554,8 +554,9 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public object Call(string name, object[] args)
|
public object Call(string name, object[] args)
|
||||||
{
|
{
|
||||||
|
if (env == null) return null;
|
||||||
if (name == null) return null;
|
if (name == null) return null;
|
||||||
if(args == null) { args = new object[] { }; }
|
if (args == null) { args = new object[] { }; }
|
||||||
|
|
||||||
if (!hookFunctions.ContainsKey(name))
|
if (!hookFunctions.ContainsKey(name))
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -204,15 +204,15 @@ namespace Barotrauma
|
|||||||
private void AddCallMetaMember(IUserDataDescriptor IUDD)
|
private void AddCallMetaMember(IUserDataDescriptor IUDD)
|
||||||
{
|
{
|
||||||
var descriptor = (StandardUserDataDescriptor)IUDD;
|
var descriptor = (StandardUserDataDescriptor)IUDD;
|
||||||
|
descriptor.RemoveMetaMember("__call");
|
||||||
descriptor.AddMetaMember("__call", new ObjectCallbackMemberDescriptor("__call", HandleCall));
|
descriptor.AddMetaMember("__call", new ObjectCallbackMemberDescriptor("__call", HandleCall));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
|
hook = new LuaHook(null);
|
||||||
lua = null;
|
game = new LuaGame(null);
|
||||||
hook = null;
|
networking = new LuaNetworking(null);
|
||||||
game = null;
|
|
||||||
luaScriptLoader = null;
|
luaScriptLoader = null;
|
||||||
|
|
||||||
luaSetup = null;
|
luaSetup = null;
|
||||||
@@ -321,8 +321,14 @@ namespace Barotrauma
|
|||||||
AddCallMetaMember(UserData.RegisterType<Vector4>());
|
AddCallMetaMember(UserData.RegisterType<Vector4>());
|
||||||
AddCallMetaMember(UserData.RegisterType<CharacterInfo>());
|
AddCallMetaMember(UserData.RegisterType<CharacterInfo>());
|
||||||
AddCallMetaMember(UserData.RegisterType<Signal>());
|
AddCallMetaMember(UserData.RegisterType<Signal>());
|
||||||
|
AddCallMetaMember(UserData.RegisterType<Color>());
|
||||||
|
|
||||||
|
#if SERVER
|
||||||
|
|
||||||
|
#elif CLIENT
|
||||||
|
UserData.RegisterType<LuaGUI>();
|
||||||
|
UserData.RegisterType<ChatBox>();
|
||||||
|
#endif
|
||||||
lua = new Script(CoreModules.Preset_SoftSandbox);
|
lua = new Script(CoreModules.Preset_SoftSandbox);
|
||||||
|
|
||||||
lua.Options.DebugPrint = PrintMessage;
|
lua.Options.DebugPrint = PrintMessage;
|
||||||
@@ -373,6 +379,7 @@ namespace Barotrauma
|
|||||||
lua.Globals["Vector2"] = UserData.CreateStatic<Vector2>();
|
lua.Globals["Vector2"] = UserData.CreateStatic<Vector2>();
|
||||||
lua.Globals["Vector3"] = UserData.CreateStatic<Vector3>();
|
lua.Globals["Vector3"] = UserData.CreateStatic<Vector3>();
|
||||||
lua.Globals["Vector4"] = UserData.CreateStatic<Vector4>();
|
lua.Globals["Vector4"] = UserData.CreateStatic<Vector4>();
|
||||||
|
lua.Globals["Color"] = UserData.CreateStatic<Color>();
|
||||||
lua.Globals["ChatMessage"] = UserData.CreateStatic<ChatMessage>();
|
lua.Globals["ChatMessage"] = UserData.CreateStatic<ChatMessage>();
|
||||||
lua.Globals["Hull"] = UserData.CreateStatic<Hull>();
|
lua.Globals["Hull"] = UserData.CreateStatic<Hull>();
|
||||||
lua.Globals["InvSlotType"] = UserData.CreateStatic<InvSlotType>();
|
lua.Globals["InvSlotType"] = UserData.CreateStatic<InvSlotType>();
|
||||||
@@ -384,6 +391,13 @@ namespace Barotrauma
|
|||||||
lua.Globals["ClientPacketHeader"] = UserData.CreateStatic<ClientPacketHeader>();
|
lua.Globals["ClientPacketHeader"] = UserData.CreateStatic<ClientPacketHeader>();
|
||||||
lua.Globals["ServerPacketHeader"] = UserData.CreateStatic<ServerPacketHeader>();
|
lua.Globals["ServerPacketHeader"] = UserData.CreateStatic<ServerPacketHeader>();
|
||||||
|
|
||||||
|
#if SERVER
|
||||||
|
|
||||||
|
#elif CLIENT
|
||||||
|
lua.Globals["GUI"] = new LuaGUI(this);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// obsolete
|
// obsolete
|
||||||
lua.Globals["CreateVector2"] = (Func<float, float, Vector2>)CreateVector2;
|
lua.Globals["CreateVector2"] = (Func<float, float, Vector2>)CreateVector2;
|
||||||
lua.Globals["CreateVector3"] = (Func<float, float, float, Vector3>)CreateVector3;
|
lua.Globals["CreateVector3"] = (Func<float, float, float, Vector3>)CreateVector3;
|
||||||
@@ -424,7 +438,9 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public LuaSetup()
|
public LuaSetup()
|
||||||
{
|
{
|
||||||
|
hook = new LuaHook(null);
|
||||||
|
game = new LuaGame(null);
|
||||||
|
networking = new LuaNetworking(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,9 +79,16 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
public readonly string SenderName;
|
public readonly string SenderName;
|
||||||
|
|
||||||
|
private Color? customColor = null;
|
||||||
|
|
||||||
public Color Color
|
public Color Color
|
||||||
{
|
{
|
||||||
get { return MessageColor[(int)Type]; }
|
get
|
||||||
|
{
|
||||||
|
if(customColor == null) return MessageColor[(int)Type];
|
||||||
|
return (Color)customColor;
|
||||||
|
}
|
||||||
|
set { customColor = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetTimeStamp()
|
public static string GetTimeStamp()
|
||||||
|
|||||||
Reference in New Issue
Block a user