[olympic,nostalgia] Cleanup with StringParam
All checks were successful
Build / build (push) Successful in 2m33s

This commit is contained in:
Gary Talent 2024-08-30 20:47:43 -05:00
parent f4a9872fe0
commit bd2e88cd88
16 changed files with 59 additions and 60 deletions

View File

@ -17,8 +17,8 @@ namespace nostalgia::core {
namespace ig = studio::ig;
PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringView const path):
Editor(path),
PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringParam path):
Editor(std::move(path)),
m_sctx(sctx),
m_tctx(sctx.tctx),
m_pal(*keel::readObj<Palette>(keelCtx(m_tctx), itemPath()).unwrapThrow()) {

View File

@ -21,7 +21,7 @@ class PaletteEditorImGui: public studio::Editor {
size_t m_page = 0;
public:
PaletteEditorImGui(studio::StudioContext &sctx, ox::StringView path);
PaletteEditorImGui(studio::StudioContext &sctx, ox::StringParam path);
void keyStateChanged(turbine::Key key, bool down) override;

View File

@ -21,13 +21,13 @@ DrawCommand::DrawCommand(
DrawCommand::DrawCommand(
TileSheet &img,
TileSheet::SubSheetIdx subSheetIdx,
const ox::Vector<std::size_t> &idxList,
ox::Vector<std::size_t> const&idxList,
int palIdx) noexcept:
m_img(img),
m_subSheetIdx(std::move(subSheetIdx)),
m_palIdx(palIdx) {
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
for (const auto idx : idxList) {
for (auto const idx : idxList) {
m_changes.emplace_back(static_cast<uint32_t>(idx), getPixel(subsheet, m_img.bpp, idx));
}
}
@ -36,7 +36,7 @@ bool DrawCommand::append(std::size_t idx) noexcept {
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
if (m_changes.back().value->idx != idx && getPixel(subsheet, m_img.bpp, idx) != m_palIdx) {
// duplicate entries are bad
auto existing = ox::find_if(m_changes.cbegin(), m_changes.cend(), [idx](const auto &c) {
auto existing = ox::find_if(m_changes.cbegin(), m_changes.cend(), [idx](auto const&c) {
return c.idx == idx;
});
if (existing == m_changes.cend()) {
@ -48,7 +48,7 @@ bool DrawCommand::append(std::size_t idx) noexcept {
return false;
}
bool DrawCommand::append(const ox::Vector<std::size_t> &idxList) noexcept {
bool DrawCommand::append(ox::Vector<std::size_t> const&idxList) noexcept {
auto out = false;
for (auto idx : idxList) {
out = append(idx) || out;
@ -58,7 +58,7 @@ bool DrawCommand::append(const ox::Vector<std::size_t> &idxList) noexcept {
ox::Error DrawCommand::redo() noexcept {
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
for (const auto &c : m_changes) {
for (auto const&c : m_changes) {
setPixel(subsheet, m_img.bpp, c.idx, static_cast<uint8_t>(m_palIdx));
}
return {};
@ -66,7 +66,7 @@ ox::Error DrawCommand::redo() noexcept {
ox::Error DrawCommand::undo() noexcept {
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
for (const auto &c : m_changes) {
for (auto const&c : m_changes) {
setPixel(subsheet, m_img.bpp, c.idx, static_cast<uint8_t>(c.oldPalIdx));
}
return {};

View File

@ -33,12 +33,12 @@ class DrawCommand: public TileSheetCommand {
DrawCommand(
TileSheet &img,
TileSheet::SubSheetIdx subSheetIdx,
const ox::Vector<std::size_t> &idxList,
ox::Vector<std::size_t> const&idxList,
int palIdx) noexcept;
bool append(std::size_t idx) noexcept;
bool append(const ox::Vector<std::size_t> &idxList) noexcept;
bool append(ox::Vector<std::size_t> const&idxList) noexcept;
ox::Error redo() noexcept final;

View File

@ -86,11 +86,11 @@ static ox::Error toPngFile(
8)));
}
TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::StringView const path):
Editor(path),
TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::StringParam path):
Editor(std::move(path)),
m_sctx(sctx),
m_tctx(m_sctx.tctx),
m_view(m_sctx, path, *undoStack()),
m_view(m_sctx, itemPath(), *undoStack()),
m_model(m_view.model()) {
std::ignore = setPaletteSelection();
// connect signal/slots

View File

@ -67,7 +67,7 @@ class TileSheetEditorImGui: public studio::Editor {
TileSheetTool m_tool = TileSheetTool::Draw;
public:
TileSheetEditorImGui(studio::StudioContext &sctx, ox::StringView path);
TileSheetEditorImGui(studio::StudioContext &sctx, ox::StringParam path);
~TileSheetEditorImGui() override = default;

View File

@ -13,7 +13,7 @@
namespace studio {
NewMenu::NewMenu() noexcept {
setTitle(ox::String("New Item"));
setTitle("New Item");
setSize({230, 140});
}

View File

@ -12,8 +12,8 @@
namespace studio {
NewProject::NewProject(ox::String projectDatadir) noexcept: m_projectDataDir(std::move(projectDatadir)) {
setTitle(ox::String("New Project"));
NewProject::NewProject(ox::StringParam projectDatadir) noexcept: m_projectDataDir(std::move(projectDatadir)) {
setTitle("New Project");
setSize({230, 140});
}

View File

@ -33,7 +33,7 @@ class NewProject: public studio::Popup {
bool m_open = false;
public:
NewProject(ox::String projectDatadir) noexcept;
NewProject(ox::StringParam projectDatadir) noexcept;
void open() noexcept override;

View File

@ -41,12 +41,12 @@ oxModelBegin(StudioConfig)
oxModelFieldRename(showProjectExplorer, show_project_explorer)
oxModelEnd()
StudioUI::StudioUI(turbine::Context &ctx, ox::StringView projectDataDir) noexcept:
StudioUI::StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexcept:
m_sctx(*this, ctx),
m_ctx(ctx),
m_projectDataDir(projectDataDir),
m_projectDataDir(std::move(projectDataDir)),
m_projectExplorer(m_ctx),
m_newProject(ox::String(projectDataDir)),
m_newProject(m_projectDataDir),
m_aboutPopup(m_ctx) {
turbine::setApplicationData(m_ctx, &m_sctx);
m_projectExplorer.fileChosen.connect(this, &StudioUI::openFile);
@ -326,11 +326,11 @@ ox::Error StudioUI::createOpenProject(ox::CRStringView path) noexcept {
return m_project->writeTypeStore();
}
ox::Error StudioUI::openProjectPath(ox::CRStringView path) noexcept {
oxRequireM(fs, keel::loadRomFs(path));
ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept {
oxRequireM(fs, keel::loadRomFs(path.view()));
oxReturnError(keel::setRomFs(keelCtx(m_ctx), std::move(fs)));
oxReturnError(
ox::make_unique_catch<studio::Project>(keelCtx(m_ctx), ox::String(path), m_projectDataDir)
ox::make_unique_catch<studio::Project>(keelCtx(m_ctx), std::move(path), m_projectDataDir)
.moveTo(m_project));
auto const sctx = applicationData<studio::StudioContext>(m_ctx);
sctx->project = m_project.get();
@ -364,7 +364,7 @@ ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab)
}
return {};
}
oxRequire(ext, studio::fileExt(path).to<ox::String>([](auto const&v) {return ox::String(v);}));
oxRequire(ext, studio::fileExt(path));
// create Editor
studio::BaseEditor *editor = nullptr;
if (!m_editorMakers.contains(ext)) {
@ -392,7 +392,7 @@ ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab)
m_activeEditorUpdatePending = editor;
}
// save to config
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&](StudioConfig &config) {
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&path](StudioConfig &config) {
if (!config.openFiles.contains(path)) {
config.openFiles.emplace_back(path);
}

View File

@ -48,7 +48,7 @@ class StudioUI: public ox::SignalHandler {
bool m_showProjectExplorer = true;
public:
explicit StudioUI(turbine::Context &ctx, ox::StringView projectDataDir) noexcept;
explicit StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexcept;
void handleKeyEvent(turbine::Key, bool down) noexcept;
@ -85,7 +85,7 @@ class StudioUI: public ox::SignalHandler {
ox::Error createOpenProject(ox::CRStringView path) noexcept;
ox::Error openProjectPath(ox::CRStringView path) noexcept;
ox::Error openProjectPath(ox::StringParam path) noexcept;
ox::Error openFile(ox::CRStringView path) noexcept;

View File

@ -123,7 +123,7 @@ class Editor: public studio::BaseEditor {
ox::String m_itemName;
public:
Editor(ox::StringView itemPath) noexcept;
Editor(ox::StringParam itemPath) noexcept;
[[nodiscard]]
ox::CStringView itemPath() const noexcept final;

View File

@ -19,17 +19,17 @@ class ItemMaker {
ox::String const parentDir;
ox::String const fileExt;
constexpr explicit ItemMaker(
ox::StringView pName,
ox::StringView pParentDir,
ox::StringView pFileExt) noexcept:
typeName(pName),
parentDir(pParentDir),
fileExt(pFileExt) {
ox::StringParam pName,
ox::StringParam pParentDir,
ox::StringParam pFileExt) noexcept:
typeName{std::move(pName)},
parentDir{std::move(pParentDir)},
fileExt{std::move(pFileExt)} {
}
virtual ~ItemMaker() noexcept = default;
[[nodiscard]]
inline virtual ox::String itemPath(ox::StringView pName) const noexcept {
virtual ox::String itemPath(ox::StringView pName) const noexcept {
return ox::sfmt("/{}/{}.{}", parentDir, pName, fileExt);
}
@ -39,8 +39,7 @@ class ItemMaker {
* @param pName
* @return path of file or error in Result
*/
virtual ox::Result<ox::String> write(
studio::StudioContext &ctx, ox::CRStringView pName) const noexcept = 0;
virtual ox::Result<ox::String> write(StudioContext &ctx, ox::StringView pName) const noexcept = 0;
};
template<typename T>
@ -50,36 +49,36 @@ class ItemMakerT: public ItemMaker {
ox::ClawFormat const m_fmt;
public:
constexpr ItemMakerT(
ox::StringView pDisplayName,
ox::StringView pParentDir,
ox::StringView fileExt,
ox::StringParam pDisplayName,
ox::StringParam pParentDir,
ox::StringParam fileExt,
ox::ClawFormat pFmt = ox::ClawFormat::Metal) noexcept:
ItemMaker(pDisplayName, pParentDir, fileExt),
ItemMaker(std::move(pDisplayName), std::move(pParentDir), std::move(fileExt)),
m_fmt(pFmt) {
}
constexpr ItemMakerT(
ox::StringView pDisplayName,
ox::StringView pParentDir,
ox::StringView fileExt,
ox::StringParam pDisplayName,
ox::StringParam pParentDir,
ox::StringParam fileExt,
T pItem,
ox::ClawFormat pFmt) noexcept:
ItemMaker(pDisplayName, pParentDir, fileExt),
ItemMaker(std::move(pDisplayName), std::move(pParentDir), std::move(fileExt)),
m_item(std::move(pItem)),
m_fmt(pFmt) {
}
constexpr ItemMakerT(
ox::StringView pDisplayName,
ox::StringView pParentDir,
ox::StringView fileExt,
ox::StringParam pDisplayName,
ox::StringParam pParentDir,
ox::StringParam fileExt,
T &&pItem,
ox::ClawFormat pFmt) noexcept:
ItemMaker(pDisplayName, pParentDir, fileExt),
m_item(std::move(pItem)),
m_fmt(pFmt) {
ItemMaker(std::move(pDisplayName), std::move(pParentDir), std::move(fileExt)),
m_item(std::move(pItem)),
m_fmt(pFmt) {
}
ox::Result<ox::String> write(studio::StudioContext &sctx, ox::CRStringView pName) const noexcept override {
ox::Result<ox::String> write(studio::StudioContext &sctx, ox::StringView const pName) const noexcept override {
auto const path = itemPath(pName);
keel::createUuidMapping(keelCtx(sctx.tctx), path, ox::UUID::generate().unwrap());
createUuidMapping(keelCtx(sctx.tctx), path, ox::UUID::generate().unwrap());
oxReturnError(sctx.project->writeObj(path, m_item, m_fmt));
return path;
}

View File

@ -35,9 +35,9 @@ class Module {
template<typename Editor>
[[nodiscard]]
studio::EditorMaker editorMaker(studio::StudioContext &ctx, ox::CRStringView ext) noexcept {
studio::EditorMaker editorMaker(studio::StudioContext &ctx, ox::StringParam ext) noexcept {
return {
{ox::String(ext)},
{std::move(ext)},
[&ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
return ox::makeCatch<Editor>(ctx, path);
}

View File

@ -39,7 +39,7 @@ class Popup {
m_size = {static_cast<float>(sz.width), static_cast<float>(sz.height)};
}
constexpr void setTitle(ox::String title) noexcept {
constexpr void setTitle(ox::StringParam title) noexcept {
m_title = std::move(title);
}

View File

@ -115,8 +115,8 @@ void BaseEditor::setRequiresConstantRefresh(bool value) noexcept {
}
Editor::Editor(ox::StringView itemPath) noexcept:
m_itemPath(itemPath),
Editor::Editor(ox::StringParam itemPath) noexcept:
m_itemPath(std::move(itemPath)),
m_itemName(m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1)) {
m_undoStack.changeTriggered.connect(this, &Editor::markUnsavedChanges);
}