|
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()
|
|
Shinya Kitaoka |
120a6e |
: TSmartObject(m_classCode)
|
|
Shinya Kitaoka |
120a6e |
, m_name("")
|
|
Shinya Kitaoka |
120a6e |
, m_table(new Table())
|
|
Shinya Kitaoka |
120a6e |
, m_palette(0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TLevel::~TLevel() {
|
|
Shinya Kitaoka |
120a6e |
if (m_palette) m_palette->release();
|
|
Shinya Kitaoka |
120a6e |
delete m_table;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string TLevel::getName() const { return m_name; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TLevel::setName(std::string name) { m_name = name; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
const TImageP &TLevel::frame(const TFrameId fid) {
|
|
Shinya Kitaoka |
120a6e |
const static TImageP none;
|
|
Shinya Kitaoka |
120a6e |
assert(m_table);
|
|
Shinya Kitaoka |
120a6e |
Iterator it = m_table->find(fid);
|
|
Shinya Kitaoka |
120a6e |
if (it == m_table->end())
|
|
Shinya Kitaoka |
120a6e |
return none; // (*m_table)[fid];
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return it->second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TLevel::setFrame(const TFrameId &fid, const TImageP &img) {
|
|
Shinya Kitaoka |
120a6e |
assert(m_table);
|
|
Shinya Kitaoka |
120a6e |
if (img) img->setPalette(getPalette());
|
|
Shinya Kitaoka |
120a6e |
(*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 |
|
|
Shinya Kitaoka |
120a6e |
TPalette *TLevel::getPalette() { return m_palette; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TLevel::setPalette(TPalette *palette) {
|
|
Shinya Kitaoka |
120a6e |
if (m_palette == palette) return;
|
|
Shinya Kitaoka |
120a6e |
if (palette) palette->addRef();
|
|
Shinya Kitaoka |
120a6e |
if (m_palette) m_palette->release();
|
|
Shinya Kitaoka |
120a6e |
m_palette = palette;
|
|
Shinya Kitaoka |
120a6e |
for (Iterator it = begin(); it != end(); ++it) {
|
|
Shinya Kitaoka |
120a6e |
TImageP &img = it->second;
|
|
Shinya Kitaoka |
120a6e |
if (img) img->setPalette(m_palette);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------
|