Skip to content
Snippets Groups Projects
Commit fb84eefb authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Allow finding of remote properties for shortcuts

parent 1adc1a5a
No related branches found
No related tags found
1 merge request!181Implements #240 custom shortcuts
Pipeline #16745 passed
......@@ -25,10 +25,12 @@ int main(int argc, char **argv) {
std::map<ftl::UUID, std::vector<ftl::NetConfigurable*>> peerConfigurables;
// FIXME: Move this elsewhere, it is not just for GUI
net->onConnect([&controller, &peerConfigurables](ftl::net::Peer *p) {
ftl::UUID peer = p->id();
auto cs = controller->getConfigurables(peer);
for (auto c : cs) {
LOG(INFO) << "NET CONFIG: " << c;
ftl::config::json_t *configuration = new ftl::config::json_t;
*configuration = controller->get(peer, c);
if (!configuration->empty()) {
......
......@@ -477,12 +477,12 @@ bool ftl::gui::Screen::keyboardEvent(int key, int scancode, int action, int modi
std::string uri = (*s).value("uri",std::string(""));
if (op == "toggle") {
auto v = ftl::config::resolve(uri, false);
auto v = ftl::config::get(uri);
if (v.is_boolean()) {
ftl::config::update(uri, !v.get<bool>());
}
} else if (op == "+=") {
auto v = ftl::config::resolve(uri, false);
auto v = ftl::config::get(uri);
if (v.is_number_float()) {
ftl::config::update(uri, v.get<float>() + (*s).value("value",0.0f));
}
......
......@@ -47,6 +47,8 @@ void removeConfigurable(Configurable *cfg);
*/
bool update(const std::string &puri, const json_t &value);
json_t &get(const std::string &puri);
/**
* Resolve a JSON schema reference, but do not wait for a remote reference
* if it is not available. A null entity is returned if not resolved.
......
......@@ -194,6 +194,7 @@ ftl::Configurable *ftl::config::find(const std::string &uri) {
actual_uri = rootCFG->getID() + uri;
}
}
auto ix = config_instance.find(actual_uri);
if (ix == config_instance.end()) return nullptr;
else return (*ix).second;
......@@ -284,6 +285,34 @@ bool ftl::config::update(const std::string &puri, const json_t &value) {
}
}
json_t &ftl::config::get(const std::string &puri) {
// Remove last component of URI
string tail = "";
string head = "";
size_t last_hash = puri.find_last_of('#');
if (last_hash != string::npos) {
size_t last = puri.find_last_of('/');
if (last != string::npos && last > last_hash) {
tail = puri.substr(last+1);
head = puri.substr(0, last);
} else {
tail = puri.substr(last_hash+1);
head = puri.substr(0, last_hash);
}
} else {
LOG(WARNING) << "Expected a # in an update URI: " << puri;
return null_json;
}
Configurable *cfg = find(head);
if (cfg) {
return cfg->getConfig()[tail];
} else {
return null_json;
}
}
json_t &ftl::config::resolve(const std::string &puri, bool eager) {
string uri_str = puri;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment