blob: f3317d5e1edcedaf5f38e0c57886116bc84d8b7c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#include "app.hpp"
#include "floormat/main.hpp"
#include "src/world.hpp"
#include "serialize/json-helper.hpp"
#include "serialize/tile-atlas.hpp"
#include "serialize/world.hpp"
#include <Corrade/Utility/Path.h>
namespace floormat {
#define FM_SAVE_BINARY
#ifdef FM_SAVE_BINARY
#define quicksave_file save_dir "/" "quicksave.dat"
#else
#define quicksave_file save_dir "/" "quicksave.json"
#endif
#define save_dir "../save"
#define quicksave_tmp quicksave_file ".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);
#if 0
#ifdef FM_SAVE_BINARY
json_helper::to_binary(world, quicksave_tmp);
#else
json_helper::to_json(world, quicksave_tmp);
#endif
#endif
Path::move(quicksave_tmp, quicksave_file);
fputs(" done\n", stderr); fflush(stderr);
}
void app::do_quickload()
{
ensure_save_directory();
if (!Path::exists(quicksave_file))
{
fm_warn("no quicksave");
return;
}
auto& world = M->world();
fputs("quickload...", stderr); fflush(stderr);
#if 0
#ifdef FM_SAVE_BINARY
world = json_helper::from_binary<struct world>(quicksave_file);
#else
world = json_helper::from_json<struct world>(quicksave_file);
#endif
#endif
fputs(" done\n", stderr); fflush(stderr);
}
} // namespace floormat
|