TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ Serialize()

nlohmann::json Serializer::Serialize ( )

Definition at line 83 of file Serializer.cpp.

84{
86 data = nlohmann::json();
87 data["type"] = "SAVEFILE";
88 data["serailizerVersion"] = TERR3D_SERIALIZER_VERSION;
89 data["maxSerailizerVersion"] = TERR3D_MAX_SERIALIZER_VERSION;
90 data["minSerailizerVersion"] = TERR3D_MIN_SERIALIZER_VERSION;
91 data["versionHash"] = MD5File(GetExecutablePath()).ToString();
92 data["name"] = "TerraForge3D v2.2.0";
93 data["mode"] = appState->mode;
94 // SAVE NODE GENERATORS DATA
95 TRY_CATCH_ERR_SERIALIZE(data["appData"] = appState->globals.appData;, "Failed to save App Data");
96 TRY_CATCH_ERR_SERIALIZE(data["appStyles"] = GetStyleData();, "Failed to save app styles");
97 TRY_CATCH_ERR_SERIALIZE(data["imguiData"] = std::string(ImGui::SaveIniSettingsToMemory());, "Failed to save ImGui Data.");
98 TRY_CATCH_ERR_SERIALIZE(data["camera"] = appState->cameras.Save();, "Failed to save cameras.");
99 TRY_CATCH_ERR_SERIALIZE(data["windows"] = appState->windows.Save();, "Failed to save window states");
100 TRY_CATCH_ERR_SERIALIZE(data["states"] = appState->states.Save();, "Failed to save states.");
101 TRY_CATCH_ERR_SERIALIZE(data["globals"] = appState->globals.Save();, "Failed to save globals.");
102 TRY_CATCH_ERR_SERIALIZE(data["sea"] = appState->seaManager->Save();, "Failed to save Sea.");
103 TRY_CATCH_ERR_SERIALIZE(data["foliage"] = appState->foliageManager->Save();, "Failed to save foliage manager.");
104 TRY_CATCH_ERR_SERIALIZE(data["projectID"] = appState->projectManager->GetId();, "Failed to save project id.");
105 TRY_CATCH_ERR_SERIALIZE(data["textureBaker"] = appState->textureBaker->Save();, "Failed to save texture baker settings.");
106 TRY_CATCH_ERR_SERIALIZE(appState->projectManager->SaveDatabase(); data["projectDatabase"] = appState->projectManager->GetDatabase();, "Failed to save project database.");
107 TRY_CATCH_ERR_SERIALIZE(data["lighting"] = appState->lightManager->Save();, "Failed to save lighting data.");
108 TRY_CATCH_ERR_SERIALIZE(data["shading"] = appState->shadingManager->Save();, "Failed to save shading data.");
109 TRY_CATCH_ERR_SERIALIZE(data["generators"] = appState->meshGenerator->Save();, "Failed to save generators.");
110 TRY_CATCH_ERR_SERIALIZE(
111
112 if (!appState->mode == ApplicationMode::CUSTOM_BASE)
113{
114 std::string baseHash = MD5File(appState->globals.currentBaseModelPath)
115 .ToString();
116 std::string projectAsset = appState->projectManager->GetAsset(baseHash);
117
118 if (projectAsset == "")
119 {
120 MkDir(appState->projectManager->GetResourcePath() + PATH_SEPARATOR "models");
121 CopyFileData(appState->globals.currentBaseModelPath, appState->projectManager->GetResourcePath() + PATH_SEPARATOR "models" PATH_SEPARATOR + baseHash + appState->globals.currentBaseModelPath.substr(appState->globals.currentBaseModelPath.find_last_of(".")));
122 appState->projectManager->RegisterAsset(baseHash, "models" PATH_SEPARATOR + baseHash + appState->globals.currentBaseModelPath.substr(appState->globals.currentBaseModelPath.find_last_of(".")));
123 }
124
125 data["baseid"] = baseHash;
126 }
127 , "Failed to save custom base model."
128 );
129 return data;
130}
a class to store JSON values
Definition: json.hpp:17860
basic_json<> json
default JSON class
Definition: json.hpp:3411