141141--- @param upper number # range: 0 (standard) to 5 (masterwork)
142142--- @param negate { negate : boolean }| nil
143143function condition_quality (tab , lower , upper , negate )
144+ local pred = function (item ) return lower <= item :getQuality () and item :getQuality () <= upper end
145+ addPositiveOrNegative (tab , pred , negate )
146+ end
147+
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 )
144153 local pred = function (item ) return lower <= item :getOverallQuality () and item :getOverallQuality () <= upper end
145154 addPositiveOrNegative (tab , pred , negate )
146155end
@@ -346,11 +355,14 @@ local options = {
346355 owned = false ,
347356 nowebs = false ,
348357 verbose = false ,
358+ totalquality = false ,
349359}
350360
351361--- @type (fun ( item : item ): boolean ) []
352362local conditions = {}
353363
364+ local minQuality , maxQuality
365+
354366local function flagsFilter (args , negate )
355367 local flags = argparse .stringList (args , " flag list" )
356368 for _ ,flag in ipairs (flags ) do
@@ -375,6 +387,7 @@ local positionals = argparse.processArgsGetopt({ ... }, {
375387 { nil , ' ignore-webs' , handler = function () options .nowebs = true end },
376388 { ' n' , ' dry-run' , handler = function () options .dryrun = true end },
377389 { nil , ' by-type' , handler = function () options .bytype = true end },
390+ { nil , ' total-quality' , handler = function () options .totalquality = true end },
378391 { ' i' , ' inside' , hasArg = true ,
379392 handler = function (name )
380393 local burrow = dfhack .burrows .findByName (name ,true )
@@ -407,14 +420,18 @@ local positionals = argparse.processArgsGetopt({ ... }, {
407420 handler = function (levelst )
408421 local level = argparse .nonnegativeInt (levelst , ' max-wear' )
409422 condition_wear (conditions , 0 , level ) end },
423+ -- Need to process total-quality argument before processing min/max-quality arguments,
424+ -- since there's no guarantee the user will call total-quality first in the command line.
410425 { ' q' , ' min-quality' , hasArg = true ,
411426 handler = function (levelst )
412427 local level = argparse .nonnegativeInt (levelst , ' min-quality' )
413- condition_quality (conditions , level , 5 ) end },
428+ minQuality = level end },
429+ -- condition_quality(conditions, level, 5) end },
414430 { ' Q' , ' max-quality' , hasArg = true ,
415431 handler = function (levelst )
416432 local level = argparse .nonnegativeInt (levelst , ' max-quality' )
417- condition_quality (conditions , 0 , level ) end },
433+ maxQuality = level end },
434+ -- condition_quality(conditions, 0, level) end },
418435 { nil , ' stockpiled' ,
419436 handler = function () condition_stockpiled (conditions ) end },
420437 { nil , ' scattered' ,
@@ -432,6 +449,22 @@ if options.help or positionals[1] == 'help' then
432449 return
433450end
434451
452+ if minQuality then
453+ if options .totalquality then
454+ condition_overall_quality (conditions , minQuality , 5 )
455+ else
456+ condition_quality (conditions , minQuality , 5 )
457+ end
458+ end
459+
460+ if maxQuality then
461+ if options .totalquality then
462+ condition_overall_quality (conditions , 0 , maxQuality )
463+ else
464+ condition_quality (conditions , 0 , maxQuality )
465+ end
466+ end
467+
435468for i = 2 ,# positionals do
436469 condition_description (conditions , positionals [i ])
437470end
0 commit comments