[keel,nostalgia,turbine] Cleanup

This commit is contained in:
2023-11-23 01:46:11 -06:00
parent a84a829769
commit b946e428ad
30 changed files with 120 additions and 122 deletions

View File

@@ -15,20 +15,11 @@
namespace nostalgia::core {
ox::Result<PaletteEditorImGui*> PaletteEditorImGui::make(turbine::Context *ctx, ox::CRStringView path) noexcept {
ox::UniquePtr<PaletteEditorImGui> out;
try {
out = ox::UniquePtr<PaletteEditorImGui>(new PaletteEditorImGui);
} catch (...) {
return OxError(1);
}
out->m_ctx = ctx;
out->m_itemPath = path;
const auto lastSlash = std::find(out->m_itemPath.rbegin(), out->m_itemPath.rend(), '/').offset();
out->m_itemName = out->m_itemPath.substr(lastSlash + 1);
oxRequire(pal, keel::readObj<Palette>(&out->m_ctx->keelCtx, ox::FileAddress(out->m_itemPath.c_str())));
out->m_pal = *pal;
return out.release();
PaletteEditorImGui::PaletteEditorImGui(turbine::Context *ctx, ox::String path):
m_ctx(ctx),
m_itemPath(std::move(path)),
m_itemName(m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1)),
m_pal(*keel::readObj<Palette>(&m_ctx->keelCtx, ox::FileAddress(m_itemPath.c_str())).unwrapThrow()) {
}
const ox::String &PaletteEditorImGui::itemName() const noexcept {
@@ -93,21 +84,25 @@ void PaletteEditorImGui::draw(turbine::Context*) noexcept {
ImGui::TableSetupColumn("Blue", ImGuiTableColumnFlags_WidthFixed, 50);
ImGui::TableSetupColumn("Color Preview", ImGuiTableColumnFlags_NoHide);
ImGui::TableHeadersRow();
constexpr auto colVal = [] (unsigned num) {
ox::Array<char, 4> numStr;
ImGui::TableNextColumn();
ox_itoa(num, numStr.data());
ImGui::SetCursorPosX(
ImGui::GetCursorPosX() + ImGui::GetColumnWidth() - ImGui::CalcTextSize(numStr.data()).x);
ImGui::Text("%s", numStr.data());
};
for (auto i = 0u; const auto c : m_pal.colors) {
ImGui::PushID(static_cast<int>(i));
ImGui::TableNextRow();
// Color No.
ImGui::TableNextColumn();
ImGui::Text("%d", i);
colVal(i);
// Red
ImGui::TableNextColumn();
ImGui::Text("%d", red16(c));
colVal(red16(c));
// Green
ImGui::TableNextColumn();
ImGui::Text("%d", green16(c));
colVal(green16(c));
// Blue
ImGui::TableNextColumn();
ImGui::Text("%d", blue16(c));
colVal(blue16(c));
// ColorPreview
ImGui::TableNextColumn();
const auto ic = ImGui::GetColorU32(ImVec4(redf(c), greenf(c), bluef(c), 1));

View File

@@ -15,15 +15,15 @@ class PaletteEditorImGui: public studio::Editor {
private:
turbine::Context *m_ctx = nullptr;
ox::String m_itemName;
ox::String m_itemPath;
ox::String m_itemName;
Palette m_pal;
std::size_t m_selectedRow = 0;
PaletteEditorImGui() noexcept = default;
public:
static ox::Result<PaletteEditorImGui*> make(turbine::Context *ctx, ox::CRStringView path) noexcept;
PaletteEditorImGui(turbine::Context *ctx, ox::String path);
/**
* Returns the name of item being edited.

View File

@@ -17,13 +17,13 @@ class StudioModule: public studio::Module {
{
{FileExt_ng},
[ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
return ox::makeCatch<TileSheetEditorImGui>(ctx, path);
return ox::makeCatch<TileSheetEditorImGui>(ctx, ox::String(path));
}
},
{
{FileExt_npal},
[ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
return PaletteEditorImGui::make(ctx, path);
return ox::makeCatch<PaletteEditorImGui>(ctx, ox::String(path));
}
}
};

View File

@@ -38,9 +38,9 @@ ox::Error toPngFile(const ox::String &path, const TileSheet::SubSheet &s, const
return OxError(static_cast<ox::ErrorCode>(lodepng_encode_file(path.c_str(), outData.data(), width, height, fmt, 8)));
}
TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context *ctx, ox::CRStringView path): m_tileSheetEditor(ctx, path) {
TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context *ctx, ox::String path): m_tileSheetEditor(ctx, path) {
m_ctx = ctx;
m_itemPath = path;
m_itemPath = std::move(path);
const auto lastSlash = ox::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset();
m_itemName = m_itemPath.substr(lastSlash + 1);
// init palette idx
@@ -393,7 +393,7 @@ void TileSheetEditorImGui::drawPaletteSelector() noexcept {
}
}
ox::Error TileSheetEditorImGui::updateActiveSubsheet(const ox::String &name, int cols, int rows) noexcept {
ox::Error TileSheetEditorImGui::updateActiveSubsheet(const ox::StringView &name, int cols, int rows) noexcept {
return model()->updateSubsheet(model()->activeSubSheetIdx(), name, cols, rows);
}

View File

@@ -55,7 +55,7 @@ class TileSheetEditorImGui: public studio::BaseEditor {
Tool m_tool = Tool::Draw;
public:
TileSheetEditorImGui(turbine::Context *ctx, ox::CRStringView path);
TileSheetEditorImGui(turbine::Context *ctx, ox::String path);
~TileSheetEditorImGui() override = default;
@@ -116,7 +116,7 @@ class TileSheetEditorImGui: public studio::BaseEditor {
void drawPaletteSelector() noexcept;
ox::Error updateActiveSubsheet(const ox::String &name, int cols, int rows) noexcept;
ox::Error updateActiveSubsheet(const ox::StringView &name, int cols, int rows) noexcept;
// slots
private:

View File

@@ -488,13 +488,13 @@ class UpdateSubSheetCommand: public TileSheetCommand {
UpdateSubSheetCommand(
TileSheet &img,
TileSheet::SubSheetIdx idx,
const ox::String &name,
ox::String name,
int cols,
int rows) noexcept:
m_img(img),
m_idx(std::move(idx)) {
m_sheet = m_img.getSubSheet(m_idx);
m_newName = name;
m_newName = std::move(name);
m_newCols = cols;
m_newRows = rows;
}
@@ -682,8 +682,8 @@ void TileSheetEditorModel::deleteTiles(const TileSheet::SubSheetIdx &idx, std::s
pushCommand(ox::make<DeleteTilesCommand>(m_img, idx, tileIdx, tileCnt));
}
ox::Error TileSheetEditorModel::updateSubsheet(const TileSheet::SubSheetIdx &idx, const ox::String &name, int cols, int rows) noexcept {
pushCommand(ox::make<UpdateSubSheetCommand>(m_img, idx, name, cols, rows));
ox::Error TileSheetEditorModel::updateSubsheet(const TileSheet::SubSheetIdx &idx, const ox::StringView &name, int cols, int rows) noexcept {
pushCommand(ox::make<UpdateSubSheetCommand>(m_img, idx, ox::String(name), cols, rows));
return {};
}

View File

@@ -72,7 +72,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
void deleteTiles(const TileSheet::SubSheetIdx &idx, std::size_t tileIdx, std::size_t tileCnt) noexcept;
ox::Error updateSubsheet(const TileSheet::SubSheetIdx &idx, const ox::String &name, int cols, int rows) noexcept;
ox::Error updateSubsheet(const TileSheet::SubSheetIdx &idx, const ox::StringView &name, int cols, int rows) noexcept;
void setActiveSubsheet(const TileSheet::SubSheetIdx&) noexcept;

View File

@@ -11,8 +11,8 @@
namespace nostalgia::core {
TileSheetEditorView::TileSheetEditorView(turbine::Context *ctx, ox::CRStringView path):
m_model(ctx, path), m_pixelsDrawer(&m_model) {
TileSheetEditorView::TileSheetEditorView(turbine::Context *ctx, ox::String path):
m_model(ctx, std::move(path)), m_pixelsDrawer(&m_model) {
// build shaders
oxThrowError(m_pixelsDrawer.buildShader());
oxThrowError(m_pixelGridDrawer.buildShader());

View File

@@ -50,7 +50,7 @@ class TileSheetEditorView: public ox::SignalHandler {
std::size_t m_palIdx = 0;
public:
TileSheetEditorView(turbine::Context *ctx, ox::CRStringView path);
TileSheetEditorView(turbine::Context *ctx, ox::String path);
~TileSheetEditorView() override = default;