Move MuzzleFlash definition onto Armament.
This commit is contained in:
@@ -44,6 +44,12 @@ namespace OpenRA.Mods.RA
|
|||||||
[Desc("Recoil recovery per-frame")]
|
[Desc("Recoil recovery per-frame")]
|
||||||
public readonly WRange RecoilRecovery = new WRange(9);
|
public readonly WRange RecoilRecovery = new WRange(9);
|
||||||
|
|
||||||
|
[Desc("Muzzle flash sequence to render")]
|
||||||
|
public readonly string MuzzleSequence = null;
|
||||||
|
|
||||||
|
[Desc("Use multiple muzzle images if non-zero")]
|
||||||
|
public readonly int MuzzleSplitFacings = 0;
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new Armament(init.self, this); }
|
public object Create(ActorInitializer init) { return new Armament(init.self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,36 +19,25 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
{
|
{
|
||||||
class WithMuzzleFlashInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<AttackBaseInfo>, Requires<ArmamentInfo>
|
class WithMuzzleFlashInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<AttackBaseInfo>, Requires<ArmamentInfo>
|
||||||
{
|
{
|
||||||
[Desc("Sequence name to use")]
|
public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.self); }
|
||||||
public readonly string Sequence = "muzzle";
|
|
||||||
|
|
||||||
[Desc("Armament name")]
|
|
||||||
public readonly string Armament = "primary";
|
|
||||||
|
|
||||||
[Desc("Are the muzzle facings split into multiple shps?")]
|
|
||||||
public readonly bool SplitFacings = false;
|
|
||||||
|
|
||||||
[Desc("Number of separate facing images that are defined in the sequences.")]
|
|
||||||
public readonly int FacingCount = 8;
|
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.self, this); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class WithMuzzleFlash : INotifyAttack, IRender, ITick
|
class WithMuzzleFlash : INotifyAttack, IRender, ITick
|
||||||
{
|
{
|
||||||
readonly WithMuzzleFlashInfo info;
|
|
||||||
Dictionary<Barrel, bool> visible = new Dictionary<Barrel, bool>();
|
Dictionary<Barrel, bool> visible = new Dictionary<Barrel, bool>();
|
||||||
Dictionary<Barrel, AnimationWithOffset> anims = new Dictionary<Barrel, AnimationWithOffset>();
|
Dictionary<Barrel, AnimationWithOffset> anims = new Dictionary<Barrel, AnimationWithOffset>();
|
||||||
Func<int> getFacing;
|
Func<int> getFacing;
|
||||||
|
|
||||||
public WithMuzzleFlash(Actor self, WithMuzzleFlashInfo info)
|
public WithMuzzleFlash(Actor self)
|
||||||
{
|
{
|
||||||
this.info = info;
|
|
||||||
var render = self.Trait<RenderSprites>();
|
var render = self.Trait<RenderSprites>();
|
||||||
var facing = self.TraitOrDefault<IFacing>();
|
var facing = self.TraitOrDefault<IFacing>();
|
||||||
|
|
||||||
var arm = self.TraitsImplementing<Armament>()
|
foreach (var arm in self.TraitsImplementing<Armament>())
|
||||||
.Single(a => a.Info.Name == info.Armament);
|
{
|
||||||
|
// Skip armaments that don't define muzzles
|
||||||
|
if (arm.Info.MuzzleSequence == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
foreach (var b in arm.Barrels)
|
foreach (var b in arm.Barrels)
|
||||||
{
|
{
|
||||||
@@ -68,18 +57,18 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
p => WithTurret.ZOffsetFromCenter(self, p, 2)));
|
p => WithTurret.ZOffsetFromCenter(self, p, 2)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Attacking(Actor self, Target target, Armament a, Barrel barrel)
|
public void Attacking(Actor self, Target target, Armament a, Barrel barrel)
|
||||||
{
|
{
|
||||||
if (a.Info.Name != info.Armament)
|
var sequence = a.Info.MuzzleSequence;
|
||||||
|
if (sequence == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (a.Info.MuzzleSplitFacings > 0)
|
||||||
|
sequence += Traits.Util.QuantizeFacing(getFacing(), a.Info.MuzzleSplitFacings).ToString();
|
||||||
|
|
||||||
visible[barrel] = true;
|
visible[barrel] = true;
|
||||||
var sequence = info.Sequence;
|
|
||||||
|
|
||||||
if (info.SplitFacings)
|
|
||||||
sequence += Traits.Util.QuantizeFacing(getFacing(), info.FacingCount).ToString();
|
|
||||||
|
|
||||||
anims[barrel].Animation.PlayThen(sequence, () => visible[barrel] = false);
|
anims[barrel].Animation.PlayThen(sequence, () => visible[barrel] = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user