////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 RWS Inc, All Rights Reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of version 2 of the GNU General Public License as published by
// the Free Software Foundation
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// AlphaAnimType.h
// Project: Postal
//
////////////////////////////////////////////////////////////////////////////////

#ifndef ALPHAANIMTYPE_H
#define ALPHAANIMTYPE_H

#include "pvr.h"

// Simple wrapper class for each frame of alpha animation
class CAlphaAnim
	{
	public:
		int16_t m_sNumAlphas;										// Number of alpha images (could be 0!)
		int16_t m_sX;													// Offset from hotspot to upper-left corner of image
		int16_t m_sY;													// Offset from hotspot to upper-left corner of image		

// todo: clean up
		PVR::cTexture *texture;

		float startU = 0.0f;
		float startV = 0.0f;	
		float endU = 0.0f;
		float endV = 0.0f;	
		uint16_t width = 0;
		uint16_t height = 0;
		uint8_t tileId = 0;
		uint8_t frameId = 0;

	
	public:
		CAlphaAnim()
			{		
			Reset();
			};
		
		~CAlphaAnim()
			{
			Reset();
			};

		CAlphaAnim& operator=(const CAlphaAnim& rhs)
			{
			Reset();
			m_sNumAlphas = rhs.m_sNumAlphas;
			m_sX = rhs.m_sX;
			m_sY = rhs.m_sY;			
			texture = rhs.texture;		
			Alloc(m_sNumAlphas);	
			return *this;
			}

		bool operator==(const CAlphaAnim& rhs) const
			{
			// Comparing two of these objects is a major undertaking.  Instead,
			// we'll always say that they are different.  This is not a great
			// solution.  In fact, it sucks.  But what the hell...
			return false;
			}

		void Reset(void)
			{
			Free();
			m_sNumAlphas = 0;
			m_sX = 0;
			m_sY = 0;
			}

		void Alloc(int16_t sNumAlphas)
			{
			Free();
			if (sNumAlphas > 0)
				{
			//	m_pimAlphaArray = new RImage[sNumAlphas];
			//	ASSERT(m_pimAlphaArray != 0);
				}
			m_sNumAlphas = sNumAlphas;
			}

		void Free(void)
			{
	//		delete []m_pimAlphaArray;
	//		m_pimAlphaArray = 0;
			}

		int16_t Load(RFile* pFile)
			{
			pFile->Read(&m_sNumAlphas);
			pFile->Read(&m_sX);
			pFile->Read(&m_sY);
			// Read and discard the image data - We are only interested in the position.
			RImage *tmp = new RImage;
			tmp->Load(pFile);
			tmp->DestroyData();
			for (int16_t s = 0; s < m_sNumAlphas; s++)
			{
				tmp->Load(pFile);
				tmp->DestroyData();
			}
			delete tmp;

			return pFile->Error();
			}	
	};

#endif //ALPHAANIMTYPE_H

////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////
