Dota 2 Вики
Регистрация
Advertisement

Документация для Модуль:Ability icon Перейти к коду ↴ [ править | очистить ]

This module provides a simple way of generating an ability icon.

Использование[]

First, load the module.

local aicon = require('Модуль:Ability icon')

The function itself has two required and one optional argument:

  • source The abilities source.
  • name The abilities name.
  • data (Optional) Already retrieved Cargo data, to prevent unnecessary queries.

Тесты[]

НетН 1 test failed.

Name Expected Actual
ДаД testDefault
ДаД testGivenData
НетН testItem Lua error -- Модуль:Ability_icon:29: bad argument #3 to 'format' (string expected, got nil)
ДаД testItemAbility
ДаД testNormalAbility
ДаД testRuneAbility


Зависимости

local p = {}

local cargoQuery = mw.ext.cargo.query
local getArgs = require('Модуль:Arguments').getArgs

local i18n = {
  error = {
    noAbilityData = 'Для этой способности нет данных'
  }
}

local runes = {
  ['богатство'] = 'Bounty',
  ['вода'] = 'Water',
  ['волшебство'] = 'Arcane',
  ['двойной урон'] = 'Double Damage',
  ['усиление урона'] = 'Double Damage',
  ['ускорение'] = 'Haste',
  ['иллюзии'] = 'Illusion',
  ['невидимость'] = 'Invisibility',
  ['регенерация'] = 'Regeneration',
  ['щит'] = 'Shield',
  ['мудрость'] = 'Wisdom',
}


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( runes[mw.ustring.lower(args.name)] )
  end

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

return p
Advertisement