small change to json formatting of resourcepack

This commit is contained in:
Lendemor 2018-05-30 02:02:50 +02:00
parent f8ddb91c8a
commit 4b82c32cb3
2 changed files with 34 additions and 41 deletions

View File

@ -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<NewResourcePack>(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();
}

View File

@ -20,7 +20,7 @@ struct ResourceInterface
template<class Archive>
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<class Archive>
void serialize(Archive & archive){
archive(m_name,CEREAL_NVP(m_resources));
archive(cereal::make_nvp("ResourcePack",m_name),CEREAL_NVP(m_resources));
}
};
/*template<class Archive>
void serialize(Archive & archive, std::shared_ptr<NewResourcePack> respack)
{
archive(respack);
}*/
/*
* Some LoadTask implementations
*/
@ -75,11 +69,11 @@ public:
template <class Archive>
void serialize(Archive & archive)
{
archive(cereal::base_class<ResourceInterface>(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<class Archive>
void serialize(Archive & archive)
{
archive(cereal::base_class<ResourceInterface>(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