I'm trying to script exporting all site maps from legends mode, and I'm at a dead end. Can anyone help?
From the lua interpreter at main legends screen, "for k,v in pairs(vs.sites) do print(k); end" will print "0 \n 1 \n 2 \n..." for the number of sites in that world.
dfhack.gui.getCurViewscreen() returns "legends" for both the main screen, and also the site maps screen.
"'LEGENDS_EXPORT_MAP'" is the key for both the world map or whatever site map is selected, and I've confirmed this by changing the binding.
Any ideas? My current code - based on exportlegends - is below.
-- Export everything from legends mode
-- use "exportlegends maps" for detailed maps, or "exportlegends all" to also export legends
gui = require 'gui'
local args = {...}
local vs = dfhack.gui.getCurViewscreen()
local i = 1
local MAPS = {
"Standard biome+site map",
"Elevations including lake and ocean floors",
"Elevations respecting water level",
"Biome",
"Hydrosphere",
"Temperature",
"Rainfall",
"Drainage",
"Savagery",
"Volcanism",
"Current vegetation",
"Evil",
"Salinity",
"Structures/fields/roads/etc.",
"Trade",
"Nobility and Holdings",
"Diplomacy",
}
-- export information and XML ('p, x')
function export_legends_info()
print(' Exporting: world map/gen info')
gui.simulateInput(vs, 'LEGENDS_EXPORT_MAP')
print(' Exporting: legends xml')
gui.simulateInput(vs, 'LEGENDS_EXPORT_XML')
end
-- presses 'd' for detailed maps
function wait_for_legends_vs()
vs = dfhack.gui.getCurViewscreen()
if i <= #MAPS then
if df.viewscreen_legendsst:is_instance(vs) then
gui.simulateInput(vs, 'LEGENDS_EXPORT_DETAILED_MAP')
dfhack.timeout(10,'frames',wait_for_export_maps_vs)
else
dfhack.timeout(10,'frames',wait_for_legends_vs)
end
end
end
-- selects detailed map and export it
function wait_for_export_maps_vs()
vs = dfhack.gui.getCurViewscreen()
if dfhack.gui.getCurFocus() == "export_graphical_map" then
vs.sel_idx = i
print(' Exporting: '..MAPS[i]..' map')
gui.simulateInput(vs, 'SELECT')
i = i + 1
dfhack.timeout(10,'frames',wait_for_legends_vs)
else
dfhack.timeout(10,'frames',wait_for_export_maps_vs)
end
end
-- export site maps
function export_site_maps()
vs = dfhack.gui.getCurViewscreen()
-- not sure what selector is...
for k, v in pairs(vs.sites) do -- enumerates sites
end
print(' Attempting to export site maps...')
-- site maps use the same key as the world tile map (default 'p')
gui.simulateInput(vs, 'LEGENDS_EXPORT_MAP') --what should context be???
end
-- main()
if dfhack.gui.getCurFocus() == "legends" then
if args[1] == "all" then
export_legends_info()
wait_for_legends_vs()
--export_site_maps()
elseif args[1] == "info" then
wait_for_legends_vs()
elseif args[1] == "maps" then
wait_for_legends_vs()
elseif args[1] == "sites" then
export_site_maps()
else dfhack.printerr('Valid arguments are "all", "info", "maps" or "sites"')
end
else
dfhack.printerr('Not in main legends view')
end