Merge pull request #38 from Diegoisawesome/master
Use project values for tilesets
This commit is contained in:
commit
3808750c23
5 changed files with 121 additions and 14 deletions
|
@ -377,6 +377,7 @@ void MainWindow::loadDataStructures() {
|
||||||
project->readSecretBaseIds();
|
project->readSecretBaseIds();
|
||||||
project->readBgEventFacingDirections();
|
project->readBgEventFacingDirections();
|
||||||
project->readMapsWithConnections();
|
project->readMapsWithConnections();
|
||||||
|
project->readTilesetProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::populateMapList() {
|
void MainWindow::populateMapList() {
|
||||||
|
|
7
map.cpp
7
map.cpp
|
@ -1,4 +1,5 @@
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
#include "project.h"
|
||||||
|
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
@ -68,7 +69,7 @@ uint16_t Map::getSelectedBlockIndex(int index) {
|
||||||
if (index < layout->tileset_primary->metatiles->length()) {
|
if (index < layout->tileset_primary->metatiles->length()) {
|
||||||
return static_cast<uint16_t>(index);
|
return static_cast<uint16_t>(index);
|
||||||
} else {
|
} else {
|
||||||
return 0x200 + static_cast<uint16_t>(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()) {
|
if (index < layout->tileset_primary->metatiles->length()) {
|
||||||
return index;
|
return index;
|
||||||
} else {
|
} else {
|
||||||
return index - 0x200 + 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++) {
|
for (int i = 0; i < length_; i++) {
|
||||||
int tile = i;
|
int tile = i;
|
||||||
if (i >= primary_length) {
|
if (i >= primary_length) {
|
||||||
tile += 0x200 - primary_length;
|
tile += Project::getNumMetatilesPrimary() - primary_length;
|
||||||
}
|
}
|
||||||
QImage metatile_image = Metatile::getMetatileImage(tile, layout->tileset_primary, layout->tileset_secondary);
|
QImage metatile_image = Metatile::getMetatileImage(tile, layout->tileset_primary, layout->tileset_secondary);
|
||||||
int map_y = i / width_;
|
int map_y = i / width_;
|
||||||
|
|
95
project.cpp
95
project.cpp
|
@ -12,6 +12,13 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QRegularExpression>
|
#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()
|
Project::Project()
|
||||||
{
|
{
|
||||||
groupNames = new QStringList;
|
groupNames = new QStringList;
|
||||||
|
@ -1121,6 +1128,64 @@ QMap<QString, QStringList> Project::getTilesets() {
|
||||||
return allTilesets;
|
return allTilesets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Project::readTilesetProperties() {
|
||||||
|
QStringList defines;
|
||||||
|
QString text = readTextFile(root + "/include/fieldmap.h");
|
||||||
|
if (!text.isNull()) {
|
||||||
|
bool error = false;
|
||||||
|
QStringList definePrefixes;
|
||||||
|
definePrefixes << "NUM_";
|
||||||
|
QMap<QString, int> defines = readCDefines(text, definePrefixes);
|
||||||
|
auto it = defines.find("NUM_TILES_IN_PRIMARY");
|
||||||
|
if (it != defines.end()) {
|
||||||
|
Project::num_tiles_primary = it.value();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
it = defines.find("NUM_TILES_TOTAL");
|
||||||
|
if (it != defines.end()) {
|
||||||
|
Project::num_tiles_total = it.value();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
it = defines.find("NUM_METATILES_IN_PRIMARY");
|
||||||
|
if (it != defines.end()) {
|
||||||
|
Project::num_metatiles_primary = it.value();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
it = defines.find("NUM_METATILES_TOTAL");
|
||||||
|
if (it != defines.end()) {
|
||||||
|
Project::num_metatiles_total = it.value();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
it = defines.find("NUM_PALS_IN_PRIMARY");
|
||||||
|
if (it != defines.end()) {
|
||||||
|
Project::num_pals_primary = it.value();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
it = defines.find("NUM_PALS_TOTAL");
|
||||||
|
if (it != defines.end()) {
|
||||||
|
Project::num_pals_total = it.value();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
qDebug() << "Some global tileset values could not be loaded. Using default values";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Project::readRegionMapSections() {
|
void Project::readRegionMapSections() {
|
||||||
QString filepath = root + "/include/constants/region_map_sections.h";
|
QString filepath = root + "/include/constants/region_map_sections.h";
|
||||||
QStringList prefixes = (QStringList() << "MAPSEC_");
|
QStringList prefixes = (QStringList() << "MAPSEC_");
|
||||||
|
@ -1666,3 +1731,33 @@ QMap<QString, int> Project::readCDefines(QString text, QStringList prefixes) {
|
||||||
}
|
}
|
||||||
return filteredDefines;
|
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;
|
||||||
|
}
|
||||||
|
|
15
project.h
15
project.h
|
@ -88,6 +88,7 @@ public:
|
||||||
QStringList getSongNames();
|
QStringList getSongNames();
|
||||||
QStringList getVisibilities();
|
QStringList getVisibilities();
|
||||||
QMap<QString, QStringList> getTilesets();
|
QMap<QString, QStringList> getTilesets();
|
||||||
|
void readTilesetProperties();
|
||||||
void readRegionMapSections();
|
void readRegionMapSections();
|
||||||
void readItemNames();
|
void readItemNames();
|
||||||
void readFlagNames();
|
void readFlagNames();
|
||||||
|
@ -114,6 +115,13 @@ public:
|
||||||
QStringList readCArray(QString text, QString label);
|
QStringList readCArray(QString text, QString label);
|
||||||
QString readCIncbin(QString text, QString label);
|
QString readCIncbin(QString text, QString label);
|
||||||
QMap<QString, int> readCDefines(QString text, QStringList prefixes);
|
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:
|
private:
|
||||||
QString getMapLayoutsTableFilepath();
|
QString getMapLayoutsTableFilepath();
|
||||||
QString getMapLayoutFilepath(QString);
|
QString getMapLayoutFilepath(QString);
|
||||||
|
@ -132,6 +140,13 @@ private:
|
||||||
void setNewMapBorder(Map *map);
|
void setNewMapBorder(Map *map);
|
||||||
void setNewMapEvents(Map *map);
|
void setNewMapEvents(Map *map);
|
||||||
void setNewMapConnections(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
|
#endif // PROJECT_H
|
||||||
|
|
17
tileset.cpp
17
tileset.cpp
|
@ -1,4 +1,5 @@
|
||||||
#include "tileset.h"
|
#include "tileset.h"
|
||||||
|
#include "project.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
@ -88,8 +89,7 @@ QImage Metatile::getMetatileTile(int tile, Tileset *primaryTileset, Tileset *sec
|
||||||
}
|
}
|
||||||
|
|
||||||
Tileset* Metatile::getBlockTileset(int metatile_index, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
Tileset* Metatile::getBlockTileset(int metatile_index, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||||
int primary_size = 0x200;
|
if (metatile_index < Project::getNumMetatilesPrimary()) {
|
||||||
if (metatile_index < primary_size) {
|
|
||||||
return primaryTileset;
|
return primaryTileset;
|
||||||
} else {
|
} else {
|
||||||
return secondaryTileset;
|
return secondaryTileset;
|
||||||
|
@ -97,24 +97,19 @@ Tileset* Metatile::getBlockTileset(int metatile_index, Tileset *primaryTileset,
|
||||||
}
|
}
|
||||||
|
|
||||||
int Metatile::getBlockIndex(int index) {
|
int Metatile::getBlockIndex(int index) {
|
||||||
int primary_size = 0x200;
|
if (index < Project::getNumMetatilesPrimary()) {
|
||||||
if (index < primary_size) {
|
|
||||||
return index;
|
return index;
|
||||||
} else {
|
} else {
|
||||||
return index - primary_size;
|
return index - Project::getNumMetatilesPrimary();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QList<QRgb>> Metatile::getBlockPalettes(Tileset *primaryTileset, Tileset *secondaryTileset) {
|
QList<QList<QRgb>> Metatile::getBlockPalettes(Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||||
QList<QList<QRgb>> palettes;
|
QList<QList<QRgb>> palettes;
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < Project::getNumPalettesPrimary(); i++) {
|
||||||
palettes.append(primaryTileset->palettes->at(i));
|
palettes.append(primaryTileset->palettes->at(i));
|
||||||
}
|
}
|
||||||
|
for (int i = Project::getNumPalettesPrimary(); i < Project::getNumPalettesTotal(); i++) {
|
||||||
// TODO: Find a reliable way to detect Ruby vs. Emerald
|
|
||||||
// Ruby's secondary tilesets only use palettes 6-11, whereas
|
|
||||||
// Emerald uses 6-12.
|
|
||||||
for (int i = 6; i < 13; i++) {
|
|
||||||
palettes.append(secondaryTileset->palettes->at(i));
|
palettes.append(secondaryTileset->palettes->at(i));
|
||||||
}
|
}
|
||||||
return palettes;
|
return palettes;
|
||||||
|
|
Loading…
Reference in a new issue