#region Copyright & License Information /* * Copyright 2007-2015 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, * see COPYING. */ #endregion using System; using System.Linq; using OpenRA.Activities; using OpenRA.Graphics; using OpenRA.Mods.Common.Activities; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("Replaces the sprite during construction.")] public class WithMakeAnimationInfo : ITraitInfo, Requires, Requires { [Desc("Sequence name to use")] [SequenceReference] public readonly string Sequence = "make"; public object Create(ActorInitializer init) { return new WithMakeAnimation(init, this); } } public class WithMakeAnimation { readonly WithMakeAnimationInfo info; readonly RenderBuilding renderBuilding; public WithMakeAnimation(ActorInitializer init, WithMakeAnimationInfo info) { this.info = info; var self = init.Self; renderBuilding = self.Trait(); var building = self.Trait(); if (!building.SkipMakeAnimation) { renderBuilding.PlayCustomAnimThen(self, info.Sequence, () => { building.NotifyBuildingComplete(self); }); } } public void Reverse(Actor self, Activity activity, bool queued = true) { renderBuilding.PlayCustomAnimBackwards(self, info.Sequence, () => { // avoids visual glitches as we wait for the actor to get destroyed renderBuilding.DefaultAnimation.PlayFetchIndex(info.Sequence, () => 0); self.QueueActivity(queued, activity); }); } } }