Module:DossiersTable

From ARK Wiki
Jump to navigation Jump to search
Template-info.png Documentation

For displaying dossiers, e.g. the newest ones on the mainpage

Parameters are pairs of:

  • Name of the Creature.
    • If the species is part of a mod, the following format is required: Mod:[ModName]:[Species], e.g. Mod:ARK Additions:Brachiosaurus (note the extra colon between the modName and the speciesName which should not be in the page-name). The expected file of the dossier needs to be saved at File:Mod [ModName] Dossier [SpeciesName].png
  • Dossier-Filename, or the special value Book which uses the expected dossier-filename (File:Dossier_<species>.png) to show the bare dossier with a book as background.
  • the optional named parameter elementWidth can be used to specify the width in px of each dossier-element. If not specified, the default value of 180 will be used.

Example

{{DossiersTable|Basilisk|Book|Bulbdog|Book|Featherlight|Book|Glowbug|Book}}
{{DossiersTable| elementWidth = 300|Basilisk|Book|Bulbdog|Book|Featherlight|Book|Glowbug|Book|Ankylosaurus|Book}}
{{DossiersTable|Mod:ARK Additions:Brachiosaurus|Book}}

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, string.format(
    	'<div style="display:inline-block;margin:1em">%s<div style="text-align:center">[[%s%s]]</div></div>',
    	dossiers[i].d,
    	dossiers[i].l,
    	( dossiers[i].ln and '|' .. dossiers[i].ln or '' )
    ) )
  end

  return string.format( '<div class="dossiers-table">%s</div>', 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