#include "editor-io.hpp" #include "game-settings.hpp" #include "serialization.hpp" #include void pke_editor_scene_save(const char *file_path) { srlztn_serialize_helper *helper = pke_serialize_init(pkeSettings.mem_bkt.game_transient); bool failed = false; std::ostringstream o; try { pke_serialize_scene(helper); pke_serialize_scene_to_stream(o, helper); } catch (std::exception &e) { fprintf(stderr, "[%s][Game_SaveSceneFile] Failed to serialize scene file: %s\n", __FILE__, e.what()); failed = false; } catch (...) { fprintf(stderr, "[%s][Game_SaveSceneFile] Failed to serialize scene file, uncaught exception.\n", __FILE__); failed = false; } if (failed == false) { std::ofstream f(file_path); if (!f.is_open()) { failed = true; } else { f << o.str(); } f.flush(); f.close(); } if (failed) { NULL_CHAR_ARR(errFileName, 256); strncpy(errFileName, file_path, 256); strncpy(errFileName + strlen(file_path), ".err", 256 - strlen(file_path)); std::ofstream errF(file_path); if (errF.is_open()) { errF << o.str(); errF.flush(); errF.close(); fprintf(stderr, "Failed to save scene file '%s', partial output saved to '%s'\n", file_path, errFileName); } else { fprintf(stderr, "Failed to save scene file '%s' and also failed to write failed output\n", file_path); } } pke_serialize_teardown(helper); } void pke_editor_scene_load(pke_level *level, const char *file_path) { std::ifstream f(file_path); if (!f.is_open()) { fprintf(stderr, "Failed to load requested scene file: '%s'\n", file_path); return; } srlztn_deserialize_helper *helper = pke_deserialize_init(level, pkeSettings.mem_bkt.game_transient); pke_deserialize_scene_from_stream(f, helper); pke_deserialize_scene(helper); pke_deserialize_teardown(helper); f.close(); } void pke_editor_project_save(const char *file_path) { (void)file_path; } void pke_editor_project_load(const char *file_path) { (void)file_path; }