mapstream:: export saveMap, loadMap, and a hook for special saving/loading

This commit is contained in:
Zeno Rogue 2020-09-21 12:02:07 +02:00
parent 3e66b520ba
commit 9f1762f0c1
1 changed files with 12 additions and 5 deletions

View File

@ -375,14 +375,15 @@ EX }
#if HDR #if HDR
struct hstream; struct hstream;
struct fhstream;
#endif #endif
EX namespace mapstream { EX namespace mapstream {
#if CAP_EDIT #if CAP_EDIT
std::map<cell*, int> cellids; EX std::map<cell*, int> cellids;
vector<cell*> cellbyid; EX vector<cell*> cellbyid;
vector<char> relspin; EX vector<char> relspin;
void load_drawing_tool(fhstream& hs) { void load_drawing_tool(fhstream& hs) {
using namespace mapeditor; using namespace mapeditor;
@ -605,6 +606,8 @@ EX namespace mapstream {
if(vernum >= 0xA810) if(vernum >= 0xA810)
f.read(mine_adjacency_rule); f.read(mine_adjacency_rule);
} }
EX hookset<void(fhstream&)> hooks_savemap, hooks_loadmap;
#if CAP_EDIT #if CAP_EDIT
void save_only_map(fhstream& f) { void save_only_map(fhstream& f) {
@ -684,6 +687,8 @@ EX namespace mapstream {
if(multi::players > 1) if(multi::players > 1)
for(int i=0; i<multi::players; i++) for(int i=0; i<multi::players; i++)
f.write(cellids[multi::player[i].at]); f.write(cellids[multi::player[i].at]);
callhooks(hooks_savemap, f);
cellids.clear(); cellids.clear();
cellbyid.clear(); cellbyid.clear();
@ -886,6 +891,8 @@ EX namespace mapstream {
} }
} }
callhooks(hooks_loadmap, f);
cellbyid.clear(); cellbyid.clear();
restartGraph(); restartGraph();
bfs(); bfs();
@ -914,7 +921,7 @@ EX namespace mapstream {
n = -1; f.write(n); n = -1; f.write(n);
} }
bool saveMap(const char *fname) { EX bool saveMap(const char *fname) {
fhstream f(fname, "wb"); fhstream f(fname, "wb");
if(!f.f) return false; if(!f.f) return false;
f.write(f.vernum); f.write(f.vernum);
@ -926,7 +933,7 @@ EX namespace mapstream {
return true; return true;
} }
bool loadMap(const string& fname) { EX bool loadMap(const string& fname) {
fhstream f(fname, "rb"); fhstream f(fname, "rb");
if(!f.f) return false; if(!f.f) return false;
f.read(f.vernum); f.read(f.vernum);