#include "asset_io.h" #include using namespace godot; namespace mtgodot { PackedByteArray read_file(const String &path) { if (path.is_empty()) { return PackedByteArray(); } // FileAccess::get_file_as_bytes handles res:// / user:// / absolute OS paths. return FileAccess::get_file_as_bytes(path); } bool file_exists(const String &path) { return !path.is_empty() && FileAccess::file_exists(path); } Image dds_from_file(const String &path) { PackedByteArray b = read_file(path); if (b.is_empty()) { return Image{}; } return load_dds(b.ptr(), (size_t)b.size()); } std::optional gr2_from_file(const String &path, gr2::LoadError *err) { PackedByteArray b = read_file(path); if (b.is_empty()) { if (err) { *err = {"open", std::string("cannot read ") + path.utf8().get_data()}; } return std::nullopt; } return gr2::File::load(b.ptr(), (size_t)b.size(), err); } } // namespace mtgodot