7#include <unordered_map>
10#include <nlohmann/json_fwd.hpp>
12#include "resource/asset_type.h"
14namespace Vkm::Engine {
22 AssetType type = AssetType::Mesh;
101 std::vector<std::string>
namesOf(AssetType type)
const;
112 static std::filesystem::path
recipePath(AssetType type,
const std::string& name);
127 static std::filesystem::path
cookedPath(AssetType type,
const std::string& name, uint64_t recipeHash);
140 static bool readRecipe(AssetType type,
const std::string& name, nlohmann::json& outSource);
155 const std::string& name,
156 const nlohmann::json& source
174 void remove(AssetType type,
const std::string& name);
181 [[nodiscard]]
bool save()
const;
195 AssetLibrary() =
default;
197 static std::string key(AssetType type,
const std::string& name);
207 void dropRowsWithoutRecipes();
212 void adoptUnrecordedRecipes();
221 static std::string uidFor(AssetType type,
const std::string& name);
224 std::unordered_map<std::string, AssetRecord> m_records;
In-memory view of the on-disk asset database manifest.
Definition asset_library.h:49
static bool readRecipe(AssetType type, const std::string &name, nlohmann::json &outSource)
Read the source object out of the recipe file for (type, name).
static bool writeRecipe(AssetType type, const std::string &name, const nlohmann::json &source)
Write source as the recipe file for (type, name).
void remove(AssetType type, const std::string &name)
Forget the record for (type, name), in memory until save().
const AssetRecord * find(AssetType type, const std::string &name) const
Resolve (type, name) to its record, or nullptr if absent.
static std::filesystem::path recipePath(AssetType type, const std::string &name)
Absolute path to the recipe file of (type, name).
std::vector< std::string > namesOf(AssetType type) const
Every registered asset name of type, sorted.
void load(Truth truth)
(Re)load the library from disk, replacing current state.
void upsert(AssetRecord record)
Record record, replacing any record for its (type, name).
Truth
Which file says an asset exists, as load() reads a project.
Definition asset_library.h:56
@ Recipes
A host that imports and cooks: a row whose recipe is gone is dropped.
Definition asset_library.h:57
@ Manifest
A host that reads only cooked assets: every row stands.
Definition asset_library.h:58
static std::filesystem::path cookedPath(AssetType type, const std::string &name, uint64_t recipeHash)
Absolute path to the cooked binary of (type, name).
bool save() const
Write the manifest, every record in key order.
size_t removeUnrecordedCooked() const
Delete every file in a kind's cooked directory that no record names.
One row of the manifest: an asset's identity, and what it was cooked from.
Definition asset_library.h:21
uint64_t recipeHash
What the cooked file was last baked from: the recipe, its source art's bytes, and the recorded key of...
Definition asset_library.h:30
std::vector< std::string > sources
The source-art files the cook read and folded into recipeHash, as project references (AssetCooker::so...
Definition asset_library.h:38