| 43 | } |
| 44 | |
| 45 | DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) { |
| 46 | if (!Core::getInstance().isMapLoaded() || !World::isFortressMode()) { |
| 47 | out.printerr("Cannot enable {} without a loaded fort.\n", plugin_name); |
| 48 | return CR_FAILURE; |
| 49 | } |
| 50 | |
| 51 | if (enable != is_enabled) { |
| 52 | is_enabled = enable; |
| 53 | DEBUG(log,out).print("{} from the API; persisting\n", |
| 54 | is_enabled ? "enabled" : "disabled"); |
| 55 | config.set_bool(CONFIG_IS_ENABLED, is_enabled); |
| 56 | if (enable) |
| 57 | EventManager::registerListener(EventManager::EventType::JOB_COMPLETED, handler); |
| 58 | else |
| 59 | cleanup(); |
| 60 | } else { |
| 61 | DEBUG(log,out).print("{} from the API, but already {} ; no action\n", |
| 62 | is_enabled ? "enabled" : "disabled", |
| 63 | is_enabled ? "enabled" : "disabled"); |
| 64 | } |
| 65 | |
| 66 | return CR_OK; |
| 67 | } |
| 68 | |
| 69 | DFhackCExport command_result plugin_shutdown ( color_ostream &out ) { |
| 70 | cleanup(); |