diff --git a/src/tools/newresourcepack.cpp b/src/tools/newresourcepack.cpp index 8296660..e98bfd9 100644 --- a/src/tools/newresourcepack.cpp +++ b/src/tools/newresourcepack.cpp @@ -26,18 +26,16 @@ void NewResourcePack::gui() if(ImGui::Button("Save resource pack")) { - // std::fstream file; - // ObjectSaver saver; - // saver.addObject(this); - // file.open("data/" + m_name + ".pack", std::ios_base::out); - // saver.saveAscii(file); - //file.close(); - - std::ofstream outputStream("data/"+m_name+".pack"); - cereal::JSONOutputArchive output(outputStream); - output(std::shared_ptr(this)); - outputStream.close(); - + try{ + std::ofstream outputStream("data/"+m_name+".pack"); + cereal::JSONOutputArchive output(outputStream); + NewResourcePack tmp; + tmp.m_name = this->m_name; + tmp.m_resources = this->m_resources; + output(tmp); + }catch(cereal::Exception e){ + std::cerr << "WUT : " << e.what() << std::endl; + } } if(ImGui::Button("Load resource pack")) { @@ -55,9 +53,9 @@ void NewResourcePack::gui() std::ifstream inputStream("data/"+m_name+".pack"); cereal::JSONInputArchive input(inputStream); NewResourcePack tmp = NewResourcePack(); - tmp.m_name = this->m_name; - tmp.m_resources = this->m_resources; input(tmp); + this->m_name = tmp.m_name; + this->m_resources = tmp.m_resources; inputStream.close(); } diff --git a/src/tools/newresourcepack.h b/src/tools/newresourcepack.h index 8020367..2c57282 100644 --- a/src/tools/newresourcepack.h +++ b/src/tools/newresourcepack.h @@ -20,7 +20,7 @@ struct ResourceInterface template void serialize(Archive & archive){ - archive(m_name); + archive(CEREAL_NVP(m_name)); } virtual void loadResource(float & progress) = 0; @@ -44,16 +44,10 @@ struct NewResourcePack template void serialize(Archive & archive){ - archive(m_name,CEREAL_NVP(m_resources)); + archive(cereal::make_nvp("ResourcePack",m_name),CEREAL_NVP(m_resources)); } }; -/*template -void serialize(Archive & archive, std::shared_ptr respack) -{ - archive(respack); -}*/ - /* * Some LoadTask implementations */ @@ -75,11 +69,11 @@ public: template void serialize(Archive & archive) { - archive(cereal::base_class(this), - m_path, - m_bitsPerPixel, - m_isVerticallyReversed, - m_needsMipMaps); + archive(CEREAL_NVP(m_name), + CEREAL_NVP(m_path), + CEREAL_NVP(m_bitsPerPixel), + CEREAL_NVP(m_isVerticallyReversed), + CEREAL_NVP(m_needsMipMaps)); } void loadResource(float & progress); @@ -111,18 +105,18 @@ public: template void serialize(Archive & archive) { - archive(cereal::base_class(this), - m_albedo, - m_metallic, - m_roughness, - m_emission, - m_opacity, - m_albedoTexture, - m_metallicTexture, - m_roughnessTexture, - m_emissionTexture, - m_normalTexture, - m_alphaMaskTexture); + archive(CEREAL_NVP(m_name), + CEREAL_NVP(m_albedo), + CEREAL_NVP(m_metallic), + CEREAL_NVP(m_roughness), + CEREAL_NVP(m_emission), + CEREAL_NVP(m_opacity), + CEREAL_NVP(m_albedoTexture), + CEREAL_NVP(m_metallicTexture), + CEREAL_NVP(m_roughnessTexture), + CEREAL_NVP(m_emissionTexture), + CEREAL_NVP(m_normalTexture), + CEREAL_NVP(m_alphaMaskTexture)); } void loadResource(float & progress); @@ -132,8 +126,9 @@ public: void gui(); }; -//CEREAL_REGISTER_TYPE(TextureResource) +CEREAL_REGISTER_TYPE(TextureResource) +CEREAL_REGISTER_POLYMORPHIC_RELATION(ResourceInterface,TextureResource) //CEREAL_REGISTER_TYPE(MaterialResource) - +//CEREAL_REGISTER_POLYMORPHIC_RELATION(ResourceInterface,MaterialResource) #endif // NEWRESOURCEPACK_H