better LuaUserData error handling and add Steam.GetWorkshopCollection
This commit is contained in:
@@ -4,6 +4,8 @@ local AddCallMetaTable = LuaSetup.AddCallMetaTable
|
|||||||
local CreateStatic = LuaSetup.CreateStatic
|
local CreateStatic = LuaSetup.CreateStatic
|
||||||
local CreateEnum = LuaUserData.CreateEnumTable
|
local CreateEnum = LuaUserData.CreateEnumTable
|
||||||
|
|
||||||
|
require("DefaultLib/Utils/SteamApi")
|
||||||
|
|
||||||
defaultLib["Byte"] = CreateStatic("Barotrauma.LuaByte", true)
|
defaultLib["Byte"] = CreateStatic("Barotrauma.LuaByte", true)
|
||||||
defaultLib["UShort"] = CreateStatic("Barotrauma.LuaUShort", true)
|
defaultLib["UShort"] = CreateStatic("Barotrauma.LuaUShort", true)
|
||||||
defaultLib["Float"] = CreateStatic("Barotrauma.LuaFloat", true)
|
defaultLib["Float"] = CreateStatic("Barotrauma.LuaFloat", true)
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
local descriptor = LuaUserData.RegisterType("Barotrauma.LuaCsSteam")
|
||||||
|
|
||||||
|
LuaUserData.AddMethod(descriptor, "GetWorkshopCollection", function (id, callback)
|
||||||
|
id = tostring(id)
|
||||||
|
|
||||||
|
Networking.RequestPostHTTP("https://api.steampowered.com/ISteamRemoteStorage/GetCollectionDetails/v1/", function (result)
|
||||||
|
local data = json.parse(result)
|
||||||
|
|
||||||
|
if data.response.collectiondetails.children == nil then
|
||||||
|
callback()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local workshopItems = {}
|
||||||
|
|
||||||
|
for key, value in pairs(data.response.collectiondetails[1].children) do
|
||||||
|
table.insert(workshopItems, value.publishedfileid)
|
||||||
|
end
|
||||||
|
|
||||||
|
if callback then
|
||||||
|
callback(workshopItems)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
"collectioncount=1&publishedfileids[0]=" .. id,
|
||||||
|
"application/x-www-form-urlencoded")
|
||||||
|
end)
|
||||||
@@ -34,8 +34,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (type == null)
|
if (type == null)
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.HandleException(new Exception($"Tried to register a type that doesn't exist: {typeName}."));
|
throw new ScriptRuntimeException($"Tried to register a type that doesn't exist: {typeName}.");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return UserData.RegisterType(type);
|
return UserData.RegisterType(type);
|
||||||
@@ -47,8 +46,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (type == null)
|
if (type == null)
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.HandleException(new Exception($"Tried to unregister a type that doesn't exist: {typeName}."));
|
throw new ScriptRuntimeException($"Tried to unregister a type that doesn't exist: {typeName}.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UserData.UnregisterType(type);
|
UserData.UnregisterType(type);
|
||||||
@@ -85,8 +83,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (type == null)
|
if (type == null)
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.HandleException(new Exception($"Tried to create a static userdata of a type that doesn't exist: {typeName}."));
|
throw new ScriptRuntimeException($"Tried to create a static userdata of a type that doesn't exist: {typeName}.");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodInfo method = typeof(UserData).GetMethod(nameof(UserData.CreateStatic), 1, new Type[0]);
|
MethodInfo method = typeof(UserData).GetMethod(nameof(UserData.CreateStatic), 1, new Type[0]);
|
||||||
@@ -100,8 +97,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (type == null)
|
if (type == null)
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.HandleException(new Exception($"Tried to create an enum table with a type that doesn't exist:: {typeName}."));
|
throw new ScriptRuntimeException($"Tried to create an enum table with a type that doesn't exist:: {typeName}.");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<string, object> result = new Dictionary<string, object>();
|
Dictionary<string, object> result = new Dictionary<string, object>();
|
||||||
@@ -132,8 +128,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (IUUD == null)
|
if (IUUD == null)
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.HandleException(new Exception($"Tried to use a UserDataDescriptor that is null to make {fieldName} accessible."));
|
throw new ScriptRuntimeException($"Tried to use a UserDataDescriptor that is null to make {fieldName} accessible.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var descriptor = (StandardUserDataDescriptor)IUUD;
|
var descriptor = (StandardUserDataDescriptor)IUUD;
|
||||||
@@ -146,8 +141,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (field == null)
|
if (field == null)
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.HandleException(new Exception($"Tried to make field '{fieldName}' accessible, but the field doesn't exist."));
|
throw new ScriptRuntimeException($"Tried to make field '{fieldName}' accessible, but the field doesn't exist.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptor.RemoveMember(fieldName);
|
descriptor.RemoveMember(fieldName);
|
||||||
@@ -170,8 +164,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (IUUD == null)
|
if (IUUD == null)
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.HandleException(new Exception($"Tried to use a UserDataDescriptor that is null to make {methodName} accessible."));
|
throw new ScriptRuntimeException($"Tried to use a UserDataDescriptor that is null to make {methodName} accessible.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var descriptor = (StandardUserDataDescriptor)IUUD;
|
var descriptor = (StandardUserDataDescriptor)IUUD;
|
||||||
@@ -184,8 +177,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (method == null)
|
if (method == null)
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.HandleException(new Exception($"Tried to make method '{methodName}' accessible, but the method doesn't exist."));
|
throw new ScriptRuntimeException($"Tried to make method '{methodName}' accessible, but the method doesn't exist.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptor.RemoveMember(methodName);
|
descriptor.RemoveMember(methodName);
|
||||||
@@ -196,8 +188,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (IUUD == null)
|
if (IUUD == null)
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.HandleException(new Exception($"Tried to use a UserDataDescriptor that is null to add method {methodName}."));
|
throw new ScriptRuntimeException($"Tried to use a UserDataDescriptor that is null to add method {methodName}.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var descriptor = (StandardUserDataDescriptor)IUUD;
|
var descriptor = (StandardUserDataDescriptor)IUUD;
|
||||||
@@ -210,12 +201,23 @@ namespace Barotrauma
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void AddField(IUserDataDescriptor IUUD, string fieldName, DynValue value)
|
||||||
|
{
|
||||||
|
if (IUUD == null)
|
||||||
|
{
|
||||||
|
throw new ScriptRuntimeException($"Tried to use a UserDataDescriptor that is null to add field {fieldName}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var descriptor = (StandardUserDataDescriptor)IUUD;
|
||||||
|
descriptor.RemoveMember(fieldName);
|
||||||
|
descriptor.AddMember(fieldName, new DynValueMemberDescriptor(fieldName, value));
|
||||||
|
}
|
||||||
|
|
||||||
public static void RemoveMember(IUserDataDescriptor IUUD, string memberName)
|
public static void RemoveMember(IUserDataDescriptor IUUD, string memberName)
|
||||||
{
|
{
|
||||||
if (IUUD == null)
|
if (IUUD == null)
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.HandleException(new Exception($"Tried to use a UserDataDescriptor that is null to remove the member {memberName}."));
|
throw new ScriptRuntimeException($"Tried to use a UserDataDescriptor that is null to remove the member {memberName}.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var descriptor = (StandardUserDataDescriptor)IUUD;
|
var descriptor = (StandardUserDataDescriptor)IUUD;
|
||||||
|
|||||||
Reference in New Issue
Block a user