Module:CoAbility

-- (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: -- Filter header for coability lists function p.Filter(frame) local md5 = require('Module:Md5') local filterWidget = '' local coabFilterValues = 'coabs=%s|coabImages=%s' local chainCoabFilterValues = 'chainCoabs=%s|chainCoabImages=%s' local imageUrl = '/media/%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: 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" | %s\n| %s\n| %s' local iconLink = 'data-sort-value="%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 --