split autobutcher out from zone

develop
myk002 2022-08-02 01:07:13 -07:00
parent 0096f7c882
commit 3f61e2302c
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
5 changed files with 1437 additions and 1798 deletions

@ -83,6 +83,7 @@ if(BUILD_SUPPORTED)
dfhack_plugin(3dveins 3dveins.cpp)
dfhack_plugin(add-spatter add-spatter.cpp)
# dfhack_plugin(advtools advtools.cpp)
dfhack_plugin(autobutcher autobutcher.cpp LINK_LIBRARIES lua)
dfhack_plugin(autochop autochop.cpp)
dfhack_plugin(autoclothing autoclothing.cpp)
dfhack_plugin(autodump autodump.cpp)
@ -178,7 +179,7 @@ if(BUILD_SUPPORTED)
dfhack_plugin(workflow workflow.cpp LINK_LIBRARIES lua)
dfhack_plugin(workNow workNow.cpp)
dfhack_plugin(xlsxreader xlsxreader.cpp LINK_LIBRARIES lua xlsxio_read_STATIC zip expat)
dfhack_plugin(zone zone.cpp LINK_LIBRARIES lua)
dfhack_plugin(zone zone.cpp)
# If you are adding a plugin that you do not intend to commit to the DFHack repo,
# see instructions for adding "external" plugins at the end of this file.

File diff suppressed because it is too large Load Diff

@ -0,0 +1,89 @@
local _ENV = mkmodule('plugins.autobutcher')
--[[
Native functions:
* autobutcher_isEnabled()
* autowatch_isEnabled()
--]]
local argparse = require('argparse')
local function is_int(val)
return val and val == math.floor(val)
end
local function is_positive_int(val)
return is_int(val) and val > 0
end
local function check_nonnegative_int(str)
local val = tonumber(str)
if is_positive_int(val) or val == 0 then return val end
qerror('expecting a non-negative integer, but got: '..tostring(str))
end
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
local function process_races(opts, races, start_idx)
if #races < start_idx then
qerror('missing list of races (or "all" or "new" keywords)')
end
for i=start_idx,#races do
local race = races[i]
if race == 'all' then
opts.races_all = true
elseif race == 'new' then
opts.races_new = true
else
local str = df.new('string')
str.value = race
opts.races:insert('#', str)
end
end
end
function parse_commandline(opts, ...)
local positionals = process_args(opts, {...})
local command = positionals[1]
if command then opts.command = command end
if opts.help or not command or command == 'now' or
command == 'autowatch' or command == 'noautowatch' or
command == 'list' or command == 'list_export' then
return
end
if command == 'watch' or command == 'unwatch' or command == 'forget' then
process_races(opts, positionals, 2)
elseif command == 'target' then
opts.fk = check_nonnegative_int(positionals[2])
opts.mk = check_nonnegative_int(positionals[3])
opts.fa = check_nonnegative_int(positionals[4])
opts.ma = check_nonnegative_int(positionals[5])
process_races(opts, positionals, 6)
elseif command == 'ticks' then
local ticks = tonumber(positionals[2])
if not is_positive_int(arg) then
qerror('number of ticks must be a positive integer: ' .. ticks)
else
opts.ticks = ticks
end
else
qerror(('unrecognized command: "%s"'):format(command))
end
end
return _ENV

@ -1,12 +0,0 @@
local _ENV = mkmodule('plugins.zone')
--[[
Native functions:
* autobutcher_isEnabled()
* autowatch_isEnabled()
--]]
return _ENV

File diff suppressed because it is too large Load Diff