refactor: no more dynvalues or userdatas
This commit is contained in:
@@ -366,7 +366,7 @@ namespace Barotrauma
|
||||
TaskPool.Update();
|
||||
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
|
||||
|
||||
GameMain.Lua.hook.Call("think", new DynValue[] { DynValue.NewNumber(elapsedTime), DynValue.NewNumber(Timing.TotalTime) });
|
||||
GameMain.Lua.hook.Call("think", new object[] { elapsedTime, Timing.TotalTime });
|
||||
|
||||
Timing.Accumulator -= Timing.Step;
|
||||
}
|
||||
|
||||
@@ -31,28 +31,15 @@ namespace Barotrauma
|
||||
private class LuaPlayer
|
||||
{
|
||||
|
||||
public static List<DynValue> GetAllCharacters()
|
||||
public static List<Character> GetAllCharacters()
|
||||
{
|
||||
List<DynValue> values = new List<DynValue>();
|
||||
|
||||
foreach (Character ch in Character.CharacterList)
|
||||
{
|
||||
values.Add(UserData.Create(ch));
|
||||
}
|
||||
|
||||
return values;
|
||||
return Character.CharacterList;
|
||||
}
|
||||
|
||||
public static List<DynValue> GetAllClients()
|
||||
public static List<Client> GetAllClients()
|
||||
{
|
||||
List<DynValue> values = new List<DynValue>();
|
||||
|
||||
foreach (Client ch in GameMain.Server.ConnectedClients)
|
||||
{
|
||||
values.Add(UserData.Create(ch));
|
||||
}
|
||||
|
||||
return values;
|
||||
return GameMain.Server.ConnectedClients;
|
||||
}
|
||||
|
||||
public static CharacterInfo CreateCharacterInfo(string speciesName, string name = "", JobPrefab jobPrefab = null, string ragdollFileName = null, int variant = 0, Rand.RandSync randSync = Rand.RandSync.Unsynced)
|
||||
@@ -364,12 +351,6 @@ namespace Barotrauma
|
||||
env = e;
|
||||
}
|
||||
|
||||
public void Simple(int time, DynValue function)
|
||||
{
|
||||
|
||||
Task.Delay(time).ContinueWith(o => { env.RunFunction(function); });
|
||||
}
|
||||
|
||||
public static double GetTime()
|
||||
{
|
||||
return Timing.TotalTime;
|
||||
@@ -469,15 +450,6 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
// hooks:
|
||||
// chatMessage
|
||||
// think
|
||||
// update
|
||||
// clientConnected
|
||||
// clientDisconnected
|
||||
// roundStart
|
||||
// roundEnd
|
||||
|
||||
public class LuaHook
|
||||
{
|
||||
public LuaSetup env;
|
||||
@@ -491,9 +463,9 @@ namespace Barotrauma
|
||||
{
|
||||
public string name;
|
||||
public string hookName;
|
||||
public DynValue function;
|
||||
public object function;
|
||||
|
||||
public HookFunction(string n, string hn, DynValue func)
|
||||
public HookFunction(string n, string hn, object func)
|
||||
{
|
||||
name = n;
|
||||
hookName = hn;
|
||||
@@ -503,7 +475,7 @@ namespace Barotrauma
|
||||
|
||||
public List<HookFunction> hookFunctions = new List<HookFunction>();
|
||||
|
||||
public void Add(string name, string hookName, DynValue function)
|
||||
public void Add(string name, string hookName, object function)
|
||||
{
|
||||
foreach (HookFunction hf in hookFunctions)
|
||||
{
|
||||
@@ -518,7 +490,7 @@ namespace Barotrauma
|
||||
hookFunctions.Add(new HookFunction(name, hookName, function));
|
||||
}
|
||||
|
||||
public DynValue Call(string name, DynValue[] args)
|
||||
public object Call(string name, object[] args)
|
||||
{
|
||||
foreach (HookFunction hf in hookFunctions)
|
||||
{
|
||||
|
||||
@@ -13,46 +13,6 @@ namespace Barotrauma
|
||||
public static void RegisterAll()
|
||||
{
|
||||
|
||||
/* // Vector 2
|
||||
|
||||
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Table, typeof(Vector2),
|
||||
dynVal => {
|
||||
Table table = dynVal.Table;
|
||||
float x = (float)((Double)table[1]);
|
||||
float y = (float)((Double)table[2]);
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
);
|
||||
Script.GlobalOptions.CustomConverters.SetClrToScriptCustomConversion<Vector2>(
|
||||
(script, vector) => {
|
||||
DynValue x = DynValue.NewNumber((double)vector.X);
|
||||
DynValue y = DynValue.NewNumber((double)vector.Y);
|
||||
DynValue dynVal = DynValue.NewTable(script, new DynValue[] { x, y });
|
||||
return dynVal;
|
||||
}
|
||||
);
|
||||
|
||||
// Vector3
|
||||
|
||||
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Table, typeof(Vector3),
|
||||
dynVal => {
|
||||
Table table = dynVal.Table;
|
||||
float x = (float)((Double)table[1]);
|
||||
float y = (float)((Double)table[2]);
|
||||
float z = (float)((Double)table[3]);
|
||||
return new Vector3(x, y, z);
|
||||
}
|
||||
);
|
||||
Script.GlobalOptions.CustomConverters.SetClrToScriptCustomConversion<Vector3>(
|
||||
(script, vector) => {
|
||||
DynValue x = DynValue.NewNumber((double)vector.X);
|
||||
DynValue y = DynValue.NewNumber((double)vector.Y);
|
||||
DynValue z = DynValue.NewNumber((double)vector.Z);
|
||||
DynValue dynVal = DynValue.NewTable(script, new DynValue[] { x, y, z });
|
||||
return dynVal;
|
||||
}
|
||||
);*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Microsoft.Xna.Framework;
|
||||
using System.Threading.Tasks;
|
||||
using Barotrauma.Items.Components;
|
||||
using System.Diagnostics;
|
||||
using NLua;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -56,19 +57,6 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void RunFunction(DynValue func)
|
||||
{
|
||||
try
|
||||
{
|
||||
lua.Call(func);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
HandleLuaException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public DynValue DoFile(string file)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -117,19 +117,18 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
var should = GameMain.Lua.hook.Call("chatMessage", new DynValue[] { DynValue.NewString(txt), UserData.Create(c), UserData.Create(type) });
|
||||
var should = GameMain.Lua.hook.Call("chatMessage", new object[] { txt, c, type });
|
||||
|
||||
|
||||
if(should != null)
|
||||
{
|
||||
if (should.CastToBool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
if (should is DynValue dyn)
|
||||
{
|
||||
if (dyn.CastToBool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == ChatMessageType.Order)
|
||||
|
||||
@@ -310,7 +310,7 @@ namespace Barotrauma.Networking
|
||||
SendConsoleMessage("Granted all permissions to " + newClient.Name + ".", newClient);
|
||||
}
|
||||
|
||||
GameMain.Lua.hook.Call("clientConnected", new MoonSharp.Interpreter.DynValue[] { MoonSharp.Interpreter.UserData.Create(newClient) });
|
||||
GameMain.Lua.hook.Call("clientConnected", new object[] { newClient });
|
||||
|
||||
|
||||
SendChatMessage($"ServerMessage.JoinedServer~[client]={clName}", ChatMessageType.Server, null, changeType: PlayerConnectionChangeType.Joined);
|
||||
@@ -2439,7 +2439,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
roundStartTime = DateTime.Now;
|
||||
|
||||
GameMain.Lua.hook.Call("roundStart", new MoonSharp.Interpreter.DynValue[] { });
|
||||
GameMain.Lua.hook.Call("roundStart", new object[] { });
|
||||
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
@@ -2561,7 +2561,7 @@ namespace Barotrauma.Networking
|
||||
Log("Ending the round...", ServerLog.MessageType.ServerMessage);
|
||||
}
|
||||
|
||||
GameMain.Lua.hook.Call("roundEnd", new MoonSharp.Interpreter.DynValue[] { });
|
||||
GameMain.Lua.hook.Call("roundEnd", new object[] { });
|
||||
|
||||
|
||||
string endMessage = TextManager.FormatServerMessage("RoundSummaryRoundHasEnded");
|
||||
@@ -2857,7 +2857,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (client == null) return;
|
||||
|
||||
GameMain.Lua.hook.Call("clientDisconnected", new MoonSharp.Interpreter.DynValue[] { MoonSharp.Interpreter.UserData.Create(client) });
|
||||
GameMain.Lua.hook.Call("clientDisconnected", new object[] { client });
|
||||
|
||||
if (gameStarted && client.Character != null)
|
||||
{
|
||||
@@ -3107,10 +3107,18 @@ namespace Barotrauma.Networking
|
||||
|
||||
var hookChatMsg = ChatMessage.Create(senderName, message, (ChatMessageType)type, senderCharacter, senderClient, changeType);
|
||||
|
||||
var should = GameMain.Lua.hook.Call("modifyChatMessage", new DynValue[] { UserData.Create(hookChatMsg), LuaSetup.CreateUserDataSafe(senderRadio) });
|
||||
var should = GameMain.Lua.hook.Call("modifyChatMessage", new object[] { hookChatMsg, senderRadio });
|
||||
|
||||
if (should != null && should.CastToBool())
|
||||
return;
|
||||
if (should != null)
|
||||
{
|
||||
if (should is DynValue dyn)
|
||||
{
|
||||
if (dyn.CastToBool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check which clients can receive the message and apply distance effects
|
||||
foreach (Client client in ConnectedClients)
|
||||
|
||||
@@ -94,10 +94,15 @@ namespace Barotrauma.Networking
|
||||
ChatMessage.CanUseRadio(sender.Character, out WifiComponent senderRadio) &&
|
||||
ChatMessage.CanUseRadio(recipient.Character, out WifiComponent recipientRadio))
|
||||
{
|
||||
var should = GameMain.Lua.hook.Call("canUseVoiceRadio", new DynValue[] { UserData.Create(sender), LuaSetup.CreateUserDataSafe(recipient) });
|
||||
var should = GameMain.Lua.hook.Call("canUseVoiceRadio", new object[] { sender, recipient });
|
||||
|
||||
if (should != null)
|
||||
return should.CastToBool();
|
||||
{
|
||||
if (should is DynValue dyn)
|
||||
{
|
||||
return dyn.CastToBool();
|
||||
}
|
||||
}
|
||||
|
||||
if (recipientRadio.CanReceive(senderRadio)) { return true; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user