[nostalgia/core/studio] Make TileSheetEditor's implementation better match data
This commit is contained in:
parent
a9f55ebd02
commit
474230ae97
@ -17,20 +17,26 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
QVector<Color32> toPixels(const NostalgiaGraphic *ng, const NostalgiaPalette *npal) {
|
QString SheetData::pixel(int index) {
|
||||||
|
return m_palette[m_pixels[index]];
|
||||||
|
}
|
||||||
|
|
||||||
|
void SheetData::updatePixels(const NostalgiaGraphic *ng, const NostalgiaPalette *npal) {
|
||||||
if (!npal) {
|
if (!npal) {
|
||||||
npal = &ng->pal;
|
npal = &ng->pal;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<Color32> out;
|
// load palette
|
||||||
out.reserve(ng->tiles.size() * sizeof(Color16));
|
for (std::size_t i = 0; i < npal->colors.size(); i++) {
|
||||||
|
auto c = toColor32(npal->colors[i]);
|
||||||
|
auto color = "#" + QString("%1").arg(QString::number(c, 16), 8, '0');
|
||||||
|
m_palette.append(color);
|
||||||
|
}
|
||||||
|
|
||||||
if (ng->bpp == 8) {
|
if (ng->bpp == 8) {
|
||||||
for (std::size_t i = 0; i < ng->tiles.size(); i++) {
|
for (std::size_t i = 0; i < ng->tiles.size(); i++) {
|
||||||
auto p = ng->tiles[i];
|
m_pixels.push_back(ng->tiles[i]);
|
||||||
auto c = p < npal->colors.size() ? npal->colors[p] : 0;
|
|
||||||
out.push_back(toColor32(c));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (std::size_t i = 0; i < ng->tiles.size() * 2; i++) {
|
for (std::size_t i = 0; i < ng->tiles.size() * 2; i++) {
|
||||||
@ -40,16 +46,12 @@ QVector<Color32> toPixels(const NostalgiaGraphic *ng, const NostalgiaPalette *np
|
|||||||
} else {
|
} else {
|
||||||
p = ng->tiles[i / 2] & 0xF;
|
p = ng->tiles[i / 2] & 0xF;
|
||||||
}
|
}
|
||||||
auto c = p < npal->colors.size() ? npal->colors[p] : 0;
|
m_pixels.push_back(p);
|
||||||
out.push_back(toColor32(c));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
void SheetData::updatePixels(const studio::Context *ctx, QString ngPath, QString palPath) {
|
||||||
QVector<Color32> toPixels(const studio::Context *ctx, QString ngPath, QString palPath = "") {
|
|
||||||
auto ng = ctx->project->loadObj<NostalgiaGraphic>(ngPath);
|
auto ng = ctx->project->loadObj<NostalgiaGraphic>(ngPath);
|
||||||
std::unique_ptr<NostalgiaPalette> npal;
|
std::unique_ptr<NostalgiaPalette> npal;
|
||||||
if (palPath == "" && ng->defaultPalette.type() == ox::FileAddressType::Path) {
|
if (palPath == "" && ng->defaultPalette.type() == ox::FileAddressType::Path) {
|
||||||
@ -61,16 +63,7 @@ QVector<Color32> toPixels(const studio::Context *ctx, QString ngPath, QString pa
|
|||||||
} catch (ox::Error) {
|
} catch (ox::Error) {
|
||||||
qWarning() << "Could not open palette" << palPath;
|
qWarning() << "Could not open palette" << palPath;
|
||||||
}
|
}
|
||||||
return toPixels(ng.get(), npal.get());
|
return updatePixels(ng.get(), npal.get());
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString SheetData::pixel(int index) {
|
|
||||||
return "#" + QString("%1").arg(QString::number(m_pixels[index], 16), 8, '0');
|
|
||||||
}
|
|
||||||
|
|
||||||
void SheetData::updatePixels(const studio::Context *ctx, QString path) {
|
|
||||||
m_pixels = toPixels(ctx, path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
|
#include <QStringList>
|
||||||
#include <QStringView>
|
#include <QStringView>
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@ -22,12 +23,15 @@ class SheetData: public QObject {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector<Color32> m_pixels;
|
QStringList m_palette;
|
||||||
|
QVector<uint8_t> m_pixels;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Q_INVOKABLE QString pixel(int index);
|
Q_INVOKABLE QString pixel(int index);
|
||||||
|
|
||||||
void updatePixels(const studio::Context *ctx, QString path);
|
void updatePixels(const NostalgiaGraphic *ng, const NostalgiaPalette *npal);
|
||||||
|
|
||||||
|
void updatePixels(const studio::Context *ctx, QString ngPath, QString palPath = "");
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void refreshTileSheet();
|
void refreshTileSheet();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user