From 57d3321d0f9f18869273dd45ee44e37977718d7e Mon Sep 17 00:00:00 2001 From: penev92 Date: Wed, 23 Feb 2022 19:47:18 +0200 Subject: [PATCH] Make WithDockingAnimation optional The `Refinery` trait has a hardcoded usage of `SpriteHarvesterDockSequence`, which requires the harvester to have `WithDockingAnimation`, making it inconvenient-at-best to NOT have a docking/unloading animation. --- .../Activities/SpriteHarvesterDockSequence.cs | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/SpriteHarvesterDockSequence.cs b/OpenRA.Mods.Common/Activities/SpriteHarvesterDockSequence.cs index af3ee2d10f..dfb01c1e3d 100644 --- a/OpenRA.Mods.Common/Activities/SpriteHarvesterDockSequence.cs +++ b/OpenRA.Mods.Common/Activities/SpriteHarvesterDockSequence.cs @@ -24,17 +24,20 @@ namespace OpenRA.Mods.Common.Activities : base(self, refinery, dockAngle, isDragRequired, dragOffset, dragLength) { wsb = self.Trait(); - wda = self.Info.TraitInfo(); + wda = self.Info.TraitInfoOrDefault(); } public override void OnStateDock(Actor self) { foreach (var trait in self.TraitsImplementing()) trait.Docked(); + foreach (var nd in Refinery.TraitsImplementing()) nd.Docked(Refinery, self); - wsb.PlayCustomAnimation(self, wda.DockSequence, () => wsb.PlayCustomAnimationRepeating(self, wda.DockLoopSequence)); + if (wda != null) + wsb.PlayCustomAnimation(self, wda.DockSequence, () => wsb.PlayCustomAnimationRepeating(self, wda.DockLoopSequence)); + dockAnimPlayed = true; dockingState = DockingState.Loop; } @@ -49,17 +52,22 @@ namespace OpenRA.Mods.Common.Activities } dockingState = DockingState.Wait; - wsb.PlayCustomAnimationBackwards(self, wda.DockSequence, - () => - { - dockingState = DockingState.Complete; - foreach (var trait in self.TraitsImplementing()) - trait.Undocked(); - if (Refinery.IsInWorld && !Refinery.IsDead) - foreach (var nd in Refinery.TraitsImplementing()) - nd.Undocked(Refinery, self); - }); + if (wda == null) + NotifyUndock(self); + else + wsb.PlayCustomAnimationBackwards(self, wda.DockSequence, () => NotifyUndock(self)); + } + + void NotifyUndock(Actor self) + { + dockingState = DockingState.Complete; + foreach (var trait in self.TraitsImplementing()) + trait.Undocked(); + + if (Refinery.IsInWorld && !Refinery.IsDead) + foreach (var nd in Refinery.TraitsImplementing()) + nd.Undocked(Refinery, self); } } }