Started mod unloading/loading
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
using System;
|
||||
using Sandbox.Definitions;
|
||||
using Sandbox.Engine.Networking;
|
||||
using Sandbox.Game.World;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using VRage.Game;
|
||||
|
||||
namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
{
|
||||
public class ModLoader
|
||||
public static class ModLoader
|
||||
{
|
||||
/* Mod loader should download and load missing mods for target server, and unload ones that arent needed
|
||||
*
|
||||
@@ -22,5 +27,80 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
//Mods that are currently loaded in this instance.
|
||||
private static List<MyObjectBuilder_Checkpoint.ModItem> CurrentLoadedMods = new List<MyObjectBuilder_Checkpoint.ModItem>();
|
||||
|
||||
//Mods that we are switching to.
|
||||
private static List<MyObjectBuilder_Checkpoint.ModItem> TargetServerMods = new List<MyObjectBuilder_Checkpoint.ModItem>();
|
||||
|
||||
|
||||
private static bool FinishedDownloadingMods = false;
|
||||
private static bool DownloadSuccess = false;
|
||||
|
||||
private static DateTime DownloadTimeout;
|
||||
|
||||
|
||||
|
||||
|
||||
public static void DownloadNewMods(List<MyObjectBuilder_Checkpoint.ModItem> Target)
|
||||
{
|
||||
CurrentLoadedMods = MySession.Static.Mods;
|
||||
TargetServerMods = Target;
|
||||
|
||||
|
||||
DownloadTimeout = DateTime.Now + TimeSpan.FromMinutes(5);
|
||||
SeamlessClient.TryShow("Downloading New Mods");
|
||||
MyWorkshop.DownloadModsAsync(Target, ModDownloadingFinished);
|
||||
|
||||
}
|
||||
|
||||
private static void ModDownloadingFinished(bool Success)
|
||||
{
|
||||
if (Success)
|
||||
{
|
||||
SeamlessClient.TryShow("Mod Downloading Finished!");
|
||||
FinishedDownloadingMods = true;
|
||||
DownloadSuccess = true;
|
||||
//May need to wait seamless loading if mods have yet to finish downloading
|
||||
}
|
||||
else
|
||||
{
|
||||
DownloadSuccess = false;
|
||||
FinishedDownloadingMods = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadyModSwitch()
|
||||
{
|
||||
|
||||
while (!FinishedDownloadingMods)
|
||||
{
|
||||
|
||||
//Break out of loop
|
||||
if (DownloadTimeout < DateTime.Now)
|
||||
break;
|
||||
|
||||
|
||||
Thread.Sleep(20);
|
||||
}
|
||||
|
||||
FinishedDownloadingMods = false;
|
||||
|
||||
//Skip mod switch
|
||||
if (!DownloadSuccess)
|
||||
return;
|
||||
|
||||
MySession.Static.ScriptManager.LoadData();
|
||||
MyDefinitionManager.Static.LoadData(TargetServerMods);
|
||||
MyLocalCache.PreloadLocalInventoryConfig();
|
||||
SeamlessClient.TryShow("Finished transfering!");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user