From 80addc92d128ea93272c7d15b53e9e1c3c406195 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 5 Mar 2023 23:04:03 -0800 Subject: [PATCH] remember default max quality for each item --- plugins/buildingplan/buildingplan.cpp | 4 +++- plugins/buildingplan/defaultitemfilters.cpp | 2 +- plugins/buildingplan/itemfilter.cpp | 20 ++++++++++++-------- plugins/buildingplan/itemfilter.h | 3 ++- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/plugins/buildingplan/buildingplan.cpp b/plugins/buildingplan/buildingplan.cpp index 99e9a9af2..ec85d7952 100644 --- a/plugins/buildingplan/buildingplan.cpp +++ b/plugins/buildingplan/buildingplan.cpp @@ -705,7 +705,9 @@ static void clearFilter(color_ostream &out, df::building_type type, int16_t subt auto &filters = get_item_filters(out, key); if (index < 0 || filters.getItemFilters().size() <= (size_t)index) return; - filters.setItemFilter(out, ItemFilter(), index); + ItemFilter filter = filters.getItemFilters()[index]; + filter.clear(); + filters.setItemFilter(out, filter, index); call_buildingplan_lua(&out, "signal_reset"); } diff --git a/plugins/buildingplan/defaultitemfilters.cpp b/plugins/buildingplan/defaultitemfilters.cpp index 851565370..3c3b2f3a9 100644 --- a/plugins/buildingplan/defaultitemfilters.cpp +++ b/plugins/buildingplan/defaultitemfilters.cpp @@ -41,7 +41,7 @@ DefaultItemFilters::DefaultItemFilters(color_ostream &out, BuildingTypeKey key, set_config_val(filter_config, FILTER_CONFIG_CUSTOM, std::get<2>(key)); item_filters.resize(jitems.size()); for (size_t idx = 0; idx < jitems.size(); ++idx) { - item_filters[idx].setMaxQuality(get_max_quality(jitems[idx])); + item_filters[idx].setMaxQuality(get_max_quality(jitems[idx]), true); } filter_config.val() = serialize_item_filters(item_filters); } diff --git a/plugins/buildingplan/itemfilter.cpp b/plugins/buildingplan/itemfilter.cpp index c7794e109..e9639f281 100644 --- a/plugins/buildingplan/itemfilter.cpp +++ b/plugins/buildingplan/itemfilter.cpp @@ -14,13 +14,13 @@ using std::vector; using namespace DFHack; -ItemFilter::ItemFilter() { +ItemFilter::ItemFilter() : default_max_quality(df::item_quality::Masterful) { clear(); } void ItemFilter::clear() { min_quality = df::item_quality::Ordinary; - max_quality = df::item_quality::Masterful; + max_quality = default_max_quality; decorated_only = false; mat_mask.whole = 0; materials.clear(); @@ -28,7 +28,7 @@ void ItemFilter::clear() { bool ItemFilter::isEmpty() const { return min_quality == df::item_quality::Ordinary - && max_quality == df::item_quality::Masterful + && max_quality == default_max_quality && !decorated_only && !mat_mask.whole && materials.empty(); @@ -62,12 +62,10 @@ static bool deserializeMaterials(string ser, set &material return true; } -ItemFilter::ItemFilter(color_ostream &out, string serialized) { - clear(); - +ItemFilter::ItemFilter(color_ostream &out, string serialized) : ItemFilter() { vector tokens; split_string(&tokens, serialized, "/"); - if (tokens.size() != 5) { + if (tokens.size() < 5) { DEBUG(status,out).print("invalid ItemFilter serialization: '%s'", serialized.c_str()); return; } @@ -78,6 +76,9 @@ ItemFilter::ItemFilter(color_ostream &out, string serialized) { setMinQuality(atoi(tokens[2].c_str())); setMaxQuality(atoi(tokens[3].c_str())); decorated_only = static_cast(atoi(tokens[4].c_str())); + + if (tokens.size() >= 6) + default_max_quality = static_cast(atoi(tokens[5].c_str())); } // format: mat,mask,elements/materials,list/minq/maxq/decorated @@ -93,6 +94,7 @@ string ItemFilter::serialize() const { ser << "/" << static_cast(min_quality); ser << "/" << static_cast(max_quality); ser << "/" << static_cast(decorated_only); + ser << "/" << static_cast(default_max_quality); return ser.str(); } @@ -114,11 +116,13 @@ void ItemFilter::setMinQuality(int quality) { max_quality = min_quality; } -void ItemFilter::setMaxQuality(int quality) { +void ItemFilter::setMaxQuality(int quality, bool is_default) { max_quality = static_cast(quality); clampItemQuality(&max_quality); if (max_quality < min_quality) min_quality = max_quality; + if (is_default) + default_max_quality = max_quality; } void ItemFilter::setDecoratedOnly(bool decorated) { diff --git a/plugins/buildingplan/itemfilter.h b/plugins/buildingplan/itemfilter.h index 1bed7b7f6..5ae59dd4a 100644 --- a/plugins/buildingplan/itemfilter.h +++ b/plugins/buildingplan/itemfilter.h @@ -15,7 +15,7 @@ public: std::string serialize() const; void setMinQuality(int quality); - void setMaxQuality(int quality); + void setMaxQuality(int quality, bool is_default = false); void setDecoratedOnly(bool decorated); void setMaterialMask(uint32_t mask); void setMaterials(const std::set &materials); @@ -33,6 +33,7 @@ public: private: df::item_quality min_quality; df::item_quality max_quality; + df::item_quality default_max_quality; bool decorated_only; df::dfhack_material_category mat_mask; std::set materials;