1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-10-30 05:23:00 +00:00

nilrider:: loading saved plans and replays

This commit is contained in:
Zeno Rogue
2022-05-02 03:38:20 +02:00
parent ae503cf322
commit 2bd079003a
2 changed files with 100 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ string new_replay_name() {
void save() {
println(hlog, "save called");
fhstream f("nilrider.save", "wt");
println(f, "version ", ver);
println(f, "NilRider version ", ver);
for(auto l: all_levels) {
for(auto& p: l->manual_replays) {
println(f, "*MANUAL");
@@ -34,4 +34,45 @@ void save() {
}
}
level *level_by_name(string s) {
for(auto l: all_levels) if(l->name == s) return l;
println(hlog, "error: unknown level ", s);
return nullptr;
}
void load() {
println(hlog, "load called");
fhstream f("nilrider.save", "rt");
if(!f.f) return;
string ver = scanline_noblank(f);
while(!feof(f.f)) {
string s = scanline_noblank(f);
if(s == "") continue;
if(s == "*MANUAL") {
string lev = scanline_noblank(f);
string name = scanline_noblank(f);
vector<int> headings;
int size = scan<int> (f);
if(size < 0 || size > 1000000) throw hstream_exception();
for(int i=0; i<size; i++) headings.push_back(scan<int>(f));
auto l = level_by_name(lev);
if(l) l->manual_replays.emplace_back(manual_replay{name, std::move(headings)});
continue;
}
if(s == "*PLANNING") {
string lev = scanline_noblank(f);
string name = scanline_noblank(f);
plan_t plan;
int size = scan<int> (f);
if(size < 0 || size > 1000000) throw hstream_exception();
plan.resize(size, {C0, C0});
for(int i=0; i<size; i++) scan(f, plan[i].at[0], plan[i].at[1], plan[i].vel[0], plan[i].vel[1]);
auto l = level_by_name(lev);
if(l) l->plan_replays.emplace_back(plan_replay{name, std::move(plan)});
continue;
}
println(hlog, "error: unknown content ", s);
}
}
}