[nostalgia] Make assets loadable through UUID references

This commit is contained in:
2023-02-12 23:37:58 -06:00
parent a96d173fdc
commit 86a3bf1248
13 changed files with 27 additions and 20 deletions
+8 -4
View File
@@ -37,7 +37,7 @@ ox::Result<std::size_t> getPreloadAddr(foundation::Context *ctx, ox::CRStringVie
template<typename T>
ox::Result<foundation::AssetRef<T>> readObjFile(
foundation::Context *ctx,
ox::CRStringView assetId,
ox::StringView assetId,
bool forceLoad) noexcept {
constexpr auto readConvert = [](Context *ctx, const ox::Buffer &buff) -> ox::Result<T> {
auto [obj, err] = readAsset<T>(buff);
@@ -50,20 +50,24 @@ ox::Result<foundation::AssetRef<T>> readObjFile(
return std::move(obj);
};
ox::StringView path;
if (ctx->useUuids) {
ox::UUIDStr uuidStr;
if (beginsWith(assetId, "uuid://")) {
assetId = assetId.substr(7);
path = ctx->uuidToPath[assetId];
} else {
path = assetId;
uuidStr = ctx->pathToUuid[path].toString();
assetId = uuidStr;
}
if (forceLoad) {
oxRequire(buff, ctx->rom->read(assetId));
oxRequire(buff, ctx->rom->read(path));
oxRequire(obj, readConvert(ctx, buff));
oxRequire(cached, ctx->assetManager.setAsset(assetId, obj));
return cached;
} else {
auto [cached, err] = ctx->assetManager.getAsset<T>(assetId);
if (err) {
oxRequire(buff, ctx->rom->read(assetId));
oxRequire(buff, ctx->rom->read(path));
oxRequire(obj, readConvert(ctx, buff));
oxReturnError(ctx->assetManager.setAsset(assetId, obj).moveTo(&cached));
}