| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  |  | // Copyright (c) 2016-2018 Easy2D - Nomango
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | #include "..\e2daction.h"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Sequence::Sequence() | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	: action_index_(0) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | e2d::Sequence::Sequence(const Actions& actions) | 
					
						
							|  |  |  |  | 	: action_index_(0) | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	this->Add(actions); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Sequence::~Sequence() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-07 00:28:54 +08:00
										 |  |  |  | 	for (auto action : actions_) | 
					
						
							| 
									
										
										
										
											2018-07-07 01:43:41 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-07 00:28:54 +08:00
										 |  |  |  | 		SafeRelease(action); | 
					
						
							| 
									
										
										
										
											2018-07-07 01:43:41 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | void e2d::Sequence::Init() | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	Action::Init(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	if (target_) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 		for (const auto& action : actions_) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 			action->target_ = target_; | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	actions_[0]->Init(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | void e2d::Sequence::Update() | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	Action::Update(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	auto &action = actions_[action_index_]; | 
					
						
							|  |  |  |  | 	action->Update(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	if (action->IsDone()) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 		++action_index_; | 
					
						
							|  |  |  |  | 		if (action_index_ == actions_.size()) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 			this->Stop(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 		else | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 			actions_[action_index_]->Init(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | void e2d::Sequence::Reset() | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	Action::Reset(); | 
					
						
							|  |  |  |  | 	for (const auto& action : actions_) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 		action->Reset(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	action_index_ = 0; | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | void e2d::Sequence::ResetTime() | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	for (const auto& action : actions_) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 		action->ResetTime(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | void e2d::Sequence::Add(Action * action) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	if (action) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 		actions_.push_back(action); | 
					
						
							|  |  |  |  | 		action->Retain(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | void e2d::Sequence::Add(const Actions& actions) | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	for (const auto &action : actions) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 		this->Add(action); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | e2d::Sequence * e2d::Sequence::Clone() const | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-07 00:28:54 +08:00
										 |  |  |  | 	auto sequence = new Sequence(); | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	for (const auto& action : actions_) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  |  | 		if (action) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 			sequence->Add(action->Clone()); | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  |  | 	return sequence; | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | e2d::Sequence * e2d::Sequence::Reverse() const | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-07 00:28:54 +08:00
										 |  |  |  | 	auto sequence = new Sequence(); | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	if (sequence && !actions_.empty()) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 		std::vector<Action*> newActions(actions_.size()); | 
					
						
							|  |  |  |  | 		for (auto iter = actions_.crbegin(), iterCrend = actions_.crend(); iter != iterCrend; ++iter) | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 			newActions.push_back((*iter)->Reverse()); | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 		sequence->Add(newActions); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  |  | 	return sequence; | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | } |