Skip to content

Commit

Permalink
turn thresholds into a sub-command
Browse files Browse the repository at this point in the history
  • Loading branch information
chdoc committed Aug 11, 2024
1 parent ea52ce9 commit a1e01c3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 34 deletions.
40 changes: 16 additions & 24 deletions docs/idle-crafting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,24 @@ select a Craftsdwarf's Workshop in the UI. More details below.
Usage
-----

::
``idle-crafting [status]``
Print statistics about the status of the tool and the satisfaction of
"craft item" needs in your fort.

idle-crafting status
idle-crafting disable
disable idle-crafting
``idle-crafting thresholds <number list>``
Set the threshold(s) for the "craft item" need (i.e. the negated
``focus_level``) at which the tool starts to generate crafting jobs for a
given unit. Units meeting higher thresholds will be prioritized. Defaults
to ``500,1000,10000``.

The ``status`` command prints statistics about the status of the tool and the
satisfaction of "craft item" needs in your fort. Both variants of the
``disable`` command disallow idle crafting at all workshops and disable the
tool.
``disable idle-crafting``
Disallow idle crafting at all workshops and disable the tool.

Examples
--------

``idle-crafting -t 10000,1000,500 status``
Reset all thresholds to defaults and print status information.

Options
-------

``-t <number list>``, ``--thresholds <number list>``
Sets the threshold(s) for the "craft item" need (i.e. the negated
``focus_level``) at which the tool starts to generate crafting jobs for a
given unit. Units meeting earlier (higher) thresholds will be
prioritized. Defaults to ``10000,1000,500``.

``idle-crafting thresholds 500,1000,10000``
Reset thresholds to defaults.

Overlay
-------
Expand All @@ -53,8 +45,8 @@ this way.

When a workshop is designated for idle crafting, this tool will create crafting
jobs and assign them to idle dwarves who have a need for crafting
objects. Currently, bone carving and stone crafting are supported, with stone
crafting being the default option. This script respects the setting for
objects. Currently, bone carving and stonecrafting are supported, with
stonecrafting being the default option. This script respects the setting for
permitted general work orders from the "Workers" tab. Thus, to designate a
workshop for bone carving, disable the stone crafting labor on for their
workshop, will keeping bone carving enabled.
workshop for bone carving, disable the stonecrafting labor while keeping the
bone carving labor enabled.
18 changes: 8 additions & 10 deletions idle-crafting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -443,16 +443,9 @@ local fulfillment_threshold =
local argparse = require('argparse')

load_state()
local positionals = argparse.processArgsGetopt({ ... }, {
{
't', 'thresholds', hasArg = true,
handler = function(optarg)
thresholds = argparse.numberList(optarg, 'thresholds')
end
}
})
local positionals = argparse.processArgsGetopt({ ... }, {})

if positionals[1] == 'status' then
if not positionals[1] or positionals[1] == 'status' then
---@type integer[]
stats = {}
for _, unit in ipairs(dfhack.units.getCitizens(true, false)) do
Expand All @@ -476,7 +469,12 @@ if positionals[1] == 'status' then
print(('Script is %s with %d workshops configured for idle crafting'):
format(enabled and 'enabled' or 'disabled', num_workshops))
print(('The thresholds for "craft item" needs are %s'):
format(table.concat(thresholds, '/')))
format(table.concat(thresholds, ',')))
elseif positionals[1] == 'thresholds' then
thresholds = argparse.numberList(positionals[2], 'thresholds')
table.sort(thresholds, function (a, b) return a > b end)
print(('Thresholds for "craft item" needs set to %s'):
format(table.concat(thresholds, ',')))
elseif positionals[1] == 'disable' then
allowed = {}
stop()
Expand Down

0 comments on commit a1e01c3

Please sign in to comment.