Merge pull request #452 from GriffinRichards/rewrite-loadmetatiles
Clean up loadTilesetMetatiles
This commit is contained in:
commit
cd697df23d
1 changed files with 6 additions and 6 deletions
|
@ -1078,8 +1078,8 @@ void Project::saveTilesetMetatiles(Tileset *tileset) {
|
||||||
QFile metatiles_file(tileset->metatiles_path);
|
QFile metatiles_file(tileset->metatiles_path);
|
||||||
if (metatiles_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
if (metatiles_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
|
int numTiles = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8;
|
||||||
for (Metatile *metatile : tileset->metatiles) {
|
for (Metatile *metatile : tileset->metatiles) {
|
||||||
int numTiles = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8;
|
|
||||||
for (int i = 0; i < numTiles; i++) {
|
for (int i = 0; i < numTiles; i++) {
|
||||||
uint16_t tile = metatile->tiles.at(i).rawValue();
|
uint16_t tile = metatile->tiles.at(i).rawValue();
|
||||||
data.append(static_cast<char>(tile));
|
data.append(static_cast<char>(tile));
|
||||||
|
@ -1583,14 +1583,14 @@ void Project::loadTilesetMetatiles(Tileset* tileset) {
|
||||||
QFile metatiles_file(tileset->metatiles_path);
|
QFile metatiles_file(tileset->metatiles_path);
|
||||||
if (metatiles_file.open(QIODevice::ReadOnly)) {
|
if (metatiles_file.open(QIODevice::ReadOnly)) {
|
||||||
QByteArray data = metatiles_file.readAll();
|
QByteArray data = metatiles_file.readAll();
|
||||||
int metatile_data_length = projectConfig.getTripleLayerMetatilesEnabled() ? 24 : 16;
|
int tilesPerMetatile = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8;
|
||||||
int num_metatiles = data.length() / metatile_data_length;
|
int bytesPerMetatile = 2 * tilesPerMetatile;
|
||||||
int num_layers = projectConfig.getTripleLayerMetatilesEnabled() ? 3 : 2;
|
int num_metatiles = data.length() / bytesPerMetatile;
|
||||||
QList<Metatile*> metatiles;
|
QList<Metatile*> metatiles;
|
||||||
for (int i = 0; i < num_metatiles; i++) {
|
for (int i = 0; i < num_metatiles; i++) {
|
||||||
Metatile *metatile = new Metatile;
|
Metatile *metatile = new Metatile;
|
||||||
int index = i * (2 * 4 * num_layers);
|
int index = i * bytesPerMetatile;
|
||||||
for (int j = 0; j < 4 * num_layers; j++) {
|
for (int j = 0; j < tilesPerMetatile; j++) {
|
||||||
uint16_t tileRaw = static_cast<unsigned char>(data[index++]);
|
uint16_t tileRaw = static_cast<unsigned char>(data[index++]);
|
||||||
tileRaw |= static_cast<unsigned char>(data[index++]) << 8;
|
tileRaw |= static_cast<unsigned char>(data[index++]) << 8;
|
||||||
metatile->tiles.append(Tile(tileRaw));
|
metatile->tiles.append(Tile(tileRaw));
|
||||||
|
|
Loading…
Reference in a new issue