@@ -59,26 +59,37 @@ void ProjectSerializer::serialize() {
5959 LOG_SUCCESS (" file::ProjectSerializer" , " Project [w]$0[] was saved" , _project->getName ());
6060}
6161
62- void ProjectSerializer::deserialize () {
63- Section section (" Section" );
62+ bool ProjectSerializer::deserialize () {
6463 fs::path attaFile = _project->getFile ();
64+ Serializer serializer;
65+ serializer.deserialize (attaFile);
6566
66- std::ifstream is (attaFile, std::ifstream::in | std::ifstream::binary);
67-
68- // Deserialize version
69- // std::string version;
70- // read(is, version);
71- // section.deserialize(is);
72- // is.close();
73-
74- // Deserialize data
75- // deserializeHeader(section["header"]);
76- // deserializeConfig(section["config"]);
77- // deserializeComponentModule(section["componentModule"]);
78- // deserializeGraphicsModule(section["graphicsModule"]);
79- // deserializeResourceModule(section["resourceModule"]);
80- // deserializePhysicsModule(section["physicsModule"]);
81- // deserializeSensorModule(section["sensorModule"]);
67+ // Make sure atta versions match
68+ bool canLoadProject = false ;
69+ for (const Section& section : serializer.getSections ()) {
70+ if (section.getName () == " project" ) {
71+ canLoadProject = deserializeProject (section);
72+ break ;
73+ }
74+ }
75+ if (!canLoadProject)
76+ return false ;
77+
78+ for (const Section& section : serializer.getSections ()) {
79+ if (section.getName () == " config" )
80+ deserializeConfig (section);
81+ else if (section.getName () == " graphics" )
82+ deserializeGraphicsModule (section);
83+ else if (section.getName () == " physics" )
84+ deserializePhysicsModule (section);
85+ else if (section.getName () == " sensor" )
86+ deserializeSensorModule (section);
87+ else if (section.getName () == " material" )
88+ deserializeMaterial (section);
89+ else if (section.getName () == " node" )
90+ deserializeNode (section);
91+ }
92+ return true ;
8293}
8394
8495Section ProjectSerializer::serializeProject () {
@@ -290,12 +301,74 @@ std::vector<Section> ProjectSerializer::serializeNodes() {
290301 return sections;
291302}
292303
293- void ProjectSerializer::deserializeProject (Section& section) {}
294- void ProjectSerializer::deserializeConfig (Section& section) {}
295- void ProjectSerializer::deserializeGraphicsModule (Section& section) {}
296- void ProjectSerializer::deserializeResourceModule (Section& section) {}
297- void ProjectSerializer::deserializePhysicsModule (Section& section) {}
298- void ProjectSerializer::deserializeSensorModule (Section& section) {}
299- void ProjectSerializer::deserializeNode (Section& section) {}
304+ bool ProjectSerializer::deserializeProject (const Section& section) {
305+ if (!section.contains (" attaVersion" )) {
306+ LOG_WARN (" file::ProjectSerializer" , " Project [w]$0[] does not have an atta version. The project will not be loaded" , _project->getName ());
307+ return false ;
308+ }
309+ std::string projectAttaVersion = std::string (section[" attaVersion" ]);
310+ if (projectAttaVersion != ATTA_VERSION) {
311+ LOG_WARN (
312+ " file::ProjectSerializer" ,
313+ " Project [w]$0[] was created with atta version [w]$1[], which does not match this atta version [w]$2[]. The project will not be loaded" ,
314+ _project->getName (), projectAttaVersion, ATTA_VERSION);
315+ return false ;
316+ }
317+
318+ // Load project name
319+ if (section.contains (" name" ))
320+ _project->_name = std::string (section[" name" ]);
321+ return true ;
322+ }
323+
324+ void ProjectSerializer::deserializeConfig (const Section& section) {
325+ if (section.contains (" dt" ))
326+ Config::setDt (float (section[" dt" ]));
327+ if (section.contains (" desiredStepSpeed" ))
328+ Config::setDesiredStepSpeed (float (section[" desiredStepSpeed" ]));
329+ }
330+
331+ void ProjectSerializer::deserializeGraphicsModule (const Section& section) {
332+ if (section.contains (" graphicsFPS" ))
333+ gfx::setGraphicsFPS (float (section[" graphicsFPS" ]));
334+ if (section.contains (" viewportRendering" ))
335+ ui::setViewportRendering (bool (section[" viewportRendering" ]));
336+ }
337+
338+ void ProjectSerializer::deserializePhysicsModule (const Section& section) {}
339+
340+ void ProjectSerializer::deserializeSensorModule (const Section& section) {}
341+
342+ void ProjectSerializer::deserializeMaterial (const Section& section) {
343+ res::Material::CreateInfo material{};
344+ if (!section.contains (" id" )) {
345+ LOG_WARN (" file::ProjectSerializer" , " Material section does not have an id. The material will not be loaded" );
346+ return ;
347+ }
348+ std::string id = std::string (section[" id" ]);
349+
350+ if (section.contains (" color" ))
351+ material.color = vec3f (section[" color" ]);
352+ if (section.contains (" colorImage" ))
353+ material.colorImage = StringId (std::string (section[" colorImage" ]));
354+ if (section.contains (" metallic" ))
355+ material.metallic = float (section[" metallic" ]);
356+ if (section.contains (" metallicImage" ))
357+ material.metallicImage = StringId (std::string (section[" metallicImage" ]));
358+ if (section.contains (" roughness" ))
359+ material.roughness = float (section[" roughness" ]);
360+ if (section.contains (" roughnessImage" ))
361+ material.roughnessImage = StringId (std::string (section[" roughnessImage" ]));
362+ if (section.contains (" ao" ))
363+ material.ao = float (section[" ao" ]);
364+ if (section.contains (" aoImage" ))
365+ material.aoImage = StringId (std::string (section[" aoImage" ]));
366+ if (section.contains (" normalImage" ))
367+ material.normalImage = StringId (std::string (section[" normalImage" ]));
368+
369+ res::create<res::Material>(id, material);
370+ }
371+
372+ void ProjectSerializer::deserializeNode (const Section& section) {}
300373
301374} // namespace atta::file
0 commit comments