diff --git a/src/nostalgia/core/gba/gfx.cpp b/src/nostalgia/core/gba/gfx.cpp index 5fa5930d..795df816 100644 --- a/src/nostalgia/core/gba/gfx.cpp +++ b/src/nostalgia/core/gba/gfx.cpp @@ -40,7 +40,7 @@ struct GbaTileMapTarget { template ox::Error modelRead(T *io, GbaPaletteTarget *t) { io->setTypeInfo("nostalgia::core::NostalgiaPalette", NostalgiaPalette::Fields); - oxReturnError(io->template field("colors", [t](auto i, Color *c) { + oxReturnError(io->template field("colors", [t](auto i, Color16 *c) { t->palette[i] = *c; return OxError(0); })); diff --git a/src/nostalgia/core/gfx.cpp b/src/nostalgia/core/gfx.cpp index f484eafc..f70aa3f5 100644 --- a/src/nostalgia/core/gfx.cpp +++ b/src/nostalgia/core/gfx.cpp @@ -11,7 +11,7 @@ namespace nostalgia::core { // map ASCII values to the nostalgia charset -char charMap[128] = { +static char charMap[128] = { 0, 0, 0, @@ -141,6 +141,14 @@ char charMap[128] = { 0, // ~ }; +Color32 toColor32(Color16 nc) { + auto r = ((nc & 0b0000000000011111) >> 0) * 8; + auto g = ((nc & 0b0000001111100000) >> 5) * 8; + auto b = ((nc & 0b0111110000000000) >> 10) * 8; + auto a = 255; + return a | (b << 8) | (g << 16) | (r << 24); +} + void puts(Context *ctx, int column, int row, const char *str) { for (int i = 0; str[i]; i++) { setTile(ctx, 0, column + i, row, charMap[static_cast(str[i])]); diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index d1b10e3b..993c152b 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -20,11 +20,17 @@ enum class TileSheetSpace { Sprite }; -using Color = uint16_t; +using Color16 = uint16_t; + +/** + * Nostalgia Core logically uses 16 bit colors, but must translate that to 32 + * bit colors in some implementations. + */ +using Color32 = uint32_t; struct NostalgiaPalette { static constexpr auto Fields = 1; - ox::Vector colors; + ox::Vector colors; }; struct NostalgiaGraphic { @@ -63,7 +69,7 @@ ox::Error model(T *io, NostalgiaGraphic *ng) { */ [[nodiscard]] ox::Error loadTileSheet(Context *ctx, TileSheetSpace tss, int section, ox::FileAddress tilesheet, ox::FileAddress palette = nullptr); -ox::Error loadTileSheet(Context *ctx, ox::FileAddress file); +[[nodiscard]] Color32 toColor32(Color16 nc); void puts(Context *ctx, int column, int row, const char *str); diff --git a/src/nostalgia/core/sdl/gfx.cpp b/src/nostalgia/core/sdl/gfx.cpp index fb88a148..61d9eedf 100644 --- a/src/nostalgia/core/sdl/gfx.cpp +++ b/src/nostalgia/core/sdl/gfx.cpp @@ -62,7 +62,7 @@ ox::Error initConsole(Context *ctx) { return loadTileSheet(ctx, TileSheetSpace::Background, 0, TilesheetAddr, PaletteAddr); } -SDL_Color createSDL_Color(Color nc) { +SDL_Color createSDL_Color(Color16 nc) { SDL_Color c; // extract the color chanels and scale them up for a 24 bit color c.r = ((nc & 0b0000000000011111) >> 0) * 8; diff --git a/src/nostalgia/core/studio/CMakeLists.txt b/src/nostalgia/core/studio/CMakeLists.txt index b2f78841..fa9d78ad 100644 --- a/src/nostalgia/core/studio/CMakeLists.txt +++ b/src/nostalgia/core/studio/CMakeLists.txt @@ -14,6 +14,7 @@ target_link_libraries( Qt5::Widgets Qt5::QuickWidgets NostalgiaStudio + NostalgiaCore OxFS OxStd ) diff --git a/src/nostalgia/core/studio/TileSheetEditor.qml b/src/nostalgia/core/studio/TileSheetEditor.qml index 89de1a67..ec728ccb 100644 --- a/src/nostalgia/core/studio/TileSheetEditor.qml +++ b/src/nostalgia/core/studio/TileSheetEditor.qml @@ -14,7 +14,7 @@ Rectangle { anchors.horizontalCenter: tileSheetEditor.horizontalCenter anchors.verticalCenter: tileSheetEditor.verticalCenter rows: 2 - columns: 3 + columns: 2 Repeater { model: tileGrid.rows * tileGrid.columns Tile { diff --git a/src/nostalgia/core/studio/plugin.cpp b/src/nostalgia/core/studio/plugin.cpp index c4b34742..cb7c0adb 100644 --- a/src/nostalgia/core/studio/plugin.cpp +++ b/src/nostalgia/core/studio/plugin.cpp @@ -16,7 +16,7 @@ using namespace nostalgia::studio; namespace nostalgia::core { -QVector Plugin::newWizards(const Context *ctx) { +QVector Plugin::newWizards(const studio::Context *ctx) { return { { tr("Tile Sheet"), diff --git a/src/nostalgia/core/studio/tilesheeteditor.cpp b/src/nostalgia/core/studio/tilesheeteditor.cpp index f0c1666a..332d2e55 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor.cpp @@ -12,29 +12,19 @@ #include #include -#include - #include "consts.hpp" #include "tilesheeteditor.hpp" namespace nostalgia::core { -uint32_t toColor32(Color nc) { - auto r = ((nc & 0b0000000000011111) >> 0) * 8; - auto g = ((nc & 0b0000001111100000) >> 5) * 8; - auto b = ((nc & 0b0111110000000000) >> 10) * 8; - auto a = 255; - return a | (b << 8) | (g << 16) | (r << 24); -} - [[nodiscard]] -QVector toPixels(const NostalgiaGraphic *ng, const NostalgiaPalette *npal) { +QVector toPixels(const NostalgiaGraphic *ng, const NostalgiaPalette *npal) { if (!npal) { npal = &ng->pal; } - QVector out; - out.reserve(ng->tiles.size() * sizeof(Color)); + QVector out; + out.reserve(ng->tiles.size() * sizeof(Color16)); if (ng->bpp == 8) { for (std::size_t i = 0; i < ng->tiles.size(); i++) { @@ -59,7 +49,7 @@ QVector toPixels(const NostalgiaGraphic *ng, const NostalgiaPalette *n } [[nodiscard]] -QVector toPixels(const studio::Context *ctx, QString ngPath, QString palPath = "") { +QVector toPixels(const studio::Context *ctx, QString ngPath, QString palPath = "") { auto ng = ctx->project->loadObj(ngPath); std::unique_ptr npal; if (palPath == "" && ng->defaultPalette.type() == ox::FileAddressType::Path) { @@ -124,7 +114,7 @@ void TileSheetEditor::saveState() { void TileSheetEditor::restoreState() { QSettings settings(m_ctx->orgName, PluginName); settings.beginGroup("TileSheetEditor/state"); - m_splitter->restoreState(settings.value("m_splitter/state").toByteArray()); + m_splitter->restoreState(settings.value("m_splitter/state", m_splitter->saveState()).toByteArray()); settings.endGroup(); } diff --git a/src/nostalgia/core/studio/tilesheeteditor.hpp b/src/nostalgia/core/studio/tilesheeteditor.hpp index c2225283..f0cdd053 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor.hpp @@ -13,6 +13,7 @@ #include #include +#include #include namespace nostalgia::core { @@ -21,7 +22,7 @@ class SheetData: public QObject { Q_OBJECT private: - QVector m_pixels; + QVector m_pixels; public: Q_INVOKABLE QString pixel(int index);