Difference between revisions of "Module:CoAbility"
Jump to navigation
Jump to search
>Eave |
>Eave m (factor in max value when sorting coabs as well) |
||
| (37 intermediate revisions by the same user not shown) | |||
| Line 3: | Line 3: | ||
local p = {} | local p = {} | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
| − | |||
-- Usage: {{#invoke:CoAbility|Filter}} | -- Usage: {{#invoke:CoAbility|Filter}} | ||
-- Filter header for coability lists | -- Filter header for coability lists | ||
function p.Filter(frame) | function p.Filter(frame) | ||
| + | local md5 = require('Module:Md5') | ||
local filterWidget = '{{#widget:CoAbilityListFilter|%s}}' | local filterWidget = '{{#widget:CoAbilityListFilter|%s}}' | ||
local coabFilterValues = 'coabs=%s|coabImages=%s' | local coabFilterValues = 'coabs=%s|coabImages=%s' | ||
| − | local chainCoabFilterValues = 'chainCoabs=%s|chainCoabImages= | + | local chainCoabFilterValues = 'chainCoabs=%s|chainCoabImages=%s' |
local imageUrl = '/images/%s/%s/%s.png' | local imageUrl = '/images/%s/%s/%s.png' | ||
| Line 20: | Line 20: | ||
for i, coab in ipairs(coabs) do | for i, coab in ipairs(coabs) do | ||
local icon = coab['AbilityIconName'] | local icon = coab['AbilityIconName'] | ||
| − | local iconHash = md5.sumhexa(icon):sub(1, 2) | + | local iconHash = md5.sumhexa(icon..'.png'):sub(1, 2) |
local iconPath = string.format(imageUrl, iconHash:sub(1,1), iconHash, icon) | local iconPath = string.format(imageUrl, iconHash:sub(1,1), iconHash, icon) | ||
result[#result+1] = string.format(coabFilterValues, icon, iconPath) | result[#result+1] = string.format(coabFilterValues, icon, iconPath) | ||
end | end | ||
| − | + | local chainCoabs = cargo.query('ChainCoAbilities', 'AbilityIconName', { | |
| − | return frame: | + | groupBy = 'AbilityIconName', |
| + | orderBy = 'AbilityIconName', | ||
| + | }) | ||
| + | for i, coab in ipairs(chainCoabs) do | ||
| + | local icon = coab['AbilityIconName'] | ||
| + | local iconHash = md5.sumhexa(icon..'.png'):sub(1, 2) | ||
| + | local iconPath = string.format(imageUrl, iconHash:sub(1,1), iconHash, icon) | ||
| + | result[#result+1] = string.format(chainCoabFilterValues, icon, iconPath) | ||
| + | end | ||
| + | return frame:preprocess(string.format(filterWidget, table.concat(result, '|'))) | ||
end | end | ||
| + | |||
| + | --[[ Entries for Adventurer Coability lists | ||
| + | Usage: {{#invoke:CoAbility|AdventurerTableEntries}} | ||
| + | Test using: | ||
| + | frame = mw.getCurrentFrame() | ||
| + | print(p.AdventurerTableEntries(frame)) | ||
| + | --]] | ||
| + | function p.AdventurerTableEntries(frame) | ||
| + | local filterValues = '|- class="grid-entry" data-element="%s" data-weapon="%s" '.. | ||
| + | 'data-rarity="%s" data-coab="%s" data-chaincoab="%s"' | ||
| + | local row = '| data-sort-value="%s" | [[File:%s 0%s r0%s.png|36px|link=%s]] [[%s|%s]]\n| %s\n| %s' | ||
| + | local iconLink = 'data-sort-value="%s %s" | [[File:%s.png|36px|link=%s]] [[%s|%s]] (\'\'\'Max:\'\'\' %s)' | ||
| + | local coabQueryWhere = 'Id="%s"' | ||
| + | |||
| + | local result = {} | ||
| + | local fields = 'Adventurers._pageName=advPage, Adventurers.Id=advId, VariationId,'.. | ||
| + | 'FullName, ElementalType, WeaponType, Rarity, ExAbilityData5, ExAbility2Data5,'.. | ||
| + | 'CoAbilities._pageName=coabPage, CoAbilities.Name=coabName, CoAbilities.AbilityIconName=coabIcon,'.. | ||
| + | 'ChainCoAbilities._pageName=ccoabPage, ChainCoAbilities.Name=ccoabName, ChainCoAbilities.AbilityIconName=ccoabIcon' | ||
| + | local units = cargo.query('Adventurers, CoAbilities, ChainCoAbilities', fields, { | ||
| + | join = 'Adventurers.ExAbilityData1=CoAbilities.Id, Adventurers.ExAbility2Data1=ChainCoAbilities.Id', | ||
| + | where = 'IsPlayable AND ReleaseDate <= NOW()', | ||
| + | groupBy = 'Adventurers._pageName', | ||
| + | orderBy = 'ElementalTypeId ASC, WeaponTypeId ASC, Rarity DESC, IdLong DESC, FullName ASC', | ||
| + | limit = 999 | ||
| + | }) | ||
| + | for i, unit in ipairs(units) do | ||
| + | local advPage = unit['advPage'] | ||
| + | local advName = unit['FullName'] | ||
| + | local element = unit['ElementalType'] | ||
| + | local weapon = unit['WeaponType'] | ||
| + | local rarity = unit['Rarity'] | ||
| + | local coabIcon = unit['coabIcon'] | ||
| + | local coabPage = unit['coabPage'] | ||
| + | local coabName = unit['coabName'] | ||
| + | local ccoabIcon = unit['ccoabIcon'] | ||
| + | local ccoabPage = unit['ccoabPage'] | ||
| + | local ccoabName = unit['ccoabName'] | ||
| + | |||
| + | local maxCoab = cargo.query('CoAbilities', 'Name', { | ||
| + | where = coabQueryWhere:format(unit['ExAbilityData5']), | ||
| + | groupBy = '_pageName', | ||
| + | limit = 1 | ||
| + | })[1] | ||
| + | local maxCCoab = cargo.query('ChainCoAbilities', 'Name', { | ||
| + | where = coabQueryWhere:format(unit['ExAbility2Data5']), | ||
| + | groupBy = '_pageName', | ||
| + | limit = 1 | ||
| + | })[1] | ||
| + | local maxCoabValue = maxCoab['Name']:match("%s(%S+)$") | ||
| + | local maxCCoabValue = maxCCoab['Name']:match("%s(%S+)$") | ||
| + | |||
| + | result[#result+1] = filterValues:format(element, weapon, rarity, coabIcon, ccoabIcon) | ||
| + | result[#result+1] = row:format( | ||
| + | advName, unit['advId'], unit['VariationId'], rarity, advPage, advPage, advName, | ||
| + | iconLink:format(coabName, maxCoabValue, coabIcon, coabPage, coabPage, coabName, maxCoabValue), | ||
| + | iconLink:format(ccoabName, maxCCoabValue, ccoabIcon, ccoabPage, ccoabPage, ccoabName, maxCCoabValue) | ||
| + | ) | ||
| + | end | ||
| + | return table.concat(result, '\n') | ||
| + | end | ||
return p | return p | ||
--</includeonly> | --</includeonly> | ||
Latest revision as of 21:20, 12 April 2020
This module abstracts away some of the logical complexity that is difficult to represent in pure Wikitext when it comes to displaying information about co-abilities and chain co-abilities.
Parameters & Invocation
{{#invoke:CoAbility|Filter}}
No arguments, populates the arguments for and calls the Co-ability filter header used in Widget:CoAbilityListFilter.
{{#invoke:CoAbility|AdventurerTableEntries}}
No arguments, populates the table rows used in Adventurer Co-abilities List.
-- <includeonly> (prevents literal interpretation of links or categories within the module code)
-- Lua Templating for Co-ability (and chain co-ability) related displays
local p = {}
local cargo = mw.ext.cargo
-- Usage: {{#invoke:CoAbility|Filter}}
-- Filter header for coability lists
function p.Filter(frame)
local md5 = require('Module:Md5')
local filterWidget = '{{#widget:CoAbilityListFilter|%s}}'
local coabFilterValues = 'coabs=%s|coabImages=%s'
local chainCoabFilterValues = 'chainCoabs=%s|chainCoabImages=%s'
local imageUrl = '/images/%s/%s/%s.png'
local result = {}
local coabs = cargo.query('CoAbilities', 'AbilityIconName', {
groupBy = 'AbilityIconName',
orderBy = 'Id',
})
for i, coab in ipairs(coabs) do
local icon = coab['AbilityIconName']
local iconHash = md5.sumhexa(icon..'.png'):sub(1, 2)
local iconPath = string.format(imageUrl, iconHash:sub(1,1), iconHash, icon)
result[#result+1] = string.format(coabFilterValues, icon, iconPath)
end
local chainCoabs = cargo.query('ChainCoAbilities', 'AbilityIconName', {
groupBy = 'AbilityIconName',
orderBy = 'AbilityIconName',
})
for i, coab in ipairs(chainCoabs) do
local icon = coab['AbilityIconName']
local iconHash = md5.sumhexa(icon..'.png'):sub(1, 2)
local iconPath = string.format(imageUrl, iconHash:sub(1,1), iconHash, icon)
result[#result+1] = string.format(chainCoabFilterValues, icon, iconPath)
end
return frame:preprocess(string.format(filterWidget, table.concat(result, '|')))
end
--[[ Entries for Adventurer Coability lists
Usage: {{#invoke:CoAbility|AdventurerTableEntries}}
Test using:
frame = mw.getCurrentFrame()
print(p.AdventurerTableEntries(frame))
--]]
function p.AdventurerTableEntries(frame)
local filterValues = '|- class="grid-entry" data-element="%s" data-weapon="%s" '..
'data-rarity="%s" data-coab="%s" data-chaincoab="%s"'
local row = '| data-sort-value="%s" | [[File:%s 0%s r0%s.png|36px|link=%s]] [[%s|%s]]\n| %s\n| %s'
local iconLink = 'data-sort-value="%s %s" | [[File:%s.png|36px|link=%s]] [[%s|%s]] (\'\'\'Max:\'\'\' %s)'
local coabQueryWhere = 'Id="%s"'
local result = {}
local fields = 'Adventurers._pageName=advPage, Adventurers.Id=advId, VariationId,'..
'FullName, ElementalType, WeaponType, Rarity, ExAbilityData5, ExAbility2Data5,'..
'CoAbilities._pageName=coabPage, CoAbilities.Name=coabName, CoAbilities.AbilityIconName=coabIcon,'..
'ChainCoAbilities._pageName=ccoabPage, ChainCoAbilities.Name=ccoabName, ChainCoAbilities.AbilityIconName=ccoabIcon'
local units = cargo.query('Adventurers, CoAbilities, ChainCoAbilities', fields, {
join = 'Adventurers.ExAbilityData1=CoAbilities.Id, Adventurers.ExAbility2Data1=ChainCoAbilities.Id',
where = 'IsPlayable AND ReleaseDate <= NOW()',
groupBy = 'Adventurers._pageName',
orderBy = 'ElementalTypeId ASC, WeaponTypeId ASC, Rarity DESC, IdLong DESC, FullName ASC',
limit = 999
})
for i, unit in ipairs(units) do
local advPage = unit['advPage']
local advName = unit['FullName']
local element = unit['ElementalType']
local weapon = unit['WeaponType']
local rarity = unit['Rarity']
local coabIcon = unit['coabIcon']
local coabPage = unit['coabPage']
local coabName = unit['coabName']
local ccoabIcon = unit['ccoabIcon']
local ccoabPage = unit['ccoabPage']
local ccoabName = unit['ccoabName']
local maxCoab = cargo.query('CoAbilities', 'Name', {
where = coabQueryWhere:format(unit['ExAbilityData5']),
groupBy = '_pageName',
limit = 1
})[1]
local maxCCoab = cargo.query('ChainCoAbilities', 'Name', {
where = coabQueryWhere:format(unit['ExAbility2Data5']),
groupBy = '_pageName',
limit = 1
})[1]
local maxCoabValue = maxCoab['Name']:match("%s(%S+)$")
local maxCCoabValue = maxCCoab['Name']:match("%s(%S+)$")
result[#result+1] = filterValues:format(element, weapon, rarity, coabIcon, ccoabIcon)
result[#result+1] = row:format(
advName, unit['advId'], unit['VariationId'], rarity, advPage, advPage, advName,
iconLink:format(coabName, maxCoabValue, coabIcon, coabPage, coabPage, coabName, maxCoabValue),
iconLink:format(ccoabName, maxCCoabValue, ccoabIcon, ccoabPage, ccoabPage, ccoabName, maxCCoabValue)
)
end
return table.concat(result, '\n')
end
return p
--</includeonly>