Tile properties to bitfield

This commit is contained in:
GriffinR 2022-08-26 19:30:40 -04:00
parent fd4ba874d2
commit aad1266e91
3 changed files with 8 additions and 25 deletions

View file

@ -8,17 +8,15 @@ class Tile
{
public:
Tile();
Tile(int tileId, bool xflip, bool yflip, int palette);
Tile(uint16_t tileId, uint16_t xflip, uint16_t yflip, uint16_t palette);
Tile(uint16_t raw);
public:
int tileId;
bool xflip;
bool yflip;
int palette;
uint16_t tileId:10;
uint16_t xflip:1;
uint16_t yflip:1;
uint16_t palette:4;
uint16_t rawValue() const;
void sanitize();
static int getIndexInTileset(int);
};

View file

@ -8,7 +8,7 @@
palette(0)
{ }
Tile::Tile(int tileId, bool xflip, bool yflip, int palette) :
Tile::Tile(uint16_t tileId, uint16_t xflip, uint16_t yflip, uint16_t palette) :
tileId(tileId),
xflip(xflip),
yflip(yflip),
@ -30,17 +30,6 @@ uint16_t Tile::rawValue() const {
| ((this->palette & 0xF) << 12));
}
void Tile::sanitize() {
if (tileId < 0 || tileId >= Project::getNumTilesTotal()) {
logWarn(QString("Resetting tile's invalid tile id '%1' to 0.").arg(tileId));
tileId = 0;
}
if (palette < 0 || palette >= Project::getNumPalettesTotal()) {
logWarn(QString("Resetting tile's invalid palette id '%1' to 0.").arg(palette));
palette = 0;
}
}
int Tile::getIndexInTileset(int tileId) {
if (tileId < Project::getNumTilesPrimary()) {
return tileId;

View file

@ -991,11 +991,8 @@ void MainWindow::setMetatileTiles(int metatileId, QJSValue tilesObj, int tileSta
// Write to metatile using as many of the given Tiles as possible
int numTileObjs = qMin(tilesObj.property("length").toInt(), numTiles);
int i = 0;
for (; i < numTileObjs; i++, tileStart++) {
Tile tile = Scripting::toTile(tilesObj.property(i));
tile.sanitize();
metatile->tiles[tileStart] = tile;
}
for (; i < numTileObjs; i++, tileStart++)
metatile->tiles[tileStart] = Scripting::toTile(tilesObj.property(i));
// Fill remainder of specified length with empty Tiles
for (; i < numTiles; i++, tileStart++)
@ -1014,7 +1011,6 @@ void MainWindow::setMetatileTiles(int metatileId, int tileId, bool xflip, bool y
// Write to metatile using Tiles of the specified value
Tile tile = Tile(tileId, xflip, yflip, palette);
tile.sanitize();
for (int i = tileStart; i <= tileEnd; i++)
metatile->tiles[i] = tile;