[nostalgia] Make assets loadable through UUID references
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace nostalgia {
|
||||
|
||||
static ox::Error pathToInode(ox::FileSystem *dest, ox::ModelObject *obj) noexcept {
|
||||
static ox::Error pathToInode(foundation::Context *ctx, ox::FileSystem *dest, ox::ModelObject *obj) noexcept {
|
||||
auto &o = *obj;
|
||||
auto type = static_cast<ox::FileAddressType>(o["type"].get<int8_t>());
|
||||
auto &data = o["data"].get<ox::ModelUnion>();
|
||||
@@ -29,28 +29,32 @@ static ox::Error pathToInode(ox::FileSystem *dest, ox::ModelObject *obj) noexcep
|
||||
case ox::FileAddressType::None:
|
||||
return {};
|
||||
}
|
||||
if (beginsWith(path, "uuid://")) {
|
||||
const auto uuid = ox::StringView(path).substr(7);
|
||||
path = ctx->uuidToPath[uuid];
|
||||
}
|
||||
oxRequire(s, dest->stat(path));
|
||||
oxReturnError(o["type"].set(static_cast<int8_t>(ox::FileAddressType::Inode)));
|
||||
return data.set(2, s.inode);
|
||||
}
|
||||
|
||||
static ox::Error transformFileAddressesObj(ox::FileSystem *dest, ox::ModelObject *obj) noexcept;
|
||||
static ox::Error transformFileAddressesVec(ox::FileSystem *dest, ox::ModelValueVector *v) noexcept;
|
||||
static ox::Error transformFileAddressesObj(foundation::Context *ctx, ox::FileSystem *dest, ox::ModelObject *obj) noexcept;
|
||||
static ox::Error transformFileAddressesVec(foundation::Context *ctx, ox::FileSystem *dest, ox::ModelValueVector *v) noexcept;
|
||||
|
||||
static ox::Error transformFileAddresses(ox::FileSystem *dest, ox::ModelValue *v) noexcept {
|
||||
static ox::Error transformFileAddresses(foundation::Context *ctx, ox::FileSystem *dest, ox::ModelValue *v) noexcept {
|
||||
if (v->type() == ox::ModelValue::Type::Object) {
|
||||
auto &obj = v->get<ox::ModelObject>();
|
||||
return transformFileAddressesObj(dest, &obj);
|
||||
return transformFileAddressesObj(ctx, dest, &obj);
|
||||
} else if (v->type() == ox::ModelValue::Type::Vector) {
|
||||
auto &vec = v->get<ox::ModelValueVector>();
|
||||
return transformFileAddressesVec(dest, &vec);
|
||||
return transformFileAddressesVec(ctx, dest, &vec);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
static ox::Error transformFileAddressesVec(ox::FileSystem *dest, ox::ModelValueVector *v) noexcept {
|
||||
static ox::Error transformFileAddressesVec(foundation::Context *ctx, ox::FileSystem *dest, ox::ModelValueVector *v) noexcept {
|
||||
for (auto &f : *v) {
|
||||
oxReturnError(transformFileAddresses(dest, &f));
|
||||
oxReturnError(transformFileAddresses(ctx, dest, &f));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -59,13 +63,13 @@ static ox::Error transformFileAddressesVec(ox::FileSystem *dest, ox::ModelValueV
|
||||
* Convert path references in Claw data to inodes to save space
|
||||
* @return error
|
||||
*/
|
||||
static ox::Error transformFileAddressesObj(ox::FileSystem *dest, ox::ModelObject *obj) noexcept {
|
||||
static ox::Error transformFileAddressesObj(foundation::Context *ctx, ox::FileSystem *dest, ox::ModelObject *obj) noexcept {
|
||||
if (obj->typeName() == "net.drinkingtea.ox.FileAddress" && obj->typeVersion() == 1) {
|
||||
return pathToInode(dest, obj);
|
||||
return pathToInode(ctx, dest, obj);
|
||||
}
|
||||
for (auto &f : *obj) {
|
||||
auto &v = f->value;
|
||||
oxReturnError(transformFileAddresses(dest, &v));
|
||||
oxReturnError(transformFileAddresses(ctx, dest, &v));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -80,7 +84,7 @@ static ox::Error doTransformations(foundation::Context *ctx, ox::TypeStore *ts,
|
||||
}
|
||||
// transform FileAddresses
|
||||
oxRequireM(obj, foundation::readAsset(ts, buff));
|
||||
oxReturnError(transformFileAddressesObj(dest, &obj));
|
||||
oxReturnError(transformFileAddressesObj(ctx, dest, &obj));
|
||||
oxReturnError(ox::writeClaw(&obj).moveTo(&buff));
|
||||
// write file to dest
|
||||
oxReturnError(dest->write(s.inode, buff.data(), buff.size()));
|
||||
|
||||
Reference in New Issue
Block a user