Skip to content

Commit aa5b63a

Browse files
committed
Put getOverallQuality method in its own function with option to call it
1 parent 3cb5ff0 commit aa5b63a

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ Template for new versions:
3333
## New Features
3434

3535
## Fixes
36-
- `item`: the ``--min-quality`` and ``--max-quality`` options now evaluate overall item quality
3736

3837
## Misc Improvements
38+
- `item`: new ``--total-quality`` option for use in conjunction with ``--min-quality`` or ``--max-quality`` to filter items according to their total quality
3939

4040
## Removed
4141

docs/item.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ Examples
4949
flood-fill to create a burrow covering an entire cavern layer).
5050

5151
``item melt -t weapon -m steel --max-quality 3``
52-
Designate all steel weapons whose quality is at most superior for melting.
52+
Designate all steel weapons whose core quality is at most superior for
53+
melting.
5354

5455
``item hide -t boulder --scattered``
5556
Hide all scattered boulders, i.e. those that are not in stockpiles.
@@ -121,6 +122,11 @@ Options
121122
Only include items whose quality level is at most ``integer``. Useful
122123
values are 0 (ordinary) to 5 (masterwork).
123124

125+
``--total-quality``
126+
Only applies to ``--min-quality`` and ``--max-quality`` options. Filter items
127+
according to their total quality (to include improvements) of instead of
128+
their core quality.
129+
124130
``--stockpiled``
125131
Only include items that are in stockpiles. Does not include empty bins,
126132
barrels, and wheelbarrows assigned as storage and transport for stockpiles.
@@ -201,8 +207,12 @@ the filter is described.
201207
see above).
202208

203209
* ``condition_quality(tab, lower, upper, negate)``
204-
Selects items with quality between ``lower`` and ``upper`` (Range 0-5, see
205-
above).
210+
Selects items with core quality between ``lower`` and ``upper`` (Range 0-5,
211+
see above).
212+
213+
* ``condition_overall_quality(tab, lower, upper, negate)``
214+
Selects items with total quality between ``lower`` and ``upper`` (Range 0-5,
215+
see above).
206216

207217
* ``condition_stockpiled(tab, negate)``
208218
Corresponds to ``--stockpiled``.

item.lua

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ end
141141
--- @param upper number # range: 0 (standard) to 5 (masterwork)
142142
--- @param negate { negate : boolean }|nil
143143
function 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)
146155
end
@@ -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)[]
352362
local conditions = {}
353363

364+
local minQuality, maxQuality
365+
354366
local 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
433450
end
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+
435468
for i=2,#positionals do
436469
condition_description(conditions, positionals[i])
437470
end

0 commit comments

Comments
 (0)