Module:Ability icon

local p = {}

local cargoQuery = mw.ext.cargo.query local getArgs = require( 'Module:Arguments' ).getArgs

local i18n = { error = { noAbilityData = 'No data available for this ability' } }

local function getAbilityData( source, name ) local cargoData = cargoQuery( 'abilities', 'image, type', {   where = string.format( 'source="%s" AND title="%s"', source, name ),    groupBy = 'source, title'  } )[1] return cargoData end

local function getItemIcon( name ) local cargoData = cargoQuery( 'items', 'image', {   where = string.format( '_pageName="%s"', name ),    groupBy = '_pageID'  } )[1] return cargoData.image end

local function getRuneIcon( name ) return string.format( 'File:Bottle (%s) icon.png', name ) end

function p.main( frame ) local args = getArgs( frame ) return p._main( args ) end

function p._main( args, abilityData ) abilityData = abilityData or getAbilityData( args.source, args.name ) assert( abilityData, i18n.error.noAbilityData )

local abilityType = abilityData.type if abilityType == 'item' then abilityData.image = getItemIcon( args.source ) elseif abilityType == 'rune' then abilityData.image = getRuneIcon( args.name ) end

if abilityData.image ~= '' then return abilityData.image else return 'File:Unknown icon.png' end end

return p