Make ScriptContext available in Actor- and PlayerProperty classes

Needed to return non-native types to Lua
This commit is contained in:
Oliver Brakmann
2014-08-17 15:47:21 +02:00
parent 1e7f04105d
commit 1c8a56d197
14 changed files with 44 additions and 31 deletions

View File

@@ -25,10 +25,10 @@ namespace OpenRA.Scripting
{
this.actor = actor;
var args = new [] { actor };
var args = new object[] { context, actor };
var objects = context.ActorCommands[actor.Info].Select(cg =>
{
var groupCtor = cg.GetConstructor(new Type[] { typeof(Actor) });
var groupCtor = cg.GetConstructor(new Type[] { typeof(ScriptContext), typeof(Actor) });
return groupCtor.Invoke(args);
});

View File

@@ -44,13 +44,23 @@ namespace OpenRA.Scripting
public abstract class ScriptActorProperties
{
protected readonly Actor self;
public ScriptActorProperties(Actor self) { this.self = self; }
protected readonly ScriptContext context;
public ScriptActorProperties(ScriptContext context, Actor self)
{
this.self = self;
this.context = context;
}
}
public abstract class ScriptPlayerProperties
{
protected readonly Player player;
public ScriptPlayerProperties(Player player) { this.player = player; }
protected readonly ScriptContext context;
public ScriptPlayerProperties(ScriptContext context, Player player)
{
this.player = player;
this.context = context;
}
}
// For global-level bindings

View File

@@ -25,10 +25,10 @@ namespace OpenRA.Scripting
{
this.player = player;
var args = new [] { player };
var args = new object[] { context, player };
var objects = context.PlayerCommands.Select(cg =>
{
var groupCtor = cg.GetConstructor(new Type[] { typeof(Player) });
var groupCtor = cg.GetConstructor(new Type[] { typeof(ScriptContext), typeof(Player) });
return groupCtor.Invoke(args);
});