Reimplementing save/load file

This commit is contained in:
Yousef Khadadeh 2026-01-01 22:46:02 +03:00
parent 260288a1b0
commit 9913eb6c8e
37 changed files with 437 additions and 350 deletions

View file

@ -2,6 +2,8 @@
#include <cereal/types/string.hpp>
#include "../World.hpp"
#include "../ScaleUpCanvas.hpp"
#include "BookmarkManager.hpp"
#include "../World.hpp"
using namespace NetworkingObjects;
@ -104,3 +106,38 @@ void BookmarkListItem::write_constructor_data(const NetObjTemporaryPtr<BookmarkL
a(*o->bookmarkData);
o->nameData.write_create_message(a);
}
void BookmarkListItem::save_file(cereal::PortableBinaryOutputArchive& a) const {
a(*nameData);
a(static_cast<bool>(folderData));
if(folderData) {
a(folderData->folderList->size());
for(auto& item : *folderData->folderList)
item.obj->save_file(a);
}
else
a(*bookmarkData);
}
void BookmarkListItem::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version, BookmarkManager& bMan) {
nameData = bMan.world.netObjMan.make_obj<NameData>();
a(*nameData);
bool isFolder;
a(isFolder);
if(isFolder) {
folderData = std::make_unique<BookmarkFolderData>();
folderData->folderList = bMan.world.netObjMan.make_obj<NetworkingObjects::NetObjOrderedList<BookmarkListItem>>();
uint32_t folderSize;
a(folderSize);
for(uint32_t i = 0; i < folderSize; i++) {
BookmarkListItem* item = new BookmarkListItem;
item->load_file(a, version, bMan);
folderData->folderList->push_back_and_send_create(folderData->folderList, item);
}
}
else {
bookmarkData = std::make_unique<BookmarkData>();
a(*bookmarkData);
}
}

View file

@ -4,6 +4,9 @@
#include <Helpers/NetworkingObjects/DelayUpdateSerializedClassManager.hpp>
#include <string>
#include "../CoordSpaceHelper.hpp"
#include <Helpers/VersionNumber.hpp>
class BookmarkManager;
struct BookmarkData {
CoordSpaceHelper coords;
@ -27,7 +30,9 @@ class BookmarkListItem {
static void register_class(World& w);
void reassign_netobj_ids_call();
void scale_up(const WorldScalar& scaleUpAmount);
void save_file(cereal::PortableBinaryOutputArchive& a) const;
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version, BookmarkManager& bMan);
void set_name(NetworkingObjects::DelayUpdateSerializedClassManager& delayedNetObjMan, const std::string& newName);
private:
struct BookmarkFolderData {

View file

@ -9,12 +9,8 @@ BookmarkManager::BookmarkManager(World& w):
world(w)
{}
void BookmarkManager::init() {
// NOTE: Should find a way for bookmarks added from the network to take into account the client's canvasScale
// Have the canvasScale variable come with the ClientData object, and the grid scale commands can be part of
// the client data class
if(world.netObjMan.is_server())
bookmarkListRoot = world.netObjMan.make_obj_from_ptr<BookmarkListItem>(new BookmarkListItem(world.netObjMan, "ROOT", true, {}));
void BookmarkManager::server_init_no_file() {
bookmarkListRoot = world.netObjMan.make_obj_from_ptr<BookmarkListItem>(new BookmarkListItem(world.netObjMan, "ROOT", true, {}));
}
void BookmarkManager::refresh_gui_data() {
@ -200,3 +196,13 @@ NetworkingObjects::NetObjOrderedListIterator<BookmarkListItem> BookmarkManager::
void BookmarkManager::scale_up(const WorldScalar& scaleUpAmount) {
bookmarkListRoot->scale_up(scaleUpAmount);
}
void BookmarkManager::save_file(cereal::PortableBinaryOutputArchive& a) const {
bookmarkListRoot->save_file(a);
}
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);
}

View file

@ -4,22 +4,19 @@
#include <Helpers/NetworkingObjects/NetObjOrderedList.hpp>
#include "../GUIStuff/Elements/TreeListing.hpp"
#include "BookmarkListItem.hpp"
#include <Helpers/VersionNumber.hpp>
class World;
class BookmarkManager {
public:
BookmarkManager(World& w);
void init();
void server_init_no_file();
void scale_up(const WorldScalar& scaleUpAmount);
void setup_list_gui(const std::string& id);
void refresh_gui_data();
template <typename Archive> void save(Archive& a) const {
}
template <typename Archive> void load(Archive& a) {
}
void save_file(cereal::PortableBinaryOutputArchive& a) const;
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version);
NetworkingObjects::NetObjOwnerPtr<BookmarkListItem> bookmarkListRoot;
private:
@ -30,5 +27,7 @@ class BookmarkManager {
std::string nameToEdit;
std::string nameForNew;
friend class BookmarkListItem;
World& world;
};