refactor: no more dynvalues or userdatas
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user