MCPcopy Create free account
hub / github.com/DFHack/dfhack / command_result plugin_enable

Function command_result plugin_enable

plugins/timestream.cpp:171–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) {
172 if (!Core::getInstance().isMapLoaded() || !World::isFortressMode()) {
173 out.printerr("Cannot enable {} without a loaded fort.\n", plugin_name);
174 return CR_FAILURE;
175 }
176
177 static EventManager::EventHandler new_unit_handler(plugin_self, on_new_active_unit, CYCLE_TICKS);
178
179 if (enable != is_enabled) {
180 is_enabled = enable;
181 DEBUG(control,out).print("{} from the API; persisting\n",
182 is_enabled ? "enabled" : "disabled");
183 config.set_bool(CONFIG_IS_ENABLED, is_enabled);
184 if (enable) {
185 reset_ephemeral_state();
186 EventManager::registerListener(EventManager::EventType::UNIT_NEW_ACTIVE, new_unit_handler);
187 do_cycle(out);
188 } else {
189 do_disable();
190 }
191 } else {
192 DEBUG(control,out).print("{} from the API, but already {}; no action\n",
193 is_enabled ? "enabled" : "disabled",
194 is_enabled ? "enabled" : "disabled");
195 }
196 return CR_OK;
197}
198
199DFhackCExport command_result plugin_shutdown(color_ostream &out) {
200 DEBUG(control,out).print("shutting down {}\n", plugin_name);

Callers

nothing calls this directly

Calls 4

reset_ephemeral_stateFunction · 0.85
do_cycleFunction · 0.70
do_disableFunction · 0.70
printMethod · 0.45

Tested by

no test coverage detected