From ff7be8d4e08d85516491a8a5e752905782c969d5 Mon Sep 17 00:00:00 2001 From: Jesse Ruderman Date: Sat, 3 Jul 2021 19:38:20 -0700 Subject: [PATCH] Add wiki links to land help --- help.cpp | 4 ++++ util.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/help.cpp b/help.cpp index 3a519e87..4f8485d0 100644 --- a/help.cpp +++ b/help.cpp @@ -1182,5 +1182,9 @@ EX void gotoHelpFor(eLand l) { help_extensions.push_back(help_extension{'t', XLAT("Galápagos shading"), [] () { tortoise::shading_enabled = !tortoise::shading_enabled; }}); + + help_extensions.push_back(help_extension{'w', XLAT("wiki"), [l] () { + open_wiki(linf[l].name); + }}); } } diff --git a/util.cpp b/util.cpp index b840b525..14e58523 100644 --- a/util.cpp +++ b/util.cpp @@ -724,4 +724,19 @@ EX void open_url(string s) { #endif } +const char *urlhex = "0123456789ABCDEF"; +EX void open_wiki(const char *title) { + string url = "https://hyperrogue.miraheze.org/wiki/"; + unsigned char c; + for (size_t i = 0; (c = title[i]); ++i) { + if (('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '_' || c == '-') + url += c; + else if (c == ' ') + url += "_"; + else + url += string("%") + urlhex[c/16] + urlhex[c%16]; + } + open_url(url); +} + }