49 lines
1.7 KiB
C++
49 lines
1.7 KiB
C++
// resource_loader.hpp
|
|
// Singleton resource loader for managing pack and filesystem access
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "resource_pack.hpp"
|
|
|
|
namespace Resource {
|
|
|
|
// Singleton class for loading resources from pack or filesystem
|
|
class Loader {
|
|
public:
|
|
static auto get() -> Loader&; // Singleton instance access
|
|
|
|
auto initialize(const std::string& pack_file, bool enable_fallback = true) -> bool; // Initialize loader with pack file
|
|
|
|
auto loadResource(const std::string& filename) -> std::vector<uint8_t>; // Load resource data
|
|
auto resourceExists(const std::string& filename) -> bool; // Check resource availability
|
|
|
|
[[nodiscard]] auto isPackLoaded() const -> bool; // Pack status queries
|
|
[[nodiscard]] auto getPackResourceCount() const -> size_t;
|
|
[[nodiscard]] auto validatePack() const -> bool; // Validate pack integrity
|
|
[[nodiscard]] auto loadAssetsConfig() const -> std::string; // Load assets.yaml from pack
|
|
|
|
void shutdown(); // Cleanup
|
|
|
|
Loader(const Loader&) = delete; // Deleted copy/move constructors
|
|
auto operator=(const Loader&) -> Loader& = delete;
|
|
Loader(Loader&&) = delete;
|
|
auto operator=(Loader&&) -> Loader& = delete;
|
|
|
|
private:
|
|
Loader() = default;
|
|
~Loader() = default;
|
|
|
|
static auto loadFromFilesystem(const std::string& filepath) -> std::vector<uint8_t>; // Filesystem helpers
|
|
static auto fileExistsOnFilesystem(const std::string& filepath) -> bool;
|
|
|
|
std::unique_ptr<Pack> resource_pack_; // Member variables
|
|
bool fallback_to_files_{true};
|
|
bool initialized_{false};
|
|
};
|
|
|
|
} // namespace Resource
|