Difference between revisions of "Module:Factions"

From BTAWiki
Jump to navigation Jump to search
(Created page with "-- Module:Factions handles translating faction tags to their full names local p = {} local mechs = require('Module:Mech').core local getArgs = require('Module:Arguments').ge...")
 
Line 40: Line 40:
  
 
   local mech = mechs.mech:new(variant)
 
   local mech = mechs.mech:new(variant)
 +
 +
  local tags = {}
  
 
   local factionList = mw.html.create('ul')
 
   local factionList = mw.html.create('ul')
Line 45: Line 47:
 
   for _, tag in ipairs(mech.tags) do
 
   for _, tag in ipairs(mech.tags) do
 
     if p.factionTags[tag] ~= nil then
 
     if p.factionTags[tag] ~= nil then
       factionList:tag('li'):wikitext(p.factionTags[tag])
+
       table.insert(tags, p.factionTags[tag])
 
     end
 
     end
 +
  end
 +
 +
  table.sort(tags)
 +
  for _, tag in ipairs(tags) do
 +
    factionList:tag('li'):wikitext(tag)
 
   end
 
   end
 
    
 
    

Revision as of 04:32, 20 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',
  ClanGhostBear = 'Clan Ghost Bear',
  ClanJadeFalcon = 'Clan Jade Falcon',
  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.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