MCPcopy Create free account
hub / github.com/DFHack/dfhack / load_state

Method load_state

plugins/autofarm.cpp:360–402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

358
359public:
360 void load_state(color_ostream& out)
361 {
362 initialize();
363
364 cfg_enabled = World::GetPersistentSiteData("autofarm/enabled");
365 if (cfg_enabled.isValid())
366 enabled = cfg_enabled.ival(0) != 0;
367 else {
368 cfg_enabled = World::AddPersistentSiteData("autofarm/enabled");
369 cfg_enabled.ival(0) = enabled;
370 }
371
372 cfg_default_threshold = World::GetPersistentSiteData("autofarm/default_threshold");
373
374 if (cfg_default_threshold.isValid())
375 defaultThreshold = cfg_default_threshold.ival(0);
376 else {
377 cfg_default_threshold = World::AddPersistentSiteData("autofarm/default_threshold");
378 cfg_default_threshold.ival(0) = defaultThreshold;
379 }
380
381 std::vector<PersistentDataItem> items;
382 World::GetPersistentSiteData(&items, "autofarm/threshold/", true);
383 for (auto& i: items) {
384 if (i.isValid())
385 {
386 const auto allPlants = world->raws.plants.all;
387 const std::string id = i.val();
388 const int val = i.ival(0);
389 const auto plant = std::find_if(std::begin(allPlants), std::end(allPlants), [id](df::plant_raw* p) { return p->id == id; });
390 if (plant != std::end(allPlants))
391 {
392 setThreshold((*plant)->index, val);
393 INFO(control, out).print("threshold of {} for plant {} in saved configuration loaded\n", val, id);
394 }
395 else
396 {
397 WARN(control, out).print("threshold for unknown plant {} in saved configuration ignored\n", id);
398 }
399 }
400 }
401
402 }
403
404 void save_state(color_ostream& out)
405 {

Callers 1

Calls 4

beginFunction · 0.85
ivalMethod · 0.80
isValidMethod · 0.45
printMethod · 0.45

Tested by

no test coverage detected