mod manifest loading
This commit is contained in:
@@ -52,13 +52,19 @@ namespace OpenRa.GameRules
|
||||
return node;
|
||||
}
|
||||
|
||||
// todo: use mod metadata to do this
|
||||
static Pair<Assembly, string>[] ModAssemblies =
|
||||
{
|
||||
Pair.New( typeof(ITraitInfo).Assembly, typeof(ITraitInfo).Namespace ),
|
||||
Pair.New( Assembly.LoadFile(Path.GetFullPath(@"mods\ra\OpenRa.Mods.RA.dll")), "OpenRa.Mods.RA" ),
|
||||
Pair.New( Assembly.LoadFile(Path.GetFullPath(@"mods\aftermath\OpenRa.Mods.Aftermath.dll")), "OpenRa.Mods.Aftermath" )
|
||||
};
|
||||
static Pair<Assembly, string>[] ModAssemblies;
|
||||
public static void LoadModAssemblies(Manifest m)
|
||||
{
|
||||
var asms = new List<Pair<Assembly, string>>();
|
||||
|
||||
// all the core stuff is in this assembly
|
||||
asms.Add(Pair.New(typeof(ITraitInfo).Assembly, typeof(ITraitInfo).Namespace));
|
||||
|
||||
// add the mods
|
||||
foreach (var a in m.Assemblies)
|
||||
asms.Add(Pair.New(Assembly.LoadFile(Path.GetFullPath(a)), Path.GetFileNameWithoutExtension(a)));
|
||||
ModAssemblies = asms.ToArray();
|
||||
}
|
||||
|
||||
static ITraitInfo LoadTraitInfo(string traitName, MiniYaml my)
|
||||
{
|
||||
|
||||
@@ -20,28 +20,20 @@ namespace OpenRa
|
||||
public static AftermathInfo Aftermath;
|
||||
public static TechTree TechTree;
|
||||
|
||||
public static Dictionary<string, ActorInfo> ActorInfo;
|
||||
public static Dictionary<string, ActorInfo> Info;
|
||||
|
||||
public static void LoadRules(string mapFileName, bool useAftermath)
|
||||
public static void LoadRules(string map, Manifest m)
|
||||
{
|
||||
if (useAftermath)
|
||||
AllRules = new IniFile(
|
||||
FileSystem.Open(mapFileName),
|
||||
FileSystem.Open("aftermathUnits.ini"),
|
||||
FileSystem.Open("units.ini"),
|
||||
FileSystem.Open("aftrmath.ini"),
|
||||
FileSystem.Open("rules.ini"));
|
||||
else
|
||||
AllRules = new IniFile(
|
||||
FileSystem.Open(mapFileName),
|
||||
FileSystem.Open("units.ini"),
|
||||
FileSystem.Open("rules.ini"));
|
||||
var legacyRules = m.LegacyRules.Reverse().ToList();
|
||||
legacyRules.Insert(0, map);
|
||||
AllRules = new IniFile(legacyRules.Select(a => FileSystem.Open(a)).ToArray());
|
||||
|
||||
General = new GeneralInfo();
|
||||
FieldLoader.Load(General, AllRules.GetSection("General"));
|
||||
|
||||
// dirty hack. all of this needs to either die or go to traitinfos
|
||||
Aftermath = new AftermathInfo();
|
||||
if (useAftermath)
|
||||
if (AllRules.GetSection("Aftermath", true).Count() > 0)
|
||||
FieldLoader.Load(Aftermath, AllRules.GetSection("Aftermath"));
|
||||
|
||||
LoadCategories(
|
||||
@@ -62,15 +54,12 @@ namespace OpenRa
|
||||
SupportPowerInfo = new InfoLoader<SupportPowerInfo>(
|
||||
Pair.New<string, Func<string, SupportPowerInfo>>("SupportPower", _ => new SupportPowerInfo()));
|
||||
|
||||
var yamlRules = MiniYaml.Merge( MiniYaml.FromFile( "ra.yaml" ), MiniYaml.FromFile( "defaults.yaml" ) );
|
||||
if( useAftermath )
|
||||
yamlRules = MiniYaml.Merge( MiniYaml.FromFile( "aftermath.yaml" ), yamlRules );
|
||||
var yamlRules = m.Rules.Reverse().Select(a => MiniYaml.FromFile(a)).Aggregate(MiniYaml.Merge);
|
||||
|
||||
yamlRules = MiniYaml.Merge( MiniYaml.FromFile( "[mod]Separate buildqueue for defense.yaml" ), yamlRules );
|
||||
|
||||
ActorInfo = new Dictionary<string, ActorInfo>();
|
||||
ActorInfo.LoadModAssemblies(m);
|
||||
Info = new Dictionary<string, ActorInfo>();
|
||||
foreach( var kv in yamlRules )
|
||||
ActorInfo.Add(kv.Key.ToLowerInvariant(), new ActorInfo(kv.Key.ToLowerInvariant(), kv.Value, yamlRules));
|
||||
Info.Add(kv.Key.ToLowerInvariant(), new ActorInfo(kv.Key.ToLowerInvariant(), kv.Value, yamlRules));
|
||||
|
||||
TechTree = new TechTree();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace OpenRa.GameRules
|
||||
|
||||
public TechTree()
|
||||
{
|
||||
foreach( var info in Rules.ActorInfo.Values )
|
||||
foreach( var info in Rules.Info.Values )
|
||||
{
|
||||
var pi = info.Traits.GetOrDefault<ProductionInfo>();
|
||||
if (pi != null)
|
||||
@@ -62,7 +62,7 @@ namespace OpenRa.GameRules
|
||||
|
||||
public IEnumerable<ActorInfo> AllBuildables(Player player, params string[] categories)
|
||||
{
|
||||
return Rules.ActorInfo.Values
|
||||
return Rules.Info.Values
|
||||
.Where( x => x.Name[ 0 ] != '^' )
|
||||
.Where( x => categories.Contains( x.Category ) )
|
||||
.Where( x => x.Traits.Contains<BuildableInfo>() );
|
||||
@@ -72,7 +72,7 @@ namespace OpenRa.GameRules
|
||||
{
|
||||
var builtAt = info.Traits.Get<BuildableInfo>().BuiltAt;
|
||||
if( builtAt.Length != 0 )
|
||||
return builtAt.Select( x => Rules.ActorInfo[ x.ToLowerInvariant() ] );
|
||||
return builtAt.Select( x => Rules.Info[ x.ToLowerInvariant() ] );
|
||||
else
|
||||
return producesIndex[ info.Category ];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user