1 #region Copyright & License Information
2 /*
3  * Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
4  * This file is part of OpenRA, which is free software. It is made
5  * available to you under the terms of the GNU General Public License
6  * as published by the Free Software Foundation, either version 3 of
7  * the License, or (at your option) any later version. For more
8  * information, see COPYING.
9  */
10 #endregion
11 
12 using System.Linq;
13 using OpenRA.Activities;
14 using OpenRA.Traits;
15 
16 namespace OpenRA.Mods.Common.Traits.Render
17 {
18 	public class WithHarvestAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>, Requires<HarvesterInfo>
19 	{
20 		[SequenceReference]
21 		[Desc("Displayed while harvesting.")]
22 		public readonly string HarvestSequence = "harvest";
23 
24 		[Desc("Which sprite body to play the animation on.")]
25 		public readonly string Body = "body";
26 
Create(ActorInitializer init)27 		public object Create(ActorInitializer init) { return new WithHarvestAnimation(init, this); }
28 	}
29 
30 	public class WithHarvestAnimation : INotifyHarvesterAction
31 	{
32 		public readonly WithHarvestAnimationInfo Info;
33 		readonly WithSpriteBody wsb;
34 
WithHarvestAnimation(ActorInitializer init, WithHarvestAnimationInfo info)35 		public WithHarvestAnimation(ActorInitializer init, WithHarvestAnimationInfo info)
36 		{
37 			Info = info;
38 			wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == Info.Body);
39 		}
40 
INotifyHarvesterAction.Harvested(Actor self, ResourceType resource)41 		void INotifyHarvesterAction.Harvested(Actor self, ResourceType resource)
42 		{
43 			var sequence = wsb.NormalizeSequence(self, Info.HarvestSequence);
44 			if (wsb.DefaultAnimation.HasSequence(sequence) && wsb.DefaultAnimation.CurrentSequence.Name != sequence)
45 				wsb.PlayCustomAnimation(self, sequence);
46 		}
47 
INotifyHarvesterAction.Docked()48 		void INotifyHarvesterAction.Docked() { }
INotifyHarvesterAction.Undocked()49 		void INotifyHarvesterAction.Undocked() { }
INotifyHarvesterAction.MovingToResources(Actor self, CPos targetCell)50 		void INotifyHarvesterAction.MovingToResources(Actor self, CPos targetCell) { }
INotifyHarvesterAction.MovingToRefinery(Actor self, Actor refineryActor)51 		void INotifyHarvesterAction.MovingToRefinery(Actor self, Actor refineryActor) { }
INotifyHarvesterAction.MovementCancelled(Actor self)52 		void INotifyHarvesterAction.MovementCancelled(Actor self) { }
53 	}
54 }
55