Skip to content

Commit 434a7db

Browse files
authored
Merge pull request DFHack#1109 from myk002/myk_markdown
update markdown for adventure mode
2 parents 0d9404a + fd82121 commit 434a7db

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

docs/markdown.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ markdown
33

44
.. dfhack-tool::
55
:summary: Export displayed text to a Markdown file.
6-
:tags: dfhack items units
6+
:tags: adventure fort items units
77

88
Saves the description of a selected unit or item to a Markdown file encoded in
99
UTF-8.

markdown.lua

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,55 +80,63 @@ end
8080

8181
local log = getFileHandle()
8282

83+
local gps = df.global.gps
84+
local mi = df.global.game.main_interface
85+
8386
if item then
8487
-- Item processing
8588
local itemRawName = dfhack.items.getDescription(item, 0, true)
86-
local itemRawDescription = df.global.game.main_interface.view_sheets.raw_description
89+
local itemRawDescription = mi.view_sheets.raw_description
8790
log:write('### ' ..
8891
dfhack.df2utf(itemRawName) .. '\n\n#### Description: \n' .. reformat(dfhack.df2utf(itemRawDescription)) .. '\n')
8992
print('Exporting description of the ' .. itemRawName)
9093
elseif unit then
9194
-- Unit processing
9295
-- Simulate UI interactions to load data into memory (click through tabs). Note: Constant might change with DF updates/patches
96+
local is_adv = dfhack.world.isAdventureMode()
9397
local screen = dfhack.gui.getDFViewscreen()
9498
local windowSize = dfhack.screen.getWindowSize()
9599

96100
-- Click "Personality"
97-
local personalityWidthConstant = 48
98-
local personalityHeightConstant = 11
101+
local personalityWidthConstant = is_adv and 68 or 48
102+
local personalityHeightConstant = is_adv and 13 or 11
99103

100-
df.global.gps.mouse_x = windowSize - personalityWidthConstant
101-
df.global.gps.mouse_y = personalityHeightConstant
104+
gps.mouse_x = windowSize - personalityWidthConstant
105+
gps.mouse_y = personalityHeightConstant
102106

103107
gui.simulateInput(screen, '_MOUSE_L')
104108

105109
-- Click "Health"
106110
local healthWidthConstant = 74
107-
local healthHeightConstant = 13
111+
local healthHeightConstant = is_adv and 15 or 13
108112

109-
df.global.gps.mouse_x = windowSize - healthWidthConstant
110-
df.global.gps.mouse_y = healthHeightConstant
113+
gps.mouse_x = windowSize - healthWidthConstant
114+
gps.mouse_y = healthHeightConstant
111115

112116
gui.simulateInput(screen, '_MOUSE_L')
113117

114118
-- Click "Health/Description"
115-
local healthDescriptionWidthConstant = 51
116-
local healthDescriptionHeightConstant = 15
119+
local healthDescriptionWidthConstant = is_adv and 74 or 51
120+
local healthDescriptionHeightConstant = is_adv and 17 or 15
117121

118-
df.global.gps.mouse_x = windowSize - healthDescriptionWidthConstant
119-
df.global.gps.mouse_y = healthDescriptionHeightConstant
122+
gps.mouse_x = windowSize - healthDescriptionWidthConstant
123+
gps.mouse_y = healthDescriptionHeightConstant
120124

121125
gui.simulateInput(screen, '_MOUSE_L')
122126

123-
local unit_description_raw = df.global.game.main_interface.view_sheets.unit_health_raw_str[0].value
124-
local unit_personality_raw = df.global.game.main_interface.view_sheets.personality_raw_str
127+
local unit_description_raw = #mi.view_sheets.unit_health_raw_str > 0 and mi.view_sheets.unit_health_raw_str[0].value or ''
128+
local unit_personality_raw = mi.view_sheets.personality_raw_str
125129

126130
log:write('### ' ..
127131
dfhack.df2utf(getNameRaceAgeProf(unit)) ..
128-
'\n\n#### Description: \n' .. reformat(dfhack.df2utf(unit_description_raw)) .. '\n\n#### Personality: \n')
129-
for _, unit_personality in ipairs(unit_personality_raw) do
130-
log:write(reformat(dfhack.df2utf(unit_personality.value)) .. '\n')
132+
'\n\n#### Description: \n' .. reformat(dfhack.df2utf(unit_description_raw)) .. '\n')
133+
if #unit_personality_raw > 0 then
134+
log:write('\n#### Personality: \n')
135+
for _, unit_personality in ipairs(unit_personality_raw) do
136+
log:write(reformat(dfhack.df2utf(unit_personality.value)) .. '\n')
137+
end
131138
end
132139
print('Exporting Health/Description & Personality/Traits data for: \n' .. dfhack.df2console(getNameRaceAgeProf(unit)))
133140
end
141+
134142
closeFileHandle(log)

0 commit comments

Comments
 (0)