Difference between revisions of "Module:Adventurer"
Jump to navigation
Jump to search
>Eave m (fixing element and weapon descriptions) |
>Eave m (some html cleanup) |
||
| Line 79: | Line 79: | ||
-- Format the content | -- Format the content | ||
| − | local card = mw.html.create('div') | + | local card = mw.html.create('div'):addClass('panel'):css('display','inline-block') |
| − | + | :tag('div'):addClass('panel-heading') | |
| − | |||
| − | :tag('div') | ||
| − | |||
:wikitext('[['..name..']]') | :wikitext('[['..name..']]') | ||
:done() | :done() | ||
| − | :tag('div') | + | :tag('div'):addClass('panel-body'):cssText('display:flex;flex-wrap:wrap;justify-content:center;') |
| − | |||
| − | |||
:tag('div') | :tag('div') | ||
:wikitext(portraitImage) | :wikitext(portraitImage) | ||
:done() | :done() | ||
| − | :tag('div') | + | :tag('div'):cssText('display:flex;flex-direction:column') |
| − | |||
:tag('div') | :tag('div') | ||
:wikitext(description) | :wikitext(description) | ||
:done() | :done() | ||
| − | :tag('hr') | + | :tag('hr'):cssText('margin:1em') |
| − | |||
:done() | :done() | ||
| − | :tag('div') | + | :tag('div'):cssText('width:360px') |
:tag('div') | :tag('div') | ||
| − | |||
:wikitext("'''Skills''': ") | :wikitext("'''Skills''': ") | ||
| − | :tag('div') | + | :tag('div'):cssText('display:inline-block') |
| − | |||
:wikitext(skill1tooltip..skill2tooltip) | :wikitext(skill1tooltip..skill2tooltip) | ||
:done() | :done() | ||
:done() | :done() | ||
| − | :tag('div') | + | :tag('div') |
| − | + | :wikitext("'''Co-Ability''': ") | |
| − | :wikitext("''' | + | :tag('div'):cssText('display:inline-block') |
| − | + | :wikitext(coability) | |
| − | + | :done() | |
| − | + | :done() | |
| − | + | :tag('div') | |
| + | :wikitext("'''Abilities''': ") | ||
| + | :tag('div'):cssText('display:inline-block') | ||
| + | :wikitext(ability1..ability2..ability3) | ||
:done() | :done() | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
:allDone() | :allDone() | ||
return tostring(card) | return tostring(card) | ||
Revision as of 03:14, 6 October 2019
Usage
This module is intended to back the rendering of more complicated Adventurer data-related templates. Currently it only supports the Template:Character info card template.
Example
Generally, this module should be called via the regular wikitext templates instead of directly. But here is example syntax for calling the functions from wikitext:
{{#invoke:Adventurer|infoCard|The Prince}}
Lua error: Error: Table Adventurers not found..
{{#invoke:Adventurer|infoCard|Name=Edward}}
Lua error: Error: Table Adventurers not found..
-- <includeonly> (prevents literal interpretation of links or categories within the module code)
-- Lua Templating for Adventurer related info.
local p = {}
local cargo = mw.ext.cargo
-- Usage: {{#invoke:Adventurer|infoCard|<name>}} or {{#invoke:Adventurer|infoCard|Name=<name>}}
-- Ex: {{#invoke:Adventurer|infoCard|Euden}} or {{#invoke:Adventurer|infoCard|Name=Elisanne}}
function p.infoCard(frame)
local name = frame.args[1] or frame.args['Name']
-- Query adventurer data
local adv = getAdventurers({
where = '_pageName="'..name..'"',
groupBy = '_pageName',
limit = 1
})[1]
if adv == nil then
return ''
end
-- CoAbility
local coability = getCoabilities({
where = string.format('Id="%s"', adv['ExAbilityData1']),
groupBy = '_pageName',
limit = 1
})[1]
if coability then
coability = coability['Name']
end
-- Abilities
local abilityKeys = {'Abilities11', 'Abilities12', 'Abilities13', 'Abilities21', 'Abilities22', 'Abilities31', 'Abilities32'}
local abilities = {}
for i, key in ipairs(abilityKeys) do
abilities[key] = '0'
if adv[key] and adv[key] ~= '0' then
local ability = getAbilities({
where = string.format('Id="%s"', adv[key]),
groupBy = '_pageName',
limit = 1
})[1]
if ability then
abilities[key] = ability['Name']
end
end
end
-- Precompute some template outputs
-- Portrait Image
local portraitFileName = string.format('%s 0%s r0%s portrait.png', adv['Id'], adv['VariationId'], adv['Rarity'])
local portraitImage = mw.title.makeTitle('File', portraitFileName)
if (portraitImage.exists) then
portraitImage = string.format('[[File:%s|300px|link=%s]]', portraitFileName, name)
else
portraitImage = string.format('[[File:Unknown.png|300px|link=%s]]', name)
end
-- Description
local mcPlusHp = adv['PlusHp0'] + adv['PlusHp1'] + adv['PlusHp2'] + adv['PlusHp3'] + adv['PlusHp4']
local mcPlusAtk = adv['PlusAtk0'] + adv['PlusAtk1'] + adv['PlusAtk2'] + adv['PlusAtk3'] + adv['PlusAtk4']
local description =
frame:expandTemplate{title='TermDescription', args={'Element', frame:expandTemplate{title='InlineIcon', args={'Icon Element', adv['ElementalType']}}..' '..adv['ElementalType']}}..
frame:expandTemplate{title='TermDescription', args={'Weapon', frame:expandTemplate{title='InlineIcon', args={'Icon Weapon', adv['WeaponType']}}..' '..adv['WeaponType']}}..
maxStatsTooltip('HP', adv['MaxHp'], mcPlusHp, adv['McFullBonusHp5'])..
maxStatsTooltip('Str', adv['MaxAtk'], mcPlusAtk, adv['McFullBonusAtk5'])..
frame:expandTemplate{title='TermDescription', args={'Class', '[[File:Icon Type Row '..adv['CharaType']..'.png|105px|link=]]'}}..
frame:expandTemplate{title='TermDescription', args={'Base Rarity', '[[File:Icon Rarity Row '..adv['Rarity']..'.png|75px|link=]]'}}..
frame:expandTemplate{title='TermDescription', args={'Obtained From', adv['Obtain']}}
-- Skills
local skill1tooltip = frame:expandTemplate{title='SkillTooltip', args={adv['Skill1Name']}}
local skill2tooltip = adv['Skill2Name'] == '' and '' or
', '..frame:expandTemplate{title='SkillTooltip', args={adv['Skill2Name']}}
-- CoAbility
local coability = frame:expandTemplate{title='Icon', args={'CoAbility', coability, size='24px'}}..' '..
frame:expandTemplate{title='CoAbilityTooltip', args={adv['ExAbilityData1'], adv['ExAbilityData2'], adv['ExAbilityData3'], adv['ExAbilityData4'], adv['ExAbilityData5']}}
-- Abilities
local ability1 = abilityIconTooltip({abilities['Abilities11'], abilities['Abilities12'], abilities['Abilities13']})
local ability2 = abilities['Abilities21'] == '0' and '' or
', '..abilityIconTooltip({abilities['Abilities21'], abilities['Abilities22']})
local ability3 = abilities['Abilities31'] == '0' and '' or
', '..abilityIconTooltip({abilities['Abilities31'], abilities['Abilities32']})
-- Format the content
local card = mw.html.create('div'):addClass('panel'):css('display','inline-block')
:tag('div'):addClass('panel-heading')
:wikitext('[['..name..']]')
:done()
:tag('div'):addClass('panel-body'):cssText('display:flex;flex-wrap:wrap;justify-content:center;')
:tag('div')
:wikitext(portraitImage)
:done()
:tag('div'):cssText('display:flex;flex-direction:column')
:tag('div')
:wikitext(description)
:done()
:tag('hr'):cssText('margin:1em')
:done()
:tag('div'):cssText('width:360px')
:tag('div')
:wikitext("'''Skills''': ")
:tag('div'):cssText('display:inline-block')
:wikitext(skill1tooltip..skill2tooltip)
:done()
:done()
:tag('div')
:wikitext("'''Co-Ability''': ")
:tag('div'):cssText('display:inline-block')
:wikitext(coability)
:done()
:done()
:tag('div')
:wikitext("'''Abilities''': ")
:tag('div'):cssText('display:inline-block')
:wikitext(ability1..ability2..ability3)
:done()
:allDone()
return tostring(card)
end
function abilityIconTooltip(abilities)
local frame = mw.getCurrentFrame()
return frame:expandTemplate{title='Icon', args = {'Ability', abilities[1], size='24px'}}..' '..
frame:expandTemplate{title='AbilityTooltip', args=abilities}
end
function maxStatsTooltip(statType, max, mcPlus, mcFullBonus)
local frame = mw.getCurrentFrame()
local total = max + mcPlus + mcFullBonus
return frame:expandTemplate{title='TermDescriptionTooltip', args={
frame:expandTemplate{title='Tooltip', args={'Total Max '..statType, '5★ Max '..statType..' with All Mana Circle Nodes and Bonus'}},
string.format('%s (%s + %s + %s)', total, max, mcPlus, mcFullBonus), 'Total (5★ Max + Mana Circle Node Stats + Mana Circle Bonus)'}}
end
function getAdventurers(queryArgs)
local tables = 'Adventurers'
local queryFields = 'Id,VariationId,CharaType,Rarity,ElementalType,WeaponType,MinHp3,MinHp4,MinHp5,MaxHp,PlusHp0,PlusHp1,PlusHp2,PlusHp3,PlusHp4,McFullBonusHp5,MinAtk3,MinAtk4,MinAtk5,MaxAtk,PlusAtk0,PlusAtk1,PlusAtk2,PlusAtk3,PlusAtk4,McFullBonusAtk5,Obtain,ExAbilityData1,ExAbilityData2,ExAbilityData3,ExAbilityData4,ExAbilityData5,Skill1Name,Skill2Name,Abilities11,Abilities12,Abilities13,Abilities21,Abilities22,Abilities31,Abilities32'
return cargo.query(tables, queryFields, queryArgs)
end
function getCoabilities(queryArgs)
local tables = 'CoAbilities'
local queryFields = 'Name'
return cargo.query(tables, queryFields, queryArgs)
end
function getAbilities(queryArgs)
local tables = 'Abilities'
local queryFields = 'Name'
return cargo.query(tables, queryFields, queryArgs)
end
return p
--</includeonly>