Can load files from previous versions

This commit is contained in:
Yousef Khadadeh 2026-01-02 09:22:52 +03:00
parent b5877ff3ca
commit eb12cdfa7c
5 changed files with 75 additions and 25 deletions

View file

@ -4,6 +4,7 @@
#include "BookmarkListItem.hpp"
#include "Helpers/NetworkingObjects/NetObjOrderedList.hpp"
#include "Helpers/NetworkingObjects/NetObjTemporaryPtr.decl.hpp"
#include <cereal/types/unordered_map.hpp>
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<BookmarkListItem>(new BookmarkListItem());
bookmarkListRoot->load_file(a, version, *this);
if(version >= VersionNumber(0, 4, 0)) {
bookmarkListRoot = world.netObjMan.make_obj_from_ptr<BookmarkListItem>(new BookmarkListItem());
bookmarkListRoot->load_file(a, version, *this);
}
else {
server_init_no_file();
std::unordered_map<std::string, BookmarkData> bookmarkMap;
std::vector<std::pair<std::string, BookmarkData>> 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));
}
}

View file

@ -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<CanvasComponentAllocator>();
compAllocator->load_file(a, version);
compAllocator->comp->compContainer = this;
if(version >= VersionNumber(0, 4, 0)) {
a(coords);
compAllocator = objMan.make_obj_direct<CanvasComponentAllocator>();
compAllocator->load_file(a, version);
compAllocator->comp->compContainer = this;
}
else {
CanvasComponentType t;
NetworkingObjects::NetObjID uselessID;
a(t, uselessID, coords);
compAllocator = objMan.make_obj_direct<CanvasComponentAllocator>(t);
compAllocator->comp->load_file(a, version);
compAllocator->comp->compContainer = this;
}
}
void CanvasComponentContainer::draw(SkCanvas* canvas, const DrawData& drawData) const {

View file

@ -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<ColorTextStyleModifier>(textColor));
textBox->set_text_style_modifier_between({0, 0}, textBox->move(RichText::TextBox::Movement::END, {0, 0}), std::make_shared<SizeTextStyleModifier>(textSize));
}
else {
TextData richText;
a(d.p1, d.p2, richText);
textBox->set_rich_text_data(richText);
}
}
std::unique_ptr<CanvasComponent> TextBoxCanvasComponent::get_data_copy() const {

View file

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

View file

@ -1,6 +1,7 @@
#include "GridManager.hpp"
#include "World.hpp"
#include "MainProgram.hpp"
#include <cereal/types/unordered_map.hpp>
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<NetworkingObjects::NetObjOrderedList<WorldGrid>>();
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<NetworkingObjects::NetObjID, WorldGrid> gridMap;
a(gridMap);
for(auto& [netID, wGrid] : gridMap)
grids->emplace_back_direct(grids, wGrid);
}
}