[nostalgia/core] Upgrade TileSheet format to support subsheets and add conversion system
This commit is contained in:
@@ -4,27 +4,40 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/defines.hpp>
|
||||
|
||||
#include <ox/claw/claw.hpp>
|
||||
#include <ox/fs/fs.hpp>
|
||||
|
||||
#include "context.hpp"
|
||||
#include "typeconv.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> readObj(Context *ctx, const ox::FileAddress &file, bool forceLoad = false) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
constexpr auto readConvert = [](const ox::Buffer &buff) -> ox::Result<T> {
|
||||
auto [obj, err] = ox::readClaw<T>(buff);
|
||||
if (err) {
|
||||
if (err != ox::Error_ClawTypeVersionMismatch && err != ox::Error_ClawTypeMismatch) {
|
||||
return err;
|
||||
}
|
||||
oxReturnError(convert(buff, T::TypeName, T::TypeVersion, &obj));
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
oxRequire(path, file.getPath());
|
||||
if (forceLoad) {
|
||||
oxRequire(buff, ctx->rom->read(file));
|
||||
oxRequire(obj, ox::readClaw<T>(buff));
|
||||
oxRequire(obj, readConvert(buff));
|
||||
oxRequire(cached, ctx->assetManager.template setAsset(path, obj));
|
||||
return cached;
|
||||
} else {
|
||||
auto [cached, err] = ctx->assetManager.template getAsset<T>(path);
|
||||
if (err) {
|
||||
oxRequire(buff, ctx->rom->read(file));
|
||||
oxRequire(obj, ox::readClaw<T>(buff));
|
||||
oxRequire(obj, readConvert(buff));
|
||||
oxReturnError(ctx->assetManager.template setAsset(path, obj).moveTo(&cached));
|
||||
}
|
||||
return cached;
|
||||
|
||||
Reference in New Issue
Block a user