Module:Infobox Rock
Documentation for this module may be created at Module:Infobox Rock/doc
--------------------------
-- Module for [[Template:Infobox Rock]]
------------------------
local p = {}
local onmain = require('Module:Mainonly').on_main
local infobox = require('Module:Infobox')
function p.main(frame)
local args = frame:getParent().args
local ret = infobox.new(args)
ret:defineParams{
{ name = 'name', func = 'name'},
{ name = 'image', func = 'image' },
{ name = 'release', func = 'release' },
{ name = 'members', func = 'has_content' },
{ name = 'ore', func = 'has_content' },
{ name = 'level', func = 'has_content' },
{ name = 'xp', func = xp_arg },
{ name = 'fatigue', func = { name = fatigue_arg, params = { 'xp' } } },
{ name = 'respawn', func = 'has_content' },
{ name = 'examine', func = 'has_content' },
{ name = 'id', func = 'has_content' },
{ name = 'id_smw', func = { name = idsmw, params = { 'id' }, flag = 'p' } },
}
ret:defineLinks({ hide = true })
ret:useSMWSubobject{
members = 'Is members only',
id_smw = 'Object ID',
}
ret:customButtonPlacement(true)
ret:create()
ret:cleanParams()
ret:addButtonsCaption()
ret:defineName('Infobox Rock')
ret:addClass('infobox-rock')
ret:addRow{
{ tag = 'argh', content = 'name', class='infobox-header', colspan = '20' }
}
:pad(20)
:addRow{
{ tag = 'argd', content = 'image', class='infobox-image infobox-full-width-content', colspan = '20' }
}
:pad(20)
:addRow{
{ tag = 'th', content = 'Released', colspan = '7' },
{ tag = 'argd', content = 'release', colspan = '13' }
}
:addRow{
{ tag = 'th', content = 'Members', colspan = '7' },
{ tag = 'argd', content = 'members', colspan = '13' }
}
:addRow{
{ tag = 'th', content = 'Ore', colspan= '7' },
{ tag = 'argd', content = 'ore', colspan = '13' }
}
:addRow{
{ tag = 'th', content = '[[Mining]] level', colspan= '7' },
{ tag = 'argd', content = 'level', colspan = '13' }
}
:addRow{
{ tag = 'th', content = 'Experience', colspan= '7' },
{ tag = 'argd', content = 'xp', colspan = '13' }
}
:addRow{
{ tag = 'th', content = 'Fatigue', colspan= '7' },
{ tag = 'argd', content = 'fatigue', colspan = '13' }
}
:addRow{
{ tag = 'th', content = 'Respawn rate', colspan= '7' },
{ tag = 'argd', content = 'respawn', colspan = '13' }
}
:addRow{
{ tag = 'th', content = '[[Examine]]', colspan= '7' },
{ tag = 'argd', content = 'examine', colspan = '13' }
}
:pad(20)
:addRow{
{ tag = 'th', content = 'Advanced data', class = 'infobox-subheader', colspan = '20' },
meta = {addClass = 'advanced-data'}
}
:pad(20, 'advanced-data')
:addRow{
{ tag = 'th', content = 'Object ID', colspan = '7' },
{ tag = 'argd', content = 'id', colspan = '13' },
meta = {addClass = 'advanced-data'}
}
ret:pad(20, 'advanced-data')
if onmain() then
local a1 = ret:param('all')
local a2 = ret:categoryData()
ret:wikitext(addcategories(a1, a2))
end
return ret:tostring()
end
function xp_arg(arg)
if not infobox.isDefined(arg) then
return nil
end
return tonumber(arg)
end
-- Calculate fatigue percentage based on xp
function fatigue_arg(xp)
if not infobox.isDefined(xp) then
return nil
end
local fatigue = xp * 16 / 750
local rounded = math.floor(fatigue * 1000) / 1000
return rounded..'%'
end
function idsmw(id)
if infobox.isDefined(id) then
local r = string.gsub(id, ',', '&&SPLITPOINT&&')
return r
end
return nil
end
function addcategories(args, catargs)
local ret = { 'Rocks', 'Scenery' }
-- Add the associated category if the parameter doesn't have content
local notdefined_args = {
image = 'Needs image',
members = 'Needs members status',
release = 'Needs release date',
examine = 'Needs examine added',
id = 'Needs ID',
}
for n, v in pairs(notdefined_args) do
if catargs[n] and catargs[n].all_defined == false then
table.insert(ret, v)
end
end
-- combine table and format category wikicode
for i, v in ipairs(ret) do
if (v ~= '') then
ret[i] = string.format('[[Category:%s]]', v)
end
end
return table.concat(ret, '')
end
return p