From b62ee4d37c84c04fa3ddaf6194f5f6a9b9fd8a86 Mon Sep 17 00:00:00 2001 From: Caleb Anderson Date: Sun, 19 Sep 2010 02:09:10 -0500 Subject: [PATCH] Fixed sequence crash --- OpenRA.Game/Traits/Render/RenderSimple.cs | 12 ++++--- .../Widgets/ViewportScrollControllerWidget.cs | 0 OpenRA.Mods.RA/Render/RenderBuilding.cs | 16 +++++----- OpenRA.Mods.RA/Render/RenderBuildingCharge.cs | 6 ++-- .../Render/RenderBuildingWarFactory.cs | 31 ++++++++----------- mods/ra/rules/structures.yaml | 3 +- 6 files changed, 34 insertions(+), 34 deletions(-) mode change 100644 => 100755 OpenRA.Game/Traits/Render/RenderSimple.cs mode change 100644 => 100755 OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs mode change 100644 => 100755 OpenRA.Mods.RA/Render/RenderBuilding.cs mode change 100644 => 100755 OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs mode change 100644 => 100755 mods/ra/rules/structures.yaml diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs old mode 100644 new mode 100755 index 403cc1df20..d7f1ac90ee --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -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 diff --git a/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs b/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs old mode 100644 new mode 100755 diff --git a/OpenRA.Mods.RA/Render/RenderBuilding.cs b/OpenRA.Mods.RA/Render/RenderBuilding.cs old mode 100644 new mode 100755 index 44f8769f9f..0218ff065d --- a/OpenRA.Mods.RA/Render/RenderBuilding.cs +++ b/OpenRA.Mods.RA/Render/RenderBuilding.cs @@ -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() ) 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().HasMakeAnimation ) anim.PlayBackwardsThen( "make", null ); diff --git a/OpenRA.Mods.RA/Render/RenderBuildingCharge.cs b/OpenRA.Mods.RA/Render/RenderBuildingCharge.cs index e2c04cec2a..6883cc6047 100755 --- a/OpenRA.Mods.RA/Render/RenderBuildingCharge.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingCharge.cs @@ -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().ChargeAudio, self.CenterLocation); - anim.PlayThen(GetPrefix(self) + "active", - () => anim.PlayRepeating(GetPrefix(self) + "idle")); + anim.PlayThen(NormalizeSequence(self, "active"), + () => anim.PlayRepeating(NormalizeSequence(self, "idle"))); } } } diff --git a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs old mode 100644 new mode 100755 index d8dfef19d2..5214793f7a --- a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs @@ -14,46 +14,43 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Render { - class RenderWarFactoryInfo : ITraitInfo, ITraitPrerequisite + 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().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().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() .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().anims.Remove( "roof" ); } - - public void Sold( Actor self ) { } } } diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml old mode 100644 new mode 100755 index ec2df3eae5..f1e2b0a060 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -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: