sandbox
Loading...
Searching...
No Matches
asset_io.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_SCENES_ASSET_IO_HPP_
3#define LIBSBX_SCENES_ASSET_IO_HPP_
4
5#include <functional>
6#include <string>
7#include <unordered_map>
8
9#include <yaml-cpp/yaml.h>
10
11#include <libsbx/utility/hashed_string.hpp>
12
13#include <libsbx/scenes/asset_registry.hpp>
14
15namespace sbx::scenes {
16
18
19public:
20
21 template<std::invocable<asset_registry&, const utility::hashed_string&, const YAML::Node&> Load>
22 auto register_loader(const std::string& category, Load&& load) -> void {
23 _loaders[category] = std::forward<Load>(load);
24 }
25
26 auto has(const std::string& category) const -> bool {
27 return _loaders.contains(category);
28 }
29
30 auto load(const std::string& category, asset_registry& assets, const utility::hashed_string& name, const YAML::Node& node) -> void {
31 std::invoke(_loaders.at(category), assets, name, node);
32 }
33
34private:
35
36 std::unordered_map<std::string, std::function<void(asset_registry&, const utility::hashed_string&, const YAML::Node&)>> _loaders;
37
38}; // class asset_io_registry
39
40} // namespace sbx::scenes
41
42#endif // LIBSBX_SCENES_ASSET_IO_HPP_
Definition: tests.cpp:6
Definition: asset_io.hpp:17
Definition: asset_registry.hpp:81
Definition: hashed_string.hpp:17