2014-07-09 04:21:52 -06:00
|
|
|
|
-- scripts/forum-dwarves.lua
|
2014-06-26 06:36:57 -06:00
|
|
|
|
-- Save a copy of a text screen for the DF forums. Use 'forumdwarves help' for more details.
|
|
|
|
|
-- original author: Caldfir
|
2014-09-26 17:36:12 -06:00
|
|
|
|
-- edited by expwnent, Mchl
|
2014-06-26 06:36:57 -06:00
|
|
|
|
|
|
|
|
|
local args = {...}
|
|
|
|
|
|
2014-11-15 13:33:48 -07:00
|
|
|
|
if args[1] == 'help' then
|
2014-06-26 06:36:57 -06:00
|
|
|
|
print([[
|
|
|
|
|
description:
|
2015-02-14 20:53:06 -07:00
|
|
|
|
This script will attempt to read the current df-screen, and if it is a
|
|
|
|
|
text-viewscreen (such as the dwarf 'thoughts' screen or an item
|
|
|
|
|
'description') then append a marked-up version of this text to the
|
|
|
|
|
target file. Previous entries in the file are not overwritten, so you
|
|
|
|
|
may use the 'forumdwarves' command multiple times to create a single
|
|
|
|
|
document containing the text from multiple screens (eg: text screens
|
|
|
|
|
from several dwarves, or text screens from multiple artifacts/items,
|
2014-11-15 13:33:48 -07:00
|
|
|
|
or some combination).
|
2014-06-26 06:36:57 -06:00
|
|
|
|
known screens:
|
2015-02-14 20:53:06 -07:00
|
|
|
|
The screens which have been tested and known to function properly with
|
2014-06-26 06:36:57 -06:00
|
|
|
|
this script are:
|
|
|
|
|
1: dwarf/unit 'thoughts' screen
|
|
|
|
|
2: item/art 'description' screen
|
|
|
|
|
3: individual 'historical item/figure' screens
|
2015-02-14 20:53:06 -07:00
|
|
|
|
There may be other screens to which the script applies. It should be
|
|
|
|
|
safe to attempt running the script with any screen active, with an
|
2014-06-26 06:36:57 -06:00
|
|
|
|
error message to inform you when the selected screen is not appropriate
|
|
|
|
|
for this script.
|
|
|
|
|
target file:
|
|
|
|
|
The target file's name is 'forumdwarves.txt'. A remider to this effect
|
2014-11-15 13:33:48 -07:00
|
|
|
|
will be displayed if the script is successful.
|
2014-06-26 06:36:57 -06:00
|
|
|
|
character encoding:
|
2015-02-14 20:53:06 -07:00
|
|
|
|
The text will likely be using system-default encoding, and as such
|
|
|
|
|
will likely NOT display special characters (eg:È,ı,Á) correctly. To
|
|
|
|
|
fix this, you need to modify the character set that you are reading
|
|
|
|
|
the document with. 'Notepad++' is a freely available program which
|
2014-06-26 06:36:57 -06:00
|
|
|
|
can do this using the following steps:
|
|
|
|
|
1: open the document in Notepad++
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2: in the menu-bar, select
|
2014-06-26 06:36:57 -06:00
|
|
|
|
Encoding->Character Sets->Western European->OEM-US
|
|
|
|
|
3: copy the text normally to wherever you want to use it
|
|
|
|
|
]])
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local utils = require 'utils'
|
|
|
|
|
local gui = require 'gui'
|
|
|
|
|
local dialog = require 'gui.dialogs'
|
|
|
|
|
local colors_css = {
|
2014-11-15 13:33:48 -07:00
|
|
|
|
[0] = 'black',
|
|
|
|
|
[1] = 'navy',
|
|
|
|
|
[2] = 'green',
|
|
|
|
|
[3] = 'teal',
|
|
|
|
|
[4] = 'maroon',
|
|
|
|
|
[5] = 'purple',
|
|
|
|
|
[6] = 'olive',
|
|
|
|
|
[7] = 'silver',
|
|
|
|
|
[8] = 'gray',
|
|
|
|
|
[9] = 'blue',
|
|
|
|
|
[10] = 'lime',
|
|
|
|
|
[11] = 'cyan',
|
|
|
|
|
[12] = 'red',
|
|
|
|
|
[13] = 'magenta',
|
|
|
|
|
[14] = 'yellow',
|
2014-06-26 06:36:57 -06:00
|
|
|
|
[15] = 'white'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local scrn = dfhack.gui.getCurViewscreen()
|
|
|
|
|
local flerb = dfhack.gui.getFocusString(scrn)
|
|
|
|
|
|
|
|
|
|
local function format_for_forum(strin)
|
|
|
|
|
local strout = strin
|
2015-02-14 20:53:06 -07:00
|
|
|
|
|
2014-06-26 06:36:57 -06:00
|
|
|
|
local newline_idx = string.find(strout, '[P]', 1, true)
|
|
|
|
|
while newline_idx ~= nil do
|
|
|
|
|
strout = string.sub(strout,1, newline_idx-1)..'\n'..string.sub(strout,newline_idx+3)
|
|
|
|
|
newline_idx = string.find(strout, '[P]', 1, true)
|
|
|
|
|
end
|
2015-02-14 20:53:06 -07:00
|
|
|
|
|
2014-06-26 06:36:57 -06:00
|
|
|
|
newline_idx = string.find(strout, '[B]', 1, true)
|
|
|
|
|
while newline_idx ~= nil do
|
|
|
|
|
strout = string.sub(strout,1, newline_idx-1)..'\n'..string.sub(strout,newline_idx+3)
|
|
|
|
|
newline_idx = string.find(strout, '[B]', 1, true)
|
|
|
|
|
end
|
2015-02-14 20:53:06 -07:00
|
|
|
|
|
2014-06-26 06:36:57 -06:00
|
|
|
|
newline_idx = string.find(strout, '[R]', 1, true)
|
|
|
|
|
while newline_idx ~= nil do
|
|
|
|
|
strout = string.sub(strout,1, newline_idx-1)..'\n'..string.sub(strout,newline_idx+3)
|
|
|
|
|
newline_idx = string.find(strout, '[R]', 1, true)
|
|
|
|
|
end
|
2015-02-14 20:53:06 -07:00
|
|
|
|
|
2014-06-26 06:36:57 -06:00
|
|
|
|
local color_idx = string.find(strout, '[C:', 1, true)
|
2014-11-15 13:33:48 -07:00
|
|
|
|
while color_idx ~= nil do
|
2014-06-26 06:36:57 -06:00
|
|
|
|
local colormatch = (string.byte(strout, color_idx+3)-48)+((string.byte(strout, color_idx+7)-48)*8)
|
|
|
|
|
strout = string.sub(strout,1, color_idx-1)..'[/color][color='..colors_css[colormatch]..']'..string.sub(strout,color_idx+9)
|
|
|
|
|
color_idx = string.find(strout, '[C:', 1, true)
|
|
|
|
|
end
|
2015-02-14 20:53:06 -07:00
|
|
|
|
|
2014-06-26 06:36:57 -06:00
|
|
|
|
return strout
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if flerb == 'textviewer' then
|
|
|
|
|
print(scrn)
|
|
|
|
|
printall(scrn)
|
2014-11-01 15:28:08 -06:00
|
|
|
|
local lines = scrn.src_text
|
2014-06-26 06:36:57 -06:00
|
|
|
|
local line = ""
|
2015-02-14 20:53:06 -07:00
|
|
|
|
|
2014-06-26 06:36:57 -06:00
|
|
|
|
if lines ~= nil then
|
|
|
|
|
local log = io.open('forumdwarves.txt', 'a')
|
|
|
|
|
log:write("[color=silver]")
|
2014-09-26 17:36:12 -06:00
|
|
|
|
log:write(scrn.title)
|
2014-11-15 13:33:48 -07:00
|
|
|
|
for n,x in ipairs(lines) do
|
2014-06-26 06:36:57 -06:00
|
|
|
|
print(x)
|
|
|
|
|
printall(x)
|
2014-09-26 17:36:12 -06:00
|
|
|
|
print(x.value)
|
|
|
|
|
printall(x.value)
|
2014-11-15 13:33:48 -07:00
|
|
|
|
if (x ~= nil) and (x.value ~= nil) then
|
|
|
|
|
log:write(format_for_forum(x.value), ' ')
|
|
|
|
|
--log:write(x[0],'\n')
|
|
|
|
|
end
|
2014-06-26 06:36:57 -06:00
|
|
|
|
end
|
|
|
|
|
log:write("[/color]\n")
|
|
|
|
|
log:close()
|
|
|
|
|
end
|
|
|
|
|
print 'data prepared for forum in \"forumdwarves.txt\"'
|
|
|
|
|
else
|
|
|
|
|
print 'this is not a textview screen'
|
|
|
|
|
end
|