Skip to content

Commit 58f77d0

Browse files
committed
add exports for layers and region pops
1 parent 8e88b02 commit 58f77d0

4 files changed

Lines changed: 113 additions & 15 deletions

File tree

‎docs/gui/export-world-map.rst‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ gui/export-world-map
55
:summary: Export world map data for GIS and other external tools.
66
:tags: inspection embark map
77

8-
This tool provides a GUI for the ``export-world-map`` plugin and a number of
8+
This tool provides a GUI for the `export-world-map` plugin and a number of
99
additional exports written in Lua. Moreover, this tool automates the process of
1010
scrolling around the embark map to generate the region tiles used for the
1111
exports.
1212

13+
The additional exports provided are:
14+
15+
* Roads and tunnels
16+
* Geological layers and the veins included in them (pure data layer)
17+
* Animal and plant populations of regions (pure data layer)
18+
1319
Usage
1420
-----
1521

‎gui/export-world-map.lua‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ local gui = require('gui')
44
local widgets = require('gui.widgets')
55

66
local roads = reqscript('internal/export-world-map/export-roads')
7+
local layers = reqscript('internal/export-world-map/export-layers')
8+
local pops = reqscript('internal/export-world-map/export-pops')
79

810
---@type df.viewscreen_choose_start_sitest
911
local viewscreen = dfhack.gui.getDFViewscreen(true)
@@ -80,8 +82,6 @@ local function invokeExport(by_world, by_date, fn)
8082
end
8183

8284
function ExportMap:startExports()
83-
self.subviews.indicator_label:setText("working ...")
84-
8585
local by_date = self.subviews.by_date:getOptionValue()
8686
local by_world = by_date or self.subviews.by_world:getOptionValue()
8787

@@ -90,8 +90,6 @@ function ExportMap:startExports()
9090
invokeExport(by_world, by_date, export.command)
9191
end
9292
end
93-
94-
self.subviews.indicator_label:setText("")
9593
end
9694

9795
---launch command from the C++ plugin
@@ -109,7 +107,9 @@ exports = {
109107
{ id = 2, key = 'rivers', desc = 'River Export (rivers.csv)' , enabled = true, command = pluginCommand("rivers") },
110108
{ id = 3, key = 'sites', desc = 'Site Export (sites.csv)' , enabled = true, command = pluginCommand("sites") },
111109
{ id = 4, key = 'elevation', desc = 'Elevation Grid Export (elevation.dat, elevation.vrt)' , enabled = true, command = pluginCommand("elevation") },
112-
{ id = 5, key = 'roads', desc = 'Road Export (roads.geojson)' , enabled = true, command = roads.export }
110+
{ id = 5, key = 'roads', desc = 'Road Export (roads.geojson)' , enabled = true, command = roads.export },
111+
{ id = 6, key = 'layers', desc = 'Export Geological Layers (layers.csv)' , enabled = true, command = layers.export },
112+
{ id = 7, key = 'pops', desc = 'Export Plant and Animal Populations (*_pops.csv)' , enabled = true, command = pops.export }
113113
}
114114

