SpriteSystemFiles/FlipBookSprite.cpp
// Method loads animation settings file
// NOTE: file layout is listed in text file witch is be located in
// "PortfolioFramework\SpriteBlitting\__FlipBookSpriteAnimationDataFileFormat.txt"
Method loads animation settings file
NOTE: file layout is listed in text file witch is be located in
"PortfolioFramework\SpriteBlitting\__FlipBookSpriteAnimationDataFileFormat.txt"
Method loads animation settings file NOTE : file layout is listed in text file witch is be located in " PortfolioFramework \ SpriteBlitting \ __FlipBookSpriteAnimationDataFileFormat . txt "
void
FlipBookSprite::LoadAnimationFile(std::string fileName)
{
	std::fstream file(fileName, std::fstream::in);
	unsigned int nuberOfAnimations = 0;
	if (!(file >> nuberOfAnimations))
		assert(false && "Failed to read number of animations");
	std::string dummy("");
	for (unsigned int i = 0; i < nuberOfAnimations; i++)
	{
		Animation tempAnimation;
		if (!(file >> dummy))
			assert(false && "Failed to read separation  line");
		if (!(file >> tempAnimation.animationID))
			assert(false && "Failed to load animation ID");
		if (!(file >> tempAnimation.loopTo))
			assert(false && "Failed to load animation loop to value");
		if (!(file >> tempAnimation.animationSpeed))
			assert(false && "Failed to load animation speed ");
		std::string keyWord("");
		if (!(file >> keyWord))
			assert(false && "Failed to load animation key word");
		if (keyWord.compare("Range") == 0 ||
			keyWord.compare("range") == 0)
		{
			unsigned int start = 0;
			unsigned int end = 0;
			if (!(file >> start))
				assert(false && "Failed to load animation range start");
			if (!(file >> end))
				assert(false && "Failed to load animation range end  ");
			tempAnimation.currentFrame = 0;
			for (unsigned int i = start; i <= end; i++)
			{
				tempAnimation.animationFrames.push_back(i);
			}
		}
		else if (keyWord.compare("Sequence") == 0 ||
				 keyWord.compare("sequence") == 0)
		{
			std::string buffer("");
			file >> buffer;
			std::string dataEntry("");
			unsigned int bufferIndex = 0;
			while (bufferIndex < buffer.size())
			{
				if (buffer[bufferIndex] == ',')
				{
					tempAnimation.animationFrames.push_back(std::stoul(dataEntry));
					dataEntry.erase();
					bufferIndex++;
					continue;
				}
				else if (buffer[bufferIndex] == ';')
				{
					tempAnimation.animationFrames.push_back(std::stoul(dataEntry));
					break;
				}
				dataEntry += buffer[bufferIndex++];
			}
		}
		m_animations.push_back(tempAnimation);
		m_animationsMap.insert(AnimationPair(tempAnimation.animationID, i));
	} 
	file.close();
}
void FlipBookSprite :: LoadAnimationFile ( std :: string fileName ) { std :: fstream file ( fileName , std :: fstream :: in ) ; unsigned int nuberOfAnimations = 0 ; if ( ! ( file >> nuberOfAnimations ) ) assert ( false && " " ) ; std :: string dummy ( " " ) ; for ( unsigned int i = 0 ; i < nuberOfAnimations ; i ++ ) { Animation tempAnimation ; if ( ! ( file >> dummy ) ) assert ( false && " " ) ; if ( ! ( file >> tempAnimation . animationID ) ) assert ( false && " " ) ; if ( ! ( file >> tempAnimation . loopTo ) ) assert ( false && " " ) ; if ( ! ( file >> tempAnimation . animationSpeed ) ) assert ( false && " " ) ; std :: string keyWord ( " " ) ; if ( ! ( file >> keyWord ) ) assert ( false && " " ) ; if ( keyWord . compare ( " " ) == 0 || keyWord . compare ( " " ) == 0 ) { unsigned int start = 0 ; unsigned int end = 0 ; if ( ! ( file >> start ) ) assert ( false && " " ) ; if ( ! ( file >> end ) ) assert ( false && " " ) ; tempAnimation . currentFrame = 0 ; for ( unsigned int i = start ; i <= end ; i ++ ) { tempAnimation . animationFrames . push_back ( i ) ; } } else if ( keyWord . compare ( " " ) == 0 || keyWord . compare ( " " ) == 0 ) { std :: string buffer ( " " ) ; file >> buffer ; std :: string dataEntry ( " " ) ; unsigned int bufferIndex = 0 ; while ( bufferIndex < buffer . size ( ) ) { if ( buffer [ bufferIndex ] == ' ' ) { tempAnimation . animationFrames . push_back ( std :: stoul ( dataEntry ) ) ; dataEntry . erase ( ) ; bufferIndex ++ ; continue ; } else if ( buffer [ bufferIndex ] == ' ' ) { tempAnimation . animationFrames . push_back ( std :: stoul ( dataEntry ) ) ; break ; } dataEntry += buffer [ bufferIndex ++ ] ; } } m_animations . push_back ( tempAnimation ) ; m_animationsMap . insert ( AnimationPair ( tempAnimation . animationID , i ) ) ; } file . close ( ) ; }
Method loads animation settings file
NOTE: file layout is listed in text file witch is be located in
"PortfolioFramework\SpriteBlitting\__FlipBookSpriteAnimationDataFileFormat.txt"
Method loads animation settings file NOTE : file layout is listed in text file witch is be located in " PortfolioFramework \ SpriteBlitting \ __FlipBookSpriteAnimationDataFileFormat . txt "
// Open file of given name // Read number of animations // iterate for number of animations, read and set animation values // Read dummy line and discard it // read Animation ID // read ID of animation to loop to // read animation speed // read the key word // Load the rest of animation data based on the keyword type // if animation frames defined as range // range start end // read animation range start // read animation end frame // Set animation current frame to default value  // push animation frames to vector // If animation frames defined as sequence // scan buffer for data // if colon than store data and continue to next buffer entry // Convert data to unsigned int and push it on to vector and increment buffer index  // if semicolon store last entry and break execution end of buffer // Convert data to unsigned int and push it on to vector and increment buffer index  // copy current byte // Insert animation to vector // Store animation index and key "animation ID" // for number of animations