mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 11:31:49 +00:00
feat: loading entities (WIP)
This commit is contained in:
parent
08cc78289d
commit
c8666910ce
16 changed files with 129 additions and 38 deletions
|
|
@ -55,9 +55,9 @@ integer_t List::integer(size_t index) const {
|
|||
}
|
||||
}
|
||||
|
||||
Map* List::map(size_t index) const {
|
||||
const Map_sptr& List::map(size_t index) const {
|
||||
if (auto* val = std::get_if<Map_sptr>(&values[index])) {
|
||||
return val->get();
|
||||
return *val;
|
||||
} else {
|
||||
throw std::runtime_error("type error");
|
||||
}
|
||||
|
|
@ -192,11 +192,11 @@ void Map::num(const std::string& key, uint& dst) const {
|
|||
dst = get(key, static_cast<integer_t>(dst));
|
||||
}
|
||||
|
||||
Map* Map::map(const std::string& key) const {
|
||||
Map_sptr Map::map(const std::string& key) const {
|
||||
auto found = values.find(key);
|
||||
if (found != values.end()) {
|
||||
if (auto* val = std::get_if<Map_sptr>(&found->second)) {
|
||||
return val->get();
|
||||
return *val;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ namespace dynamic {
|
|||
std::string str(size_t index) const;
|
||||
number_t num(size_t index) const;
|
||||
integer_t integer(size_t index) const;
|
||||
Map* map(size_t index) const;
|
||||
const Map_sptr& map(size_t index) const;
|
||||
List* list(size_t index) const;
|
||||
bool flag(size_t index) const;
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ namespace dynamic {
|
|||
void num(const std::string& key, uint64_t& dst) const;
|
||||
void num(const std::string& key, ubyte& dst) const;
|
||||
void num(const std::string& key, double& dst) const;
|
||||
Map* map(const std::string& key) const;
|
||||
Map_sptr map(const std::string& key) const;
|
||||
List* list(const std::string& key) const;
|
||||
void flag(const std::string& key, bool& dst) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,15 @@ namespace dynamic {
|
|||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
template<int n>
|
||||
void get_vec(const dynamic::Map_sptr& root, const std::string& name, glm::vec<n, float>& vec) {
|
||||
if (const auto& list = root->list(name)) {
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
vec[i] = list->num(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // DATA_DYNAMIC_UTIL_HPP_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue