| 299 | IMPLEMENT_VMETHOD_INTERPOSE(autogem_hook, render); |
| 300 | |
| 301 | bool read_config(color_ostream &out) { |
| 302 | std::string path = "save/" + World::ReadWorldFolder() + "/autogems.json"; |
| 303 | if (!Filesystem::isfile(path)) { |
| 304 | // no need to require the config file to exist |
| 305 | return true; |
| 306 | } |
| 307 | |
| 308 | std::ifstream f(path); |
| 309 | Json::Value config; |
| 310 | try { |
| 311 | if (!f.good() || !(f >> config)) { |
| 312 | out.printerr("autogems: failed to read autogems.json\n"); |
| 313 | return false; |
| 314 | } |
| 315 | } |
| 316 | catch (Json::Exception &e) { |
| 317 | out.printerr("autogems: failed to read autogems.json: {}\n", e.what()); |
| 318 | return false; |
| 319 | } |
| 320 | |
| 321 | if (config["blacklist"].isArray()) { |
| 322 | blacklist.clear(); |
| 323 | for (int i = 0; i < int(config["blacklist"].size()); i++) { |
| 324 | Json::Value item = config["blacklist"][i]; |
| 325 | if (item.isInt()) { |
| 326 | blacklist.insert(mat_index(item.asInt())); |
| 327 | } |
| 328 | else { |
| 329 | out.printerr("autogems: illegal item at position {} in blacklist\n", i); |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | return true; |
| 334 | } |
| 335 | |
| 336 | command_result cmd_reload_config(color_ostream &out, std::vector<std::string>&) { |
| 337 | return read_config(out) ? CR_OK : CR_FAILURE; |
no test coverage detected