Use implicit copy constructor/assignment for Metatile
This commit is contained in:
parent
8187b2d4bb
commit
6a825d0b39
4 changed files with 29 additions and 55 deletions
|
@ -11,7 +11,9 @@ class Metatile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Metatile();
|
Metatile();
|
||||||
Metatile(const Metatile &other);
|
Metatile(const Metatile &other) = default;
|
||||||
|
Metatile &operator=(const Metatile &other) = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QList<Tile> tiles;
|
QList<Tile> tiles;
|
||||||
uint16_t behavior; // 8 bits RSE, 9 bits FRLG
|
uint16_t behavior; // 8 bits RSE, 9 bits FRLG
|
||||||
|
@ -20,8 +22,6 @@ public:
|
||||||
uint8_t terrainType; // FRLG only
|
uint8_t terrainType; // FRLG only
|
||||||
QString label;
|
QString label;
|
||||||
|
|
||||||
Metatile *copy();
|
|
||||||
void copyInPlace(Metatile*);
|
|
||||||
static int getBlockIndex(int);
|
static int getBlockIndex(int);
|
||||||
static QPoint coordFromPixmapCoord(const QPointF &pixelCoord);
|
static QPoint coordFromPixmapCoord(const QPointF &pixelCoord);
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,39 +9,6 @@ Metatile::Metatile() :
|
||||||
terrainType(0)
|
terrainType(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Metatile::Metatile(const Metatile &other) :
|
|
||||||
tiles(other.tiles),
|
|
||||||
behavior(other.behavior),
|
|
||||||
layerType(other.layerType),
|
|
||||||
encounterType(other.encounterType),
|
|
||||||
terrainType(other.terrainType),
|
|
||||||
label(other.label)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
Metatile* Metatile::copy() {
|
|
||||||
Metatile *copy = new Metatile;
|
|
||||||
copy->behavior = this->behavior;
|
|
||||||
copy->layerType = this->layerType;
|
|
||||||
copy->encounterType = this->encounterType;
|
|
||||||
copy->terrainType = this->terrainType;
|
|
||||||
copy->label = this->label;
|
|
||||||
for (const 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) {
|
int Metatile::getBlockIndex(int index) {
|
||||||
if (index < Project::getNumMetatilesPrimary()) {
|
if (index < Project::getNumMetatilesPrimary()) {
|
||||||
return index;
|
return index;
|
||||||
|
|
|
@ -36,7 +36,7 @@ Tileset* Tileset::copy() {
|
||||||
}
|
}
|
||||||
copy->metatiles = new QList<Metatile*>;
|
copy->metatiles = new QList<Metatile*>;
|
||||||
for (Metatile *metatile : *this->metatiles) {
|
for (Metatile *metatile : *this->metatiles) {
|
||||||
copy->metatiles->append(metatile->copy());
|
copy->metatiles->append(new Metatile(*metatile));
|
||||||
}
|
}
|
||||||
copy->palettes = new QList<QList<QRgb>>;
|
copy->palettes = new QList<QList<QRgb>>;
|
||||||
for (QList<QRgb> palette : *this->palettes) {
|
for (QList<QRgb> palette : *this->palettes) {
|
||||||
|
|
|
@ -262,7 +262,7 @@ void TilesetEditor::restoreWindowState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TilesetEditor::initMetatileHistory() {
|
void TilesetEditor::initMetatileHistory() {
|
||||||
MetatileHistoryItem *commit = new MetatileHistoryItem(0, nullptr, this->metatile->copy());
|
MetatileHistoryItem *commit = new MetatileHistoryItem(0, nullptr, new Metatile(*metatile));
|
||||||
metatileHistory.push(commit);
|
metatileHistory.push(commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ void TilesetEditor::onMetatileLayerTileChanged(int x, int y) {
|
||||||
QPoint(4, 1),
|
QPoint(4, 1),
|
||||||
QPoint(5, 1),
|
QPoint(5, 1),
|
||||||
};
|
};
|
||||||
Metatile *prevMetatile = this->metatile->copy();
|
Metatile *prevMetatile = new Metatile(*this->metatile);
|
||||||
QPoint dimensions = this->tileSelector->getSelectionDimensions();
|
QPoint dimensions = this->tileSelector->getSelectionDimensions();
|
||||||
QList<Tile> tiles = this->tileSelector->getSelectedTiles();
|
QList<Tile> tiles = this->tileSelector->getSelectedTiles();
|
||||||
int selectedTileIndex = 0;
|
int selectedTileIndex = 0;
|
||||||
|
@ -401,7 +401,8 @@ void TilesetEditor::onMetatileLayerTileChanged(int x, int y) {
|
||||||
this->metatileLayersItem->draw();
|
this->metatileLayersItem->draw();
|
||||||
this->hasUnsavedChanges = true;
|
this->hasUnsavedChanges = true;
|
||||||
|
|
||||||
MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), prevMetatile, this->metatile->copy());
|
MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(),
|
||||||
|
prevMetatile, new Metatile(*this->metatile));
|
||||||
metatileHistory.push(commit);
|
metatileHistory.push(commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,9 +466,10 @@ void TilesetEditor::on_checkBox_yFlip_stateChanged(int checked)
|
||||||
void TilesetEditor::on_comboBox_metatileBehaviors_activated(const QString &metatileBehavior)
|
void TilesetEditor::on_comboBox_metatileBehaviors_activated(const QString &metatileBehavior)
|
||||||
{
|
{
|
||||||
if (this->metatile) {
|
if (this->metatile) {
|
||||||
Metatile *prevMetatile = this->metatile->copy();
|
Metatile *prevMetatile = new Metatile(*this->metatile);
|
||||||
this->metatile->behavior = static_cast<uint8_t>(project->metatileBehaviorMap[metatileBehavior]);
|
this->metatile->behavior = static_cast<uint8_t>(project->metatileBehaviorMap[metatileBehavior]);
|
||||||
MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), prevMetatile, this->metatile->copy());
|
MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(),
|
||||||
|
prevMetatile, new Metatile(*this->metatile));
|
||||||
metatileHistory.push(commit);
|
metatileHistory.push(commit);
|
||||||
this->hasUnsavedChanges = true;
|
this->hasUnsavedChanges = true;
|
||||||
}
|
}
|
||||||
|
@ -482,9 +484,10 @@ void TilesetEditor::saveMetatileLabel()
|
||||||
{
|
{
|
||||||
// Only commit if the field has changed.
|
// Only commit if the field has changed.
|
||||||
if (this->metatile && this->metatile->label != this->ui->lineEdit_metatileLabel->text()) {
|
if (this->metatile && this->metatile->label != this->ui->lineEdit_metatileLabel->text()) {
|
||||||
Metatile *prevMetatile = this->metatile->copy();
|
Metatile *prevMetatile = new Metatile(*this->metatile);
|
||||||
this->metatile->label = this->ui->lineEdit_metatileLabel->text();
|
this->metatile->label = this->ui->lineEdit_metatileLabel->text();
|
||||||
MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), prevMetatile, this->metatile->copy());
|
MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(),
|
||||||
|
prevMetatile, new Metatile(*this->metatile));
|
||||||
metatileHistory.push(commit);
|
metatileHistory.push(commit);
|
||||||
this->hasUnsavedChanges = true;
|
this->hasUnsavedChanges = true;
|
||||||
}
|
}
|
||||||
|
@ -493,9 +496,10 @@ void TilesetEditor::saveMetatileLabel()
|
||||||
void TilesetEditor::on_comboBox_layerType_activated(int layerType)
|
void TilesetEditor::on_comboBox_layerType_activated(int layerType)
|
||||||
{
|
{
|
||||||
if (this->metatile) {
|
if (this->metatile) {
|
||||||
Metatile *prevMetatile = this->metatile->copy();
|
Metatile *prevMetatile = new Metatile(*this->metatile);
|
||||||
this->metatile->layerType = static_cast<uint8_t>(layerType);
|
this->metatile->layerType = static_cast<uint8_t>(layerType);
|
||||||
MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), prevMetatile, this->metatile->copy());
|
MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(),
|
||||||
|
prevMetatile, new Metatile(*this->metatile));
|
||||||
metatileHistory.push(commit);
|
metatileHistory.push(commit);
|
||||||
this->hasUnsavedChanges = true;
|
this->hasUnsavedChanges = true;
|
||||||
}
|
}
|
||||||
|
@ -504,9 +508,10 @@ void TilesetEditor::on_comboBox_layerType_activated(int layerType)
|
||||||
void TilesetEditor::on_comboBox_encounterType_activated(int encounterType)
|
void TilesetEditor::on_comboBox_encounterType_activated(int encounterType)
|
||||||
{
|
{
|
||||||
if (this->metatile) {
|
if (this->metatile) {
|
||||||
Metatile *prevMetatile = this->metatile->copy();
|
Metatile *prevMetatile = new Metatile(*this->metatile);
|
||||||
this->metatile->encounterType = static_cast<uint8_t>(encounterType);
|
this->metatile->encounterType = static_cast<uint8_t>(encounterType);
|
||||||
MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), prevMetatile, this->metatile->copy());
|
MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(),
|
||||||
|
prevMetatile, new Metatile(*this->metatile));
|
||||||
metatileHistory.push(commit);
|
metatileHistory.push(commit);
|
||||||
this->hasUnsavedChanges = true;
|
this->hasUnsavedChanges = true;
|
||||||
}
|
}
|
||||||
|
@ -515,9 +520,10 @@ void TilesetEditor::on_comboBox_encounterType_activated(int encounterType)
|
||||||
void TilesetEditor::on_comboBox_terrainType_activated(int terrainType)
|
void TilesetEditor::on_comboBox_terrainType_activated(int terrainType)
|
||||||
{
|
{
|
||||||
if (this->metatile) {
|
if (this->metatile) {
|
||||||
Metatile *prevMetatile = this->metatile->copy();
|
Metatile *prevMetatile = new Metatile(*this->metatile);
|
||||||
this->metatile->terrainType = static_cast<uint8_t>(terrainType);
|
this->metatile->terrainType = static_cast<uint8_t>(terrainType);
|
||||||
MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), prevMetatile, this->metatile->copy());
|
MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(),
|
||||||
|
prevMetatile, new Metatile(*this->metatile));
|
||||||
metatileHistory.push(commit);
|
metatileHistory.push(commit);
|
||||||
this->hasUnsavedChanges = true;
|
this->hasUnsavedChanges = true;
|
||||||
}
|
}
|
||||||
|
@ -811,7 +817,7 @@ void TilesetEditor::on_actionUndo_triggered()
|
||||||
Metatile *temp = Tileset::getMetatile(commit->metatileId, this->primaryTileset, this->secondaryTileset);
|
Metatile *temp = Tileset::getMetatile(commit->metatileId, this->primaryTileset, this->secondaryTileset);
|
||||||
if (temp) {
|
if (temp) {
|
||||||
this->metatile = temp;
|
this->metatile = temp;
|
||||||
this->metatile->copyInPlace(prev);
|
*this->metatile = *prev;
|
||||||
this->metatileSelector->select(commit->metatileId);
|
this->metatileSelector->select(commit->metatileId);
|
||||||
this->metatileSelector->draw();
|
this->metatileSelector->draw();
|
||||||
this->metatileLayersItem->draw();
|
this->metatileLayersItem->draw();
|
||||||
|
@ -828,8 +834,8 @@ void TilesetEditor::on_actionRedo_triggered()
|
||||||
|
|
||||||
Metatile *temp = Tileset::getMetatile(commit->metatileId, this->primaryTileset, this->secondaryTileset);
|
Metatile *temp = Tileset::getMetatile(commit->metatileId, this->primaryTileset, this->secondaryTileset);
|
||||||
if (temp) {
|
if (temp) {
|
||||||
this->metatile = Tileset::getMetatile(commit->metatileId, this->primaryTileset, this->secondaryTileset);
|
this->metatile = temp;
|
||||||
this->metatile->copyInPlace(next);
|
*this->metatile = *next;
|
||||||
this->metatileSelector->select(commit->metatileId);
|
this->metatileSelector->select(commit->metatileId);
|
||||||
this->metatileSelector->draw();
|
this->metatileSelector->draw();
|
||||||
this->metatileLayersItem->draw();
|
this->metatileLayersItem->draw();
|
||||||
|
@ -905,8 +911,9 @@ void TilesetEditor::importTilesetMetatiles(Tileset *tileset, bool primary)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Metatile *prevMetatile = tileset->metatiles->at(i)->copy();
|
Metatile *prevMetatile = new Metatile(*tileset->metatiles->at(i));
|
||||||
MetatileHistoryItem *commit = new MetatileHistoryItem(static_cast<uint16_t>(metatileIdBase + i), prevMetatile, metatiles->at(i)->copy());
|
MetatileHistoryItem *commit = new MetatileHistoryItem(static_cast<uint16_t>(metatileIdBase + i),
|
||||||
|
prevMetatile, new Metatile(*metatiles->at(i)));
|
||||||
metatileHistory.push(commit);
|
metatileHistory.push(commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue