Dota 2 Вики
мНет описания правки
мНет описания правки
Строка 1: Строка 1:
 
local p = {}
 
local p = {}
  +
 
local cargo = mw.ext.cargo
 
local cargo = mw.ext.cargo
 
local getArgs = require('Модуль:Arguments').getArgs
 
local getArgs = require('Модуль:Arguments').getArgs
  +
  +
local i18n = {
  +
error = {
  +
noAbilityData = 'Для этой способности нет данных'
 
}
  +
}
   
 
local runes = {
 
local runes = {
Строка 13: Строка 20:
 
}
 
}
   
  +
function p.main(frame)
 
  +
local function getAbilityData( source, name )
local args = getArgs(frame)
 
  +
local cargoData = cargoQuery( 'abilities', 'image, type', {
return p._main(args)
 
  +
where = string.format( 'source="%s" AND title="%s"', source, name ),
  +
groupBy = 'source, title'
  +
} )[1]
 
return cargoData
 
end
 
end
   
function p._main(args, data)
+
local function getItemIcon( name )
  +
local cargoData = cargoQuery( 'items', 'image', {
if not data then
 
  +
where = string.format( '_pageName="%s"', name ),
mw.log('Генерируются данные.')
 
  +
groupBy = '_pageID'
data = mw.ext.cargo.query( 'abilities', 'image, type', { where='source="' .. args.source .. '" AND title="' .. args.name .. '"', groupBy='source, title' } )[1]
 
  +
} )[1]
  +
return cargoData.image
  +
end
  +
  +
local function getRuneIcon( name )
 
return string.format( 'File:Bottle (%s) icon.png', runes[mw.ustring.lower(args.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
 
end
  +
 
if data.type == 'item' then
+
if abilityData.image ~= '' then
  +
return abilityData.image
return mw.ext.cargo.query( 'items', 'image,', { where='_pageName="' .. args.source .. '"', groupBy='_pageID' } )[1]['image']
 
elseif data.type == 'rune' then
 
return string.format('File:Bottle (%s) icon.png', runes[mw.ustring.lower(args.name)])
 
elseif data.image ~= '' then
 
return data.image
 
 
else
 
else
 
return 'File:Unknown icon.png'
 
return 'File:Unknown icon.png'
 
end
 
end
 
end
 
end
 
   
 
return p
 
return p

Версия от 21:03, 14 января 2020

Документация для Модуль: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.

Тесты

НетН 4 tests failed.

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


Зависимости

local p = {}

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

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

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


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', runes[mw.ustring.lower(args.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