1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-27 14:37:16 +00:00

save colors in save

This commit is contained in:
Zeno Rogue 2024-08-20 13:48:34 +02:00
parent c65c92282e
commit 890a3540f5

View File

@ -1,6 +1,6 @@
namespace nilrider { namespace nilrider {
const string ver = "0.1"; const string ver = "0.2";
string new_replay_name() { string new_replay_name() {
time_t timer; time_t timer;
@ -26,11 +26,13 @@ void save() {
} }
} }
} }
println(f, "*COLORS\n");
for(auto l: all_levels) { for(auto l: all_levels) {
for(auto& p: l->manual_replays) { for(auto& p: l->manual_replays) {
println(f, "*MANUAL"); println(f, "*MANUAL");
println(f, l->name); println(f, l->name);
println(f, p.name); println(f, p.name);
fprintf(f.f, "%08x %08x %08x %08x\n", p.cs.wheel1, p.cs.wheel2, p.cs.seat, p.cs.seatpost);
println(f, isize(p.headings)); println(f, isize(p.headings));
for(auto t: p.headings) println(f, t); for(auto t: p.headings) println(f, t);
println(f); println(f);
@ -39,6 +41,7 @@ void save() {
println(f, "*PLANNING"); println(f, "*PLANNING");
println(f, l->name); println(f, l->name);
println(f, p.name); println(f, p.name);
fprintf(f.f, "%08x %08x %08x %08x\n", p.cs.wheel1, p.cs.wheel2, p.cs.seat, p.cs.seatpost);
println(f, isize(p.plan)); println(f, isize(p.plan));
for(auto t: p.plan) println(f, hr::format("%.6f %.6f %.6f %.6f", t.at[0], t.at[1], t.vel[0], t.vel[1])); for(auto t: p.plan) println(f, hr::format("%.6f %.6f %.6f %.6f", t.at[0], t.at[1], t.vel[0], t.vel[1]));
println(f); println(f);
@ -53,8 +56,21 @@ level *level_by_name(string s) {
return nullptr; return nullptr;
} }
colorscheme load_colors(fhstream& f, bool have_colors) {
if(have_colors) {
colorscheme s(0);
fscanf(f.f, "%x%x%x%x", &s.wheel1, &s.wheel2, &s.seat, &s.seatpost);
return s;
}
else {
colorscheme s(2);
return s;
}
}
void load() { void load() {
#if CAP_SAVE #if CAP_SAVE
bool have_colors = false;
println(hlog, "load called"); println(hlog, "load called");
fhstream f("nilrider.save", "rt"); fhstream f("nilrider.save", "rt");
if(!f.f) return; if(!f.f) return;
@ -62,27 +78,30 @@ void load() {
while(!feof(f.f)) { while(!feof(f.f)) {
string s = scanline_noblank(f); string s = scanline_noblank(f);
if(s == "") continue; if(s == "") continue;
if(s == "*COLORS") { have_colors = true; }
if(s == "*MANUAL") { if(s == "*MANUAL") {
string lev = scanline_noblank(f); string lev = scanline_noblank(f);
string name = scanline_noblank(f); string name = scanline_noblank(f);
colorscheme cs = load_colors(f, have_colors);
vector<int> headings; vector<int> headings;
int size = scan<int> (f); int size = scan<int> (f);
if(size < 0 || size > 1000000) throw hstream_exception(); if(size < 0 || size > 1000000) throw hstream_exception();
for(int i=0; i<size; i++) headings.push_back(scan<int>(f)); for(int i=0; i<size; i++) headings.push_back(scan<int>(f));
auto l = level_by_name(lev); auto l = level_by_name(lev);
if(l) l->manual_replays.emplace_back(manual_replay{name, colorscheme(2), std::move(headings)}); if(l) l->manual_replays.emplace_back(manual_replay{name, cs, std::move(headings)});
continue; continue;
} }
if(s == "*PLANNING") { if(s == "*PLANNING") {
string lev = scanline_noblank(f); string lev = scanline_noblank(f);
string name = scanline_noblank(f); string name = scanline_noblank(f);
colorscheme cs = load_colors(f, have_colors);
plan_t plan; plan_t plan;
int size = scan<int> (f); int size = scan<int> (f);
if(size < 0 || size > 1000000) throw hstream_exception(); if(size < 0 || size > 1000000) throw hstream_exception();
plan.resize(size, {C0, C0}); 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]); 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); auto l = level_by_name(lev);
if(l) l->plan_replays.emplace_back(plan_replay{name, colorscheme(2), std::move(plan)}); if(l) l->plan_replays.emplace_back(plan_replay{name, cs, std::move(plan)});
continue; continue;
} }
if(s == "*RECORD") { if(s == "*RECORD") {