
#include "TileAnimeList.h"





//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////



///and load from file
void TileAnimeList::load( )
{

	ifstream inData;
	inData.open("animelist.txt" );
	
	char trash;
	int num = 0;
	int num2 = 0;
			 
	inData >> num;
	inData >> trash;	

	while( 	numItems2 < num)
  	{

	TileAnimationConfig* nd;
	nd = new TileAnimationConfig();

inData >> num2;
nd->animeObject.Set_animate_id(num2);
inData >> trash;


inData >> num2;
nd->animeObject.Set_num_frames(num2);
inData >> trash;


inData >> num2;
nd->animeObject.Set_frame1(num2);
inData >> trash;


inData >> num2;
nd->animeObject.Set_frame2(num2);
inData >> trash;

inData >> num2;
nd->animeObject.Set_frame3(num2);
inData >> trash;

inData >> num2;
nd->animeObject.Set_frame4(num2);
inData >> trash;

inData >> num2;
nd->animeObject.Set_frame5(num2);
		
	nd->SetNext( head );
	head = nd;

	numItems2++;
	
	}

	inData.close();
	
	
}




TileAnimeList::TileAnimeList()
{

	head = NULL;
	numItems2 = 0;

}

	



///and save to file
void TileAnimeList::save( )
{
	TileAnimationConfig* nd;
	nd = head;
	
	ofstream outData;
	outData.open("datastuff.txt" );
	
	outData << numItems2;
	outData << ",";
	outData << endl;
	while( nd != NULL ) 
	{
outData << nd->animeObject.Get_animate_id();
outData << ",";
outData << nd->animeObject.Get_num_frames();
outData << ",";
outData << nd->animeObject.Get_frame1();
outData << ",";
outData << nd->animeObject.Get_frame2();
outData << ",";
outData << nd->animeObject.Get_frame3();
outData << ",";
outData << nd->animeObject.Get_frame4();	
outData << ",";
outData << nd->animeObject.Get_frame5();	

	 
		
		nd = nd->GetNext( );

	}
	
	
	outData.close();
	
}
////






void TileAnimeList::traverse2( )
{
	TileAnimationConfig* nd;
	nd = head;
	
	for( int i = 0; i < numItems2; i++ )
	{
		
		nd = nd->GetNext();
	}
	
}

bool TileAnimeList::isEmpty( )
{
	return( numItems2 == 0 );
}

int TileAnimeList::GetNumItems( )
{
	return numItems2;
}

bool TileAnimeList::IsInList( int d )
{
	TileAnimationConfig* nd;
	nd = head;
	while( nd != NULL )
	{
		if( nd->animeObject.Get_animate_id() == d )
			return true;
		nd = nd->GetNext( );
	}
	return false;
}



int TileAnimeList::IndexOf( int d )
{
	TileAnimationConfig* nd;
	nd = head;
	int index = 0;
	while( nd != NULL )
	{
		if( nd->animeObject.Get_animate_id() == d )
			return index;
		nd = nd->GetNext( );
		index++;
	}
	return -1;
}









int TileAnimeList::Find_animate_id( int d ,int c)
{
	TileAnimationConfig* nd;
	nd = head;
	int index = 0;
	
	while( nd != NULL )
	{

		if( nd->animeObject.Get_animate_id() == d )
		{

			if (c == 1)
			{
			nd->animeObject.Set_corrent_frame(nd->animeObject.Get_frame2());

			}
			else if(c == 2)
			{
			nd->animeObject.Set_corrent_frame(nd->animeObject.Get_frame3());

			}
			else if(c == 3)
			{
			nd->animeObject.Set_corrent_frame(nd->animeObject.Get_frame4());

			}
			else if(c == 4)
			{
			nd->animeObject.Set_corrent_frame(nd->animeObject.Get_frame5());

			}
			else 
			{
			nd->animeObject.Set_corrent_frame(nd->animeObject.Get_frame1());

			}

			return nd->animeObject.Get_corrent_frame();
		}
		nd = nd->GetNext( );
		index++;
	}
	return -1;
}








TileAnimeList::~TileAnimeList()
{

}