Make ScriptContext available in Actor- and PlayerProperty classes
Needed to return non-native types to Lua
This commit is contained in:
@@ -25,10 +25,10 @@ namespace OpenRA.Scripting
|
|||||||
{
|
{
|
||||||
this.actor = actor;
|
this.actor = actor;
|
||||||
|
|
||||||
var args = new [] { actor };
|
var args = new object[] { context, actor };
|
||||||
var objects = context.ActorCommands[actor.Info].Select(cg =>
|
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);
|
return groupCtor.Invoke(args);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -44,13 +44,23 @@ namespace OpenRA.Scripting
|
|||||||
public abstract class ScriptActorProperties
|
public abstract class ScriptActorProperties
|
||||||
{
|
{
|
||||||
protected readonly Actor self;
|
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
|
public abstract class ScriptPlayerProperties
|
||||||
{
|
{
|
||||||
protected readonly Player player;
|
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
|
// For global-level bindings
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ namespace OpenRA.Scripting
|
|||||||
{
|
{
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
var args = new [] { player };
|
var args = new object[] { context, player };
|
||||||
var objects = context.PlayerCommands.Select(cg =>
|
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);
|
return groupCtor.Invoke(args);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
[ScriptPropertyGroup("Support Powers")]
|
[ScriptPropertyGroup("Support Powers")]
|
||||||
public class ChronsphereProperties : ScriptActorProperties, Requires<ChronoshiftPowerInfo>
|
public class ChronsphereProperties : ScriptActorProperties, Requires<ChronoshiftPowerInfo>
|
||||||
{
|
{
|
||||||
public ChronsphereProperties(Actor self)
|
public ChronsphereProperties(ScriptContext context, Actor self)
|
||||||
: base(self) { }
|
: base(context, self) { }
|
||||||
|
|
||||||
[Desc("Chronoshift a group of actors. A duration of 0 will teleport the actors permanently.")]
|
[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)
|
public void Chronoshift(LuaTable unitLocationPairs, int duration = 0, bool killCargo = false)
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
[ScriptPropertyGroup("Combat")]
|
[ScriptPropertyGroup("Combat")]
|
||||||
public class CombatProperties : ScriptActorProperties, Requires<AttackBaseInfo>, Requires<IMoveInfo>
|
public class CombatProperties : ScriptActorProperties, Requires<AttackBaseInfo>, Requires<IMoveInfo>
|
||||||
{
|
{
|
||||||
public CombatProperties(Actor self) : base(self) { }
|
public CombatProperties(ScriptContext context, Actor self)
|
||||||
|
: base(context, self) { }
|
||||||
|
|
||||||
[ScriptActorPropertyActivity]
|
[ScriptActorPropertyActivity]
|
||||||
[Desc("Seek out and attack nearby targets.")]
|
[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))));
|
self.QueueActivity(new AttackMove.AttackMoveActivity(self, new Move.Move(cell, WRange.FromCells(closeEnough))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
readonly IFacing facing;
|
readonly IFacing facing;
|
||||||
readonly AutoTarget autotarget;
|
readonly AutoTarget autotarget;
|
||||||
|
|
||||||
public GeneralProperties(Actor self) : base(self)
|
public GeneralProperties(ScriptContext context, Actor self)
|
||||||
|
: base(context, self)
|
||||||
{
|
{
|
||||||
facing = self.TraitOrDefault<IFacing>();
|
facing = self.TraitOrDefault<IFacing>();
|
||||||
autotarget = self.TraitOrDefault<AutoTarget>();
|
autotarget = self.TraitOrDefault<AutoTarget>();
|
||||||
@@ -135,4 +136,4 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
return self.HasScriptProperty(name);
|
return self.HasScriptProperty(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
public class GuardProperties : ScriptActorProperties, Requires<GuardInfo>, Requires<IMoveInfo>
|
public class GuardProperties : ScriptActorProperties, Requires<GuardInfo>, Requires<IMoveInfo>
|
||||||
{
|
{
|
||||||
Guard guard;
|
Guard guard;
|
||||||
public GuardProperties(Actor self)
|
public GuardProperties(ScriptContext context, Actor self)
|
||||||
: base(self)
|
: base(context, self)
|
||||||
{
|
{
|
||||||
guard = self.Trait<Guard>();
|
guard = self.Trait<Guard>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
public class HealthProperties : ScriptActorProperties, Requires<HealthInfo>
|
public class HealthProperties : ScriptActorProperties, Requires<HealthInfo>
|
||||||
{
|
{
|
||||||
Health health;
|
Health health;
|
||||||
public HealthProperties(Actor self)
|
public HealthProperties(ScriptContext context, Actor self)
|
||||||
: base(self)
|
: base(context, self)
|
||||||
{
|
{
|
||||||
health = self.Trait<Health>();
|
health = self.Trait<Health>();
|
||||||
}
|
}
|
||||||
@@ -41,8 +41,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
public class InvulnerableProperties : ScriptActorProperties, Requires<ScriptInvulnerableInfo>
|
public class InvulnerableProperties : ScriptActorProperties, Requires<ScriptInvulnerableInfo>
|
||||||
{
|
{
|
||||||
ScriptInvulnerable invulnerable;
|
ScriptInvulnerable invulnerable;
|
||||||
public InvulnerableProperties(Actor self)
|
public InvulnerableProperties(ScriptContext context, Actor self)
|
||||||
: base(self)
|
: base(context, self)
|
||||||
{
|
{
|
||||||
invulnerable = self.Trait<ScriptInvulnerable>();
|
invulnerable = self.Trait<ScriptInvulnerable>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
{
|
{
|
||||||
readonly MissionObjectives mo;
|
readonly MissionObjectives mo;
|
||||||
|
|
||||||
public MissionObjectiveProperties(Player player)
|
public MissionObjectiveProperties(ScriptContext context, Player player)
|
||||||
: base(player)
|
: base(context, player)
|
||||||
{
|
{
|
||||||
mo = player.PlayerActor.Trait<MissionObjectives>();
|
mo = player.PlayerActor.Trait<MissionObjectives>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
[ScriptPropertyGroup("Movement")]
|
[ScriptPropertyGroup("Movement")]
|
||||||
public class MobileProperties : ScriptActorProperties, Requires<MobileInfo>
|
public class MobileProperties : ScriptActorProperties, Requires<MobileInfo>
|
||||||
{
|
{
|
||||||
public MobileProperties(Actor self) : base(self) { }
|
public MobileProperties(ScriptContext context, Actor self)
|
||||||
|
: base(context, self) { }
|
||||||
|
|
||||||
[ScriptActorPropertyActivity]
|
[ScriptActorPropertyActivity]
|
||||||
[Desc("Moves within the cell grid. closeEnough defines an optional range " +
|
[Desc("Moves within the cell grid. closeEnough defines an optional range " +
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
{
|
{
|
||||||
readonly Player p;
|
readonly Player p;
|
||||||
|
|
||||||
public PlayerProperties(Player player)
|
public PlayerProperties(ScriptContext context, Player player)
|
||||||
: base(player)
|
: base(context, player)
|
||||||
{
|
{
|
||||||
p = player;
|
p = player;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
{
|
{
|
||||||
readonly Production p;
|
readonly Production p;
|
||||||
|
|
||||||
public ProductionProperties(Actor self)
|
public ProductionProperties(ScriptContext context, Actor self)
|
||||||
: base(self)
|
: base(context, self)
|
||||||
{
|
{
|
||||||
p = self.Trait<Production>();
|
p = self.Trait<Production>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
{
|
{
|
||||||
readonly PlayerResources pr;
|
readonly PlayerResources pr;
|
||||||
|
|
||||||
public ResourceProperties(Player player)
|
public ResourceProperties(ScriptContext context, Player player)
|
||||||
: base(player)
|
: base(context, player)
|
||||||
{
|
{
|
||||||
pr = player.PlayerActor.Trait<PlayerResources>();
|
pr = player.PlayerActor.Trait<PlayerResources>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
{
|
{
|
||||||
readonly Cargo cargo;
|
readonly Cargo cargo;
|
||||||
|
|
||||||
public TransportProperties(Actor self)
|
public TransportProperties(ScriptContext context, Actor self)
|
||||||
: base(self)
|
: base(context, self)
|
||||||
{
|
{
|
||||||
cargo = self.Trait<Cargo>();
|
cargo = self.Trait<Cargo>();
|
||||||
}
|
}
|
||||||
@@ -46,8 +46,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
{
|
{
|
||||||
readonly ParaDrop paradrop;
|
readonly ParaDrop paradrop;
|
||||||
|
|
||||||
public ParadropPowers(Actor self)
|
public ParadropPowers(ScriptContext context, Actor self)
|
||||||
: base(self)
|
: base(context, self)
|
||||||
{
|
{
|
||||||
paradrop = self.Trait<ParaDrop>();
|
paradrop = self.Trait<ParaDrop>();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user