Fixed sequence crash

This commit is contained in:
Caleb Anderson
2010-09-19 02:09:10 -05:00
committed by Chris Forbes
parent 532afc3ff8
commit b62ee4d37c
6 changed files with 34 additions and 34 deletions

12
OpenRA.Game/Traits/Render/RenderSimple.cs Normal file → Executable file
View File

@@ -62,16 +62,20 @@ namespace OpenRA.Traits
a.Animation.Tick(); a.Animation.Tick();
} }
protected virtual string GetPrefix(Actor self) protected virtual string NormalizeSequence(Actor self, string baseSequence)
{ {
return self.GetDamageState() >= DamageState.Heavy ? "damaged-" : ""; string damageState = self.GetDamageState() >= DamageState.Heavy ? "damaged-" : "";
if (anim.HasSequence(damageState + baseSequence))
return damageState + baseSequence;
else
return baseSequence;
} }
public void PlayCustomAnim(Actor self, string name) public void PlayCustomAnim(Actor self, string name)
{ {
if (anim.HasSequence(name)) if (anim.HasSequence(name))
anim.PlayThen(GetPrefix(self) + name, anim.PlayThen(NormalizeSequence(self, name),
() => anim.PlayRepeating(GetPrefix(self) + "idle")); () => anim.PlayRepeating(NormalizeSequence(self, "idle")));
} }
public class AnimationWithOffset public class AnimationWithOffset

0
OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs Normal file → Executable file
View File

16
OpenRA.Mods.RA/Render/RenderBuilding.cs Normal file → Executable file
View File

@@ -58,28 +58,28 @@ namespace OpenRA.Mods.RA.Render
void Complete( Actor self ) void Complete( Actor self )
{ {
anim.PlayRepeating( GetPrefix(self) + "idle" ); anim.PlayRepeating( NormalizeSequence(self, "idle") );
foreach( var x in self.TraitsImplementing<INotifyBuildComplete>() ) foreach( var x in self.TraitsImplementing<INotifyBuildComplete>() )
x.BuildingComplete( self ); x.BuildingComplete( self );
} }
public void PlayCustomAnimThen(Actor self, string name, Action a) public void PlayCustomAnimThen(Actor self, string name, Action a)
{ {
anim.PlayThen(GetPrefix(self) + name, anim.PlayThen(NormalizeSequence(self, name),
() => { anim.PlayRepeating(GetPrefix(self) + "idle"); a(); }); () => { anim.PlayRepeating(NormalizeSequence(self, "idle")); a(); });
} }
public void PlayCustomAnimRepeating(Actor self, string name) public void PlayCustomAnimRepeating(Actor self, string name)
{ {
anim.PlayThen(GetPrefix(self) + name, anim.PlayThen(NormalizeSequence(self, name),
() => { PlayCustomAnimRepeating(self, name); }); () => { PlayCustomAnimRepeating(self, name); });
} }
public void PlayCustomAnimBackwards(Actor self, string name, Action a) public void PlayCustomAnimBackwards(Actor self, string name, Action a)
{ {
var hasSequence = anim.HasSequence(GetPrefix(self) + name); var hasSequence = anim.HasSequence(NormalizeSequence(self, name));
anim.PlayBackwardsThen(hasSequence ? GetPrefix(self) + name : name, anim.PlayBackwardsThen(NormalizeSequence(self, name),
() => { anim.PlayRepeating(GetPrefix(self) + "idle"); a(); }); () => { anim.PlayRepeating(NormalizeSequence(self, "idle")); a(); });
} }
public virtual void Damaged(Actor self, AttackInfo e) public virtual void Damaged(Actor self, AttackInfo e)
@@ -102,7 +102,7 @@ namespace OpenRA.Mods.RA.Render
anim.ReplaceAnim("idle"); anim.ReplaceAnim("idle");
} }
public void Selling( Actor self ) public virtual void Selling( Actor self )
{ {
if( self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation ) if( self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation )
anim.PlayBackwardsThen( "make", null ); anim.PlayBackwardsThen( "make", null );

View File

@@ -27,8 +27,8 @@ namespace OpenRA.Mods.RA.Render
public void PlayCharge(Actor self) public void PlayCharge(Actor self)
{ {
Sound.Play(self.Info.Traits.Get<RenderBuildingChargeInfo>().ChargeAudio, self.CenterLocation); Sound.Play(self.Info.Traits.Get<RenderBuildingChargeInfo>().ChargeAudio, self.CenterLocation);
anim.PlayThen(GetPrefix(self) + "active", anim.PlayThen(NormalizeSequence(self, "active"),
() => anim.PlayRepeating(GetPrefix(self) + "idle")); () => anim.PlayRepeating(NormalizeSequence(self, "idle")));
} }
} }
} }

