2023-02-06 19:38:16 -07:00
|
|
|
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()
|
2023-02-08 15:01:38 -07:00
|
|
|
print(('tailor is %s'):format(isEnabled() and "enabled" or "disabled"))
|
2023-02-06 19:38:16 -07:00
|
|
|
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,
|
2023-02-17 11:10:23 -07:00
|
|
|
idxs.leather or -1,
|
|
|
|
idxs.adamantine or -1)
|
2023-02-06 19:38:16 -07:00
|
|
|
end
|
|
|
|
|
2023-03-25 13:56:04 -06:00
|
|
|
function setDebugMode(opt)
|
|
|
|
local fl = (opt[1] == "true" or opt[1] == "on")
|
|
|
|
tailor_setDebugFlag(fl)
|
|
|
|
end
|
|
|
|
|
2023-02-06 19:38:16 -07:00
|
|
|
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)
|
2023-03-25 13:56:04 -06:00
|
|
|
elseif command == 'debugging' then
|
|
|
|
setDebugMode(positionals)
|
2023-02-06 19:38:16 -07:00
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return _ENV
|