Module:Taunt Nav

From Dota 2 Wiki
Jump to: navigation, search

Documentation for Module:Taunt Nav Jump to code ↴ [ edit | purge ]

Reality Rift icon.png
▶️ Planeshift.
The documentation for this module can be found at Template:Taunt Nav.
You may be forwarded to another wiki language, in case a translation is not available.


local p = {}
local cargo = mw.ext.cargo

local i18n = {
  -- Modules
  module_cosmetic = 'Module:Cosmetic',
  module_arguments = 'Module:Arguments',
  -- Templates
  template_navbox = 'Navbox',
  template_hero_entry = 'Hero entry',
  -- Navbox settings
  navbox_name = 'Taunt Nav',
  navbox_title = '[[Taunt (Equipment)|Taunts]]',
  -- Cargo
  table_name = 'cosmetic_items',
  taunt_prefab = 'Taunt',
  -- Errors
  error_no_data = 'Failed to get Cargo data',
}

local cosmetic = require(i18n.module_cosmetic)._main
local getArgs = require(i18n.module_arguments).getArgs


function p.main(frame)
  local args = getArgs(frame, {
    wrappers = {
      'Template:Taunt Nav'
    }
  })
  local navbox = {
    name = i18n.navbox_name,
    border = args['border'] or nil,
    state = args['state'] or 'autocollapse',
    style = 'text-align: center;',
    groupstyle = 'text-align: center;',
    title = i18n.navbox_title,
  }
  
  local heroes = cargo.query(i18n.table_name, 'hero', { where='prefab="'..i18n.taunt_prefab..'"', groupBy='hero' })
  assert(heroes, i18n.error_no_data)
  
  for i,data in ipairs(heroes) do
    local cargo_taunts = cargo.query(i18n.table_name, '_pageName', { where='prefab="'..i18n.taunt_prefab..'" AND hero="' .. data.hero .. '"', groupBy='_pageID' })
    local taunts = {}
    
    for _,taunt in ipairs(cargo_taunts) do
      local cosmetic_item = tostring(cosmetic({ taunt._pageName }))
      table.insert(taunts, cosmetic_item)
    end
    
    navbox['group' .. i] = frame:expandTemplate{ title = i18n.template_hero_entry, args = { data.hero } }
    navbox['list' .. i] = table.concat(taunts, ' ')
  end
  
  return frame:expandTemplate{ title = i18n.template_navbox, args = navbox }
end


return p