allow multiple filters

develop
Myk Taylor 2023-03-20 23:25:52 -07:00
parent cabdfe67bf
commit 876425fbc8
No known key found for this signature in database
5 changed files with 403 additions and 381 deletions

@ -77,14 +77,15 @@ Options
to the stockpile, but no other settings are changed. In ``disable`` mode,
enabled settings in the file are *removed* from the current stockpile
configuration, and nothing else is changed.
``-f``, ``--filter <filter>``
When importing, only modify the settings that contain the given substring.
``-f``, ``--filter <search>[,<search>...]``
When importing, only modify the settings that contain at least one of the
given substrings.
Configuration elements
----------------------
The different configuration elements you can include in an exported settings file
are:
The different configuration elements you can include in an exported settings
file are:
:containers: Max bins, max barrels, and num wheelbarrows.
:general: Whether the stockpile takes from links only and whether organic
@ -104,9 +105,9 @@ DFHack comes with a library of useful stockpile settings files that are ready
for import. If the stockpile configuration that you need isn't directly
represented, you can often use the ``enable`` and ``disable`` modes and/or
the ``filter`` option to transform an existing saved stockpile setting. Some
stockpile configurations can only be achieved with filters since the contents
of the stockpile lists are different for each world. For example, to disable
all tallow in your main food stockpile, you'd run this command::
stockpile configurations can only be achieved with filters since the stockpile
lists are different for each world. For example, to disable all tallow in your
main food stockpile, you'd run this command::
stockpiles import category_food -m disable -f tallow
@ -134,18 +135,34 @@ entire category, or with a filter, any matchable subset thereof::
category_weapons
category_wood
For many of the categories, there are also settings files that manipulate interesting
subsets of that category.
For many of the categories, there are also subcategory prefixes that you can
match with filters and convenient pre-made settings files that manipulate
interesting category subsets.
Ammo stockpile adjustments
~~~~~~~~~~~~~~~~~~~~~~~~~~
bolts
metalammo
boneammo
woodammo
masterworkammo
artifactammo
Subcategory prefixes::
type/
mats/
other/
core/
total/
Convenience settings files::
bolts
metalammo
boneammo
woodammo
Example commands for a stockpile of metal bolts::
stockpiles import category_ammo
stockpiles import -m disable -f other/ category_ammo
stockpiles import -m disable -f type/ category_ammo
stockpiles import -m enable bolts
Animal stockpile adjustments
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@ -113,7 +113,7 @@ local function import_stockpile(name, opts)
else
name = STOCKPILES_LIBRARY_DIR .. '/' .. name
end
stockpiles_import(name, get_sp_id(opts), opts.mode, opts.filter)
stockpiles_import(name, get_sp_id(opts), opts.mode, table.concat(opts.filters, ','))
end
local valid_includes = {general=true, categories=true, types=true}
@ -145,11 +145,11 @@ local function process_args(opts, args)
opts.includes = {}
opts.mode = 'set'
opts.filter = ''
opts.filters = {}
return argparse.processArgsGetopt(args, {
{'f', 'filter', hasArg=true,
handler=function(arg) opts.filter = arg end},
handler=function(arg) opts.filters = argparse.stringList(arg) end},
{'h', 'help', handler=function() opts.help = true end},
{'i', 'include', hasArg=true,
handler=function(arg) opts.includes = parse_include(arg) end},

File diff suppressed because it is too large Load Diff

@ -81,12 +81,12 @@ public:
/**
* Again, copied from message.cc
*/
bool parse_from_istream(std::istream* input, DeserializeMode mode, const std::string& filter);
bool parse_from_istream(std::istream* input, DeserializeMode mode, const std::vector<std::string>& filters);
/**
* Read stockpile settings from file
*/
bool unserialize_from_file(const std::string& file, DeserializeMode mode, const std::string& filter);
bool unserialize_from_file(const std::string& file, DeserializeMode mode, const std::vector<std::string>& filters);
private:
df::building_stockpilest* mPile;
@ -96,7 +96,7 @@ private:
void write(uint32_t includedElements);
// parse serialized data into ui indices
void read(DeserializeMode mode, const std::string& filter);
void read(DeserializeMode mode, const std::vector<std::string>& filters);
void write_containers();
void read_containers(DeserializeMode mode);
@ -104,38 +104,38 @@ private:
void read_general(DeserializeMode mode);
bool write_ammo(dfstockpiles::StockpileSettings::AmmoSet* ammo);
void read_ammo(DeserializeMode mode, const std::string& filter);
void read_ammo(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_animals(dfstockpiles::StockpileSettings::AnimalsSet* animals);
void read_animals(DeserializeMode mode, const std::string& filter);
void read_animals(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_armor(dfstockpiles::StockpileSettings::ArmorSet* armor);
void read_armor(DeserializeMode mode, const std::string& filter);
void read_armor(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_bars_blocks(dfstockpiles::StockpileSettings::BarsBlocksSet* bars_blocks);
void read_bars_blocks(DeserializeMode mode, const std::string& filter);
void read_bars_blocks(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_cloth(dfstockpiles::StockpileSettings::ClothSet* cloth);
void read_cloth(DeserializeMode mode, const std::string& filter);
void read_cloth(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_coins(dfstockpiles::StockpileSettings::CoinSet* coins);
void read_coins(DeserializeMode mode, const std::string& filter);
void read_coins(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_finished_goods(dfstockpiles::StockpileSettings::FinishedGoodsSet* finished_goods);
void read_finished_goods(DeserializeMode mode, const std::string& filter);
void read_finished_goods(DeserializeMode mode, const std::vector<std::string>& filters);
food_pair food_map(df::enums::organic_mat_category::organic_mat_category cat);
bool write_food(dfstockpiles::StockpileSettings::FoodSet* food);
void read_food(DeserializeMode mode, const std::string& filter);
void read_food(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_furniture(dfstockpiles::StockpileSettings::FurnitureSet* furniture);
void read_furniture(DeserializeMode mode, const std::string& filter);
void read_furniture(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_gems(dfstockpiles::StockpileSettings::GemsSet* gems);
void read_gems(DeserializeMode mode, const std::string& filter);
void read_gems(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_leather(dfstockpiles::StockpileSettings::LeatherSet* leather);
void read_leather(DeserializeMode mode, const std::string& filter);
void read_leather(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_corpses(dfstockpiles::StockpileSettings::CorpsesSet* corpses);
void read_corpses(DeserializeMode mode, const std::string& filter);
void read_corpses(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_refuse(dfstockpiles::StockpileSettings::RefuseSet* refuse);
void read_refuse(DeserializeMode mode, const std::string& filter);
void read_refuse(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_sheet(dfstockpiles::StockpileSettings::SheetSet* sheet);
void read_sheet(DeserializeMode mode, const std::string& filter);
void read_sheet(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_stone(dfstockpiles::StockpileSettings::StoneSet* stone);
void read_stone(DeserializeMode mode, const std::string& filter);
void read_stone(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_weapons(dfstockpiles::StockpileSettings::WeaponsSet* weapons);
void read_weapons(DeserializeMode mode, const std::string& filter);
void read_weapons(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_wood(dfstockpiles::StockpileSettings::WoodSet* wood);
void read_wood(DeserializeMode mode, const std::string& filter);
void read_wood(DeserializeMode mode, const std::vector<std::string>& filters);
};

@ -129,9 +129,12 @@ static bool stockpiles_import(color_ostream& out, string fname, int id, string m
else if (mode_str == "disable")
mode = DESERIALIZE_MODE_DISABLE;
vector<string> filters;
split_string(&filters, filter, ",", true);
try {
StockpileSerializer cereal(sp);
if (!cereal.unserialize_from_file(fname, mode, filter)) {
if (!cereal.unserialize_from_file(fname, mode, filters)) {
out.printerr("deserialization failed: '%s'\n", fname.c_str());
return false;
}