[nostalgia,studio] Cleanup, simplify string handling

This commit is contained in:
Gary Talent 2023-12-04 21:45:23 -06:00
parent 0d606643f5
commit 195fd7a113
7 changed files with 29 additions and 56 deletions

View File

@ -15,7 +15,7 @@
namespace nostalgia::core {
PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::String path):
PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path):
m_ctx(ctx),
m_itemPath(std::move(path)),
m_itemName(m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1)),

View File

@ -21,7 +21,7 @@ class PaletteEditorImGui: public studio::Editor {
std::size_t m_selectedRow = 0;
public:
PaletteEditorImGui(turbine::Context &ctx, ox::String path);
PaletteEditorImGui(turbine::Context &ctx, ox::CRStringView path);
/**
* Returns the name of item being edited.

View File

@ -13,7 +13,7 @@
namespace nostalgia::core {
template<bool alpha = false>
ox::Error toPngFile(const ox::String &path, const TileSheet::SubSheet &s, const Palette &pal, int8_t bpp) noexcept {
ox::Error toPngFile(ox::CStringView const&path, TileSheet::SubSheet const&s, Palette const&pal, int8_t bpp) noexcept {
ox::Vector<uint8_t> pixels;
s.readPixelsTo(&pixels, bpp);
const unsigned rows = s.rows == -1 ? static_cast<unsigned>(pixels.size()) / PixelsPerTile : static_cast<unsigned>(s.rows);
@ -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::String path):
TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context &ctx, ox::CRStringView path):
m_ctx(ctx),
m_itemPath(std::move(path)),
m_itemPath(path),
m_tileSheetEditor(m_ctx, m_itemPath) {
const auto lastSlash = ox::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset();
m_itemName = m_itemPath.substr(lastSlash + 1);
@ -242,7 +242,7 @@ studio::UndoStack *TileSheetEditorImGui::undoStack() noexcept {
}
[[nodiscard]]
ox::Vec2 TileSheetEditorImGui::clickPos(const ImVec2 &winPos, ox::Vec2 clickPos) noexcept {
ox::Vec2 TileSheetEditorImGui::clickPos(ImVec2 const&winPos, ox::Vec2 clickPos) noexcept {
clickPos.x -= winPos.x + 10;
clickPos.y -= winPos.y + 10;
return clickPos;
@ -276,7 +276,7 @@ void TileSheetEditorImGui::exportSubhseetToPng() noexcept {
}
}
void TileSheetEditorImGui::drawTileSheet(const ox::Vec2 &fbSize) noexcept {
void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
const auto winPos = ImGui::GetWindowPos();
const auto fbSizei = ox::Size(static_cast<int>(fbSize.x), static_cast<int>(fbSize.y));
if (m_framebuffer.width != fbSizei.width || m_framebuffer.height != fbSizei.height) {
@ -394,7 +394,7 @@ void TileSheetEditorImGui::drawPaletteSelector() noexcept {
}
}
ox::Error TileSheetEditorImGui::updateActiveSubsheet(const ox::StringView &name, int cols, int rows) noexcept {
ox::Error TileSheetEditorImGui::updateActiveSubsheet(ox::StringView const&name, int cols, int rows) noexcept {
return model()->updateSubsheet(model()->activeSubSheetIdx(), name, cols, rows);
}

View File

@ -32,10 +32,10 @@ class TileSheetEditorImGui: public studio::BaseEditor {
int m_rows = 0;
bool m_show = false;
public:
ox::Signal<ox::Error(const ox::StringView &name, int cols, int rows)> inputSubmitted;
constexpr void show(const ox::String &name, int cols, int rows) noexcept {
ox::Signal<ox::Error(ox::StringView const&name, int cols, int rows)> inputSubmitted;
constexpr void show(ox::StringView const&name, int cols, int rows) noexcept {
m_show = true;
m_name = name.c_str();
m_name = name;
m_cols = cols;
m_rows = rows;
}
@ -55,7 +55,7 @@ class TileSheetEditorImGui: public studio::BaseEditor {
Tool m_tool = Tool::Draw;
public:
TileSheetEditorImGui(turbine::Context &ctx, ox::String path);
TileSheetEditorImGui(turbine::Context &ctx, ox::CRStringView path);
~TileSheetEditorImGui() override = default;
@ -80,7 +80,7 @@ class TileSheetEditorImGui: public studio::BaseEditor {
studio::UndoStack *undoStack() noexcept final;
[[nodiscard]]
static ox::Vec2 clickPos(const ImVec2 &winPos, ox::Vec2 clickPos) noexcept;
static ox::Vec2 clickPos(ImVec2 const&winPos, ox::Vec2 clickPos) noexcept;
protected:
ox::Error saveItem() noexcept override;
@ -100,28 +100,14 @@ class TileSheetEditorImGui: public studio::BaseEditor {
return m_tileSheetEditor.model();
}
void setPalette();
void saveState();
void restoreState();
[[nodiscard]]
ox::String paletteName(const ox::String &palettePath) const;
[[nodiscard]]
ox::String palettePath(const ox::String &palettePath) const;
void drawTileSheet(const ox::Vec2 &fbSize) noexcept;
void drawTileSheet(ox::Vec2 const&fbSize) noexcept;
void drawPaletteSelector() noexcept;
ox::Error updateActiveSubsheet(const ox::StringView &name, int cols, int rows) noexcept;
ox::Error updateActiveSubsheet(ox::StringView const&name, int cols, int rows) noexcept;
// slots
private:
ox::Error updateAfterClicked() noexcept;
ox::Error markUnsavedChanges(const studio::UndoCommand*) noexcept;
};

View File

@ -8,23 +8,22 @@
namespace nostalgia::scene {
constexpr ox::StringLiteral FileExt_nscn("nscn");
class StudioModule: public studio::Module {
public:
ox::Vector<studio::EditorMaker> editors(turbine::Context &ctx) const noexcept override;
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(turbine::Context&) const noexcept override;
ox::Vector<studio::EditorMaker> editors(turbine::Context &ctx) const noexcept override {
return {
studio::editorMaker<SceneEditorImGui>(ctx, FileExt_nscn),
};
}
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(turbine::Context&) const noexcept override {
ox::Vector<ox::UPtr<studio::ItemMaker>> out;
out.emplace_back(ox::make<studio::ItemMakerT<SceneDoc>>("Scene", "Scenes", FileExt_nscn));
return out;
}
};
ox::Vector<studio::EditorMaker> StudioModule::editors(turbine::Context &ctx) const noexcept {
return {
studio::editorMaker<SceneEditorImGui>(ctx, "nscn"),
};
}
ox::Vector<ox::UPtr<studio::ItemMaker>> StudioModule::itemMakers(turbine::Context&) const noexcept {
ox::Vector<ox::UPtr<studio::ItemMaker>> out;
return out;
}
static StudioModule mod;
const studio::Module *studioModule() noexcept {
return &mod;

View File

@ -39,18 +39,7 @@ studio::EditorMaker editorMaker(turbine::Context &ctx, ox::CRStringView ext) noe
return {
{ox::String(ext)},
[&ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
return ox::makeCatch<Editor>(ctx, ox::String(path));
}
};
}
template<typename Editor>
[[nodiscard]]
studio::EditorMaker editorMaker(turbine::Context *ctx, ox::Vector<ox::String> exts) noexcept {
return {
std::move(exts),
[ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
return ox::makeCatch<Editor>(ctx, ox::String(path));
return ox::makeCatch<Editor>(ctx, path);
}
};
}

View File

@ -106,7 +106,6 @@ class Project {
template<typename T>
ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat fmt) noexcept {
// write MetalClaw
oxRequireM(buff, ox::writeClaw(obj, fmt));
// write to FS
oxReturnError(writeBuff(path, buff));
@ -117,7 +116,7 @@ ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat f
// write out type store
const auto descPath = ox::sfmt("/{}/type_descriptors", m_projectDataDir);
oxReturnError(mkdir(descPath));
for (const auto &t : m_typeStore.typeList()) {
for (auto const&t : m_typeStore.typeList()) {
oxRequireM(typeOut, ox::writeClaw(*t, ox::ClawFormat::Organic));
// replace garbage last character with new line
*typeOut.back().value = '\n';