Module:Skill
Jump to navigation
Jump to search
Module used by Template:Skill to do a cargo query and display a little infobox about the skills.
The above documentation is transcluded from Module:Skill/doc. (edit | history)
local p = {}
function p.main(frame)
if frame == mw.getCurrentFrame() then
args = require('Module:ProcessArgs').merge(true)
else
frame = mw.getCurrentFrame()
end
if (args.name == nil or args.name == '') then
return frame:preprocess('<span style="color:red">Error! You must enter a <code>name</code> parameter!</span>')
end
local skill = args.name or ''
local result = mw.ext.cargo.query(
'Skills',
'_pageName, name, image, cooldown, consumes, cost, skilltype, skilltier',
{
where = '_pageName="' .. skill .. '"',
limit = 1
}
)
if not (result[1]) then
return frame:preprocess('<span style="color:red">Error! Could not get data for '.. skill ..'!</span>')
end
local descResult = mw.ext.cargo.query(
'Descriptions',
'_pageName, description',
{
where = '_pageName="' .. skill .. '"',
limit = 1
}
)
if not (descResult[1]) then
return frame:preprocess('<span style="color:red">Error! Could not get description for '.. skill ..'!</span>')
end
-- our Query results
local skillData = result[1]
local desc = descResult[1].description
-- Build the HTML
local html = mw.html.create()
local mainStyle = 'padding: 0px; margin: 0px; min-width: 300px; border: 1px solid #222; color: #FFF; background-color: #000;'
local mainDiv = html:tag('div'):addClass('skillbox'):cssText(mainStyle)
-- Header Div
local headerStyle = 'float: left; background-color: #151515; width: 100%; height: 25px; vertical-align: middle; text-align: center; font-size: 15pt; font-weight: 475; line-height: 25px !important;'
local headerDiv = mainDiv:tag('div'):addClass('heading'):cssText(headerStyle)
headerDiv:wikitext('[['..skill..']]')
-- Image
mainDiv:tag('div'):cssText('float:left; padding-bottom: 0px !important; padding-right: 5px'):wikitext(frame:preprocess('[[File:' .. skillData.image .. '|84x128px|link=' .. skillData._pageName .. '|frameless]]'))
-- Skill Info
-- costs (purchase and activate costs)
local costsStyle = 'display: block; text-align: left; padding-top: 3px; padding-right: 5px; margin-left: 5px;'
local costsDiv = mainDiv:tag('div'):cssText(costsStyle):addClass('skillDesc')
local costsOutput = ''
local skillCost = ''
local skillConsume = ''
local skillCooldown = ''
local separator = ' | '
-- define obtaining/training cost
if skillData.skilltier == 'Quest' then skillCost = '<span style="color: #FFFFFF">Quest</span>'
elseif skillData.skilltier == 'Starter' then skillCost = '<span style="color: #FFFFFF">Starter</span>'
else skillCost = skillData.cost end
-- define rsource consumption
if skillData.skilltype == 'Passive' then skillConsume = '<span style="color: #555">Passive</span>'
elseif args.manacost ~= nil and args.manacost ~= '' then skillConsume = args.manacost .. ' {{mana}}'
elseif args.staminacost ~= nil and args.staminacost ~= '' then skillConsume = args.staminacost .. ' {{stamina}}'
elseif args.healthcost ~= nil and args.healthcost ~= '' then skillConsume = args.healthcost .. ' {{health}}'
else skillConsume = skillData.consumes end
-- define cooldown
if args.cooldown ~= nil and args.cooldown ~= '' then skillCooldown = args.cooldown .. ' seconds {{cooldown}}'
elseif skillData.skilltype ~= 'Passive' then skillCooldown = skillData.cooldown .. ' {{cooldown}}' end
costsOutput = skillCost .. separator .. skillConsume
if skillCooldown ~= '' then costsOutput = costsOutput .. separator .. skillCooldown end
costsDiv:wikitext(frame:preprocess('<b style="font-size: 87%">'..costsOutput..'</b>'))
-- and just chuck the description in the remaining div area
mainDiv:tag('hr'):cssText('margin-right: 5px; margin-bottom: 8px;')
mainDiv:wikitext(frame:preprocess('<i style="display: blockl font-size: 90%; line-height: 18px;">' .. desc .. '</i>'))
mainDiv:tag('div'):cssText('clear: both;'):done()
return html:done()
end
return p