Skip to content

Commit f7d2eb7

Browse files
committed
Update scripts/markdown.lua to work with 'announcelist' screens (most notably announcements and combat reports)
1 parent 2b3d034 commit f7d2eb7

1 file changed

Lines changed: 67 additions & 1 deletion

File tree

markdown.lua

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ local dialog = require 'gui.dialogs'
5050
local scrn = dfhack.gui.getCurViewscreen()
5151
local flerb = dfhack.gui.getFocusString(scrn)
5252

53+
local months = {
54+
[1] = 'Granite',
55+
[2] = 'Slate',
56+
[3] = 'Felsite',
57+
[4] = 'Hematite',
58+
[5] = 'Malachite',
59+
[6] = 'Galena',
60+
[7] = 'Limestone',
61+
[8] = 'Sandstone',
62+
[9] = 'Timber',
63+
[10] = 'Moonstone',
64+
[11] = 'Opal',
65+
[12] = 'Obsidian',
66+
}
5367

5468
local function reformat(strin)
5569
local strout = strin
@@ -85,6 +99,34 @@ local function reformat(strin)
8599
return strout
86100
end
87101

102+
local function formattime(year, ticks)
103+
-- Dwarf Mode month is 33600 ticks long
104+
local month = math.floor(ticks / 33600)
105+
local dayRemainder = ticks - month * 33600
106+
107+
-- Dwarf Mode day is 1200 ticks long
108+
local day = math.floor(dayRemainder / 1200)
109+
local timeRemainder = dayRemainder - day * 1200
110+
111+
-- Assuming a 24h day each Dwarf Mode tick corresponds to 72 seconds
112+
local seconds = timeRemainder * 72
113+
114+
local H = string.format("%02.f", math.floor(seconds / 3600));
115+
local m = string.format("%02.f", math.floor(seconds / 60 - (H * 60)));
116+
local i = string.format("%02.f", math.floor(seconds - H * 3600 - m * 60));
117+
118+
day = day + 1
119+
if (day == 1 or day == 21) then
120+
day = day .. 'st'
121+
elseif (day == 2 or day == 22) then
122+
day = day .. 'nd'
123+
else
124+
day = day .. 'th'
125+
end
126+
127+
return (day .. " " .. months[month + 1] .. " " .. year .. " " .. H .. ":" .. m..":" .. i)
128+
end
129+
88130
if flerb == 'textviewer' then
89131

90132
local lines = scrn.src_text
@@ -106,6 +148,30 @@ if flerb == 'textviewer' then
106148
log:close()
107149
end
108150
print 'Data exported to "markdownexport.txt"'
151+
152+
elseif flerb == 'announcelist' then
153+
154+
local lines = scrn.reports
155+
156+
if lines ~= nil then
157+
local log = io.open('markdownexport.txt', 'a')
158+
local lastTime = ""
159+
160+
for n,x in ipairs(lines) do
161+
local currentTime = formattime(x.year, x.time)
162+
if (currentTime ~= lastTime) then
163+
lastTime = currentTime
164+
log:write('\n***\n\n')
165+
log:write('## ' .. currentTime .. '\n')
166+
end
167+
-- debug output
168+
-- print(x.text)
169+
log:write(x.text .. '\n')
170+
end
171+
172+
log:close()
173+
end
174+
print 'Data exported to "markdownexport.txt"'
109175
else
110-
print 'This is not a textview screen. Can\'t export data, sorry.'
176+
print 'This is not a textview nor a announcelist screen. Can\'t export data, sorry.'
111177
end

0 commit comments

Comments
 (0)