Toast Engine
Loading...
Searching...
No Matches
asset_registry.hpp
1#pragma once
2
3#include "core_types.hpp"
4#include "schema.hpp"
5
6#include <functional>
7#include <memory>
8#include <string>
9#include <string_view>
10#include <unordered_map>
11
12namespace assets {
13
14class TOAST_API AssetRegistry {
15public:
16 using RawLoader = std::function<std::unique_ptr<Asset>(std::vector<uint8_t>)>;
17 using TomlLoader = std::function<std::unique_ptr<Asset>(toml::table)>;
18 using SchemaTomlLoader = std::function<std::unique_ptr<Asset>(toml::table, Handle<Schema>)>;
19
20 static void init();
21
22 static void registerRaw(std::string_view type, RawLoader loader);
23 static void registerToml(std::string_view type, TomlLoader loader);
24 static void registerSchemaToml(std::string_view type, SchemaTomlLoader loader);
25
26 [[nodiscard]]
27 static auto hasRaw(std::string_view type) -> bool;
28
29 [[nodiscard]]
30 static auto hasToml(std::string_view type) -> bool;
31
32 [[nodiscard]]
33 static auto hasSchemaToml(std::string_view type) -> bool;
34
35 static auto createRaw(std::string_view type, std::vector<uint8_t> data) -> std::unique_ptr<Asset>;
36 static auto createToml(std::string_view type, toml::table table) -> std::unique_ptr<Asset>;
37 static auto createSchemaToml(std::string_view type, toml::table table, Handle<Schema> schema) -> std::unique_ptr<Asset>;
38
39 static void registerLuaName(std::string_view type, std::string_view lua_name);
40
41 [[nodiscard]]
42 static auto registeredLuaNames() -> const std::unordered_map<std::string, std::string>&;
43
44private:
45 static std::unordered_map<std::string, RawLoader> s_raw;
46 static std::unordered_map<std::string, TomlLoader> s_toml;
47 static std::unordered_map<std::string, SchemaTomlLoader> s_schema_toml;
48 static std::unordered_map<std::string, std::string> s_lua_names;
49};
50
51} // namespace assets
Definition asset_registry.hpp:14
Type-safe smart pointer for assets.
Definition core_types.hpp:149
Base types for the asset system.
Used as "reflection data" for Data types.