added Steam.DownloadWorkshopItem and Steam.GetWorkshopItem
This commit is contained in:
@@ -232,4 +232,20 @@ Register("Microsoft.Xna.Framework.Vector4")
|
||||
Register("Microsoft.Xna.Framework.Color")
|
||||
Register("Microsoft.Xna.Framework.Point")
|
||||
Register("Microsoft.Xna.Framework.Rectangle")
|
||||
Register("Microsoft.Xna.Framework.Matrix")
|
||||
Register("Microsoft.Xna.Framework.Matrix")
|
||||
|
||||
local friend = Register("Steamworks.Friend")
|
||||
|
||||
LuaUserData.RemoveMember(friend, "InviteToGame")
|
||||
LuaUserData.RemoveMember(friend, "SendMessage")
|
||||
|
||||
local workshopItem = Register("Steamworks.Ugc.Item")
|
||||
|
||||
LuaUserData.RemoveMember(workshopItem, "Subscribe")
|
||||
LuaUserData.RemoveMember(workshopItem, "DownloadAsync")
|
||||
LuaUserData.RemoveMember(workshopItem, "Unsubscribe")
|
||||
LuaUserData.RemoveMember(workshopItem, "AddFavorite")
|
||||
LuaUserData.RemoveMember(workshopItem, "RemoveFavorite")
|
||||
LuaUserData.RemoveMember(workshopItem, "Vote")
|
||||
LuaUserData.RemoveMember(workshopItem, "GetUserVote")
|
||||
LuaUserData.RemoveMember(workshopItem, "Edit")
|
||||
@@ -103,6 +103,11 @@ namespace Barotrauma
|
||||
return DynValue.NewString(v.ToString());
|
||||
});
|
||||
|
||||
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.String, typeof(UInt64), v =>
|
||||
{
|
||||
return UInt64.Parse(v.String);
|
||||
});
|
||||
|
||||
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.UserData, typeof(object), v =>
|
||||
{
|
||||
if (v.UserData.Object is LuaByte lbyte)
|
||||
|
||||
@@ -60,6 +60,8 @@ namespace Barotrauma
|
||||
public LuaCsTimer Timer { get; private set; }
|
||||
|
||||
public LuaCsNetworking Networking { get; private set; }
|
||||
public LuaCsSteam Steam { get; private set; }
|
||||
|
||||
public LuaCsModStore ModStore { get; private set; }
|
||||
private LuaRequire require { get; set; }
|
||||
|
||||
@@ -301,6 +303,7 @@ namespace Barotrauma
|
||||
{
|
||||
Hook?.Update();
|
||||
Timer?.Update();
|
||||
Steam?.Update();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
@@ -325,6 +328,7 @@ namespace Barotrauma
|
||||
Game = new LuaGame();
|
||||
Networking = new LuaCsNetworking();
|
||||
Timer = new LuaCsTimer();
|
||||
Steam = new LuaCsSteam();
|
||||
LuaScriptLoader = null;
|
||||
lua = null;
|
||||
Lua = null;
|
||||
@@ -371,6 +375,7 @@ namespace Barotrauma
|
||||
Game = new LuaGame();
|
||||
Networking = new LuaCsNetworking();
|
||||
Timer = new LuaCsTimer();
|
||||
Steam = new LuaCsSteam();
|
||||
Hook.Initialize();
|
||||
ModStore.Initialize();
|
||||
|
||||
@@ -384,6 +389,7 @@ namespace Barotrauma
|
||||
UserData.RegisterType<LuaCsTimer>();
|
||||
UserData.RegisterType<LuaCsFile>();
|
||||
UserData.RegisterType<LuaCsNetworking>();
|
||||
UserData.RegisterType<LuaCsSteam>();
|
||||
UserData.RegisterType<LuaUserData>();
|
||||
UserData.RegisterType<IUserDataDescriptor>();
|
||||
|
||||
@@ -406,6 +412,7 @@ namespace Barotrauma
|
||||
lua.Globals["Timer"] = Timer;
|
||||
lua.Globals["File"] = UserData.CreateStatic<LuaCsFile>();
|
||||
lua.Globals["Networking"] = Networking;
|
||||
lua.Globals["Steam"] = Steam;
|
||||
|
||||
lua.Globals["SERVER"] = IsServer;
|
||||
lua.Globals["CLIENT"] = IsClient;
|
||||
|
||||
90
Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSteam.cs
Normal file
90
Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSteam.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using Steamworks;
|
||||
using Steamworks.Data;
|
||||
using Barotrauma.Steam;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class LuaCsSteam
|
||||
{
|
||||
private struct WorkshopItemDownload
|
||||
{
|
||||
public ulong ID;
|
||||
public string Destination;
|
||||
public LuaCsAction Callback;
|
||||
}
|
||||
|
||||
List<WorkshopItemDownload> itemsBeingDownloaded = new List<WorkshopItemDownload>();
|
||||
|
||||
public LuaCsSteam()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private async void DownloadWorkshopItemAsync(WorkshopItemDownload download)
|
||||
{
|
||||
Steamworks.Ugc.Item? item = await SteamManager.Workshop.GetItem(download.ID);
|
||||
|
||||
if (!item.HasValue) { return; }
|
||||
|
||||
if (item.Value.IsInstalled)
|
||||
{
|
||||
if (download.Callback != null)
|
||||
{
|
||||
Directory.Move(item.Value.Directory, download.Destination);
|
||||
download.Callback(item);
|
||||
}
|
||||
|
||||
itemsBeingDownloaded.Remove(download);
|
||||
return;
|
||||
}
|
||||
|
||||
SteamUGC.Download(item.Value.Id, true);
|
||||
|
||||
if (!itemsBeingDownloaded.Contains(download))
|
||||
{
|
||||
itemsBeingDownloaded.Add(download);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void DownloadWorkshopItem(ulong id, string destination, LuaCsAction callback)
|
||||
{
|
||||
if (!LuaCsFile.IsPathAllowedException(destination)) { return; }
|
||||
|
||||
DownloadWorkshopItemAsync(new WorkshopItemDownload()
|
||||
{
|
||||
ID = id,
|
||||
Destination = destination,
|
||||
Callback = callback
|
||||
});
|
||||
}
|
||||
|
||||
public void DownloadWorkshopItem(Steamworks.Ugc.Item item, string destination, LuaCsAction callback)
|
||||
{
|
||||
DownloadWorkshopItem(item.Id.Value, destination, callback);
|
||||
}
|
||||
|
||||
public async void GetWorkshopItem(UInt64 id, LuaCsAction callback)
|
||||
{
|
||||
Steamworks.Ugc.Item? item = await SteamManager.Workshop.GetItem(id);
|
||||
callback(item);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (itemsBeingDownloaded.Count > 0) // SteamUGC.OnDownloadItemResult for some reason doesn't work, so i need to do this stupid thing.
|
||||
{
|
||||
foreach (var item in itemsBeingDownloaded)
|
||||
{
|
||||
DownloadWorkshopItemAsync(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user