porymap/src/core/metatile.cpp

48 lines
1.2 KiB
C++
Raw Normal View History

2018-09-25 01:12:29 +01:00
#include "metatile.h"
#include "tileset.h"
#include "project.h"
Metatile::Metatile()
{
tiles = new QList<Tile>;
}
2018-10-03 01:01:15 +01:00
Metatile* Metatile::copy() {
Metatile *copy = new Metatile;
copy->behavior = this->behavior;
copy->layerType = this->layerType;
copy->encounterType = this->encounterType;
copy->terrainType = this->terrainType;
2018-10-03 01:01:15 +01:00
copy->tiles = new QList<Tile>;
copy->label = this->label;
2018-10-03 01:01:15 +01:00
for (Tile tile : *this->tiles) {
copy->tiles->append(tile);
}
return copy;
}
void Metatile::copyInPlace(Metatile *other) {
this->behavior = other->behavior;
this->layerType = other->layerType;
this->encounterType = other->encounterType;
this->terrainType = other->terrainType;
this->label = other->label;
for (int i = 0; i < this->tiles->length(); i++) {
(*this->tiles)[i] = other->tiles->at(i);
}
}
int Metatile::getBlockIndex(int index) {
if (index < Project::getNumMetatilesPrimary()) {
return index;
} else {
return index - Project::getNumMetatilesPrimary();
}
}
QPoint Metatile::coordFromPixmapCoord(const QPointF &pixelCoord) {
int x = static_cast<int>(pixelCoord.x()) / 16;
int y = static_cast<int>(pixelCoord.y()) / 16;
return QPoint(x, y);
}