write palette of region map image, fix ruby city map render
This commit is contained in:
parent
a475823fee
commit
5bfc32fb7f
8 changed files with 65 additions and 22 deletions
|
@ -1,15 +1,16 @@
|
|||
#ifndef PALETTEPARSER_H
|
||||
#define PALETTEPARSER_H
|
||||
#ifndef PALETTEUTIL_H
|
||||
#define PALETTEUTIL_H
|
||||
|
||||
#include <QList>
|
||||
#include <QRgb>
|
||||
#include <QString>
|
||||
|
||||
class PaletteParser
|
||||
class PaletteUtil
|
||||
{
|
||||
public:
|
||||
PaletteParser();
|
||||
PaletteUtil();
|
||||
QList<QRgb> parse(QString filepath, bool *error);
|
||||
void writeJASC(QString filepath, QVector<QRgb> colors, int offset, int nColors);
|
||||
private:
|
||||
QList<QRgb> parsePal(QString filepath, bool *error);
|
||||
QList<QRgb> parseJASC(QString filepath, bool *error);
|
||||
|
@ -20,4 +21,4 @@ private:
|
|||
int clampColorValue(int value);
|
||||
};
|
||||
|
||||
#endif // PALETTEPARSER_H
|
||||
#endif // PALETTEUTIL_H
|
|
@ -24,7 +24,7 @@ SOURCES += src/core/block.cpp \
|
|||
src/core/maplayout.cpp \
|
||||
src/core/metatile.cpp \
|
||||
src/core/metatileparser.cpp \
|
||||
src/core/paletteparser.cpp \
|
||||
src/core/paletteutil.cpp \
|
||||
src/core/parseutil.cpp \
|
||||
src/core/tile.cpp \
|
||||
src/core/tileset.cpp \
|
||||
|
@ -80,7 +80,7 @@ HEADERS += include/core/block.h \
|
|||
include/core/maplayout.h \
|
||||
include/core/metatile.h \
|
||||
include/core/metatileparser.h \
|
||||
include/core/paletteparser.h \
|
||||
include/core/paletteutil.h \
|
||||
include/core/parseutil.h \
|
||||
include/core/tile.h \
|
||||
include/core/tileset.h \
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#include "paletteparser.h"
|
||||
#include "paletteutil.h"
|
||||
#include "log.h"
|
||||
#include <QFileInfo>
|
||||
#include <QRegularExpression>
|
||||
|
||||
PaletteParser::PaletteParser()
|
||||
PaletteUtil::PaletteUtil()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QList<QRgb> PaletteParser::parse(QString filepath, bool *error) {
|
||||
QList<QRgb> PaletteUtil::parse(QString filepath, bool *error) {
|
||||
QFileInfo info(filepath);
|
||||
QString extension = info.completeSuffix();
|
||||
if (extension.isNull()) {
|
||||
|
@ -34,7 +34,7 @@ QList<QRgb> PaletteParser::parse(QString filepath, bool *error) {
|
|||
return QList<QRgb>();
|
||||
}
|
||||
|
||||
QList<QRgb> PaletteParser::parsePal(QString filepath, bool *error) {
|
||||
QList<QRgb> PaletteUtil::parsePal(QString filepath, bool *error) {
|
||||
QFile file(filepath);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
*error = true;
|
||||
|
@ -53,7 +53,7 @@ QList<QRgb> PaletteParser::parsePal(QString filepath, bool *error) {
|
|||
}
|
||||
}
|
||||
|
||||
QList<QRgb> PaletteParser::parseJASC(QString filepath, bool *error) {
|
||||
QList<QRgb> PaletteUtil::parseJASC(QString filepath, bool *error) {
|
||||
QFile file(filepath);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
*error = true;
|
||||
|
@ -120,7 +120,7 @@ QList<QRgb> PaletteParser::parseJASC(QString filepath, bool *error) {
|
|||
return palette;
|
||||
}
|
||||
|
||||
QList<QRgb> PaletteParser::parseAdvanceMapPal(QString filepath, bool *error) {
|
||||
QList<QRgb> PaletteUtil::parseAdvanceMapPal(QString filepath, bool *error) {
|
||||
QFile file(filepath);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
*error = true;
|
||||
|
@ -152,7 +152,7 @@ QList<QRgb> PaletteParser::parseAdvanceMapPal(QString filepath, bool *error) {
|
|||
return palette;
|
||||
}
|
||||
|
||||
QList<QRgb> PaletteParser::parseAdobeColorTable(QString filepath, bool *error) {
|
||||
QList<QRgb> PaletteUtil::parseAdobeColorTable(QString filepath, bool *error) {
|
||||
QFile file(filepath);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
*error = true;
|
||||
|
@ -184,7 +184,7 @@ QList<QRgb> PaletteParser::parseAdobeColorTable(QString filepath, bool *error) {
|
|||
return palette;
|
||||
}
|
||||
|
||||
QList<QRgb> PaletteParser::parseTileLayerPro(QString filepath, bool *error) {
|
||||
QList<QRgb> PaletteUtil::parseTileLayerPro(QString filepath, bool *error) {
|
||||
QFile file(filepath);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
*error = true;
|
||||
|
@ -222,7 +222,7 @@ QList<QRgb> PaletteParser::parseTileLayerPro(QString filepath, bool *error) {
|
|||
return palette;
|
||||
}
|
||||
|
||||
QList<QRgb> PaletteParser::parseAdvancePaletteEditor(QString filepath, bool *error) {
|
||||
QList<QRgb> PaletteUtil::parseAdvancePaletteEditor(QString filepath, bool *error) {
|
||||
QFile file(filepath);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
*error = true;
|
||||
|
@ -267,7 +267,35 @@ QList<QRgb> PaletteParser::parseAdvancePaletteEditor(QString filepath, bool *err
|
|||
return palette;
|
||||
}
|
||||
|
||||
int PaletteParser::clampColorValue(int value) {
|
||||
void PaletteUtil::writeJASC(QString filepath, QVector<QRgb> palette, int offset, int nColors) {
|
||||
if (!nColors) {
|
||||
logWarn(QString("Cannot save a palette with no colors."));
|
||||
return;
|
||||
}
|
||||
if (offset > palette.size() || offset + nColors > palette.size()) {
|
||||
logWarn("Palette offset out of range for color table.");
|
||||
return;
|
||||
}
|
||||
|
||||
QString text = "JASC-PAL\n0100\n";
|
||||
text += QString::number(nColors) + "\n";
|
||||
|
||||
for (int i = offset; i < offset + nColors; i++) {
|
||||
QRgb color = palette.at(i);
|
||||
text += QString::number(qRed(color)) + " "
|
||||
+ QString::number(qGreen(color)) + " "
|
||||
+ QString::number(qBlue(color)) + "\n";
|
||||
}
|
||||
|
||||
QFile file(filepath);
|
||||
if (file.open(QIODevice::WriteOnly)) {
|
||||
file.write(text.toUtf8());
|
||||
} else {
|
||||
logWarn(QString("Could not write to file '%1': ").arg(filepath) + file.errorString());
|
||||
}
|
||||
}
|
||||
|
||||
int PaletteUtil::clampColorValue(int value) {
|
||||
if (value < 0) {
|
||||
value = 0;
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#include "regionmap.h"
|
||||
#include "paletteutil.h"
|
||||
#include "log.h"
|
||||
#include "config.h"
|
||||
|
||||
|
@ -45,6 +46,9 @@ void RegionMap::saveTileImages() {
|
|||
QImage pngImage = QImage::fromData(imageData);
|
||||
this->region_map_png_path = project->root + "/graphics/pokenav/region_map.png";
|
||||
pngImage.save(pngPath());
|
||||
|
||||
PaletteUtil parser;
|
||||
parser.writeJASC(project->root + "/graphics/pokenav/region_map.pal", pngImage.colorTable(), 0x70, 0x20);
|
||||
}
|
||||
QFile cityTileFile(cityTilesPath());
|
||||
if (cityTileFile.open(QIODevice::ReadOnly)) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "citymappixmapitem.h"
|
||||
#include "imageproviders.h"
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <QFile>
|
||||
|
@ -14,6 +15,11 @@ void CityMapPixmapItem::init() {
|
|||
if (!binFile.open(QIODevice::ReadOnly)) return;
|
||||
|
||||
data = binFile.readAll();
|
||||
if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokeruby) {
|
||||
for (int i = 0; i < data.size(); i++)
|
||||
data[i] = data[i] ^ 0x80;
|
||||
}
|
||||
|
||||
binFile.close();
|
||||
}
|
||||
|
||||
|
@ -39,6 +45,10 @@ void CityMapPixmapItem::save() {
|
|||
logError(QString("Cannot save city map tilemap to %1.").arg(file));
|
||||
return;
|
||||
}
|
||||
if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokeruby) {
|
||||
for (int i = 0; i < data.size(); i++)
|
||||
data[i] = data[i] ^ 0x80;
|
||||
}
|
||||
binFile.write(data);
|
||||
binFile.close();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "paletteeditor.h"
|
||||
#include "ui_paletteeditor.h"
|
||||
#include "paletteparser.h"
|
||||
#include "paletteutil.h"
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include "log.h"
|
||||
|
@ -268,7 +268,7 @@ void PaletteEditor::on_actionImport_Palette_triggered()
|
|||
return;
|
||||
}
|
||||
|
||||
PaletteParser parser;
|
||||
PaletteUtil parser;
|
||||
bool error = false;
|
||||
QList<QRgb> palette = parser.parse(filepath, &error);
|
||||
if (error) {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "log.h"
|
||||
#include "imageproviders.h"
|
||||
#include "metatileparser.h"
|
||||
#include "paletteparser.h"
|
||||
#include "paletteutil.h"
|
||||
#include "imageexport.h"
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
@ -408,7 +408,7 @@ void TilesetEditor::importTilesetTiles(Tileset *tileset, bool primary) {
|
|||
return;
|
||||
}
|
||||
|
||||
PaletteParser parser;
|
||||
PaletteUtil parser;
|
||||
bool error = false;
|
||||
QList<QRgb> palette = parser.parse(filepath, &error);
|
||||
if (error) {
|
||||
|
|
Loading…
Reference in a new issue