port 2D step 5b: PackInitialize + pack:// asset_io backend over the ported EterPackManager
Platform UserInterface PackInitialize/PackSingletons (40250 bootstrap, on-disk dbname resolution), EterBase/FileLoader.cpp mirror, mtpack40250 backend behind asset_io's pack:// scheme and a Metin2Pack node. port_eterpack_test now registers through PackInitialize. Nothing reads pack:// at runtime yet; port-map stays TODO. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,19 +2,51 @@
|
||||
|
||||
#include <godot_cpp/classes/file_access.hpp>
|
||||
|
||||
#include "platform/PackBackend.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
namespace mtgodot {
|
||||
|
||||
namespace {
|
||||
bool pack_name(const String &path, std::string &name) {
|
||||
if (!path.begins_with(PACK_SCHEME)) {
|
||||
return false;
|
||||
}
|
||||
name = path.substr(String(PACK_SCHEME).length()).utf8().get_data();
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
PackedByteArray read_file(const String &path) {
|
||||
if (path.is_empty()) {
|
||||
return PackedByteArray();
|
||||
}
|
||||
std::string name;
|
||||
if (pack_name(path, name)) {
|
||||
std::vector<uint8_t> bytes;
|
||||
PackedByteArray out;
|
||||
if (mtpack40250::read(name, bytes)) {
|
||||
out.resize((int64_t)bytes.size());
|
||||
if (!bytes.empty()) {
|
||||
std::memcpy(out.ptrw(), bytes.data(), bytes.size());
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
// FileAccess::get_file_as_bytes handles res:// / user:// / absolute OS paths.
|
||||
return FileAccess::get_file_as_bytes(path);
|
||||
}
|
||||
|
||||
bool file_exists(const String &path) {
|
||||
std::string name;
|
||||
if (pack_name(path, name)) {
|
||||
return mtpack40250::exists(name);
|
||||
}
|
||||
return !path.is_empty() && FileAccess::file_exists(path);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user