Builds an infobox for a conservation animal page.
Documentation
Package function
p.buildInfobox(frame)(function)- Builds an infobox for a conservation animal page.
- Parameter:
frameFrame object or animal name if calling within other modules (table) - Returns: Resultant wikitext of infobox element (string)
- Created with Docbunto
See Also
Code
local ConservationData = require('Module:Conservation/data')
local Infobox = require('Module:InfoboxBuilder')
local Version = require('Module:Version')
return {
--- Builds an infobox for a conservation animal page.
-- @function p.buildInfobox
-- @param {table} frame Frame object or animal name if calling within other modules
-- @returns {string} Resultant wikitext of infobox element
buildInfobox = function(frame)
local animalName = frame.args and frame.args[1] or frame
assert(animalName, 'p.buildInfoBox(frame): empty frame arguments')
local animal = ConservationData['Animals'][animalName] or
error('p.buildInfoBox(frame): "'..animalName..'" does not exist in [[Module:Conservation/data]]')
local image = ''
do
local images = { animal.FullImg, animal.CodexImg, animal.InGameImg, animal.OtherImg }
local imagesize = 0
for i, v in pairs(images) do
imagesize = imagesize + 1
end
if imagesize > 1 then
local map = { 'Full', 'Codex', 'In-game', 'Other' }
image = { '<gallery>' }
for i, v in pairs(images) do
table.insert(image, ('%s|%s'):format(v,map[i]))
end
table.insert(image, '</gallery>')
image = table.concat(image, '\n')
else
if imagesize == 1 then
for i, v in pairs(images) do
image = v
break
end
end
end
end
local age = ('%d year%s %d month%s - <br />%d year%s %d month%s')
:format(
animal.MinAge.Year, animal.MinAge.Year == 1 and '' or 's',
animal.MinAge.Month, animal.MinAge.Month == 1 and '' or 's',
animal.MaxAge.Year, animal.MaxAge.Year == 1 and '' or 's',
animal.MaxAge.Month, animal.MaxAge.Month == 1 and '' or 's',
nil)
local infobox = Infobox('WARFRAME Wiki:L10n/general.json', 'WARFRAME Wiki:L10n/meta.json')
:tag('title')
:tag('default'):tag('b'):wikitext(animalName):done():done()
:done()
:tag('image')
:tag('default'):wikitext(image or 'Panel.png'):done()
:done()
:group()
:caption('UpdateInfoboxData', '[[Module:Conservation/data|📝 %s]]', 'update-infobox-data')
:done()
:header('%s', 'general-information')
:row('TranqsNeeded', 'Tranq Shots Needed', animal.TranqsNeeded or 1)
:row('Origin', 'Origin', animal.Origin or 'Unknown')
:row('Introduced', '%s', Version.getVersionLink(animal.Introduced) or '?', 'introduced')
:row('Faction', '%s', animal.Faction or 'Wild', 'faction')
:group():header('%s', 'statistics')
:row('Health', '[[Health]]', animal.Health or '?')
:row('Armor', '[[Armor]]', animal.Armor or '?')
:row('ArmorDR', 'Dmg. Reduction', ('%.0f%%'):format(100 * (animal.Armor / (animal.Armor + 300) ) ) )
:row('Weight', 'Weight', animal.MinWeight..' kg - '..animal.MaxWeight..' kg')
:row('Age', 'Age', age)
:done()
:group():header('%s', 'miscellaneous')
:row('CodexScans', '[[Codex]] Scan', animal.CodexScans or '?')
:header(animal.Call and 'Call')
:caption('CallFile', animal.Call and '[[File:'..animal.Call..']]' or 'N/A')
:done()
return animalEntry and tostring(infobox) or frame:preprocess(tostring(infobox))
end
}