Difference between revisions of "Module:Factions"

From BTAWiki
Jump to navigation Jump to search
(Fixed typo)
Line 36: Line 36:
 
   Tortuga = 'Tortuga Dominions'
 
   Tortuga = 'Tortuga Dominions'
 
}
 
}
 +
 +
 +
function p.factionMechs(frame)
 +
  local tpl_args = getArgs(frame, {parentFirst=true})
 +
 +
  local faction = tpl_args[1]
 +
  local where = string.format('Mech.MechTags HOLDS "%s"', faction)
 +
 +
  local factionMechData = mw.ext.cargo.query(
 +
    'Mech,Chassis','Chassis.Name=Name,Chassis.VariantName=VariantName',
 +
    { join = 'Mech.ChassisID=Chassis.Id', where=where }
 +
  )
 +
 +
  local mechsList = mw.html.create('ul')
 +
  mechsList:cssText('column-count: 3;-moz-column-count: 3;-webkit-column-count: 3')
 +
  for _, mech in ipairs(factionMechData) do
 +
    mechsList:tag('li'):wikitext(string.format(
 +
      '[[%s#%s|%s %s]]', mech['Name'], mech['VariantName'],
 +
      mech['Name'], mech['VariantName']
 +
    ))
 +
  end
 +
  return mechsList
 +
end
  
 
function p.mechFactions(frame)
 
function p.mechFactions(frame)

Revision as of 05:39, 21 January 2021

Documentation for this module may be created at Module:Factions/doc

-- Module:Factions handles translating faction tags to their full names

local p = {}

local mechs = require('Module:Mech').core
local getArgs = require('Module:Arguments').getArgs

p.factionTags = {
  AuriganDirectorate = 'Aurigan Directorate',
  AuriganMercenaries = 'Mercenaries',
  AuriganPirates = 'Pirates',
  AuriganRestoration = 'Aurigan Restoration (Arano)',
  Chainelane = 'Chainelane Isles',
  Circinus = 'Circinus Federation',
  ClanDiamondShark = 'Clan Diamond Shark',
  ClanGhostBear = 'Clan Ghost Bear',
  ClanJadeFalcon = 'Clan Jade Falcon',
  ClanNovaCat = 'Clan Nova Cat',
  ClanWolf = 'Clan Wolf',
  ComStar = 'Comstar',
  Davion = 'Federated Suns (Davion)',
  Delphi = 'New Delphi Compact',
  Hanse = 'Hanseatic League',
  JarnFolk = 'JarnFolk',
  Kurita = 'Draconis Combine (Kurita)',
  Liao = 'Capellan Confederation (Liao)',
  Locals = 'Local Government',
  MagistocracyOfCanopus = 'Magistocracy of Canopus',
  Marian = 'Marian Hegemony',
  Marik = 'Free Worlds League (Marik)',
  Outworld = 'Outworld Alliance',
  Rasalhague = 'Free Rasalhague Republic',
  Rim = 'Rim Collection',
  Steiner = 'Lyran Commonwealth (Steiner)',
  TaurianConcordat = 'Taurian Concordat',
  Tortuga = 'Tortuga Dominions'
}


function p.factionMechs(frame)
  local tpl_args = getArgs(frame, {parentFirst=true})

  local faction = tpl_args[1]
  local where = string.format('Mech.MechTags HOLDS "%s"', faction)

  local factionMechData = mw.ext.cargo.query(
    'Mech,Chassis','Chassis.Name=Name,Chassis.VariantName=VariantName',
    { join = 'Mech.ChassisID=Chassis.Id', where=where }
  )

  local mechsList = mw.html.create('ul')
  mechsList:cssText('column-count: 3;-moz-column-count: 3;-webkit-column-count: 3')
  for _, mech in ipairs(factionMechData) do
    mechsList:tag('li'):wikitext(string.format(
      '[[%s#%s|%s %s]]', mech['Name'], mech['VariantName'], 
      mech['Name'], mech['VariantName']
    ))
  end
  return mechsList
end

function p.mechFactions(frame)
  local tpl_args = getArgs(frame, {parentFirst=true})
  variant = tpl_args[1]

  local mech = mechs.mech:new(variant)

  local tags = {}

  local factionList = mw.html.create('ul')

  for _, tag in ipairs(mech.tags) do
    if p.factionTags[tag] ~= nil then
      table.insert(tags, p.factionTags[tag])
    end
  end

  table.sort(tags)
  for _, tag in ipairs(tags) do
    factionList:tag('li'):wikitext(tag)
  end
  
  return factionList
end

return p