migrate from dynamic::Value to dv::value & total erase namespace 'dynamic'
This commit is contained in:
+19
-22
@@ -8,7 +8,6 @@
|
||||
#include "constants.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentPack.hpp"
|
||||
#include "data/dynamic.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "files/engine_paths.hpp"
|
||||
#include "files/files.hpp"
|
||||
@@ -130,7 +129,7 @@ static std::string assets_def_folder(AssetType tag) {
|
||||
}
|
||||
|
||||
void AssetsLoader::processPreload(
|
||||
AssetType tag, const std::string& name, dynamic::Map* map
|
||||
AssetType tag, const std::string& name, const dv::value& map
|
||||
) {
|
||||
std::string defFolder = assets_def_folder(tag);
|
||||
std::string path = defFolder + "/" + name;
|
||||
@@ -138,36 +137,34 @@ void AssetsLoader::processPreload(
|
||||
add(tag, path, name);
|
||||
return;
|
||||
}
|
||||
map->str("path", path);
|
||||
map.at("path").get(path);
|
||||
switch (tag) {
|
||||
case AssetType::SOUND:
|
||||
case AssetType::SOUND: {
|
||||
bool keepPCM = false;
|
||||
add(tag,
|
||||
path,
|
||||
name,
|
||||
std::make_shared<SoundCfg>(map->get("keep-pcm", false)));
|
||||
std::make_shared<SoundCfg>(map.at("keep-pcm").get(keepPCM)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
add(tag, path, name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void AssetsLoader::processPreloadList(AssetType tag, dynamic::List* list) {
|
||||
void AssetsLoader::processPreloadList(AssetType tag, const dv::value& list) {
|
||||
if (list == nullptr) {
|
||||
return;
|
||||
}
|
||||
for (uint i = 0; i < list->size(); i++) {
|
||||
auto value = list->get(i);
|
||||
switch (static_cast<dynamic::Type>(value.index())) {
|
||||
case dynamic::Type::string:
|
||||
processPreload(tag, std::get<std::string>(value), nullptr);
|
||||
for (const auto& value : list) {
|
||||
switch (value.getType()) {
|
||||
case dv::value_type::string:
|
||||
processPreload(tag, value.asString(), nullptr);
|
||||
break;
|
||||
case dynamic::Type::map: {
|
||||
auto map = std::get<dynamic::Map_sptr>(value);
|
||||
auto name = map->get<std::string>("name");
|
||||
processPreload(tag, name, map.get());
|
||||
case dv::value_type::object:
|
||||
processPreload(tag, value["name"].asString(), value);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw std::runtime_error("invalid entry type");
|
||||
}
|
||||
@@ -176,12 +173,12 @@ void AssetsLoader::processPreloadList(AssetType tag, dynamic::List* list) {
|
||||
|
||||
void AssetsLoader::processPreloadConfig(const fs::path& file) {
|
||||
auto root = files::read_json(file);
|
||||
processPreloadList(AssetType::ATLAS, root->list("atlases").get());
|
||||
processPreloadList(AssetType::FONT, root->list("fonts").get());
|
||||
processPreloadList(AssetType::SHADER, root->list("shaders").get());
|
||||
processPreloadList(AssetType::TEXTURE, root->list("textures").get());
|
||||
processPreloadList(AssetType::SOUND, root->list("sounds").get());
|
||||
processPreloadList(AssetType::MODEL, root->list("models").get());
|
||||
processPreloadList(AssetType::ATLAS, root["atlases"]);
|
||||
processPreloadList(AssetType::FONT, root["fonts"]);
|
||||
processPreloadList(AssetType::SHADER, root["shaders"]);
|
||||
processPreloadList(AssetType::TEXTURE, root["textures"]);
|
||||
processPreloadList(AssetType::SOUND, root["sounds"]);
|
||||
processPreloadList(AssetType::MODEL, root["models"]);
|
||||
// layouts are loaded automatically
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,7 @@
|
||||
#include "interfaces/Task.hpp"
|
||||
#include "typedefs.hpp"
|
||||
#include "Assets.hpp"
|
||||
|
||||
namespace dynamic {
|
||||
class Map;
|
||||
class List;
|
||||
}
|
||||
#include "data/dv.hpp"
|
||||
|
||||
class ResPaths;
|
||||
class AssetsLoader;
|
||||
@@ -61,9 +57,9 @@ class AssetsLoader {
|
||||
void tryAddSound(const std::string& name);
|
||||
|
||||
void processPreload(
|
||||
AssetType tag, const std::string& name, dynamic::Map* map
|
||||
AssetType tag, const std::string& name, const dv::value& map
|
||||
);
|
||||
void processPreloadList(AssetType tag, dynamic::List* list);
|
||||
void processPreloadList(AssetType tag, const dv::value& list);
|
||||
void processPreloadConfig(const std::filesystem::path& file);
|
||||
void processPreloadConfigs(const Content* content);
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "coders/json.hpp"
|
||||
#include "coders/obj.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "data/dynamic.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "files/engine_paths.hpp"
|
||||
#include "files/files.hpp"
|
||||
@@ -220,17 +219,17 @@ static void read_anim_file(
|
||||
std::vector<std::pair<std::string, int>>& frameList
|
||||
) {
|
||||
auto root = files::read_json(animFile);
|
||||
auto frameArr = root->list("frames");
|
||||
float frameDuration = DEFAULT_FRAME_DURATION;
|
||||
std::string frameName;
|
||||
|
||||
if (frameArr) {
|
||||
for (size_t i = 0; i < frameArr->size(); i++) {
|
||||
auto currentFrame = frameArr->list(i);
|
||||
if (auto found = root.at("frames")) {
|
||||
auto& frameArr = *found;
|
||||
for (size_t i = 0; i < frameArr.size(); i++) {
|
||||
auto currentFrame = frameArr[i];
|
||||
|
||||
frameName = currentFrame->str(0);
|
||||
if (currentFrame->size() > 1) {
|
||||
frameDuration = currentFrame->integer(1);
|
||||
frameName = currentFrame[0].asString();
|
||||
if (currentFrame.size() > 1) {
|
||||
frameDuration = currentFrame[1].asNumber();
|
||||
}
|
||||
frameList.emplace_back(frameName, frameDuration);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user