1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-11-26 02:14:48 +00:00

exporting/importing quotient lists

This commit is contained in:
Zeno Rogue
2025-10-09 09:38:09 +02:00
parent 510331cc14
commit 5f725332fe
2 changed files with 70 additions and 9 deletions

View File

@@ -203,12 +203,7 @@ string statstring() {
set<buckethash_t> seen_outputs; set<buckethash_t> seen_outputs;
struct qdata { auto& all_found = arb::current.quotients;
string name;
vector<int> connections;
};
vector<qdata> all_found;
void create() { void create() {
clear_all(); clear_all();
@@ -357,7 +352,7 @@ void recurse() {
println(hlog, "[", isize(all_found), "] ", bqo); println(hlog, "[", isize(all_found), "] ", bqo);
auto ss = statstring(); auto ss = statstring();
if(ss == "ERROR") return; if(ss == "ERROR") return;
all_found.push_back(qdata{ss + format(" %016lX", (long) vhash), bqo}); all_found.push_back(arb::quotient_data{ss + format(" %016lX", (long) vhash), bqo});
if(!(cgflags & qCLOSED)) return; if(!(cgflags & qCLOSED)) return;
} }
indenter ind(2); indenter ind(2);
@@ -487,6 +482,43 @@ bool aq_drawcell(cell *c, const shiftmatrix& V) {
return false; return false;
} }
string export_filename = "tessellations/exported.tes";
EX bool export_tes(string fname) {
fhstream f(fname, "wt");
if(!f.f) return false;
auto& ac = arb::current_or_slided();
println(f, "## ", ac.name, " (exported)");
println(f, (cgflags & qAFFINE) ? "a2." : hyperbolic ? "h2." : euclid ? "e2." : "s2.");
auto& shs = ac.shapes;
for(int i=0; i<isize(shs); i++) {
print(f, "tile(");
for(int j=0; j<shs[i].cycle_length; j++)
print(f, format("%.15f,%.15f,", shs[i].edges[j], shs[i].angles[j]));
print(f, "*", shs[i].size() / shs[i].cycle_length);
if(shs[i].symmetric_value) print(f, ",|", shs[i].symmetric_value);
println(f, ")");
}
for(int i=0; i<isize(shs); i++) {
for(int j=0; j<shs[i].cycle_length; j++) {
auto& co = shs[i].connections[j];
println(f, "c(", i, ",", j, ",", co.sid, ",", co.eid, ",", co.mirror, ")");
}
}
for(auto& af: all_found) {
println(f, "#/ ", af.name);
print(f, "quotient(");
int ct = 0;
for(auto v: af.connections) {
if(ct++) print(f, ",");
print(f, v &~ quotientspace::symmask);
if(v & quotientspace::symmask) print(f, "^");
}
println(f, ")");
}
return true;
}
void show_auto_dialog() { void show_auto_dialog() {
cmode = sm::SIDE | sm::DIALOG_STRICT_X; cmode = sm::SIDE | sm::DIALOG_STRICT_X;
if(running) cmode |= sm::NO_EXIT; if(running) cmode |= sm::NO_EXIT;
@@ -512,13 +544,19 @@ void show_auto_dialog() {
} }
running = false; running = false;
}); });
dialog::addSelItem(XLAT("quotients found"), its(isize(all_found)), 'n'); dialog::addSelItem(XLAT("export the quotients found"), its(isize(all_found)), 'E');
dialog::add_action([] {
dialog::openFileDialog(export_filename, XLAT("export to file:"), ".tes",
[] () {
return export_tes(export_filename);
});
});
if(running) dialog::addBreak(100); if(running) dialog::addBreak(100);
else dialog::addBack(); else dialog::addBack();
dialog::display(); dialog::display();
} }
EX void enable_quotient_data(const struct qdata& q) { EX void enable_quotient_data(const struct arb::quotient_data& q) {
stop_game(); stop_game();
cgflags |= qANYQ | qCLOSED; cgflags |= qANYQ | qCLOSED;
quotient_data = q.connections; quotient_data = q.connections;
@@ -563,6 +601,7 @@ auto aqhook =
arg::add3("-aq-test", [] { try { default_list(); create(); } catch(aq_overflow&) { println(hlog, "AQ overflow"); } }) arg::add3("-aq-test", [] { try { default_list(); create(); } catch(aq_overflow&) { println(hlog, "AQ overflow"); } })
+ arg::add3("-aq-auto", [] { displaying = false; running = true; arg::shift(); auto_create(arg::argi()); }) + arg::add3("-aq-auto", [] { displaying = false; running = true; arg::shift(); auto_create(arg::argi()); })
+ arg::add3("-aq-enable", [] { arg::shift(); enable_by_id(arg::argi()); }) + arg::add3("-aq-enable", [] { arg::shift(); enable_by_id(arg::argi()); })
+ arg::add3("-aq-export", [] { arg::shift(); export_tes(arg::args()); })
+ arg::add3("-d:aq", [] { arg::launch_dialog(show_dialog); }) + arg::add3("-d:aq", [] { arg::launch_dialog(show_dialog); })
+ addHook(hooks_configfile, 100, [] { + addHook(hooks_configfile, 100, [] {
param_i(aq_max, "aq_max") param_i(aq_max, "aq_max")

View File

@@ -117,6 +117,11 @@ struct intslider {
int max; int max;
}; };
struct quotient_data {
string name;
vector<int> connections;
};
struct arbi_tiling { struct arbi_tiling {
int order; int order;
@@ -162,6 +167,8 @@ struct arbi_tiling {
eGeometryClass get_class() { return get_geometry().kind; } eGeometryClass get_class() { return get_geometry().kind; }
ld scale(); ld scale();
vector<quotient_data> quotients;
}; };
#endif #endif
@@ -961,6 +968,7 @@ EX void set_defaults(arb::arbi_tiling& c, bool keep_sliders, string fname) {
c.sliders.clear(); c.sliders.clear();
c.intsliders.clear(); c.intsliders.clear();
} }
c.quotients.clear();
} }
EX void load(const string& fname, bool load_as_slided IS(false), bool keep_sliders IS(false)) { EX void load(const string& fname, bool load_as_slided IS(false), bool keep_sliders IS(false)) {
@@ -986,6 +994,7 @@ EX void load(const string& fname, bool load_as_slided IS(false), bool keep_slide
c.shapes[ai].flags |= f; c.shapes[ai].flags |= f;
ep.force_eat(")"); ep.force_eat(")");
}; };
string quotname = "unnamed";
while(true) { while(true) {
ep.extra_params["distunit"] = distunit; ep.extra_params["distunit"] = distunit;
@@ -995,6 +1004,7 @@ EX void load(const string& fname, bool load_as_slided IS(false), bool keep_slide
if(ep.next() == 0) break; if(ep.next() == 0) break;
if(ep.eat("#")) { if(ep.eat("#")) {
bool doubled = ep.eat("#"); bool doubled = ep.eat("#");
bool is_quotname = ep.eat("/");
while(ep.eat(" ")) ; while(ep.eat(" ")) ;
string s = ""; string s = "";
while(ep.next() >= 32) s += ep.next(), ep.at++; while(ep.next() >= 32) s += ep.next(), ep.at++;
@@ -1005,6 +1015,7 @@ EX void load(const string& fname, bool load_as_slided IS(false), bool keep_slide
c.comment += "\n"; c.comment += "\n";
} }
} }
if(is_quotname) quotname = s;
} }
else if(ep.eat("c2(")) { else if(ep.eat("c2(")) {
ld curv = ep.rparse(0); ld curv = ep.rparse(0);
@@ -1236,6 +1247,17 @@ EX void load(const string& fname, bool load_as_slided IS(false), bool keep_slide
ep.force_eat(")"); ep.force_eat(")");
throw connection_debug_request(i); throw connection_debug_request(i);
} }
else if(ep.eat("quotient(")) {
c.quotients.emplace_back(quotient_data{quotname, {}});
auto& con = c.quotients.back().connections;
con.push_back(ep.iparse(0));
while(true) {
if(ep.eat("^")) con.back() ^= quotientspace::symmask;
else if(ep.eat(",")) con.push_back(ep.iparse(0));
else if(ep.eat(")")) break;
else throw hr_parse_exception("expecing ), ^ or comma, " + ep.where());
}
}
else if(ep.eat("stretch_shear(")) { else if(ep.eat("stretch_shear(")) {
ld stretch = ep.rparse(0); ld stretch = ep.rparse(0);
ep.force_eat(","); ep.force_eat(",");