stockpiles: disable gui/script when plugin is disabled

develop
Casey Link 2014-12-05 13:27:58 +01:00
parent 0f06eb7f6f
commit 332566f6a1
3 changed files with 16 additions and 2 deletions

@ -7,6 +7,7 @@ local _ENV = mkmodule('plugins.stockpiles')
* stockpiles_list_settings(dir_path), list files in directory
* stockpiles_load(file), with full path
* stockpiles_save(file), with full path
* isEnabled()
--]]
--

@ -494,6 +494,12 @@ static std::vector<std::string> clean_dfstock_list ( const std::string &path )
return files;
}
static bool isEnabled( lua_State *L )
{
Lua::Push(L, is_enabled);
return 1;
}
static int stockpiles_list_settings ( lua_State *L )
{
auto path = luaL_checkstring ( L, 1 );

@ -2,6 +2,10 @@
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")
@ -9,6 +13,7 @@ function world_guard()
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")
@ -39,7 +44,10 @@ function usage()
print("")
end
if args.load then
if not check_enabled() then
qerror("Stockpiles plugin not enabled. Enable it with: enable stockpiles")
return
elseif args.load then
if not guard() then return end
stock.load_settings()
elseif args.save then
@ -52,4 +60,3 @@ elseif args.dir then
else
usage()
end