Rework mod enumeration / caching.
- Replaced ModMetadata.AllMods with Game.Mods. - Store / reference mod Manifest instead of ModMetadata. - Removes engine dependency on ModContent class.
This commit is contained in:
@@ -21,6 +21,7 @@ using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenRA.Chat;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Primitives;
|
||||
@@ -35,6 +36,8 @@ namespace OpenRA
|
||||
public const int Timestep = 40;
|
||||
public const int TimestepJankThreshold = 250; // Don't catch up for delays larger than 250ms
|
||||
|
||||
public static InstalledMods Mods { get; private set; }
|
||||
|
||||
public static ModData ModData;
|
||||
public static Settings Settings;
|
||||
public static ICursor Cursor;
|
||||
@@ -300,22 +303,23 @@ namespace OpenRA
|
||||
|
||||
GlobalChat = new GlobalChat();
|
||||
|
||||
Mods = new InstalledMods();
|
||||
Console.WriteLine("Available mods:");
|
||||
foreach (var mod in ModMetadata.AllMods)
|
||||
Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
|
||||
foreach (var mod in Mods)
|
||||
Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Mod.Title, mod.Value.Mod.Version);
|
||||
|
||||
InitializeMod(Settings.Game.Mod, args);
|
||||
}
|
||||
|
||||
public static bool IsModInstalled(string modId)
|
||||
{
|
||||
return ModMetadata.AllMods[modId].RequiresMods.All(IsModInstalled);
|
||||
return Mods.ContainsKey(modId) && Mods[modId].RequiresMods.All(IsModInstalled);
|
||||
}
|
||||
|
||||
public static bool IsModInstalled(KeyValuePair<string, string> mod)
|
||||
{
|
||||
return ModMetadata.AllMods.ContainsKey(mod.Key)
|
||||
&& ModMetadata.AllMods[mod.Key].Version == mod.Value
|
||||
return Mods.ContainsKey(mod.Key)
|
||||
&& Mods[mod.Key].Mod.Version == mod.Value
|
||||
&& IsModInstalled(mod.Key);
|
||||
}
|
||||
|
||||
@@ -347,7 +351,7 @@ namespace OpenRA
|
||||
ModData = null;
|
||||
|
||||
// Fall back to default if the mod doesn't exist or has missing prerequisites.
|
||||
if (!ModMetadata.AllMods.ContainsKey(mod) || !IsModInstalled(mod))
|
||||
if (!IsModInstalled(mod))
|
||||
mod = new GameSettings().Mod;
|
||||
|
||||
Console.WriteLine("Loading mod: {0}", mod);
|
||||
@@ -355,7 +359,7 @@ namespace OpenRA
|
||||
|
||||
Sound.StopVideo();
|
||||
|
||||
ModData = new ModData(mod, true);
|
||||
ModData = new ModData(Mods[mod], Mods, true);
|
||||
|
||||
using (new PerfTimer("LoadMaps"))
|
||||
ModData.MapCache.LoadMaps();
|
||||
@@ -468,7 +472,7 @@ namespace OpenRA
|
||||
ThreadPool.QueueUserWorkItem(_ =>
|
||||
{
|
||||
var mod = ModData.Manifest.Mod;
|
||||
var directory = Platform.ResolvePath("^", "Screenshots", mod.Id, mod.Version);
|
||||
var directory = Platform.ResolvePath("^", "Screenshots", ModData.Manifest.Id, mod.Version);
|
||||
Directory.CreateDirectory(directory);
|
||||
|
||||
var filename = TimestampedFilename();
|
||||
|
||||
Reference in New Issue
Block a user