Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tlevel.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
DEFINE_CLASS_CODE(TLevel, 7)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TLevel::TLevel()
Toshihiro Shimizu 890ddd
	: TSmartObject(m_classCode), m_name(""), m_table(new Table()), m_palette(0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TLevel::~TLevel()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_palette)
Toshihiro Shimizu 890ddd
		m_palette->release();
Toshihiro Shimizu 890ddd
	delete m_table;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
std::string TLevel::getName() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_name;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
void TLevel::setName(std::string name)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_name = name;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
const TImageP &TLevel::frame(const TFrameId fid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const static TImageP none;
Toshihiro Shimizu 890ddd
	assert(m_table);
Toshihiro Shimizu 890ddd
	Iterator it = m_table->find(fid);
Toshihiro Shimizu 890ddd
	if (it == m_table->end())
Toshihiro Shimizu 890ddd
		return none; // (*m_table)[fid];
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return it->second;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevel::setFrame(const TFrameId &fid, const TImageP &img)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_table);
Toshihiro Shimizu 890ddd
	if (img)
Toshihiro Shimizu 890ddd
		img->setPalette(getPalette());
Toshihiro Shimizu 890ddd
	(*m_table)[fid] = img;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
// brutto e inefficiente
Toshihiro Shimizu 890ddd
int TLevel::getIndex(const TFrameId fid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
  int index = 0;
Toshihiro Shimizu 890ddd
  for(Iterator it = m_table->begin(); it != m_table->end(); it++, index++)
Toshihiro Shimizu 890ddd
    if(it->first == fid) return index;
Toshihiro Shimizu 890ddd
  return -1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPalette *TLevel::getPalette()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_palette;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TLevel::setPalette(TPalette *palette)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_palette == palette)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (palette)
Toshihiro Shimizu 890ddd
		palette->addRef();
Toshihiro Shimizu 890ddd
	if (m_palette)
Toshihiro Shimizu 890ddd
		m_palette->release();
Toshihiro Shimizu 890ddd
	m_palette = palette;
Toshihiro Shimizu 890ddd
	for (Iterator it = begin(); it != end(); ++it) {
Toshihiro Shimizu 890ddd
		TImageP &img = it->second;
Toshihiro Shimizu 890ddd
		if (img)
Toshihiro Shimizu 890ddd
			img->setPalette(m_palette);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------