[nostalgia] Move pack transforms to modules
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
#include <ox/model/modelvalue.hpp>
|
||||
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
#include <nostalgia/core/typeconv.hpp>
|
||||
#include <nostalgia/core/typestore.hpp>
|
||||
#include <nostalgia/foundation/media.hpp>
|
||||
|
||||
@@ -42,7 +41,7 @@ static ox::Error pathToInode(ox::FileSystem *dest, ox::ModelObject *obj) noexcep
|
||||
* @param buff buffer holding file
|
||||
* @return error
|
||||
*/
|
||||
static ox::Error transformObj(ox::FileSystem *dest, ox::ModelObject *obj) noexcept {
|
||||
static ox::Error transformFileAddresses(ox::FileSystem *dest, ox::ModelObject *obj) noexcept {
|
||||
for (auto &f : *obj) {
|
||||
auto &v = f->value;
|
||||
if (v.type() != ox::ModelValue::Type::Object) {
|
||||
@@ -52,31 +51,30 @@ static ox::Error transformObj(ox::FileSystem *dest, ox::ModelObject *obj) noexce
|
||||
if (o.typeName() == "net.drinkingtea.ox.FileAddress" && o.typeVersion() == 1) {
|
||||
oxReturnError(pathToInode(dest, &o));
|
||||
} else {
|
||||
oxReturnError(transformObj(dest, &o));
|
||||
oxReturnError(transformFileAddresses(dest, &o));
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
static ox::Error doTransformations(foundation::Context *ctx, core::TypeStore *ts, ox::FileSystem *dest, ox::CRStringView filePath) noexcept {
|
||||
if (endsWith(filePath, ".ng") || endsWith(filePath, ".npal")) {
|
||||
// load file
|
||||
oxRequire(s, dest->stat(filePath));
|
||||
oxRequireM(buff, dest->read(s.inode));
|
||||
if (endsWith(filePath, ".ng")) {
|
||||
oxReturnError(foundation::convertBuffToBuff<core::CompactTileSheet>(ctx, buff, ox::ClawFormat::Metal).moveTo(&buff));
|
||||
}
|
||||
oxRequireM(obj, ox::readClaw(ts, buff));
|
||||
// do transformations
|
||||
oxReturnError(transformObj(dest, &obj));
|
||||
oxReturnError(ox::writeClaw(&obj).moveTo(&buff));
|
||||
// write file to dest
|
||||
oxReturnError(dest->write(s.inode, buff.data(), buff.size()));
|
||||
// load file
|
||||
oxRequire(s, dest->stat(filePath));
|
||||
// do transformations
|
||||
oxRequireM(buff, dest->read(s.inode));
|
||||
for (auto tr : ctx->packTransforms) {
|
||||
oxReturnError(tr(ctx, &buff));
|
||||
}
|
||||
// transform FileAddresses
|
||||
oxRequireM(obj, ox::readClaw(ts, buff));
|
||||
oxReturnError(transformFileAddresses(dest, &obj));
|
||||
oxReturnError(ox::writeClaw(&obj).moveTo(&buff));
|
||||
// write file to dest
|
||||
oxReturnError(dest->write(s.inode, buff.data(), buff.size()));
|
||||
return {};
|
||||
}
|
||||
|
||||
// claw file transformations are broken out because path to inode
|
||||
// claw file transformations are broken out from copy because path to inode
|
||||
// transformations need to be done after the copy to the new FS is complete
|
||||
static ox::Error transformClaw(foundation::Context *ctx, core::TypeStore *ts, ox::FileSystem *dest, ox::CRStringView path) noexcept {
|
||||
// copy
|
||||
|
||||
Reference in New Issue
Block a user