diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 41c50e293c..7472aeea1e 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -267,7 +267,14 @@ namespace OpenRA Renderer.SheetSize = Settings.Game.SheetSize; Renderer = new Renderer(); - LobbyInfo.GlobalSettings.Mods = Settings.Game.Mods; + Console.WriteLine("Available mods:"); + foreach(var mod in ModData.AllMods) + Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version); + + // Discard any invalid mods + LobbyInfo.GlobalSettings.Mods = Settings.Game.Mods.Where(m => ModData.AllMods.ContainsKey(m)).ToArray(); + Console.WriteLine("Loading mods: {0}",string.Join(",",LobbyInfo.GlobalSettings.Mods)); + modData = new ModData( LobbyInfo.GlobalSettings.Mods ); Sound.Initialize(); diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 36c758ecf6..2af12676e3 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -19,6 +19,35 @@ namespace OpenRA { public class ModData { + public static readonly Dictionary AllMods = ValidateMods(Directory.GetDirectories("mods").Select(x => x.Substring(5)).ToArray()); + + public static Dictionary ValidateMods(string[] mods) + { + var ret = new Dictionary(); + foreach (var m in mods) + { + if (!File.Exists("mods" + Path.DirectorySeparatorChar + m + Path.DirectorySeparatorChar + "mod.yaml")) + continue; + + var yaml = new MiniYaml( null, MiniYaml.FromFile("mods" + Path.DirectorySeparatorChar + m + Path.DirectorySeparatorChar + "mod.yaml")); + if (!yaml.NodesDict.ContainsKey("Metadata")) + { + System.Console.WriteLine("Invalid mod: "+m); + continue; + } + + ret.Add(m,FieldLoader.Load(yaml.NodesDict["Metadata"])); + } + return ret; + } + + public class Mod + { + public string Title; + public string Description; + public string Version; + } + public readonly Manifest Manifest; public readonly ObjectCreator ObjectCreator; public readonly SheetBuilder SheetBuilder; @@ -28,7 +57,7 @@ namespace OpenRA public ILoadScreen LoadScreen = null; public ModData( params string[] mods ) - { + { Manifest = new Manifest( mods ); ObjectCreator = new ObjectCreator( Manifest ); LoadScreen = ObjectCreator.CreateObject(Manifest.LoadScreen); diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 2fc2bdba80..602c54811e 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -1,4 +1,7 @@ -# Classic Command and Conquer -- Package Manifest +Metadata: + Title: Command & Conquer + Description: OpenRA Reimagining of the classic game + Version: a0001 Folders: . diff --git a/mods/default/mod.yaml b/mods/default/mod.yaml index e652c54e9b..a8a131c8b4 100644 --- a/mods/default/mod.yaml +++ b/mods/default/mod.yaml @@ -1,4 +1,7 @@ -# Default Game Mod +Metadata: + Title: Default Mod Template + Description: Minimal template for creating a base mod + Version: a0001 Folders: . diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 9e5046236c..ae9bc3e9e5 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -1,4 +1,7 @@ -# Classic Red Alert Mod -- Package Manifest +Metadata: + Title: Red Alert + Description: OpenRA Reimagining of the classic game + Version: a0001 Folders: . diff --git a/mods/ra_perf/mod.yaml b/mods/ra_perf/mod.yaml index fd2e137b79..69dc54d51d 100644 --- a/mods/ra_perf/mod.yaml +++ b/mods/ra_perf/mod.yaml @@ -1,4 +1,7 @@ -# RA Performance Tests -- Package Manifest +Metadata: + Title: RA Perf + Description: Performance Test map pack + Version: a0001 Folders: ./mods/ra_perf