diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2018-06-30 08:09:00 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2018-06-30 08:33:23 +0200 |
commit | 27d0fe2f7d4c3d7b2a650f869a9a7d566c46b2d7 (patch) | |
tree | 5239fb9dab5d51bd6a2f5b019b5b0326c09e45c8 /src/AssetManager.hpp | |
parent | Replaced fallback model to diamond block model (diff) | |
download | AltCraft-27d0fe2f7d4c3d7b2a650f869a9a7d566c46b2d7.tar AltCraft-27d0fe2f7d4c3d7b2a650f869a9a7d566c46b2d7.tar.gz AltCraft-27d0fe2f7d4c3d7b2a650f869a9a7d566c46b2d7.tar.bz2 AltCraft-27d0fe2f7d4c3d7b2a650f869a9a7d566c46b2d7.tar.lz AltCraft-27d0fe2f7d4c3d7b2a650f869a9a7d566c46b2d7.tar.xz AltCraft-27d0fe2f7d4c3d7b2a650f869a9a7d566c46b2d7.tar.zst AltCraft-27d0fe2f7d4c3d7b2a650f869a9a7d566c46b2d7.zip |
Diffstat (limited to '')
-rw-r--r-- | src/AssetManager.hpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/AssetManager.hpp b/src/AssetManager.hpp index c386f7c..5273a2a 100644 --- a/src/AssetManager.hpp +++ b/src/AssetManager.hpp @@ -142,6 +142,17 @@ inline bool operator==(const BlockModel::ElementData::FaceData::Uv &lhs, return lhs.x1 == rhs.x1 && lhs.y1 == rhs.y1 && lhs.x2 == rhs.x2 && lhs.y2 == rhs.y2; } +struct Asset { + virtual ~Asset(); +}; + +struct AssetTreeNode { + std::vector<std::unique_ptr<AssetTreeNode>> childs; + std::string name; + AssetTreeNode *parent; + std::unique_ptr<Asset> asset; +}; + class AssetManager { Texture *textureAtlas; std::map<std::string, BlockId> assetIds; @@ -149,6 +160,7 @@ class AssetManager { std::map<BlockTextureId,glm::vec4> textureAtlasIndexes; std::map<std::string, BlockModel> models; std::map<BlockId, std::string> blockIdToBlockName; + std::unique_ptr<AssetTreeNode> assetTree; public: AssetManager(); @@ -177,4 +189,27 @@ public: std::string GetAssetNameByBlockId(BlockId block); void ParseBlockModels(); + + void LoadAssets(); + + template <typename T> + T *GetAsset(const std::string &assetName) { + AssetTreeNode *node = assetTree.get(); + unsigned int pos = 1; + unsigned int prevPos = 1; + size_t x = assetName.size(); + while (pos < assetName.size()) { + for (; assetName[pos] != '/' && pos < assetName.size(); pos++); + std::string dirName = assetName.substr(prevPos, pos - prevPos); + for (const auto &asset : node->childs) { + if (asset->name == dirName) { + node = asset.get(); + break; + } + } + pos++; + prevPos = pos; + } + return dynamic_cast<T*>(node->asset.get()); + } }; |