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

Function setMaterialFilter

plugins/buildingplan/buildingplan.cpp:900–955  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

898}
899
900static int setMaterialFilter(lua_State *L) {
901 color_ostream *out = Lua::GetOutput(L);
902 if (!out)
903 out = &Core::getInstance().getConsole();
904 df::building_type type = (df::building_type)luaL_checkint(L, 1);
905 int16_t subtype = luaL_checkint(L, 2);
906 int32_t custom = luaL_checkint(L, 3);
907 int index = luaL_checkint(L, 4);
908 DEBUG(control,*out).print(
909 "entering setMaterialFilter building_type={} subtype={} custom={} index={}\n",
910 ENUM_AS_STR(type), subtype, custom, index);
911 BuildingTypeKey key(type, subtype, custom);
912 auto &filters = get_item_filters(*out, key).getItemFilters();
913 if (index < 0 || filters.size() <= (size_t)index)
914 return 0;
915 set<MaterialInfo> mats;
916 vector<string> matstrs;
917 Lua::GetVector(L, matstrs, 5);
918 for (auto &mat : matstrs) {
919 if (mat_cache.count(mat))
920 mats.emplace(mat_cache.at(mat).first);
921 }
922 DEBUG(control,*out).print(
923 "setting material filter for building_type={} subtype={} custom={} index={} to {} materials\n",
924 ENUM_AS_STR(type), subtype, custom, index, mats.size());
925 ItemFilter filter = filters[index];
926 filter.setMaterials(mats);
927 // ensure relevant masks are explicitly enabled
928 df::dfhack_material_category mask = filter.getMaterialMask();
929 if (!mats.size())
930 mask.whole = 0; // if all materials are disabled, reset the mask
931 for (auto & mat : mats) {
932 if (mat.matches(stone_cat))
933 mask.whole |= stone_cat.whole;
934 else if (mat.matches(wood_cat))
935 mask.whole |= wood_cat.whole;
936 else if (mat.matches(metal_cat))
937 mask.whole |= metal_cat.whole;
938 else if (mat.matches(glass_cat))
939 mask.whole |= glass_cat.whole;
940 else if (mat.matches(gem_cat))
941 mask.whole |= gem_cat.whole;
942 else if (mat.matches(clay_cat))
943 mask.whole |= clay_cat.whole;
944 else if (mat.matches(cloth_cat))
945 mask.whole |= cloth_cat.whole;
946 else if (mat.matches(silk_cat))
947 mask.whole |= silk_cat.whole;
948 else if (mat.matches(yarn_cat))
949 mask.whole |= yarn_cat.whole;
950 }
951 filter.setMaterialMask(mask.whole);
952 get_item_filters(*out, key).setItemFilter(*out, filter, index);
953 Lua::CallLuaModuleFunction(*out, "plugins.buildingplan", "signal_reset");
954 return 0;
955}
956
957static int getMaterialFilter(lua_State *L) {

Callers

nothing calls this directly

Calls 11

get_item_filtersFunction · 0.85
GetVectorFunction · 0.85
CallLuaModuleFunctionFunction · 0.85
setMaterialsMethod · 0.80
getMaterialMaskMethod · 0.80
setMaterialMaskMethod · 0.80
setItemFilterMethod · 0.80
printMethod · 0.45
sizeMethod · 0.45
countMethod · 0.45
matchesMethod · 0.45

Tested by

no test coverage detected