Squashed 'deps/nostalgia/' changes from 312097a7..8419b137

8419b137 [turbine,studio] Fix some popup window resize weirdness, cleanup some function names
ed1160ec [nostalgia] Update release notes
1e217780 [nostalgia/gfx/studio/tilesheet] Ensure config file has a Claw header
78379f58 [studio] Add ability to remember recent projects in config
4322f720 [keel] Fix ox::Result<DstType> convert(Context &ctx, ox::BufferView const&src)
26f1a605 [ox/std] Make Vector::remove take a MaybeView_t
c4c1d477 [keel] Cleanup ox::Error(0) instance
fab012d3 [ox] Cleanup all ox::Error(0) instances

git-subtree-dir: deps/nostalgia
git-subtree-split: 8419b137e5dec1dabc15a0d34c7ce729970c3b7f
This commit is contained in:
2025-05-24 01:44:07 -05:00
parent e90dd88747
commit 08236fc790
39 changed files with 388 additions and 202 deletions

View File

@@ -4,21 +4,21 @@
#pragma once
#include <ox/claw/claw.hpp>
#include <ox/fs/fs.hpp>
#include <ox/model/typenamecatcher.hpp>
#include <ox/oc/oc.hpp>
#include <ox/std/buffer.hpp>
#include <ox/std/defines.hpp>
#include <ox/std/fmt.hpp>
#include <ox/std/trace.hpp>
#include <ox/std/string.hpp>
#include <ox/std/trace.hpp>
#include <keel/context.hpp>
namespace studio {
namespace detail {
inline ox::String slashesToPct(ox::StringView str) noexcept {
inline ox::String slashesToPct(ox::StringViewCR str) noexcept {
auto out = ox::String{str};
for (auto&c: out) {
if (c == '/' || c == '\\') {
@@ -30,78 +30,102 @@ inline ox::String slashesToPct(ox::StringView str) noexcept {
}
[[nodiscard]]
ox::String configPath(keel::Context const&ctx) noexcept;
ox::String configPath(keel::Context const&kctx) noexcept;
template<typename T>
ox::Result<T> readConfig(keel::Context &ctx, ox::StringViewCR name) noexcept {
ox::Result<T> readConfig(keel::Context &kctx, ox::StringViewCR name) noexcept {
oxAssert(name != "", "Config type has no TypeName");
auto const path = ox::sfmt("/{}.json", detail::slashesToPct(name));
ox::PassThroughFS fs(configPath(ctx));
ox::PassThroughFS fs(configPath(kctx));
auto const [buff, err] = fs.read(path);
if (err) {
//oxErrf("Could not read config file: {} - {}\n", path, toStr(err));
return err;
}
return ox::readOC<T>(buff);
OX_REQUIRE(id, ox::readClawTypeId(buff));
ox::Result<T> out;
if (id != ox::ModelTypeId_v<T>) {
out = keel::convert<T>(kctx, buff);
} else {
out = ox::readClaw<T>(buff);
}
OX_RETURN_ERROR(out);
OX_RETURN_ERROR(keel::ensureValid(out.value));
return out;
}
template<typename T>
ox::Result<T> readConfig(keel::Context &ctx) noexcept {
ox::Result<T> readConfig(keel::Context &kctx) noexcept {
constexpr auto TypeName = ox::requireModelTypeName<T>();
return readConfig<T>(ctx, TypeName);
return readConfig<T>(kctx, TypeName);
}
template<typename T>
ox::Error writeConfig(keel::Context &ctx, ox::StringViewCR name, T const&data) noexcept {
ox::Error writeConfig(keel::Context &kctx, ox::StringViewCR name, T const&data) noexcept {
oxAssert(name != "", "Config type has no TypeName");
auto const path = ox::sfmt("/{}.json", detail::slashesToPct(name));
ox::PassThroughFS fs(configPath(ctx));
ox::PassThroughFS fs(configPath(kctx));
if (auto const err = fs.mkdir("/", true)) {
//oxErrf("Could not create config directory: {} - {}\n", path, toStr(err));
return err;
}
OX_REQUIRE_M(buff, ox::writeOC(data));
OX_REQUIRE_M(buff, ox::writeClaw(data, ox::ClawFormat::Organic));
*buff.back().value = '\n';
if (auto const err = fs.write(path, buff.data(), buff.size())) {
//oxErrf("Could not read config file: {} - {}\n", path, toStr(err));
return ox::Error(2, "Could not read config file");
return ox::Error{2, "Could not read config file"};
}
return {};
}
template<typename T>
ox::Error writeConfig(keel::Context &ctx, T const&data) noexcept {
ox::Error writeConfig(keel::Context &kctx, T const&data) noexcept {
constexpr auto TypeName = ox::requireModelTypeName<T>();
return writeConfig(ctx, TypeName, data);
return writeConfig(kctx, TypeName, data);
}
template<typename T, typename Func>
void openConfig(keel::Context &ctx, ox::StringViewCR name, Func f) noexcept {
void openConfig(keel::Context &kctx, ox::StringViewCR name, Func f) noexcept {
oxAssert(name != "", "Config type has no TypeName");
auto const [c, err] = readConfig<T>(ctx, name);
auto const [c, err] = readConfig<T>(kctx, name);
oxLogError(err);
f(c);
}
template<typename T, typename Func>
void openConfig(keel::Context &ctx, Func f) noexcept {
void openConfig(keel::Context &kctx, Func f) noexcept {
constexpr auto TypeName = ox::requireModelTypeName<T>();
openConfig<T>(ctx, TypeName, f);
openConfig<T>(kctx, TypeName, f);
}
template<typename T, typename Func>
void editConfig(keel::Context &ctx, ox::StringViewCR name, Func f) noexcept {
void editConfig(keel::Context &kctx, ox::StringViewCR name, Func f) noexcept {
oxAssert(name != "", "Config type has no TypeName");
auto [c, err] = readConfig<T>(ctx, name);
auto [c, err] = readConfig<T>(kctx, name);
oxLogError(err);
f(c);
oxLogError(writeConfig(ctx, name, c));
oxLogError(writeConfig(kctx, name, c));
}
template<typename T, typename Func>
void editConfig(keel::Context &ctx, Func f) noexcept {
void editConfig(keel::Context &kctx, Func f) noexcept {
constexpr auto TypeName = ox::requireModelTypeName<T>();
editConfig<T>(ctx, TypeName, f);
editConfig<T>(kctx, TypeName, f);
}
/**
* Older config files didn't use ClawHeaders, so they can't
* use the normal conversion system.
* Functions like this shouldn't be necessary moving forward.
*/
template<typename T>
ox::Error headerizeConfigFile(keel::Context &kctx, ox::StringViewCR name = ox::ModelTypeName_v<T>) noexcept {
auto const path = ox::sfmt("/{}.json", name);
ox::PassThroughFS fs(configPath(kctx));
OX_REQUIRE_M(buff, fs.read(path));
OX_REQUIRE_M(cv1, ox::readOC<T>(buff));
OX_RETURN_ERROR(ox::writeClaw(cv1, ox::ClawFormat::Organic).moveTo(buff));
return fs.write(path, buff);
}
}

View File

@@ -275,6 +275,9 @@ void QuestionPopup::draw(Context &ctx) noexcept {
ImGui::OpenPopup(m_title.c_str());
m_stage = Stage::Open;
m_open = true;
// require extended refresh in case new contents require resize
// this can take around a second
turbine::requireRefreshFor(ctx.tctx, 1000);
[[fallthrough]];
case Stage::Open:
centerNextWindow(ctx.tctx);