Dota 2 Wiki
Registre-se
Advertisement

A documentação para este módulo pode ser criada na página Módulo:SkillListLite/doc

local p = {}
local cargo = mw.ext.cargo
local aicon = require( 'Module:Ability icon' )._main
local color = require( 'Module:Color' )._main
local getArgs = require( 'Module:Arguments' ).getArgs

local i18n = {
	-- Ability types
	type_item = 'item',
	type_rune = 'rune',
	-- Rune icons
	rune_icon_prefix = 'File:Bottle (',
	rune_icon_suffix = ') icon.png',
	-- Errors
	error_prefix = 'Lua error',
	error_category = 'Category:Pages with script errors',
	error_missing_arg = 'Missing argument',
	error_no_data = 'Found no Cargo data',
}


function p.main(frame)
  local args = getArgs(frame, {
    wrappers = {
      'Template:SkillListLite'
    }
  })
  return p._main(args)
end

function p._main(args)
  local li_error = function(message)
    -- A custom error message that works properly in the skill list.
		return string.format('<li class="skilllist-lite" style="background-color: #c00; color: white;">%s: %s.[[%s]]', i18n.error_prefix, message, i18n.error_category)
  end

  if not args and args.source and args.name then
    return li_error(i18n.error_missing_arg)
  end
  
  local sourcetext = args.sourcetext or args.source
  local nametext = args.nametext or args.name
  
  local cargo_output = cargo.query( 'abilities', 'image, type', { where='_pageName="' .. args.source .. '" AND title="' .. args.name .. '"', groupBy='source, title' } )[1]
  if not cargo_output then
    return li_error(i18n.error_no_data)
  end
  local image = aicon(args, cargo_output)
  
  return '<li class="skilllist-lite" style="background-color: ' .. color({ cargo_output.type }) .. '">' .. '[[' .. image .. '|24px|link=' .. args.source .. '#' .. args.name .. ']] [[' .. args.source .. '|' .. sourcetext .. ']] – [[' .. args.source .. '#' .. args.name .. '|' .. nametext .. ']]'
end


return p
Advertisement