Squashed 'deps/nostalgia/' changes from c501fc04..ab025e88
ab025e88 [nostalgia] Change Palette converter color idx to be 0 based bd2e88cd [olympic,nostalgia] Cleanup with StringParam f4a9872f [ox/std] Add StringParam f8aa60e4 [ox/std] Fix itoa result length calculation 3ead305f [nostalgia/core/studio/tilesheeteditor] Fix Fill command to properly end eb498ca5 [ox/event] Comment out Signal disconnect warning git-subtree-dir: deps/nostalgia git-subtree-split: ab025e88daed941b926fd8d9d9b824c22c32749c
This commit is contained in:
parent
88617af409
commit
a1a34f27f9
4
deps/ox/src/ox/event/signal.hpp
vendored
4
deps/ox/src/ox/event/signal.hpp
vendored
@ -264,8 +264,8 @@ class Signal<Error(Args...)> {
|
||||
}
|
||||
|
||||
void cleanup(Signal *signal) noexcept final {
|
||||
auto err = m_receiver->destruction.disconnectSignal(signal);
|
||||
oxErrorf("{}", toStr(err));
|
||||
std::ignore = m_receiver->destruction.disconnectSignal(signal);
|
||||
//oxErrorf("{}", toStr(err));
|
||||
//oxAssert(err, "Signal could not notify receiver that it is being destroyed. Destruction of receiver will cause use-after-free.");
|
||||
}
|
||||
|
||||
|
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
@ -128,6 +128,7 @@ install(
|
||||
stringview.hpp
|
||||
strongint.hpp
|
||||
strconv.hpp
|
||||
stringparam.hpp
|
||||
strops.hpp
|
||||
trace.hpp
|
||||
typeinfo.hpp
|
||||
|
4
deps/ox/src/ox/std/istring.hpp
vendored
4
deps/ox/src/ox/std/istring.hpp
vendored
@ -234,12 +234,16 @@ constexpr auto itoa(Integer v) noexcept {
|
||||
switch (sizeof(Integer)) {
|
||||
case 1:
|
||||
out = 3;
|
||||
break;
|
||||
case 2:
|
||||
out = 5;
|
||||
break;
|
||||
case 4:
|
||||
out = 10;
|
||||
break;
|
||||
case 8:
|
||||
out = 21;
|
||||
break;
|
||||
}
|
||||
return out + ox::is_signed_v<Integer>;
|
||||
}();
|
||||
|
1
deps/ox/src/ox/std/std.hpp
vendored
1
deps/ox/src/ox/std/std.hpp
vendored
@ -46,6 +46,7 @@
|
||||
#include "stddef.hpp"
|
||||
#include "string.hpp"
|
||||
#include "stringliteral.hpp"
|
||||
#include "stringparam.hpp"
|
||||
#include "stringview.hpp"
|
||||
#include "strongint.hpp"
|
||||
#include "strops.hpp"
|
||||
|
32
deps/ox/src/ox/std/stringparam.hpp
vendored
Normal file
32
deps/ox/src/ox/std/stringparam.hpp
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2015 - 2024 gary@drinkingtea.net
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "string.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
class StringParam {
|
||||
private:
|
||||
ox::String m_value;
|
||||
public:
|
||||
StringParam(StringParam const&) = delete;
|
||||
constexpr StringParam(StringParam &&o) noexcept: m_value{std::move(o.m_value)} {}
|
||||
constexpr StringParam(char const*value) noexcept: m_value{value} {}
|
||||
constexpr StringParam(detail::BaseStringView const&value) noexcept: m_value{value} {}
|
||||
constexpr StringParam(ox::String const&value) noexcept: m_value{value} {}
|
||||
constexpr StringParam(ox::String &&value) noexcept: m_value{std::move(value)} {}
|
||||
constexpr operator ox::String() && noexcept { return std::move(m_value); }
|
||||
explicit constexpr operator ox::CStringView() const noexcept { return m_value; }
|
||||
explicit constexpr operator ox::StringView() const noexcept { return m_value; }
|
||||
[[nodiscard]]
|
||||
constexpr ox::CStringView view() const noexcept { return m_value; }
|
||||
};
|
||||
|
||||
}
|
@ -29,7 +29,7 @@ ox::Error PaletteV2ToPaletteV3Converter::convert(
|
||||
dst.pages = std::move(src.pages);
|
||||
if (!dst.pages.empty()) {
|
||||
for (size_t i = 0; i < dst.pages[0].size(); ++i) {
|
||||
dst.colorInfo.emplace_back(ox::sfmt("Color {}", i));
|
||||
dst.colorInfo.emplace_back(ox::sfmt("Color {}", i + 1));
|
||||
}
|
||||
}
|
||||
return {};
|
||||
|
@ -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()) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 {};
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -87,12 +87,12 @@ void TileSheetEditorView::clickFill(ox::Vec2 const&paneSize, ox::Vec2 const&clic
|
||||
void TileSheetEditorView::releaseMouseButton(TileSheetTool tool) noexcept {
|
||||
switch (tool) {
|
||||
case TileSheetTool::Draw:
|
||||
case TileSheetTool::Fill:
|
||||
m_model.endDrawCommand();
|
||||
break;
|
||||
case TileSheetTool::Select:
|
||||
m_model.completeSelection();
|
||||
break;
|
||||
case TileSheetTool::Fill:
|
||||
case TileSheetTool::None:
|
||||
break;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
namespace studio {
|
||||
|
||||
NewMenu::NewMenu() noexcept {
|
||||
setTitle(ox::String("New Item"));
|
||||
setTitle("New Item");
|
||||
setSize({230, 140});
|
||||
}
|
||||
|
||||
|
@ -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});
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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),
|
||||
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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user