Merge pull request #11065 from abcdefg30/luaMapActors
Add a lua method for querying all actors that are currently InWorld
This commit is contained in:
@@ -21,10 +21,13 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public class MapGlobal : ScriptGlobal
|
||||
{
|
||||
readonly SpawnMapActors sma;
|
||||
readonly World world;
|
||||
|
||||
public MapGlobal(ScriptContext context)
|
||||
: base(context)
|
||||
{
|
||||
sma = context.World.WorldActor.Trait<SpawnMapActors>();
|
||||
world = context.World;
|
||||
|
||||
// Register map actors as globals (yuck!)
|
||||
foreach (var kv in sma.Actors)
|
||||
@@ -133,5 +136,8 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
return Context.World.ActorsHavingTrait<ScriptTags>(t => t.HasTag(tag)).ToArray();
|
||||
}
|
||||
|
||||
[Desc("Returns a table of all the actors that are currently on the map/in the world.")]
|
||||
public Actor[] ActorsInWorld { get { return world.Actors.ToArray(); } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using Eluant;
|
||||
using OpenRA.Scripting;
|
||||
@@ -54,6 +55,20 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
return true;
|
||||
}
|
||||
|
||||
[Desc("Returns the original collection filtered with the func.")]
|
||||
public LuaTable Where(LuaValue[] collection, LuaFunction func)
|
||||
{
|
||||
var t = Context.CreateTable();
|
||||
|
||||
foreach (var c in collection)
|
||||
using (var ret = func.Call(c))
|
||||
using (var result = ret.FirstOrDefault())
|
||||
if (result != null && result.ToBoolean())
|
||||
t.Add(t.Count + 1, c);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
[Desc("Returns the first n values from a collection.")]
|
||||
public LuaValue[] Take(int n, LuaValue[] source)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user