2014-12-02 12:23:12 -07:00
|
|
|
-- lave/load stockpile settings with a GUI
|
|
|
|
|
|
|
|
local stock = require 'plugins.stockpiles'
|
|
|
|
|
2014-12-05 05:27:58 -07:00
|
|
|
function check_enabled()
|
|
|
|
return stock.isEnabled()
|
|
|
|
end
|
|
|
|
|
2014-12-02 12:23:12 -07:00
|
|
|
function world_guard()
|
|
|
|
if not dfhack.isMapLoaded() then
|
|
|
|
qerror("World is not loaded")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
2014-12-05 05:27:58 -07:00
|
|
|
|
2014-12-02 12:23:12 -07:00
|
|
|
function guard()
|
|
|
|
if not string.match(dfhack.gui.getCurFocus(), '^dwarfmode/QueryBuilding/Some/Stockpile') then
|
|
|
|
qerror("This script requires a stockpile selected in the 'q' mode")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
utils = require('utils')
|
|
|
|
validArgs = validArgs or utils.invert({
|
|
|
|
'help',
|
|
|
|
'load',
|
|
|
|
'save',
|
|
|
|
'dir',
|
|
|
|
})
|
|
|
|
|
|
|
|
args = utils.processArgs({...}, validArgs)
|
|
|
|
|
|
|
|
function usage()
|
|
|
|
print("")
|
|
|
|
print("Stockpile Settings. Arguments: ")
|
2014-12-02 12:29:42 -07:00
|
|
|
print("-save to save the current stockpile")
|
|
|
|
print("-load to load settings into the current stockpile")
|
|
|
|
print("-dir <path> set the default directory to save settings into")
|
2014-12-02 12:23:12 -07:00
|
|
|
if dfhack.isMapLoaded() then
|
2014-12-02 12:29:42 -07:00
|
|
|
print(" Current directory is: " .. stock.get_path())
|
2014-12-02 12:23:12 -07:00
|
|
|
end
|
|
|
|
print("")
|
|
|
|
end
|
|
|
|
|
2014-12-05 05:27:58 -07:00
|
|
|
if not check_enabled() then
|
|
|
|
qerror("Stockpiles plugin not enabled. Enable it with: enable stockpiles")
|
|
|
|
elseif args.load then
|
2014-12-02 12:23:12 -07:00
|
|
|
if not guard() then return end
|
|
|
|
stock.load_settings()
|
|
|
|
elseif args.save then
|
|
|
|
if not guard() then return end
|
|
|
|
local sp = dfhack.gui.getSelectedBuilding(true)
|
|
|
|
stock.save_settings(sp)
|
|
|
|
elseif args.dir then
|
|
|
|
if not world_guard() then return end
|
|
|
|
stock.set_path(args.dir)
|
|
|
|
else
|
|
|
|
usage()
|
|
|
|
end
|