summaryrefslogtreecommitdiffhomepage
path: root/editor/save.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-28 22:47:20 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-28 22:47:20 +0200
commit9954b8b4f5fb95470e127a4f24a0c73289dd49a9 (patch)
treecf1586b0ebc57837714fc809d523e847f0e286db /editor/save.cpp
parent280b4c235fe11dd629f882f0fb5054384fcee1d7 (diff)
a
Diffstat (limited to 'editor/save.cpp')
-rw-r--r--editor/save.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/editor/save.cpp b/editor/save.cpp
new file mode 100644
index 00000000..6b6f5ce2
--- /dev/null
+++ b/editor/save.cpp
@@ -0,0 +1,54 @@
+#include "app.hpp"
+#include "floormat/main.hpp"
+#include "src/world.hpp"
+#include <Corrade/Utility/Path.h>
+
+namespace floormat {
+
+#define save_dir "../save"
+#define quicksave_file save_dir "/" "quicksave.dat"
+#define quicksave_tmp save_dir "/" "quicksave.tmp"
+
+namespace Path = Corrade::Utility::Path;
+using std::filesystem::path;
+
+static bool ensure_save_directory()
+{
+ if (Path::make(save_dir))
+ return true;
+ else
+ {
+ fm_warn("failed to create save directory '%s'", save_dir);
+ return false;
+ }
+}
+
+void app::do_quicksave()
+{
+ if (!ensure_save_directory())
+ return;
+ auto& world = M->world();
+ world.collect(true);
+ if (Path::exists(quicksave_tmp))
+ Path::remove(quicksave_tmp);
+ fputs("quicksave... ", stderr); fflush(stderr);
+ world.serialize(quicksave_tmp);
+ Path::move(quicksave_tmp, quicksave_file);
+ fputs("done\n", stderr); fflush(stderr);
+}
+
+void app::do_quickload()
+{
+ if (!ensure_save_directory())
+ return;
+ if (!Path::exists(quicksave_file))
+ {
+ fm_warn("no quicksave");
+ return;
+ }
+ fputs("quickload... ", stderr); fflush(stderr);
+ M->world() = world::deserialize(quicksave_file);
+ fputs("done\n", stderr); fflush(stderr);
+}
+
+} // namespace floormat