main
Brett 2025-07-10 12:08:09 -04:00
parent 17955ef486
commit c91e8b3cb7
2 changed files with 28 additions and 5 deletions

View File

@ -136,7 +136,11 @@ public:
return sqlite3_bind_null(statement, col); return sqlite3_bind_null(statement, col);
} else if constexpr (std::is_same_v<Decay, std::string> || std::is_same_v<Decay, std::string_view>) } else if constexpr (std::is_same_v<Decay, std::string> || std::is_same_v<Decay, std::string_view>)
{ {
return sqlite3_bind_text(statement, col, type.data(), type.size(), nullptr); auto str_copy = new char[type.size()];
std::memcpy(str_copy, type.data(), type.size());
return sqlite3_bind_text(statement, col, str_copy, type.size(), [](void* ptr) {
delete[] static_cast<char*>(ptr);
});
} else if constexpr (std::is_same_v<Decay, char*> || std::is_same_v<Decay, const char*>) } else if constexpr (std::is_same_v<Decay, char*> || std::is_same_v<Decay, const char*>)
{ {
return sqlite3_bind_text(statement, col, type, -1, nullptr); return sqlite3_bind_text(statement, col, type, -1, nullptr);

View File

@ -25,9 +25,10 @@ asset_loader_t::asset_loader_t(std::string folder, std::string name): db{name
{ {
if (!std::filesystem::exists(folder)) if (!std::filesystem::exists(folder))
throw std::runtime_error("Folder does not exist!"); throw std::runtime_error("Folder does not exist!");
if (!std::filesystem::exists(folder + "minecraft/models/block/"))
throw std::runtime_error("Required Minecraft folder does not exist!");
/*
* Tables
*/
auto texture_table = db.builder().create_table("textures"); auto texture_table = db.builder().create_table("textures");
texture_table.with_column<std::string>("name").primary_key(); texture_table.with_column<std::string>("name").primary_key();
texture_table.with_column<blt::u32>("width").not_null(); texture_table.with_column<blt::u32>("width").not_null();
@ -35,9 +36,27 @@ asset_loader_t::asset_loader_t(std::string folder, std::string name): db{name
texture_table.with_column<std::byte*>("data").not_null(); texture_table.with_column<std::byte*>("data").not_null();
texture_table.build().execute(); texture_table.build().execute();
std::optional<std::filesystem::path> model_folder;
std::optional<std::filesystem::path> texture_folder;
auto block_model_folder = folder + "minecraft/models/block/"; auto block_model_folder = folder + "minecraft/models/block/";
for (const auto& entry : std::filesystem::directory_iterator(block_model_folder)) for (const auto& entry : std::filesystem::directory_iterator(block_model_folder))
{ {
if (entry.path().extension() != ".json") if (!entry.is_directory())
continue; continue;
if (entry.path().string().find("models") != std::string::npos)
{
model_folder = entry.path();
}
if (entry.path().string().find("textures") != std::string::npos)
{
texture_folder = entry.path();
}
}
if (!model_folder)
throw std::runtime_error("Could not find model folder!");
if (!texture_folder)
throw std::runtime_error("Could not find texture folder!");
} }