-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathstockpiles.lua
74 lines (62 loc) · 1.83 KB
/
stockpiles.lua
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
74
-- lave/load stockpile settings with a GUI
local helpstr = [====[
gui/stockpiles
==============
An in-game interface for `stocksettings`, to
load and save stockpile settings from the :kbd:`q` menu.
Usage:
:gui/stockpiles -save: to save the current stockpile
:gui/stockpiles -load: to load settings into the current stockpile
:gui/stockpiles -dir <path>: set the default directory to save settings into
:gui/stockpiles -help: to see this message
Don't forget to ``enable stockpiles`` and create the ``stocksettings`` directory in
the DF folder before trying to use the GUI.
]====]
local stock = require 'plugins.stockpiles'
function check_enabled()
return stock.isEnabled()
end
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(helpstr)
if dfhack.isMapLoaded() then
print(" Current directory is: " .. stock.get_path())
end
print("")
end
if not check_enabled() then
qerror("Stockpiles plugin not enabled. Enable it with: enable stockpiles")
elseif 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