diff --git a/Barotrauma/BarotraumaShared/Lua/DefaultLib/LibShared.lua b/Barotrauma/BarotraumaShared/Lua/DefaultLib/LibShared.lua index 7bc3f1f56..84e949d51 100644 --- a/Barotrauma/BarotraumaShared/Lua/DefaultLib/LibShared.lua +++ b/Barotrauma/BarotraumaShared/Lua/DefaultLib/LibShared.lua @@ -4,6 +4,8 @@ local AddCallMetaTable = LuaSetup.AddCallMetaTable local CreateStatic = LuaSetup.CreateStatic local CreateEnum = LuaUserData.CreateEnumTable +require("DefaultLib/Utils/SteamApi") + defaultLib["Byte"] = CreateStatic("Barotrauma.LuaByte", true) defaultLib["UShort"] = CreateStatic("Barotrauma.LuaUShort", true) defaultLib["Float"] = CreateStatic("Barotrauma.LuaFloat", true) diff --git a/Barotrauma/BarotraumaShared/Lua/DefaultLib/Utils/SteamApi.lua b/Barotrauma/BarotraumaShared/Lua/DefaultLib/Utils/SteamApi.lua new file mode 100644 index 000000000..1f9e74979 --- /dev/null +++ b/Barotrauma/BarotraumaShared/Lua/DefaultLib/Utils/SteamApi.lua @@ -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) \ No newline at end of file diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Lua/LuaClasses/LuaUserData.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Lua/LuaClasses/LuaUserData.cs index 650cf9d54..184dd852b 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Lua/LuaClasses/LuaUserData.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Lua/LuaClasses/LuaUserData.cs @@ -34,8 +34,7 @@ namespace Barotrauma if (type == null) { - GameMain.LuaCs.HandleException(new Exception($"Tried to register a type that doesn't exist: {typeName}.")); - return null; + throw new ScriptRuntimeException($"Tried to register a type that doesn't exist: {typeName}."); } return UserData.RegisterType(type); @@ -47,8 +46,7 @@ namespace Barotrauma if (type == null) { - GameMain.LuaCs.HandleException(new Exception($"Tried to unregister a type that doesn't exist: {typeName}.")); - return; + throw new ScriptRuntimeException($"Tried to unregister a type that doesn't exist: {typeName}."); } UserData.UnregisterType(type); @@ -85,8 +83,7 @@ namespace Barotrauma if (type == null) { - GameMain.LuaCs.HandleException(new Exception($"Tried to create a static userdata of a type that doesn't exist: {typeName}.")); - return null; + throw new ScriptRuntimeException($"Tried to create a static userdata of a type that doesn't exist: {typeName}."); } MethodInfo method = typeof(UserData).GetMethod(nameof(UserData.CreateStatic), 1, new Type[0]); @@ -100,8 +97,7 @@ namespace Barotrauma if (type == null) { - GameMain.LuaCs.HandleException(new Exception($"Tried to create an enum table with a type that doesn't exist:: {typeName}.")); - return null; + throw new ScriptRuntimeException($"Tried to create an enum table with a type that doesn't exist:: {typeName}."); } Dictionary result = new Dictionary(); @@ -132,8 +128,7 @@ namespace Barotrauma { if (IUUD == null) { - GameMain.LuaCs.HandleException(new Exception($"Tried to use a UserDataDescriptor that is null to make {fieldName} accessible.")); - return; + throw new ScriptRuntimeException($"Tried to use a UserDataDescriptor that is null to make {fieldName} accessible."); } var descriptor = (StandardUserDataDescriptor)IUUD; @@ -146,8 +141,7 @@ namespace Barotrauma if (field == null) { - GameMain.LuaCs.HandleException(new Exception($"Tried to make field '{fieldName}' accessible, but the field doesn't exist.")); - return; + throw new ScriptRuntimeException($"Tried to make field '{fieldName}' accessible, but the field doesn't exist."); } descriptor.RemoveMember(fieldName); @@ -170,8 +164,7 @@ namespace Barotrauma { if (IUUD == null) { - GameMain.LuaCs.HandleException(new Exception($"Tried to use a UserDataDescriptor that is null to make {methodName} accessible.")); - return; + throw new ScriptRuntimeException($"Tried to use a UserDataDescriptor that is null to make {methodName} accessible."); } var descriptor = (StandardUserDataDescriptor)IUUD; @@ -184,8 +177,7 @@ namespace Barotrauma if (method == null) { - GameMain.LuaCs.HandleException(new Exception($"Tried to make method '{methodName}' accessible, but the method doesn't exist.")); - return; + throw new ScriptRuntimeException($"Tried to make method '{methodName}' accessible, but the method doesn't exist."); } descriptor.RemoveMember(methodName); @@ -196,8 +188,7 @@ namespace Barotrauma { if (IUUD == null) { - GameMain.LuaCs.HandleException(new Exception($"Tried to use a UserDataDescriptor that is null to add method {methodName}.")); - return; + throw new ScriptRuntimeException($"Tried to use a UserDataDescriptor that is null to add method {methodName}."); } 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) { if (IUUD == null) { - GameMain.LuaCs.HandleException(new Exception($"Tried to use a UserDataDescriptor that is null to remove the member {memberName}.")); - return; + throw new ScriptRuntimeException($"Tried to use a UserDataDescriptor that is null to remove the member {memberName}."); } var descriptor = (StandardUserDataDescriptor)IUUD;