diff --git a/src/Bookmarks/BookmarkManager.cpp b/src/Bookmarks/BookmarkManager.cpp index d51e4bc..96b27e0 100644 --- a/src/Bookmarks/BookmarkManager.cpp +++ b/src/Bookmarks/BookmarkManager.cpp @@ -4,6 +4,7 @@ #include "BookmarkListItem.hpp" #include "Helpers/NetworkingObjects/NetObjOrderedList.hpp" #include "Helpers/NetworkingObjects/NetObjTemporaryPtr.decl.hpp" +#include BookmarkManager::BookmarkManager(World& w): world(w) @@ -202,7 +203,21 @@ void BookmarkManager::save_file(cereal::PortableBinaryOutputArchive& a) const { } void BookmarkManager::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version) { - bookmarkListRoot = world.netObjMan.make_obj_from_ptr(new BookmarkListItem()); - - bookmarkListRoot->load_file(a, version, *this); + if(version >= VersionNumber(0, 4, 0)) { + bookmarkListRoot = world.netObjMan.make_obj_from_ptr(new BookmarkListItem()); + bookmarkListRoot->load_file(a, version, *this); + } + else { + server_init_no_file(); + std::unordered_map bookmarkMap; + std::vector> bookmarkDataSorted; + a(bookmarkMap); + for(auto& [name, bData] : bookmarkMap) + bookmarkDataSorted.emplace_back(name, bData); + std::sort(bookmarkDataSorted.begin(), bookmarkDataSorted.end(), [](auto& aPair, auto& bPair) { + return aPair.first < bPair.first; + }); + for(auto& [name, bData] : bookmarkDataSorted) + bookmarkListRoot->get_folder_list()->push_back_and_send_create(bookmarkListRoot->get_folder_list(), new BookmarkListItem(world.netObjMan, name, false, bData)); + } } diff --git a/src/CanvasComponents/CanvasComponentContainer.cpp b/src/CanvasComponents/CanvasComponentContainer.cpp index 8fb4955..beb579b 100644 --- a/src/CanvasComponents/CanvasComponentContainer.cpp +++ b/src/CanvasComponents/CanvasComponentContainer.cpp @@ -63,10 +63,20 @@ void CanvasComponentContainer::save_file(cereal::PortableBinaryOutputArchive& a) } void CanvasComponentContainer::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version, NetObjManager& objMan) { - a(coords); - compAllocator = objMan.make_obj_direct(); - compAllocator->load_file(a, version); - compAllocator->comp->compContainer = this; + if(version >= VersionNumber(0, 4, 0)) { + a(coords); + compAllocator = objMan.make_obj_direct(); + compAllocator->load_file(a, version); + compAllocator->comp->compContainer = this; + } + else { + CanvasComponentType t; + NetworkingObjects::NetObjID uselessID; + a(t, uselessID, coords); + compAllocator = objMan.make_obj_direct(t); + compAllocator->comp->load_file(a, version); + compAllocator->comp->compContainer = this; + } } void CanvasComponentContainer::draw(SkCanvas* canvas, const DrawData& drawData) const { diff --git a/src/CanvasComponents/TextBoxCanvasComponent.cpp b/src/CanvasComponents/TextBoxCanvasComponent.cpp index af75640..785bd85 100644 --- a/src/CanvasComponents/TextBoxCanvasComponent.cpp +++ b/src/CanvasComponents/TextBoxCanvasComponent.cpp @@ -40,7 +40,12 @@ void TextBoxCanvasComponent::save_file(cereal::PortableBinaryOutputArchive& a) c } void TextBoxCanvasComponent::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version) { - if(version < VersionNumber(0, 3, 0)) { + if(version >= VersionNumber(0, 3, 0)) { + TextData richText; + a(d.p1, d.p2, richText); + textBox->set_rich_text_data(richText); + } + else { bool loadedEditing; // Unused Vector4f textColor; float textSize; @@ -51,11 +56,6 @@ void TextBoxCanvasComponent::load_file(cereal::PortableBinaryInputArchive& a, Ve textBox->set_text_style_modifier_between({0, 0}, textBox->move(RichText::TextBox::Movement::END, {0, 0}), std::make_shared(textColor)); textBox->set_text_style_modifier_between({0, 0}, textBox->move(RichText::TextBox::Movement::END, {0, 0}), std::make_shared(textSize)); } - else { - TextData richText; - a(d.p1, d.p2, richText); - textBox->set_rich_text_data(richText); - } } std::unique_ptr TextBoxCanvasComponent::get_data_copy() const { diff --git a/src/DrawingProgram/Layers/DrawingProgramLayerManager.cpp b/src/DrawingProgram/Layers/DrawingProgramLayerManager.cpp index cf119cd..62a8480 100644 --- a/src/DrawingProgram/Layers/DrawingProgramLayerManager.cpp +++ b/src/DrawingProgram/Layers/DrawingProgramLayerManager.cpp @@ -2,6 +2,9 @@ #include "../../World.hpp" #include "Helpers/NetworkingObjects/NetObjOrderedList.hpp" #include "Helpers/Parallel.hpp" +#include "../../CanvasComponents/CanvasComponentContainer.hpp" +#include "../../CanvasComponents/CanvasComponentAllocator.hpp" +#include "../../CanvasComponents/CanvasComponent.hpp" DrawingProgramLayerManager::DrawingProgramLayerManager(DrawingProgram& drawProg): drawP(drawProg), // initialize drawP first for next objects to be initialized properly @@ -104,11 +107,25 @@ CanvasComponentContainer::ObjInfo* DrawingProgramLayerManager::add_component_to_ void DrawingProgramLayerManager::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version) { - layerTreeRoot = drawP.world.netObjMan.make_obj_from_ptr(new DrawingProgramLayerListItem()); - layerTreeRoot->load_file(a, version, *this); - commitUpdateOnComponentInsert = false; - layerTreeRoot->get_folder().set_component_list_callbacks(*this); // Only need to call set_component_list_callbacks on root, and the rest will get the callbacks set as well - commitUpdateOnComponentInsert = true; + if(version >= VersionNumber(0, 4, 0)) { + layerTreeRoot = drawP.world.netObjMan.make_obj_from_ptr(new DrawingProgramLayerListItem()); + layerTreeRoot->load_file(a, version, *this); + commitUpdateOnComponentInsert = false; + layerTreeRoot->get_folder().set_component_list_callbacks(*this); // Only need to call set_component_list_callbacks on root, and the rest will get the callbacks set as well + commitUpdateOnComponentInsert = true; + } + else { + server_init_no_file(); + auto editingLayerTmpPtr = editingLayer.lock(); + uint64_t compCount; + a(compCount); + for(uint64_t i = 0; i < compCount; i++) { + CanvasComponentContainer* newContainer = new CanvasComponentContainer(); + newContainer->load_file(a, version, drawP.world.netObjMan); + editingLayerTmpPtr->get_layer().components->push_back_and_send_create(editingLayerTmpPtr->get_layer().components, newContainer); + } + } + auto flattenedCompList = get_flattened_component_list(); parallel_loop_container(flattenedCompList, [&drawP = drawP](CanvasComponentContainer::ObjInfo* comp) { comp->obj->commit_update_dont_invalidate_cache(drawP); diff --git a/src/GridManager.cpp b/src/GridManager.cpp index 03b5f25..b7da80f 100644 --- a/src/GridManager.cpp +++ b/src/GridManager.cpp @@ -1,6 +1,7 @@ #include "GridManager.hpp" #include "World.hpp" #include "MainProgram.hpp" +#include GridManager::GridManager(World& w): world(w) {} @@ -79,12 +80,19 @@ void GridManager::save_file(cereal::PortableBinaryOutputArchive& a) const { void GridManager::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version) { grids = world.netObjMan.make_obj>(); - - uint32_t gridSize; - a(gridSize); - for(uint32_t i = 0; i < gridSize; i++) { - WorldGrid* g = new WorldGrid; - a(*g); - grids->push_back_and_send_create(grids, g); + if(version >= VersionNumber(0, 4, 0)) { + uint32_t gridSize; + a(gridSize); + for(uint32_t i = 0; i < gridSize; i++) { + WorldGrid* g = new WorldGrid; + a(*g); + grids->push_back_and_send_create(grids, g); + } + } + else if(version >= VersionNumber(0, 2, 0)) { + std::unordered_map gridMap; + a(gridMap); + for(auto& [netID, wGrid] : gridMap) + grids->emplace_back_direct(grids, wGrid); } }