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

Method read_gems

plugins/stockpiles/StockpileSerializer.cpp:1980–2035  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1978}
1979
1980void StockpileSettingsSerializer::read_gems(color_ostream& out, DeserializeMode mode, const vector<string>& filters) {
1981 auto & pgems = mSettings->gems;
1982 read_category<StockpileSettings_GemsSet>(out, "gems", mode,
1983 std::bind(&StockpileSettings::has_gems, mBuffer),
1984 std::bind(&StockpileSettings::gems, mBuffer),
1985 mSettings->flags.whole,
1986 mSettings->flags.mask_gems,
1987 [&]() {
1988 pgems.cut_other_mats.clear();
1989 pgems.cut_mats.clear();
1990 pgems.rough_other_mats.clear();
1991 pgems.rough_mats.clear();
1992 },
1993 [&](bool all, char val) {
1994 auto & bgems = mBuffer.gems();
1995
1996 unserialize_list_material(out, "mats/rough", all, val, filters, gem_mat_is_allowed,
1997 [&](const size_t& idx) -> const string& { return bgems.rough_mats(idx); },
1998 bgems.rough_mats_size(), pgems.rough_mats);
1999
2000 unserialize_list_material(out, "mats/cut", all, val, filters, gem_cut_mat_is_allowed,
2001 [&](const size_t& idx) -> const string& { return bgems.cut_mats(idx); },
2002 bgems.cut_mats_size(), pgems.cut_mats);
2003
2004 const size_t builtin_size = std::extent<decltype(world->raws.mat_table.builtin)>::value;
2005 pgems.rough_other_mats.resize(builtin_size, '\0');
2006 pgems.cut_other_mats.resize(builtin_size, '\0');
2007 if (all) {
2008 for (size_t idx = 0; idx < builtin_size; ++idx) {
2009 MaterialInfo mi;
2010 mi.decode(idx, -1);
2011 if (gem_other_mat_is_allowed(mi))
2012 set_filter_elem(out, "other/rough", filters, val, mi.getToken(), idx, pgems.rough_other_mats.at(idx));
2013 if (!mi.isValid())
2014 mi.decode(0, idx);
2015 if (gem_other_mat_is_allowed(mi))
2016 set_filter_elem(out, "other/cut", filters, val, mi.getToken(), idx, pgems.cut_other_mats.at(idx));
2017 }
2018 return;
2019 } else {
2020 MaterialInfo mi;
2021 for (int i = 0; i < (int)builtin_size; ++i) {
2022 if (i < bgems.rough_other_mats_size()) {
2023 string id = bgems.rough_other_mats(i);
2024 if (mi.find(id) && mi.isValid() && size_t(mi.type) < builtin_size)
2025 set_filter_elem(out, "other/rough", filters, val, id, mi.type, pgems.rough_other_mats.at(mi.type));
2026 }
2027 if (i < bgems.cut_other_mats_size()) {
2028 string id = bgems.cut_other_mats(i);
2029 if (mi.find(id) && mi.isValid() && size_t(mi.type) < builtin_size)
2030 set_filter_elem(out, "other/cut", filters, val, id, mi.type, pgems.cut_other_mats.at(mi.type));
2031 }
2032 }
2033 }
2034 });
2035}
2036
2037bool StockpileSettingsSerializer::write_leather(color_ostream& out, StockpileSettings::LeatherSet* leather) {

Callers

nothing calls this directly

Calls 9

gem_other_mat_is_allowedFunction · 0.85
set_filter_elemFunction · 0.85
clearMethod · 0.45
resizeMethod · 0.45
decodeMethod · 0.45
getTokenMethod · 0.45
isValidMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected