[nostalgia/core/studio] Remove old unused files

This commit is contained in:
Gary Talent 2023-06-01 23:27:07 -05:00
parent 8c43baedea
commit 1d35f6ce70
8 changed files with 0 additions and 353 deletions

View File

@ -1,105 +0,0 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <QColor>
#include <QImage>
#include <QMap>
#include <nostalgia/core/core.hpp>
#include "imgconv.hpp"
namespace nostalgia::core {
[[nodiscard]]
static uint16_t toGbaColor(QColor c) {
const auto r = static_cast<uint32_t>(c.red()) >> 3;
const auto g = static_cast<uint32_t>(c.green()) >> 3;
const auto b = static_cast<uint32_t>(c.blue()) >> 3;
const auto a = static_cast<uint32_t>(c.alpha() > 128 ? 1 : 0);
return (a << 15) | (r << 10) | (g << 5) | (b << 0);
}
[[nodiscard]]
static int countColors(const QImage &img, int argTiles) {
QMap<QRgb, bool> colors;
// copy pixels as color ids
for (int x = 0; x < img.width(); x++) {
for (int y = 0; y < img.height(); y++) {
auto destI = pointToIdx(img.width(), x, y);
if (destI <= argTiles * PixelsPerTile) {
auto c = img.pixel(x, y);
// assign color a color id for the palette
if (!colors.contains(c)) {
colors[c] = true;
}
}
}
}
return colors.size();
}
[[nodiscard]]
ox::UniquePtr<core::NostalgiaGraphic> imgToNg(QString argSrc, int argBpp) {
QImage src(argSrc);
if (src.isNull()) {
return {};
}
const auto Pixels = src.width() * src.height();
const auto Tiles = Pixels / PixelsPerTile;
const auto Colors = countColors(src, Tiles);
if (argBpp != 4 && argBpp != 8) {
argBpp = Colors > 16 ? 8 : 4;
}
QMap<QRgb, int> colors;
auto ng = std::make_unique<core::NostalgiaGraphic>();
ng->pal.colors.resize(static_cast<std::size_t>(countColors(src, Tiles)));
if (argBpp == 4) {
ng->pixels.resize(static_cast<std::size_t>(Pixels / 2));
} else {
ng->pixels.resize(static_cast<std::size_t>(Pixels));
}
ng->bpp = argBpp;
ng->columns = src.width() / TileWidth;
ng->rows = src.height() / TileHeight;
int colorIdx = 0;
// copy pixels as color ids
for (int x = 0; x < src.width(); x++) {
for (int y = 0; y < src.height(); y++) {
auto destI = pointToIdx(src.width(), x, y);
if (destI < Tiles * PixelsPerTile) {
const auto c = src.pixel(x, y);
// assign color a color id for the palette
if (!colors.contains(c)) {
colors[c] = colorIdx;
colorIdx++;
}
// set pixel color
if (argBpp == 4) {
if (destI % 2) { // is odd number pixel
ng->pixels[static_cast<std::size_t>(destI / 2)] |= colors[c] << 4;
} else {
ng->pixels[static_cast<std::size_t>(destI / 2)] |= colors[c];
}
} else {
ng->pixels[static_cast<std::size_t>(destI)] = static_cast<std::size_t>(colors[c]);
}
}
}
}
// store colors in palette with the corresponding color id
for (auto key : colors.keys()) {
auto colorId = static_cast<std::size_t>(colors[key]);
ng->pal.colors[colorId] = toGbaColor(key);
}
return ng;
}
}

View File

@ -1,19 +0,0 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/std/error.hpp>
#include <ox/std/types.hpp>
#include <ox/mc/mc.hpp>
#include <nostalgia/core/gfx.hpp>
namespace nostalgia::core {
[[nodiscard]]
ox::UniquePtr<core::NostalgiaGraphic> imgToNg(ox::String argInPath, int argBpp = -1);
}

View File

@ -1,60 +0,0 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <QBuffer>
#include <QDebug>
#include <QFile>
#include <nostalgia/core/consts.hpp>
#include "imgconv.hpp"
#include "import_tilesheet_wizard.hpp"
namespace nostalgia::core {
ImportTilesheetWizardMainPage::ImportTilesheetWizardMainPage(const studio::Context *ctx) {
m_ctx = ctx;
addLineEdit(tr("&Tile Sheet Name:"), QString(TileSheetName) + "*", "", [this](QString) {
auto importPath = field(ImportPath).toString();
if (QFile(importPath).exists()) {
return 0;
} else {
this->showValidationError(tr("Invalid image file: %1").arg(importPath));
return 1;
}
}
);
auto fileTypes = "(*.png);;(*.bmp);;(*.jpg);;(*.jpeg)";
addPathBrowse(tr("Tile Sheet &Path:"), QString(ImportPath) + "*", "",
QFileDialog::ExistingFile, fileTypes);
}
ImportTilesheetWizardPalettePage::ImportTilesheetWizardPalettePage(const studio::Context *ctx) {
m_ctx = ctx;
addLineEdit(tr("Palette &Name:"), PaletteName);
}
int ImportTilesheetWizardPalettePage::accept() {
const auto tilesheetName = field(TileSheetName).toString();
const auto importPath = field(ImportPath).toString();
const auto paletteName = field(PaletteName).toString();
const auto outPath = TileSheetDir + tilesheetName + FileExt_ng;
if (!QFile(importPath).exists()) {
return OxError(1);
}
auto ng = imgToNg(importPath, 0);
if (!ng) {
return OxError(1);
}
const auto paletteOutPath = PaletteDir + paletteName + FileExt_npal;
core::NostalgiaPalette pal;
pal = std::move(ng->pal);
m_ctx->project->writeObj(paletteOutPath, &pal);
auto defaultPalette = paletteOutPath.toUtf8();
ng->defaultPalette = defaultPalette.data();
m_ctx->project->writeObj(outPath, ng.get());
return 0;
}
}

