-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathtailor.lua
More file actions
73 lines (61 loc) · 1.89 KB
/
tailor.lua
File metadata and controls
73 lines (61 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
local _ENV = mkmodule('plugins.tailor')
local argparse = require('argparse')
local utils = require('utils')
local function process_args(opts, args)
if args[1] == 'help' then
opts.help = true
return
end
return argparse.processArgsGetopt(args, {
{'h', 'help', handler=function() opts.help = true end},
})
end
function status()
dfhack.print(('tailor is %s'):format(isEnabled() and "enabled" or "disabled"))
print((' %s confiscating tattered clothing'):format(tailor_getConfiscate() and "and" or "but not"))
print(('tailor %s automating dye'):format(tailor_getAutomateDye() and "is" or "is not"))
print('materials preference order:')
for _,name in ipairs(tailor_getMaterialPreferences()) do
print((' %s'):format(name))
end
end
function setMaterials(names)
local idxs = utils.invert(names)
tailor_setMaterialPreferences(
idxs.silk or -1,
idxs.cloth or -1,
idxs.yarn or -1,
idxs.leather or -1,
idxs.adamantine or -1)
end
function setConfiscate(opt)
local fl = argparse.boolean(opt[1], "set confiscate")
tailor_setConfiscate(fl)
end
function setAutomateDye(opt)
local fl = argparse.boolean(opt[1], "set dye")
tailor_setAutomateDye(fl)
end
function parse_commandline(...)
local args, opts = {...}, {}
local positionals = process_args(opts, args)
if opts.help then
return false
end
local command = table.remove(positionals, 1)
if not command or command == 'status' then
status()
elseif command == 'now' then
tailor_doCycle()
elseif command == 'materials' then
setMaterials(positionals)
elseif command == 'confiscate' then
setConfiscate(positionals)
elseif command == 'dye' then
setAutomateDye(positionals)
else
return false
end
return true
end
return _ENV