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.
This commit is contained in:
@@ -24,17 +24,20 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
: base(self, refinery, dockAngle, isDragRequired, dragOffset, dragLength)
|
: base(self, refinery, dockAngle, isDragRequired, dragOffset, dragLength)
|
||||||
{
|
{
|
||||||
wsb = self.Trait<WithSpriteBody>();
|
wsb = self.Trait<WithSpriteBody>();
|
||||||
wda = self.Info.TraitInfo<WithDockingAnimationInfo>();
|
wda = self.Info.TraitInfoOrDefault<WithDockingAnimationInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnStateDock(Actor self)
|
public override void OnStateDock(Actor self)
|
||||||
{
|
{
|
||||||
foreach (var trait in self.TraitsImplementing<INotifyHarvesterAction>())
|
foreach (var trait in self.TraitsImplementing<INotifyHarvesterAction>())
|
||||||
trait.Docked();
|
trait.Docked();
|
||||||
|
|
||||||
foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>())
|
foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>())
|
||||||
nd.Docked(Refinery, self);
|
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;
|
dockAnimPlayed = true;
|
||||||
dockingState = DockingState.Loop;
|
dockingState = DockingState.Loop;
|
||||||
}
|
}
|
||||||
@@ -49,17 +52,22 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
}
|
}
|
||||||
|
|
||||||
dockingState = DockingState.Wait;
|
dockingState = DockingState.Wait;
|
||||||
wsb.PlayCustomAnimationBackwards(self, wda.DockSequence,
|
|
||||||
() =>
|
|
||||||
{
|
|
||||||
dockingState = DockingState.Complete;
|
|
||||||
foreach (var trait in self.TraitsImplementing<INotifyHarvesterAction>())
|
|
||||||
trait.Undocked();
|
|
||||||
|
|
||||||
if (Refinery.IsInWorld && !Refinery.IsDead)
|
if (wda == null)
|
||||||
foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>())
|
NotifyUndock(self);
|
||||||
nd.Undocked(Refinery, self);
|
else
|
||||||
});
|
wsb.PlayCustomAnimationBackwards(self, wda.DockSequence, () => NotifyUndock(self));
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotifyUndock(Actor self)
|
||||||
|
{
|
||||||
|
dockingState = DockingState.Complete;
|
||||||
|
foreach (var trait in self.TraitsImplementing<INotifyHarvesterAction>())
|
||||||
|
trait.Undocked();
|
||||||
|
|
||||||
|
if (Refinery.IsInWorld && !Refinery.IsDead)
|
||||||
|
foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>())
|
||||||
|
nd.Undocked(Refinery, self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user