@@ -145,6 +145,15 @@ function condition_quality(tab, lower, upper, negate)
145145 addPositiveOrNegative (tab , pred , negate )
146146end
147147
148+ --- @param tab conditions
149+ --- @param lower number # range: 0 (standard) to 5 (masterwork)
150+ --- @param upper number # range: 0 (standard) to 5 (masterwork)
151+ --- @param negate { negate : boolean }| nil
152+ function condition_overall_quality (tab , lower , upper , negate )
153+ local pred = function (item ) return lower <= item :getOverallQuality () and item :getOverallQuality () <= upper end
154+ addPositiveOrNegative (tab , pred , negate )
155+ end
156+
148157--- @param tab conditions
149158--- @param negate { negate : boolean }| nil
150159function condition_forbid (tab , negate )
@@ -346,11 +355,15 @@ local options = {
346355 owned = false ,
347356 nowebs = false ,
348357 verbose = false ,
358+ filterquality = false ,
359+ totalquality = false ,
349360}
350361
351362--- @type (fun ( item : item ): boolean ) []
352363local conditions = {}
353364
365+ local minQuality , maxQuality = 0 , 5
366+
354367local function flagsFilter (args , negate )
355368 local flags = argparse .stringList (args , " flag list" )
356369 for _ ,flag in ipairs (flags ) do
@@ -375,6 +388,7 @@ local positionals = argparse.processArgsGetopt({ ... }, {
375388 { nil , ' ignore-webs' , handler = function () options .nowebs = true end },
376389 { ' n' , ' dry-run' , handler = function () options .dryrun = true end },
377390 { nil , ' by-type' , handler = function () options .bytype = true end },
391+ { nil , ' total-quality' , handler = function () options .totalquality = true end },
378392 { ' i' , ' inside' , hasArg = true ,
379393 handler = function (name )
380394 local burrow = dfhack .burrows .findByName (name ,true )
@@ -407,14 +421,18 @@ local positionals = argparse.processArgsGetopt({ ... }, {
407421 handler = function (levelst )
408422 local level = argparse .nonnegativeInt (levelst , ' max-wear' )
409423 condition_wear (conditions , 0 , level ) end },
424+ -- Need to process total-quality argument before processing min/max-quality arguments,
425+ -- since there's no guarantee the user will call total-quality first in the command line.
410426 { ' q' , ' min-quality' , hasArg = true ,
411427 handler = function (levelst )
412428 local level = argparse .nonnegativeInt (levelst , ' min-quality' )
413- condition_quality (conditions , level , 5 ) end },
429+ minQuality = level options .filterquality = true end },
430+ -- condition_quality(conditions, level, 5) end },
414431 { ' Q' , ' max-quality' , hasArg = true ,
415432 handler = function (levelst )
416433 local level = argparse .nonnegativeInt (levelst , ' max-quality' )
417- condition_quality (conditions , 0 , level ) end },
434+ maxQuality = level options .filterquality = true end },
435+ -- condition_quality(conditions, 0, level) end },
418436 { nil , ' stockpiled' ,
419437 handler = function () condition_stockpiled (conditions ) end },
420438 { nil , ' scattered' ,
@@ -432,6 +450,14 @@ if options.help or positionals[1] == 'help' then
432450 return
433451end
434452
453+ if options .filterquality then
454+ if options .totalquality then
455+ condition_overall_quality (conditions , minQuality , maxQuality )
456+ else
457+ condition_quality (conditions , minQuality , maxQuality )
458+ end
459+ end
460+
435461for i = 2 ,# positionals do
436462 condition_description (conditions , positionals [i ])
437463end
0 commit comments