Route content check via FileSystemLoader.
This allows mods with custom content requirements to use the default load screen implementations.
This commit is contained in:
@@ -10,10 +10,19 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.FileSystem
|
||||
{
|
||||
public class DefaultFileSystemLoader : IFileSystemLoader
|
||||
[RequireExplicitImplementation]
|
||||
public interface IFileSystemExternalContent
|
||||
{
|
||||
public bool InstallContentIfRequired(ModData modData);
|
||||
}
|
||||
|
||||
public class DefaultFileSystemLoader : IFileSystemLoader, IFileSystemExternalContent
|
||||
{
|
||||
public readonly Dictionary<string, string> Packages = null;
|
||||
|
||||
@@ -23,5 +32,24 @@ namespace OpenRA.Mods.Common.FileSystem
|
||||
foreach (var kv in Packages)
|
||||
fileSystem.Mount(kv.Key, kv.Value);
|
||||
}
|
||||
|
||||
bool IFileSystemExternalContent.InstallContentIfRequired(ModData modData)
|
||||
{
|
||||
// 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 false;
|
||||
|
||||
var content = modData.Manifest.Get<ModContent>();
|
||||
var contentInstalled = content.Packages
|
||||
.Where(p => p.Value.Required)
|
||||
.All(p => p.Value.TestFiles.All(f => File.Exists(Platform.ResolvePath(f))));
|
||||
|
||||
if (contentInstalled)
|
||||
return false;
|
||||
|
||||
Game.InitializeMod(content.ContentInstallerMod, new Arguments("Content.Mod=" + modData.Manifest.Id));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Mods.Common.FileSystem;
|
||||
using OpenRA.Mods.Common.Widgets.Logic;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
@@ -126,21 +126,10 @@ namespace OpenRA.Mods.Common.LoadScreens
|
||||
if (graphicSettings.GLProfile != GLProfile.Automatic && graphicSettings.GLProfile != Game.Renderer.GLProfile)
|
||||
graphicSettings.GLProfile = GLProfile.Automatic;
|
||||
|
||||
// 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>())
|
||||
if (ModData.FileSystemLoader is not IFileSystemExternalContent content)
|
||||
return true;
|
||||
|
||||
var content = ModData.Manifest.Get<ModContent>();
|
||||
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(new[] { "Content.Mod=" + ModData.Manifest.Id }));
|
||||
return false;
|
||||
return !content.InstallContentIfRequired(ModData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user