#pragma once #include "AbstractResource.h" #include #include "AbstractConfigWithTempl.h" #include "TemplResource.h" #include "Utils/SingletonHolder.hpp" namespace asst { class ResourceLoader final : public SingletonHolder, public AbstractResource { public: virtual ~ResourceLoader() override = default; virtual bool load(const std::filesystem::path& path) override; bool loaded() const noexcept; private: template requires std::is_base_of_v bool load_resource(const std::filesystem::path& path) { if (!std::filesystem::exists(path)) { return m_loaded; } return SingletonHolder::get_instance().load(path); } template requires std::is_base_of_v bool async_load_config(const std::filesystem::path& path) { if (!std::filesystem::exists(path)) { return m_loaded; } SingletonHolder::get_instance().async_load(path); return true; } template requires std::is_base_of_v bool load_resource_with_templ(const std::filesystem::path& path, const std::filesystem::path& templ_dir) { if (!load_resource(path)) { return false; } static auto& templ_ins = SingletonHolder::get_instance(); const auto& required = SingletonHolder::get_instance().get_templ_required(); templ_ins.set_load_required(required); return load_resource(templ_dir); } private: bool m_loaded = false; }; } // namespace asst