View File

@ -1,38 +0,0 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <nostalgia/studio/studio.hpp>
#include "consts.hpp"
namespace nostalgia::core {
constexpr auto TileSheetName = "tilesheetName";
constexpr auto ImportPath = "importPath";
constexpr auto Palette = "palette";
constexpr auto PaletteName = "paletteName";
class ImportTilesheetWizardMainPage: public studio::WizardFormPage {
private:
//static constexpr auto BPP = "bpp";
const studio::Context *m_ctx = nullptr;
public:
ImportTilesheetWizardMainPage(const studio::Context *args);
};
class ImportTilesheetWizardPalettePage: public studio::WizardFormPage {
private:
//static constexpr auto BPP = "bpp";
const studio::Context *m_ctx = nullptr;
public:
ImportTilesheetWizardPalettePage(const studio::Context *args);
int accept();
};
}

View File

@ -1,46 +0,0 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <QBuffer>
#include <QFile>
#include <nostalgia/core/consts.hpp>
#include <nostalgia/core/gfx.hpp>
#include "consts.hpp"
#include "new_tilesheet_wizard.hpp"
namespace nostalgia::core {
NewTilesheetWizardPage::NewTilesheetWizardPage(const studio::Context *ctx) {
m_ctx = ctx;
addLineEdit(tr("&Tile Sheet Name:"), QString(TileSheetName) + "*", "", [](QString) {
return 0;
});
m_palettePicker = addComboBox(tr("&Palette:"), QString(Palette) + "*", {""});
m_ctx->project->subscribe(studio::ProjectEvent::FileRecognized, m_palettePicker, [this](QString path) {
if (path.startsWith(PaletteDir) && path.endsWith(FileExt_npal)) {
m_palettePicker->addItem(studio::filePathToName(path, PaletteDir, FileExt_npal), path);
}
});
}
int NewTilesheetWizardPage::accept() {
const auto tilesheetName = field(TileSheetName).toString();
const auto palette = m_palettePicker->itemData(field(Palette).toInt()).toString();
const auto outPath = QString(TileSheetDir) + tilesheetName + FileExt_ng;
auto err = m_ctx->project->exists(outPath);
if (err) {
showValidationError(tr("A tile sheet with this name already exists."));
return err;
}
NostalgiaGraphic ng;
ng.columns = 1;
ng.rows = 1;
ng.defaultPalette = palette.toUtf8().data();
m_ctx->project->writeObj(outPath, &ng);
return 0;
}
}

View File

@ -1,26 +0,0 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <nostalgia/studio/studio.hpp>
namespace nostalgia::core {
class NewTilesheetWizardPage: public studio::WizardFormPage {
private:
static constexpr auto TileSheetName = "projectName";
static constexpr auto Palette = "palette";
class QComboBox *m_palettePicker = nullptr;
const studio::Context *m_ctx = nullptr;
public:
NewTilesheetWizardPage(const studio::Context *args);
int accept();
private:
};
}

View File

@ -1,35 +0,0 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <QBuffer>
#include <QDebug>
#include <nostalgia/core/consts.hpp>
#include <nostalgia/core/gfx.hpp>
#include "consts.hpp"
#include "newpalettewizard.hpp"
namespace nostalgia::core {
NewPaletteWizardPage::NewPaletteWizardPage(const studio::Context *ctx) {
m_ctx = ctx;
addLineEdit(tr("&Palette Name:"), QString(PaletteName) + "*", "", [](QString) {
return 0;
});
}
int NewPaletteWizardPage::accept() {
const auto paletteName = field(PaletteName).toString();
const auto path = PaletteDir + paletteName + FileExt_npal;
if (m_ctx->project->exists(path)) {
showValidationError(tr("A palette with this name already exists."));
return 1;
}
NostalgiaPalette pal;
m_ctx->project->writeObj(path, &pal);
return 0;
}
}

View File

@ -1,24 +0,0 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <nostalgia/studio/studio.hpp>
namespace nostalgia::core {
class NewPaletteWizardPage: public studio::WizardFormPage {
private:
static constexpr auto PaletteName = "paletteName";
const studio::Context *m_ctx = nullptr;
public:
NewPaletteWizardPage(const studio::Context *args);
int accept();
private:
};
}