31
OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs Normal file → Executable file
View File

@@ -14,12 +14,12 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render namespace OpenRA.Mods.RA.Render
{ {
class RenderWarFactoryInfo : ITraitInfo, ITraitPrerequisite<RenderSimpleInfo> class RenderWarFactoryInfo : RenderBuildingInfo
{ {
public object Create(ActorInitializer init) { return new RenderWarFactory(init.self); } public override object Create(ActorInitializer init) { return new RenderWarFactory(init); }
} }
class RenderWarFactory : INotifyBuildComplete, INotifyDamage, ITick, INotifyProduction, INotifySold class RenderWarFactory : RenderBuilding, INotifyBuildComplete, INotifyDamage, ITick, INotifyProduction, INotifySold
{ {
public Animation roof; public Animation roof;
[Sync] [Sync]
@@ -27,33 +27,30 @@ namespace OpenRA.Mods.RA.Render
[Sync] [Sync]
int2 openExit; int2 openExit;
string GetPrefix(Actor self) public RenderWarFactory(ActorInitializer init)
: base(init)
{ {
return self.GetDamageState() >= DamageState.Heavy ? "damaged-" : ""; roof = new Animation(GetImage(init.self));
}
public RenderWarFactory(Actor self)
{
roof = new Animation(self.Trait<RenderSimple>().GetImage(self));
} }
public void BuildingComplete( Actor self ) public void BuildingComplete( Actor self )
{ {
roof.Play( GetPrefix(self) + "idle-top" ); roof.Play( NormalizeSequence(self, "idle-top") );
self.Trait<RenderSimple>().anims.Add( "roof", new RenderSimple.AnimationWithOffset( roof ) { ZOffset = 24 } ); self.Trait<RenderSimple>().anims.Add( "roof", new RenderSimple.AnimationWithOffset( roof ) { ZOffset = 24 } );
} }
public void Tick(Actor self) public override void Tick(Actor self)
{ {
base.Tick(self);
if (isOpen && !self.World.WorldActor.Trait<UnitInfluence>() if (isOpen && !self.World.WorldActor.Trait<UnitInfluence>()
.GetUnitsAt(openExit).Any()) .GetUnitsAt(openExit).Any())
{ {
isOpen = false; isOpen = false;
roof.PlayBackwardsThen(GetPrefix(self) + "build-top", () => roof.Play(GetPrefix(self) + "idle-top")); roof.PlayBackwardsThen(NormalizeSequence(self, "build-top"), () => roof.Play(NormalizeSequence(self, "idle-top")));
} }
} }
public void Damaged(Actor self, AttackInfo e) public override void Damaged(Actor self, AttackInfo e)
{ {
if (!e.DamageStateChanged) return; if (!e.DamageStateChanged) return;
@@ -65,14 +62,12 @@ namespace OpenRA.Mods.RA.Render
public void UnitProduced(Actor self, Actor other, int2 exit) public void UnitProduced(Actor self, Actor other, int2 exit)
{ {
roof.PlayThen(GetPrefix(self) + "build-top", () => {isOpen = true; openExit = exit;}); roof.PlayThen(NormalizeSequence(self, "build-top"), () => { isOpen = true; openExit = exit; });
} }
public void Selling( Actor self ) public override void Selling( Actor self )
{ {
self.Trait<RenderSimple>().anims.Remove( "roof" ); self.Trait<RenderSimple>().anims.Remove( "roof" );
} }
public void Sold( Actor self ) { }
} }
} }

3
mods/ra/rules/structures.yaml Normal file → Executable file
View File

@@ -529,6 +529,7 @@ WEAP:
Range: 4 Range: 4
Bib: Bib:
RenderWarFactory: RenderWarFactory:
-RenderBuilding:
RallyPoint: RallyPoint:
Exit@1: Exit@1:
SpawnOffset: 5,0 SpawnOffset: 5,0
@@ -942,8 +943,8 @@ WEAF:
Range: 4 Range: 4
Bib: Bib:
RenderWarFactory: RenderWarFactory:
RenderBuilding:
Image: WEAP Image: WEAP
-RenderBuilding:
Fake: Fake:
IronCurtainable: IronCurtainable:
-EmitInfantryOnSell: -EmitInfantryOnSell: