Modulo:DossiersTable
Jump to navigation
Jump to search
La documentazione per questo modulo può essere creata in Modulo:DossiersTable/man
local p = {}
function p.dossierList( f )
local args = f:getParent().args
local elementWidth = tonumber(args.elementWidth) ~= nil and args.elementWidth or 180
local isSpecies = true
local species, modName, linkPrefix = '', nil, ''
local dossiers = {}
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 results = {}
for i=1, #dossiers do
table.insert(results, '<div style="display:inline-block;margin:1em">'..dossiers[i].d..'<div style="text-align:center">[[' .. dossiers[i].l .. (dossiers[i].ln and '|'..dossiers[i].ln or '') .. ']]</div></div>')
end
return table.concat(results)
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