115115
local SELECTED_ICON = dfhack.pen.parse{ch=string.char(251), fg=COLOR_LIGHTGREEN}
@@ -158,7 +158,7 @@ function ExportMap:init()
158158
text = "Select exports to place in dfhack-config/map-export:",
159159
},
160160
widgets.List{
161-
frame={t=9, h = 6},
161+
frame={t=9, h = 7},
162162
view_id = "export_list",
163163
on_submit=self:callback("toggleExport"),
164164
icon_width = 2,
@@ -167,7 +167,7 @@ function ExportMap:init()
167167
widgets.CycleHotkeyLabel{
168168
view_id = 'by_world',
169169
key = 'CUSTOM_W',
170-
frame = { w = 40, h = 1 , t = 15, l = 0 },
170+
frame = { w = 40, h = 1 , t = 17, l = 0 },
171171
options = { { label = 'Yes' , value = true, pen = COLOR_LIGHTGREEN}, { label = 'No' , value = false} },
172172
initial_option = false,
173173
label = "Create folder for world name",
@@ -180,7 +180,7 @@ function ExportMap:init()
180180
widgets.CycleHotkeyLabel{
181181
view_id = 'by_date',
182182
key = 'CUSTOM_D',
183-
frame = { w = 40, h = 1 , t = 16, l = 0 },
183+
frame = { w = 40, h = 1 , t = 18, l = 0 },
184184
options = { { label = 'Yes' , value = true, pen = COLOR_LIGHTGREEN}, { label = 'No' , value = false} },
185185
initial_option = false,
186186
label = "Create subfolder for world date",
@@ -191,18 +191,13 @@ function ExportMap:init()
191191
end
192192
},
193193
widgets.TextButton{
194-
frame = { w = 18, h = 1 , t = 18 },
194+
frame = { w = 18, h = 1 , t = 20 },
195195
label = "Run Map Exports!",
196196
on_click = self:callback('startExports'),
197197
enabled = function()
198198
local cur,max = getLoadedTileRatio()
199199
return cur == max
200200
end
201-
},
202-
widgets.Label{
203-
view_id = 'indicator_label',
204-
frame={ t = 20 , h = 1 },
205-
text = ""
206201
}
207202
}
208203
self:updateRatio()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--@ module = true
2+
local util = reqscript('internal/export-world-map/util')
3+
4+
function writeOutput(out)
5+
local column_headers = "geo_index;type;material;top_height;bottom_height\n"
6+
out:write(column_headers)
7+
8+
for _, geo_biome in ipairs(df.global.world.world_data.geo_biomes) do
9+
for _, layer in ipairs(geo_biome.layers) do
10+
out:write(('%s;%s;%s;%s;%s\n'):format(
11+
geo_biome.index,
12+
"LAYER",
13+
df.inorganic_raw.find(layer.mat_index).id,
14+
layer.top_height,
15+
layer.bottom_height
16+
))
17+
for i = 0, #layer.vein_mat - 1 do
18+
local material = df.inorganic_raw[layer.vein_mat[i]]
19+
out:write(('%s;%s;%s;%s;%s\n'):format(
20+
geo_biome.index,
21+
df.inclusion_type[layer.vein_type[i]],
22+
df.inorganic_raw.find(layer.vein_mat[i]).id,
23+
layer.top_height,
24+
layer.bottom_height
25+
))
26+
end
27+
end
28+
end
29+
end
30+
31+
--- export geological layers
32+
function export(by_world, by_date)
33+
return function()
34+
local out = io.open(util.getOutputFolder(by_world, by_date).."layers.csv", 'w')
35+
writeOutput(out)
36+
out:close()
37+
end
38+
end
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--@ module = true
2+
local util = reqscript('internal/export-world-map/util')
3+
4+
local plants_filename = "plant_pops.csv"
5+
local creature_filename = "creature_pops.csv"
6+
local vermin_filename = "vermin_pops.csv"
7+
local column_headers = "region_id;population_type;raw_id;pop_count_min;pop_count_max\n"
8+
9+
function writeOutput(base_folder)
10+
local plants = io.open(base_folder..plants_filename, 'w')
11+
local creatures = io.open(base_folder..creature_filename, 'w')
12+
local vermin = io.open(base_folder..vermin_filename, 'w')
13+
14+
plants:write(column_headers)
15+
creatures:write(column_headers)
16+
vermin:write(column_headers)
17+
18+
for _, region in ipairs(df.global.world.world_data.regions) do
19+
for _, pop in ipairs(region.population) do
20+
local raw_id
21+
local out
22+
if pop.type >= 5 then
23+
raw_id = df.plant_raw.find(pop.plant).id
24+
out = plants
25+
else
26+
raw_id = df.creature_raw.find(pop.plant).creature_id
27+
if
28+
pop.type == df.world_population_type.Vermin or
29+
pop.type == df.world_population_type.VerminInnumerable
30+
then
31+
out = vermin
32+
else
33+
out = creatures
34+
end
35+
end
36+
37+
if out then
38+
out:write(('%s;%s;%s;%s;%s\n'):format(
39+
region.index,
40+
df.world_population_type[pop.type],
41+
raw_id,
42+
pop.count_min,
43+
pop.count_max
44+
))
45+
end
46+
end
47+
end
48+
49+
plants:close()
50+
vermin:close()
51+
creatures:close()
52+
end
53+
54+
--- export animal and plant populations
55+
function export(by_world, by_date)
56+
return function()
57+
writeOutput(util.getOutputFolder(by_world, by_date))
58+
end
59+
end

0 commit comments

Comments
 (0)