[keel] Fix loading assets by path

This commit is contained in:
Gary Talent 2025-02-19 21:47:00 -06:00
parent cb21ff3f04
commit 202595b2a6

View File

@ -64,12 +64,16 @@ ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexce
namespace detail { namespace detail {
template<typename T> template<typename T>
constexpr auto makeLoader(Context &ctx) { constexpr auto makeLoader(Context &ctx) {
return [&ctx](ox::StringViewCR assetId) -> ox::Result<T> { return [&ctx](ox::StringView assetId) -> ox::Result<T> {
auto const p = ctx.uuidToPath.at(assetId); if (!beginsWith(assetId, "/")) {
if (p.error) { auto const p = ctx.uuidToPath.at(assetId);
return ox::Error{1, "Asset ID not found"}; if (p.error) {
oxErrf("Could not find asset: {}", assetId);
return ox::Error{1, "Asset ID not found"};
}
assetId = *p.value;
} }
OX_REQUIRE(buff, ctx.rom->read(*p.value)); OX_REQUIRE(buff, ctx.rom->read(assetId));
auto [obj, err] = readAsset<T>(buff); auto [obj, err] = readAsset<T>(buff);
if (err) { if (err) {
if (err != ox::Error_ClawTypeVersionMismatch && err != ox::Error_ClawTypeMismatch) { if (err != ox::Error_ClawTypeVersionMismatch && err != ox::Error_ClawTypeMismatch) {