Unhardcode modchooser mod for content installation.

This commit is contained in:
Paul Chote
2017-01-27 17:07:55 +00:00
parent 657ba90ae3
commit 9b6afd3c37
5 changed files with 29 additions and 11 deletions

View File

@@ -379,16 +379,12 @@ namespace OpenRA
ModData = new ModData(Mods[mod], Mods, true);
ExternalMods.Register(ModData.Manifest);
if (!ModData.LoadScreen.BeforeLoad())
return;
using (new PerfTimer("LoadMaps"))
ModData.MapCache.LoadMaps();
// Mod assets are missing!
if (!ModData.LoadScreen.RequiredContentIsInstalled())
{
InitializeMod("modchooser", new Arguments());
return;
}
ModData.InitializeLoaders(ModData.DefaultFileSystem);
Renderer.InitializeFonts(ModData);

View File

@@ -222,9 +222,19 @@ namespace OpenRA
public interface ILoadScreen : IDisposable
{
/// <summary>Initializes the loadscreen with yaml data from the LoadScreen block in mod.yaml.</summary>
void Init(ModData m, Dictionary<string, string> info);
/// <summary>Called at arbitrary times during mod load to rerender the loadscreen.</summary>
void Display();
bool RequiredContentIsInstalled();
/// <summary>
/// Called before loading the mod assets.
/// Returns false if mod loading should be aborted (e.g. switching to another mod instead).
/// </summary>
bool BeforeLoad();
/// <summary>Called when the engine expects to connect to a server/replay or load the shellmap.</summary>
void StartGame(Arguments args);
}
}

View File

@@ -109,12 +109,23 @@ namespace OpenRA.Mods.Common.LoadScreens
GC.SuppressFinalize(this);
}
public bool RequiredContentIsInstalled()
public bool BeforeLoad()
{
// If a ModContent section is defined then we need to make sure that the
// required content is installed or switch to the defined content installer.
if (!modData.Manifest.Contains<ModContent>())
return true;
var content = modData.Manifest.Get<ModContent>();
return content.Packages
var contentInstalled = content.Packages
.Where(p => p.Value.Required)
.All(p => p.Value.TestFiles.All(f => File.Exists(Platform.ResolvePath(f))));
if (contentInstalled)
return true;
Game.InitializeMod(content.ContentInstallerMod, new Arguments());
return false;
}
}
}

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.LoadScreens
sprite.Sheet.Dispose();
}
public bool RequiredContentIsInstalled()
public bool BeforeLoad()
{
return true;
}

View File

@@ -85,6 +85,7 @@ namespace OpenRA
public readonly string InstallPromptMessage;
public readonly string QuickDownload;
public readonly string HeaderMessage;
public readonly string ContentInstallerMod = "modchooser";
[FieldLoader.LoadUsing("LoadPackages")]
public readonly Dictionary<string, ModPackage> Packages = new Dictionary<string, ModPackage>();