Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:TabelaDokumentacji/opis
local p = {}
function p.dossierList( f )
local args = f:getParent().args
local dossiers = {}
local columnsCount = tonumber(args.columnsCount) ~= nil and args.columnsCount or 2
local elementWidth = tonumber(args.elementWidth) ~= nil and args.elementWidth or 180
local isSpecies = true
local species, modName, linkPrefix = '', nil, ''
for _,arg in ipairs(args) do
if isSpecies then
-- if species is part of a mod, the species is expected to have the format "Mod:[ModName]:[Species]"
modName, species = string.match(arg, '^Mod:([^:]+):(.+)$')
if species == nil then
species = arg
linkPrefix = ''
else
linkPrefix = 'Mod:'..modName..' '
end
else
local link = linkPrefix..species
local linkName = species
if linkPrefix == '' then linkName = nil end
if arg == 'Book' then
table.insert(dossiers, {d = p.dossierImage(species, elementWidth, species, modName), l = link, ln = linkName})
else
table.insert(dossiers, {d = '[[File:'..arg..'|center|'..elementWidth..'px|link='..link..']]', l = link, ln = linkName})
end
end
isSpecies = not isSpecies
end
local result = ''
for i=1, #dossiers, columnsCount do
result = result .. '<tr>'
for ii = 0, columnsCount - 1 do
local iii = ii + i
if iii < #dossiers + 1 then
result = result .. '<td style="text-align:center">' .. dossiers[iii].d .. '</td>'
end
end
result = result .. '</tr><tr>'
for ii = 0, columnsCount - 1 do
local iii = ii + i
if iii < #dossiers + 1 then
result = result .. '<td style="text-align:center">[[' .. dossiers[iii].l .. (dossiers[iii].ln and '|'..dossiers[iii].ln or '') .. ']]</td>'
end
end
result = result .. '</tr>'
end
return '<table style="margin: 1em auto;">'
.. result
..'</table>'
end
function p.dossierImage(species,width,link,modName)
local modFilePrefix, modSpeciesNamePrefix = '', ''
if modName ~= nil then
-- set modName to the prefix that all mod-files should use
modFilePrefix = 'Mod '..modName..' '
-- set modSpeciesNamePrefix to the prefix that all mod species should have
modSpeciesNamePrefix = 'Mod:'..modName..' '
end
-- grab species name from file name File:Dossier Species.png or Dossier Species.png or use parameter
local diname = string.match(species, '^File:Dossier[ _]([^.]*)%.png$')
if diname == nil then
diname = string.match(species, '^Dossier[ _]([^.]*)%.png$')
end
if diname == nil then
diname = species
end
if width == nil then
width = 4000
end
width = string.match(width, '%d*') -- only the digits from second parameter
local height = math.floor(width * 2660 / 4000 + 0.5) -- scaled height according to requested width
if link == nil then -- check for link
link = ''
else
link = '|link='..modSpeciesNamePrefix..link
end
local result = '<span style="display:inline-block;position:relative;width:'..width..'px;height:'..height..'px;">' -- container with size
.. '<span style="position:absolute;top:0;left:0;">[[File:Dossier_Empty.png|'..width..'px|link=]]</span>' -- book as background
.. '<span style="position:absolute;top:0;left:0;">[[File:'..modFilePrefix..'Dossier_'..diname..'.png|'..width..'px'..link..']]</span>' -- dossier pages of the creature
.. '</span>'
return result
end
return p