Module:Garrison ability

From Wowpedia
Jump to: navigation, search

Garrison ability implements {{Garrison ability}}


local getArgs = require('Module:Arguments').getArgs
local p = {}
local data = mw.loadData('Module:Garrison ability/data')

local function composeImage(data, size)
  return string.format('[[File:%s.png|%s|%s: %s|alt=%s|link=Garrison Missions#Counters]]', data[2], size, data[1], data[3], data[1])
end

local function composeList(data,size)
  return string.format("* <span class=\"linkicon\">[[File:%s.png|%s|link=|alt=]]</span> '''%s''' — %s", data[2] ,size ,data[1] ,data[3])
end

local function composeName(data,size)
  return string.format("%s<br>%s",composeImage(data,size),data[1])
end

local modeSwitch = {
  ['icon'] = composeImage,
  ['list'] = composeList,
  ['name'] = composeName,
}

function p.abilities(frame)
  local args = getArgs(frame, {wrappers = 'Template:Garrison ability'})
  return p._abilities(args)
end

function p._abilities(args)
  local size=args.size or '18px'
  args.size = nil

  local compose=modeSwitch[args.mode or 'icon']
  local sep = (args.mode == 'list') and '\n' or ' '
  args.mode = nil

  local t = {}
  for k,v in ipairs(args) do
    if type(k) == 'number' then
      local d = data[string.lower(v)]
      if d ~= nil then
        t[#t+1] = compose(d,size)
      end
    end
  end

  return table.concat(t,sep)
end
return p