Move static tileset vars to Project
This commit is contained in:
parent
a6fc81ae1a
commit
363ea86a2a
5 changed files with 67 additions and 34 deletions
7
map.cpp
7
map.cpp
|
@ -1,4 +1,5 @@
|
|||
#include "map.h"
|
||||
#include "project.h"
|
||||
|
||||
#include <QTime>
|
||||
#include <QDebug>
|
||||
|
@ -68,7 +69,7 @@ uint16_t Map::getSelectedBlockIndex(int index) {
|
|||
if (index < layout->tileset_primary->metatiles->length()) {
|
||||
return static_cast<uint16_t>(index);
|
||||
} else {
|
||||
return static_cast<uint16_t>(Tileset::num_metatiles_primary + index - layout->tileset_primary->metatiles->length());
|
||||
return static_cast<uint16_t>(Project::getNumMetatilesPrimary() + index - layout->tileset_primary->metatiles->length());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +77,7 @@ int Map::getDisplayedBlockIndex(int index) {
|
|||
if (index < layout->tileset_primary->metatiles->length()) {
|
||||
return index;
|
||||
} else {
|
||||
return index - Tileset::num_metatiles_primary + layout->tileset_primary->metatiles->length();
|
||||
return index - Project::getNumMetatilesPrimary() + layout->tileset_primary->metatiles->length();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -337,7 +338,7 @@ QPixmap Map::renderMetatiles() {
|
|||
for (int i = 0; i < length_; i++) {
|
||||
int tile = i;
|
||||
if (i >= primary_length) {
|
||||
tile += Tileset::num_metatiles_primary - primary_length;
|
||||
tile += Project::getNumMetatilesPrimary() - primary_length;
|
||||
}
|
||||
QImage metatile_image = Metatile::getMetatileImage(tile, layout->tileset_primary, layout->tileset_secondary);
|
||||
int map_y = i / width_;
|
||||
|
|
55
project.cpp
55
project.cpp
|
@ -12,6 +12,13 @@
|
|||
#include <QMessageBox>
|
||||
#include <QRegularExpression>
|
||||
|
||||
int Project::num_tiles_primary = 512;
|
||||
int Project::num_tiles_total = 1024;
|
||||
int Project::num_metatiles_primary = 512;
|
||||
int Project::num_metatiles_total = 1024;
|
||||
int Project::num_pals_primary = 6;
|
||||
int Project::num_pals_total = 13;
|
||||
|
||||
Project::Project()
|
||||
{
|
||||
groupNames = new QStringList;
|
||||
|
@ -1131,50 +1138,44 @@ void Project::readTilesetProperties() {
|
|||
QMap<QString, int> defines = readCDefines(text, definePrefixes);
|
||||
auto it = defines.find("NUM_TILES_IN_PRIMARY");
|
||||
if (it != defines.end()) {
|
||||
Tileset::num_tiles_primary = it.value();
|
||||
Project::num_tiles_primary = it.value();
|
||||
}
|
||||
else {
|
||||
Tileset::num_tiles_primary = 512;
|
||||
error = true;
|
||||
}
|
||||
it = defines.find("NUM_TILES_TOTAL");
|
||||
if (it != defines.end()) {
|
||||
Tileset::num_tiles_total = it.value();
|
||||
Project::num_tiles_total = it.value();
|
||||
}
|
||||
else {
|
||||
Tileset::num_tiles_total = 1024;
|
||||
error = true;
|
||||
}
|
||||
it = defines.find("NUM_METATILES_IN_PRIMARY");
|
||||
if (it != defines.end()) {
|
||||
Tileset::num_metatiles_primary = it.value();
|
||||
Project::num_metatiles_primary = it.value();
|
||||
}
|
||||
else {
|
||||
Tileset::num_metatiles_primary = 512;
|
||||
error = true;
|
||||
}
|
||||
it = defines.find("NUM_METATILES_TOTAL");
|
||||
if (it != defines.end()) {
|
||||
Tileset::num_metatiles_total = it.value();
|
||||
Project::num_metatiles_total = it.value();
|
||||
}
|
||||
else {
|
||||
Tileset::num_metatiles_total = 1024;
|
||||
error = true;
|
||||
}
|
||||
it = defines.find("NUM_PALS_IN_PRIMARY");
|
||||
if (it != defines.end()) {
|
||||
Tileset::num_pals_primary = it.value();
|
||||
Project::num_pals_primary = it.value();
|
||||
}
|
||||
else {
|
||||
Tileset::num_pals_primary = 6;
|
||||
error = true;
|
||||
}
|
||||
it = defines.find("NUM_PALS_TOTAL");
|
||||
if (it != defines.end()) {
|
||||
Tileset::num_pals_total = it.value();
|
||||
Project::num_pals_total = it.value();
|
||||
}
|
||||
else {
|
||||
Tileset::num_pals_total = 13;
|
||||
error = true;
|
||||
}
|
||||
|
||||
|
@ -1730,3 +1731,33 @@ QMap<QString, int> Project::readCDefines(QString text, QStringList prefixes) {
|
|||
}
|
||||
return filteredDefines;
|
||||
}
|
||||
|
||||
int Project::getNumTilesPrimary()
|
||||
{
|
||||
return Project::num_tiles_primary;
|
||||
}
|
||||
|
||||
int Project::getNumTilesTotal()
|
||||
{
|
||||
return Project::num_tiles_total;
|
||||
}
|
||||
|
||||
int Project::getNumMetatilesPrimary()
|
||||
{
|
||||
return Project::num_metatiles_primary;
|
||||
}
|
||||
|
||||
int Project::getNumMetatilesTotal()
|
||||
{
|
||||
return Project::num_metatiles_total;
|
||||
}
|
||||
|
||||
int Project::getNumPalettesPrimary()
|
||||
{
|
||||
return Project::num_pals_primary;
|
||||
}
|
||||
|
||||
int Project::getNumPalettesTotal()
|
||||
{
|
||||
return Project::num_pals_total;
|
||||
}
|
||||
|
|
14
project.h
14
project.h
|
@ -115,6 +115,13 @@ public:
|
|||
QStringList readCArray(QString text, QString label);
|
||||
QString readCIncbin(QString text, QString label);
|
||||
QMap<QString, int> readCDefines(QString text, QStringList prefixes);
|
||||
|
||||
static int getNumTilesPrimary();
|
||||
static int getNumTilesTotal();
|
||||
static int getNumMetatilesPrimary();
|
||||
static int getNumMetatilesTotal();
|
||||
static int getNumPalettesPrimary();
|
||||
static int getNumPalettesTotal();
|
||||
private:
|
||||
QString getMapLayoutsTableFilepath();
|
||||
QString getMapLayoutFilepath(QString);
|
||||
|
@ -133,6 +140,13 @@ private:
|
|||
void setNewMapBorder(Map *map);
|
||||
void setNewMapEvents(Map *map);
|
||||
void setNewMapConnections(Map *map);
|
||||
|
||||
static int num_tiles_primary;
|
||||
static int num_tiles_total;
|
||||
static int num_metatiles_primary;
|
||||
static int num_metatiles_total;
|
||||
static int num_pals_primary;
|
||||
static int num_pals_total;
|
||||
};
|
||||
|
||||
#endif // PROJECT_H
|
||||
|
|
18
tileset.cpp
18
tileset.cpp
|
@ -1,4 +1,5 @@
|
|||
#include "tileset.h"
|
||||
#include "project.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QImage>
|
||||
|
@ -9,13 +10,6 @@ Tileset::Tileset()
|
|||
|
||||
}
|
||||
|
||||
int Tileset::num_tiles_primary;
|
||||
int Tileset::num_tiles_total;
|
||||
int Tileset::num_metatiles_primary;
|
||||
int Tileset::num_metatiles_total;
|
||||
int Tileset::num_pals_primary;
|
||||
int Tileset::num_pals_total;
|
||||
|
||||
Metatile::Metatile()
|
||||
{
|
||||
tiles = new QList<Tile>;
|
||||
|
@ -95,7 +89,7 @@ QImage Metatile::getMetatileTile(int tile, Tileset *primaryTileset, Tileset *sec
|
|||
}
|
||||
|
||||
Tileset* Metatile::getBlockTileset(int metatile_index, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||
if (metatile_index < Tileset::num_metatiles_primary) {
|
||||
if (metatile_index < Project::getNumMetatilesPrimary()) {
|
||||
return primaryTileset;
|
||||
} else {
|
||||
return secondaryTileset;
|
||||
|
@ -103,19 +97,19 @@ Tileset* Metatile::getBlockTileset(int metatile_index, Tileset *primaryTileset,
|
|||
}
|
||||
|
||||
int Metatile::getBlockIndex(int index) {
|
||||
if (index < Tileset::num_metatiles_primary) {
|
||||
if (index < Project::getNumMetatilesPrimary()) {
|
||||
return index;
|
||||
} else {
|
||||
return index - Tileset::num_metatiles_primary;
|
||||
return index - Project::getNumMetatilesPrimary();
|
||||
}
|
||||
}
|
||||
|
||||
QList<QList<QRgb>> Metatile::getBlockPalettes(Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||
QList<QList<QRgb>> palettes;
|
||||
for (int i = 0; i < Tileset::num_pals_primary; i++) {
|
||||
for (int i = 0; i < Project::getNumPalettesPrimary(); i++) {
|
||||
palettes.append(primaryTileset->palettes->at(i));
|
||||
}
|
||||
for (int i = Tileset::num_pals_primary; i < Tileset::num_pals_total; i++) {
|
||||
for (int i = Project::getNumPalettesPrimary(); i < Project::getNumPalettesTotal(); i++) {
|
||||
palettes.append(secondaryTileset->palettes->at(i));
|
||||
}
|
||||
return palettes;
|
||||
|
|
|
@ -24,13 +24,6 @@ public:
|
|||
QList<QImage> *tiles = nullptr;
|
||||
QList<Metatile*> *metatiles = nullptr;
|
||||
QList<QList<QRgb>> *palettes = nullptr;
|
||||
|
||||
static int num_tiles_primary;
|
||||
static int num_tiles_total;
|
||||
static int num_metatiles_primary;
|
||||
static int num_metatiles_total;
|
||||
static int num_pals_primary;
|
||||
static int num_pals_total;
|
||||
};
|
||||
|
||||
class Metatile
|
||||
|
|
Loading…
Reference in a new issue