Filter the lua PlayerProperties on Requires
This commit is contained in:
@@ -155,9 +155,11 @@ namespace OpenRA.Scripting
|
|||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
ActorCommands = new Cache<ActorInfo, Type[]>(FilterActorCommands);
|
ActorCommands = new Cache<ActorInfo, Type[]>(FilterActorCommands);
|
||||||
PlayerCommands = Game.ModData.ObjectCreator
|
|
||||||
|
var knownPlayerCommands = Game.ModData.ObjectCreator
|
||||||
.GetTypesImplementing<ScriptPlayerProperties>()
|
.GetTypesImplementing<ScriptPlayerProperties>()
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
PlayerCommands = FilterCommands(world.Map.Rules.Actors["player"], knownPlayerCommands);
|
||||||
|
|
||||||
runtime.Globals["GameDir"] = Platform.GameDir;
|
runtime.Globals["GameDir"] = Platform.GameDir;
|
||||||
runtime.DoBuffer(File.Open(Platform.ResolvePath(".", "lua", "scriptwrapper.lua"), FileMode.Open, FileAccess.Read).ReadAllText(), "scriptwrapper.lua").Dispose();
|
runtime.DoBuffer(File.Open(Platform.ResolvePath(".", "lua", "scriptwrapper.lua"), FileMode.Open, FileAccess.Read).ReadAllText(), "scriptwrapper.lua").Dispose();
|
||||||
@@ -280,9 +282,14 @@ namespace OpenRA.Scripting
|
|||||||
|
|
||||||
static readonly object[] NoArguments = new object[0];
|
static readonly object[] NoArguments = new object[0];
|
||||||
Type[] FilterActorCommands(ActorInfo ai)
|
Type[] FilterActorCommands(ActorInfo ai)
|
||||||
|
{
|
||||||
|
return FilterCommands(ai, knownActorCommands);
|
||||||
|
}
|
||||||
|
|
||||||
|
Type[] FilterCommands(ActorInfo ai, Type[] knownCommands)
|
||||||
{
|
{
|
||||||
var method = typeof(ActorInfo).GetMethod("HasTraitInfo");
|
var method = typeof(ActorInfo).GetMethod("HasTraitInfo");
|
||||||
return knownActorCommands.Where(c => ExtractRequiredTypes(c)
|
return knownCommands.Where(c => ExtractRequiredTypes(c)
|
||||||
.All(t => (bool)method.MakeGenericMethod(t).Invoke(ai, NoArguments)))
|
.All(t => (bool)method.MakeGenericMethod(t).Invoke(ai, NoArguments)))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user