stockpiles: integrate gui plugin into dfhack.init-example

develop
Casey Link 2014-12-02 20:23:12 +01:00
parent 1cde8cffa4
commit b6118d272c
3 changed files with 77 additions and 5 deletions

@ -72,9 +72,13 @@ keybinding add Ctrl-Shift-Z@dwarfmode/Default "stocks show"
# open an overview window summarising some stocks (dfstatus) # open an overview window summarising some stocks (dfstatus)
keybinding add Ctrl-Shift-I@dwarfmode/Default "gui/dfstatus" keybinding add Ctrl-Shift-I@dwarfmode/Default "gui/dfstatus"
# q->stockpile; p - copy & paste stockpiles # q->stockpile - copy & paste stockpiles
keybinding add Alt-P copystock keybinding add Alt-P copystock
# q->stockpile - load and save stockpile settings out of game
keybinding add Alt-L@dwarfmode/QueryBuilding/Some/Stockpile "gui/stockpiles -load"
keybinding add Alt-S@dwarfmode/QueryBuilding/Some/Stockpile "gui/stockpiles -save"
# q->workshop - duplicate the selected job # q->workshop - duplicate the selected job
keybinding add Ctrl-D job-duplicate keybinding add Ctrl-D job-duplicate
@ -189,7 +193,7 @@ enable search
enable automaterial enable automaterial
# Other interface improvement tools # Other interface improvement tools
enable dwarfmonitor mousequery automelt autotrade buildingplan resume trackstop zone stocks autochop enable dwarfmonitor mousequery automelt autotrade buildingplan resume trackstop zone stocks autochop stockpiles
# allow the fortress bookkeeper to queue jobs through the manager # allow the fortress bookkeeper to queue jobs through the manager
stockflow enable stockflow enable

@ -14,9 +14,13 @@ local gui = require 'gui'
local script = require 'gui.script' local script = require 'gui.script'
local persist = require 'persist-table' local persist = require 'persist-table'
if persist.GlobalTable.stockpiles == nil then function init()
if dfhack.isMapLoaded() then
if persist.GlobalTable.stockpiles == nil then
persist.GlobalTable.stockpiles = {} persist.GlobalTable.stockpiles = {}
persist.GlobalTable.stockpiles['settings_path'] = './stocksettings' persist.GlobalTable.stockpiles['settings_path'] = './stocksettings'
end
end
end end
function tablify(iterableObject) function tablify(iterableObject)
@ -28,6 +32,7 @@ function tablify(iterableObject)
end end
function load_settings() function load_settings()
init()
script.start(function() script.start(function()
local path = persist.GlobalTable.stockpiles['settings_path'] local path = persist.GlobalTable.stockpiles['settings_path']
local list = stockpiles_list_settings(path) local list = stockpiles_list_settings(path)
@ -40,6 +45,7 @@ function load_settings()
end end
function save_settings(stockpile) function save_settings(stockpile)
init()
script.start(function() script.start(function()
--local sp = dfhack.gui.geSelectedBuilding(true) --local sp = dfhack.gui.geSelectedBuilding(true)
local suggested = stockpile.name local suggested = stockpile.name
@ -55,6 +61,7 @@ function save_settings(stockpile)
end end
function manage_settings(sp) function manage_settings(sp)
init()
if not guard() then return false end if not guard() then return false end
script.start(function() script.start(function()
local list = {'Load', 'Save'} local list = {'Load', 'Save'}
@ -78,7 +85,13 @@ function guard()
end end
function set_path(path) function set_path(path)
init()
persist.GlobalTable.stockpiles['settings_path'] = path persist.GlobalTable.stockpiles['settings_path'] = path
end end
function get_path()
init()
return persist.GlobalTable.stockpiles['settings_path']
end
return _ENV return _ENV

@ -0,0 +1,55 @@
-- lave/load stockpile settings with a GUI
local stock = require 'plugins.stockpiles'
function world_guard()
if not dfhack.isMapLoaded() then
qerror("World is not loaded")
return false
end
return true
end
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: ")
print("-save to save the current stockpile")
print("-load to load settings into the current stockpile")
print("-dir set the default directory to save settings into")
if dfhack.isMapLoaded() then
print(" Current directory is: " .. stock.get_path())
end
print("")
end
if args.load then
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