#pragma once #include "uuid.h" #include "interfaces/IShader.hpp" #include #include #include #include #include "interfaces/IAsset.hpp" #include "json.hpp" namespace TSE { struct Material : public IAsset { private: string name; IShader* shader; std::unordered_map> values; public: Material(); Material(const string& name, IShader* shader); Material(const string& name, IShader* shader, uuids::uuid id); template void SetValue(const string& key, const T& value); template T GetValue(const string& key) const; template void SetValue(const string& key, const T* value); bool HasValue(const string& key) const; int GetValueCount() const; std::tuple& GetValueAt(int i); string& GetName(); IShader* GetShader() const; void SetShader(IShader* shader); uuids::uuid GetID() const; bool LoadAsset(string& path) override; void SaveAsset() override; nlohmann::ordered_json GenerateMaterialJson(); void Hash() override; string assetType() override; void UnloadAsset() override; protected: void SaveMeta() override; }; template void Material::SetValue(const string& key, const T& value) { values[key] = std::make_tuple(value, typeid(T).name(), key); } template T Material::GetValue(const string& key) const { auto it = values.find(key); if (it == values.end()) { throw std::runtime_error("Material::GetValue - key '" + key + "' not found"); } auto [a,b,c] = it->second; return std::any_cast(a); } template void Material::SetValue(const string& key, const T* value) { values[key] = std::make_tuple(value, typeid(T).name(), key); } } // namespace TSE