[nostalgia] Add support for asset UUID headers

This commit is contained in:
2023-02-12 00:02:41 -06:00
parent 2b821b73ff
commit 1b7b6e306e
14 changed files with 144 additions and 31 deletions

View File

@@ -22,7 +22,7 @@ ox::String configPath(const core::Context *ctx) noexcept;
template<typename T>
ox::Result<T> readConfig(core::Context *ctx, ox::CRStringView name) noexcept {
oxAssert(ox_strcmp(name, ""), "Config type has no TypeName");
oxAssert(name != "", "Config type has no TypeName");
const auto path = ox::sfmt("/{}.json", name);
ox::PassThroughFS fs(configPath(ctx));
const auto [buff, err] = fs.read(path);
@@ -41,7 +41,7 @@ ox::Result<T> readConfig(core::Context *ctx) noexcept {
template<typename T>
ox::Error writeConfig(core::Context *ctx, ox::CRStringView name, T *data) noexcept {
oxAssert(ox_strcmp(name, ""), "Config type has no TypeName");
oxAssert(name != "", "Config type has no TypeName");
const auto path = ox::sfmt("/{}.json", name);
ox::PassThroughFS fs(configPath(ctx));
if (const auto err = fs.mkdir("/", true)) {
@@ -66,8 +66,9 @@ ox::Error writeConfig(core::Context *ctx, T *data) noexcept {
template<typename T, typename Func>
void openConfig(core::Context *ctx, const auto &name, Func f) noexcept {
oxAssert(name != "", "Config type has no TypeName");
const auto c = readConfig<T>(ctx, name);
f(&c.value);
const auto [c, err] = readConfig<T>(ctx, name);
oxLogError(err);
f(&c);
}
template<typename T, typename Func>
@@ -79,9 +80,10 @@ void openConfig(core::Context *ctx, Func f) noexcept {
template<typename T, typename Func>
void editConfig(core::Context *ctx, const auto &name, Func f) noexcept {
oxAssert(ox_strcmp(name, ""), "Config type has no TypeName");
auto c = readConfig<T>(ctx, name);
f(&c.value);
oxLogError(writeConfig(ctx, name, &c.value));
auto [c, err] = readConfig<T>(ctx, name);
oxLogError(err);
f(&c);
oxLogError(writeConfig(ctx, name, &c));
}
template<typename T, typename Func>

View File

@@ -13,6 +13,7 @@
#include <ox/std/hashmap.hpp>
#include <nostalgia/core/typestore.hpp>
#include <nostalgia/foundation/media.hpp>
#include "nostalgiastudio_export.h"
@@ -129,9 +130,9 @@ template<typename T>
ox::Result<T> Project::loadObj(const ox::String &path) const noexcept {
oxRequire(buff, loadBuff(path));
if constexpr (ox::is_same_v<T, ox::ModelObject>) {
return ox::readClaw(&m_typeStore, buff);
return foundation::readAsset(&m_typeStore, buff);
} else {
return ox::readClaw<T>(buff);
return foundation::readAsset<T>(buff);
}
}