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);
});

View File

@@ -17,8 +17,8 @@ namespace OpenRA.Mods.RA.Scripting
[ScriptPropertyGroup("Support Powers")]
public class ChronsphereProperties : ScriptActorProperties, Requires<ChronoshiftPowerInfo>
{
public ChronsphereProperties(Actor self)
: base(self) { }
public ChronsphereProperties(ScriptContext context, Actor self)
: base(context, self) { }
[Desc("Chronoshift a group of actors. A duration of 0 will teleport the actors permanently.")]
public void Chronoshift(LuaTable unitLocationPairs, int duration = 0, bool killCargo = false)

View File

@@ -17,7 +17,8 @@ namespace OpenRA.Mods.RA.Scripting
[ScriptPropertyGroup("Combat")]
public class CombatProperties : ScriptActorProperties, Requires<AttackBaseInfo>, Requires<IMoveInfo>
{
public CombatProperties(Actor self) : base(self) { }
public CombatProperties(ScriptContext context, Actor self)
: base(context, self) { }
[ScriptActorPropertyActivity]
[Desc("Seek out and attack nearby targets.")]
@@ -35,4 +36,4 @@ namespace OpenRA.Mods.RA.Scripting
self.QueueActivity(new AttackMove.AttackMoveActivity(self, new Move.Move(cell, WRange.FromCells(closeEnough))));
}
}
}
}

View File

@@ -21,7 +21,8 @@ namespace OpenRA.Mods.RA.Scripting
readonly IFacing facing;
readonly AutoTarget autotarget;
public GeneralProperties(Actor self) : base(self)
public GeneralProperties(ScriptContext context, Actor self)
: base(context, self)
{
facing = self.TraitOrDefault<IFacing>();
autotarget = self.TraitOrDefault<AutoTarget>();
@@ -135,4 +136,4 @@ namespace OpenRA.Mods.RA.Scripting
return self.HasScriptProperty(name);
}
}
}
}

View File

@@ -17,8 +17,8 @@ namespace OpenRA.Mods.RA.Scripting
public class GuardProperties : ScriptActorProperties, Requires<GuardInfo>, Requires<IMoveInfo>
{
Guard guard;
public GuardProperties(Actor self)
: base(self)
public GuardProperties(ScriptContext context, Actor self)
: base(context, self)
{
guard = self.Trait<Guard>();
}

View File

@@ -17,8 +17,8 @@ namespace OpenRA.Mods.RA.Scripting
public class HealthProperties : ScriptActorProperties, Requires<HealthInfo>
{
Health health;
public HealthProperties(Actor self)
: base(self)
public HealthProperties(ScriptContext context, Actor self)
: base(context, self)
{
health = self.Trait<Health>();
}
@@ -41,8 +41,8 @@ namespace OpenRA.Mods.RA.Scripting
public class InvulnerableProperties : ScriptActorProperties, Requires<ScriptInvulnerableInfo>
{
ScriptInvulnerable invulnerable;
public InvulnerableProperties(Actor self)
: base(self)
public InvulnerableProperties(ScriptContext context, Actor self)
: base(context, self)
{
invulnerable = self.Trait<ScriptInvulnerable>();
}

View File

@@ -20,8 +20,8 @@ namespace OpenRA.Mods.RA.Scripting
{
readonly MissionObjectives mo;
public MissionObjectiveProperties(Player player)
: base(player)
public MissionObjectiveProperties(ScriptContext context, Player player)
: base(context, player)
{
mo = player.PlayerActor.Trait<MissionObjectives>();
}

View File

@@ -17,7 +17,8 @@ namespace OpenRA.Mods.RA.Scripting
[ScriptPropertyGroup("Movement")]
public class MobileProperties : ScriptActorProperties, Requires<MobileInfo>
{
public MobileProperties(Actor self) : base(self) { }
public MobileProperties(ScriptContext context, Actor self)
: base(context, self) { }
[ScriptActorPropertyActivity]
[Desc("Moves within the cell grid. closeEnough defines an optional range " +

View File

@@ -18,8 +18,8 @@ namespace OpenRA.Mods.RA.Scripting
{
readonly Player p;
public PlayerProperties(Player player)
: base(player)
public PlayerProperties(ScriptContext context, Player player)
: base(context, player)
{
p = player;
}

View File

@@ -20,8 +20,8 @@ namespace OpenRA.Mods.RA.Scripting
{
readonly Production p;
public ProductionProperties(Actor self)
: base(self)
public ProductionProperties(ScriptContext context, Actor self)
: base(context, self)
{
p = self.Trait<Production>();
}

View File

@@ -19,8 +19,8 @@ namespace OpenRA.Mods.RA.Scripting
{
readonly PlayerResources pr;
public ResourceProperties(Player player)
: base(player)
public ResourceProperties(ScriptContext context, Player player)
: base(context, player)
{
pr = player.PlayerActor.Trait<PlayerResources>();
}

View File

@@ -21,8 +21,8 @@ namespace OpenRA.Mods.RA.Scripting
{
readonly Cargo cargo;
public TransportProperties(Actor self)
: base(self)
public TransportProperties(ScriptContext context, Actor self)
: base(context, self)
{
cargo = self.Trait<Cargo>();
}
@@ -46,8 +46,8 @@ namespace OpenRA.Mods.RA.Scripting
{
readonly ParaDrop paradrop;
public ParadropPowers(Actor self)
: base(self)
public ParadropPowers(ScriptContext context, Actor self)
: base(context, self)
{
paradrop = self.Trait<ParaDrop>();
}