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

View File

@@ -16,7 +16,7 @@ namespace OpenRA.Mods.RA.Render
public override object Create(ActorInitializer init) { return new RenderBuildingCharge(init); }
}
/* used for tesla */
/* used for tesla */
public class RenderBuildingCharge : RenderBuilding
{
public RenderBuildingCharge( ActorInitializer init )
@@ -27,8 +27,8 @@ namespace OpenRA.Mods.RA.Render
public void PlayCharge(Actor self)
{
Sound.Play(self.Info.Traits.Get<RenderBuildingChargeInfo>().ChargeAudio, self.CenterLocation);
anim.PlayThen(GetPrefix(self) + "active",
() => anim.PlayRepeating(GetPrefix(self) + "idle"));
anim.PlayThen(NormalizeSequence(self, "active"),
() => anim.PlayRepeating(NormalizeSequence(self, "idle")));
}
}
}

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

@@ -14,46 +14,43 @@ using OpenRA.Traits;
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;
[Sync]
bool isOpen;
[Sync]
int2 openExit;
string GetPrefix(Actor self)
{
return self.GetDamageState() >= DamageState.Heavy ? "damaged-" : "";
}
public RenderWarFactory(Actor self)
public RenderWarFactory(ActorInitializer init)
: base(init)
{
roof = new Animation(self.Trait<RenderSimple>().GetImage(self));
roof = new Animation(GetImage(init.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 } );
}
public void Tick(Actor self)
public override void Tick(Actor self)
{
base.Tick(self);
if (isOpen && !self.World.WorldActor.Trait<UnitInfluence>()
.GetUnitsAt(openExit).Any())
{
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;
@@ -65,14 +62,12 @@ namespace OpenRA.Mods.RA.Render
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" );
}
public void Sold( Actor self ) { }
}
}

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

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