feat: saving/loading resource entries

This commit is contained in:
MihailRis
2024-07-11 21:56:27 +03:00
parent ca8652ffab
commit 45c4da048c
9 changed files with 63 additions and 8 deletions
+24 -3
View File
@@ -3,6 +3,8 @@
#include "content_fwd.hpp"
#include "../data/dynamic_fwd.hpp"
#include <string>
#include <vector>
#include <memory>
@@ -109,14 +111,20 @@ public:
class ResourceIndices {
std::vector<std::string> names;
std::unordered_map<std::string, size_t> indices;
std::vector<dynamic::Map_sptr> savedData;
public:
ResourceIndices() {}
static constexpr size_t MISSING = -1;
void add(std::string name) {
void add(std::string name, dynamic::Map_sptr map) {
indices[name] = names.size();
names.push_back(name);
savedData.push_back(map);
}
const std::string& getName(size_t index) const {
return names.at(index);
}
size_t indexOf(const std::string& name) const {
@@ -126,6 +134,18 @@ public:
}
return MISSING;
}
dynamic::Map_sptr getSavedData(size_t index) const {
return savedData.at(index);
}
void saveData(size_t index, dynamic::Map_sptr map) {
savedData.at(index) = map;
}
size_t size() const {
return names.size();
}
};
constexpr const char* to_string(ResourceType type) {
@@ -142,7 +162,7 @@ inline std::optional<ResourceType> ResourceType_from(std::string_view str) {
return std::nullopt;
}
using ResourceIndicesSet = ResourceIndices[static_cast<size_t>(ResourceType::LAST)+1];
using ResourceIndicesSet = ResourceIndices[RESOURCE_TYPES_COUNT];
/// @brief Content is a definitions repository
class Content {
@@ -165,7 +185,8 @@ public:
ContentUnitDefs<EntityDef> entities,
UptrsMap<std::string, ContentPackRuntime> packs,
UptrsMap<std::string, BlockMaterial> blockMaterials,
UptrsMap<std::string, rigging::SkeletonConfig> skeletons
UptrsMap<std::string, rigging::SkeletonConfig> skeletons,
const ResourceIndicesSet& resourceIndices
);
~Content();