From 8ac4fe6d5ba5091923c7fdf1fa88724d827706fa Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Fri, 26 May 2017 19:11:17 +0500 Subject: 2017-05-26 --- src/core/AssetManager.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/core/AssetManager.cpp (limited to 'src/core/AssetManager.cpp') diff --git a/src/core/AssetManager.cpp b/src/core/AssetManager.cpp new file mode 100644 index 0000000..9913c18 --- /dev/null +++ b/src/core/AssetManager.cpp @@ -0,0 +1,70 @@ +#include +#include +#include "AssetManager.hpp" + +namespace fs = std::experimental::filesystem; + +const fs::path pathToAssets = "./assets/"; +const fs::path pathToAssetsList = "./items.json"; +const fs::path pathToTextureIndex = "./textures.json"; + +AssetManager::AssetManager() { + for (auto &it:fs::recursive_directory_iterator(pathToAssets)) { + + } + LoadIds(); + LoadTextureResources(); +} + +void AssetManager::LoadIds() { + std::ifstream in(pathToAssetsList); + nlohmann::json index; + in >> index; + for (auto &it:index) { + int id = it["type"].get(); + int state = it["meta"].get(); + std::string blockName = it["text_type"].get(); + assetIds[blockName] = Block(id, state, 0); + } + LOG(INFO) << "Loaded " << assetIds.size() << " ids"; +} + +AssetManager::~AssetManager() { + delete textureAtlas; +} + +//TODO: This function must be replaced with runtime texture atlas generating +void AssetManager::LoadTextureResources() { + std::ifstream in(pathToTextureIndex); + nlohmann::json index; + in >> index; + std::string filename = index["meta"]["image"].get(); + for (auto &it:index["frames"]) { + auto frame = it["frame"]; + TextureCoord coord; + coord.x = frame["x"].get(); + coord.y = frame["y"].get(); + coord.w = frame["w"].get(); + coord.h = frame["h"].get(); + std::string assetName = it["filename"].get(); + assetName.insert(0,"minecraft/textures/"); + assetName.erase(assetName.length()-4); + LOG(ERROR)<texture; +} + +TextureCoord AssetManager::GetTextureByAssetName(std::string AssetName) { + return TextureCoord{0, 0, 0, 0}; +} + +std::string AssetManager::GetTextureAssetNameByBlockId(unsigned short BlockId, unsigned char BlockSide) { + +} + +const GLuint AssetManager::GetTextureAtlas() { + return textureAtlas->texture; +} -- cgit v1.2.3