Difference between revisions of "Module:TestModulePleaseIgnore"
Jump to navigation
Jump to search
Line 434: | Line 434: | ||
local function sortByNamesFromIds(first, second) | local function sortByNamesFromIds(first, second) | ||
− | return p.factionIdsToNames[first] or "a" < p.factionIdsToNames[second] or "b" | + | if p.factionIdsToNames[first] or "a" == p.factionIdsToNames[second] or "b" then |
+ | return false | ||
+ | else | ||
+ | return p.factionIdsToNames[first] or "a" < p.factionIdsToNames[second] or "b" | ||
+ | end | ||
end | end | ||
Revision as of 05:37, 28 March 2023
Documentation for this module may be created at Module:TestModulePleaseIgnore/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 = '[[Local Pirates|Pirates]]', AuriganRestoration = '[[Aurigan Coalition|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]]', DaneSacellum = '[[Dane Sacellum]]', Davion = '[[Federated Suns|Federated Suns (Davion)]]', DarkCaste = '[[Dark Caste]]', Delphi = '[[New Delphi Compact]]', Hanse = '[[Hanseatic League]]', Ives = '[[St. Ives Compact]]', JacobsonHaven = '[[Jacobson Haven]]', JarnFolk = '[[JàrnFòlk]]', Kurita = '[[Draconis Combine|Draconis Combine (Kurita)]]', Liao = '[[Capellan Confederation|Capellan Confederation (Liao)]]', Locals = 'Local Government', MagistracyofCanopus = '[[Magistracy of Canopus]]', MallardRepublic = '[[Mallard Republic]]', Marian = '[[Marian Hegemony]]', Marik = '[[Free Worlds League|Free Worlds League (Marik)]]', Outworld = '[[Outworlds Alliance]]', Rasalhague = '[[Free Rasalhague Republic]]', Rim = '[[Rim Collection]]', SanctuaryAlliance = '[[Sanctuary Alliance]]', Steiner = '[[Lyran Commonwealth|Lyran Commonwealth (Steiner)]]', TaurianConcordat = '[[Taurian Concordat]]', Tortuga = '[[Tortuga Dominions]]', WordOfBlake = '[[Word of Blake]]' } p.factionIdsToNames = { ["Axumite"] = "Axumite Providence", ["Castile"] = "Nueva Castile", ["Chainelane"] = "Chainelane Isles", ["Circinus"] = "Circinus Federation", ["ClanBurrock"] = "Clan Burrock", ["ClanCloudCobra"] = "Clan Cloud Cobra", ["ClanCoyote"] = "Clan Coyote", ["ClanDiamondShark"] = "Clan Diamond Shark", ["ClanFireMandrill"] = "Clan Fire Mandrill", ["ClanGhostBear"] = "Clan Ghost Bear", ["ClanGoliathScorpion"] = "Clan Goliath Scorpion", ["ClanHellsHorses"] = "Clan Hell's Horses", ["ClanIceHellion"] = "Clan Ice Hellion", ["ClanJadeFalcon"] = "Clan Jade Falcon", ["ClanNovaCat"] = "Clan Nova Cat", ["ClansGeneric"] = "Clans", ["ClanSmokeJaguar"] = "Clan Smoke Jaguar", ["ClanSnowRaven"] = "Clan Snow Raven", ["ClanStarAdder"] = "Clan Star Adder", ["ClanSteelViper"] = "Clan Steel Viper", ["ClanWolf"] = "Clan Wolf", ["ClanWolfInExile"] = "Clan Wolf-in-Exile", ["ComStar"] = "ComStar", ["DaneSacellum"] = "Dane Sacellum", ["DarkCaste"] = "The Dark Caste", ["Delphi"] = "New Delphi Compact", ["Elysia"] = "Elysian Fields", ["Mercenaries"] = "Mercenaries", ["Hanse"] = "Hanseatic League", ["Illyrian"] = "Illyrian Palatinate", ["Ives"] = "St. Ives Compact", ["JacobsonHaven"] = "Jacobson Haven", ["JarnFolk"] = "JarnFolk", ["Lothian"] = "Lothian League", ["MallardRepublic"] = "Mallard Republic", ["Marian"] = "Marian Hegemony", ["Oberon"] = "Oberon Confederation", ["Outworld"] = "Outworld Alliance", ["Rasalhague"] = "Free Rasalhague Republic", ["Rim"] = "Rim Collection", ["SanctuaryAlliance"] = "Sanctuary Alliance", ["SecuritySolutionsInc"] = "Security Solutions, Inc.", ["Tortuga"] = "Tortuga Dominions", ["Valkyrate"] = "Greater Valkyrate", ["Wolfs_Dragoons"] = "Wolf's Dragoons", ["WordOfBlake"] = "Word of Blake", ["10thLyranGuards"] = "10th Lyran Guards", ["11thArmyVEta"] = "11th Army V-Eta", ["11thAvalonHussars"] = "11th Avalon Hussars", ["12thVeganRangers"] = "12th Vegan Rangers", ["15thLyranRegulars"] = "15th Lyran Regulars", ["1stAllianceAirWing"] = "1st Alliance Air Wing", ["1stKitteryBorderers"] = "1st Kittery Borderers", ["1stKnightsOfTheInnerSphere"] = "1st Knights of the Inner Sphere", ["1stMcCarronsArmoredCavalry"] = "1st McCarron's Armored Cavalry", ["1stSwordOfLight"] = "1st Sword Of Light", ["1stTyr"] = "1st Tyr", ["21stCentauriLancers"] = "21st Centauri Lancers", ["2ndArmyVMu"] = "2nd Army V-Mu", ["2ndCanopianFusiliers"] = "2nd Canopian Fusiliers", ["2ndCrucisLancers"] = "2nd Crucis Lancers", ["2ndFreemen"] = "2nd Freemen", ["2ndFreeWorldsGuards"] = "2nd Free Worlds Guards", ["2ndLegionOfVega"] = "2nd Legion Of Vega", ["30thMarikMilitia"] = "30th Marik Militia", ["3rdAllianceAirWing"] = "3rd Alliance Air Wing", ["3rdNightStalkers"] = "3rd Night Stalkers", ["3rdTaurianLancers"] = "3rd Taurian Lancers", ["40thShadowDivision"] = "40th Shadow Division", ["4thAllianceAirWing"] = "4th Alliance Air Wing", ["4thKavalleri"] = "4th Kavalleri", ["51stDarkPanzerJaegers"] = "51st Dark Panzer Jaegers", ["5thDonegalGuards"] = "5th Donegal Guards", ["6thConfederationReserveCavalry"] = "6th Confederation Reserve Cavalry", ["6thLyranGuards"] = "6th Lyran Guards", ["7thArmyVIota"] = "7th Army V-Iota", ["9thDivisionWoB"] = "9th Division III-Gamma", ["AlwaysFaithful"] = "Always Faithful", ["AntianLanciarii"] = "Antian Lanciarii", ["AvantisAngels"] = "Avanti's Angels", ["BandOfTheDamned"] = "Band of the Damned", ["BannockburnsBandits"] = "Bannockburn's Bandits", ["BarrettsFusiliers"] = "Barrett's Fusiliers", ["BlackCaravel"] = "Black Caravel", ["Blackhearts"] = "The Blackhearts", ["BlackOutlaws"] = "The Black Outlaws", ["BlueStarIrregulars"] = "Blue Star Irregulars", ["BroadswordLegion"] = "Broadsword Legion", ["BronsonsHorde"] = "Bronson's Horde", ["BullardsArmoredCavalry"] = "Bullard's Armored Cavalry", ["BurrsBlackCobras"] = "Burr's Black Cobras", ["CaesarsCohorts"] = "Caesar's Cohorts", ["CamachosCaballeros"] = "Camacho's Caballeros", ["CanopianHighlanders"] = "Canopian Highlanders", ["CGBThetaGalaxy"] = "CGB Theta Galaxy", ["CJFIotaGalaxy"] = "CJF Iota Galaxy", ["CleanKill"] = "Clean Kill", ["CNCOmicronGalaxy"] = "CNC Omicron Galaxy", ["CohorsMorituri"] = "Cohors Morituri", ["CWEpsilonGalaxy"] = "CW Epsilon Galaxy", ["DavionAssaultGuards"] = "Davion Assault Guards", ["DeathCommandos"] = "Death Commandos", ["DeathsConsorts"] = "Death's Consorts", ["Dioscuri"] = "Dioscuri", ["DismalDisinherited"] = "Dismal Disinherited", ["Dragonslayers"] = "Dragonslayers", ["EridaniLightHorse"] = "Eridani Light Horse", ["FederatedFreemen"] = "Federated Freemen", ["FistOfMokal"] = "Fist Of Mokal", ["GraysGhosts"] = "Gray's Ghosts", ["GreenburgsGodzillas"] = "Greenburg's Godzillas", ["GrimDetermination"] = "Grim Determination", ["HarcourtsDestructors"] = "Harcourt's Destructors", ["HarlocksWarriors"] = "Harlock's Warriors", ["HsienHotheads"] = "Hsien Hotheads", ["ILegioMartiaVictrix"] = "I Legio Martia Victrix", ["IrukjandiCompany"] = "Irukjandi Company", ["JacobsJuggernauts"] = "Jacob's Juggernauts", ["KhorsakovsCossacks"] = "Khorsakov's Cossacks", ["KnightsOfCaerbannog"] = "Knights of Caerbannog", ["KnightsOfStCameron"] = "Knights Of St. Cameron", ["LangendorfLancers"] = "Langendorf Lancers", ["LethalInjection"] = "Lethal Injection", ["LindonsBattalion"] = "Lindon's Battalion", ["LoneStarRegiment"] = "Lone Star Regiment", ["LongwoodsBluecoats"] = "Longwood's Bluecoats", ["MagistracyCavaliers"] = "Magistracy Cavaliers", ["MobileFire"] = "Mobile Fire", ["MorrisonsExtractors"] = "Morrison's Extractors", ["NarhalsRaiders"] = "Narhal's Raiders", ["NewBeltPirates"] = "New Belt Pirates", ["NorthwindHighlanders"] = "Northwind Highlanders", ["OlsonsRangers"] = "Olson's Rangers", ["PleiadesHussars"] = "Pleiades Hussars", ["QuintsOlympianGroundpounders"] = "Quint's Olympian Groundpounders", ["RamiliesRaiders"] = "Ramilie's Raiders", ["RaventhirsIronHand"] = "Raventhir's Iron Hand", ["RomanovsCrusaders"] = "Romanov's Crusaders", ["RubinskysLightHorse"] = "Rubinsky's Light Horse", ["ScreamingEagles"] = "Screaming Eagles", ["ShenSeTian"] = "Shen-Se Tian", ["SimonsonsCutthroats"] = "Simonson's Cutthroats", ["SmithsonsChineseBandits"] = "Smithson's Chinese Bandits", ["SnordsIrregulars"] = "Snord's Irregulars", ["SolarisVIIMercLeague"] = "Solaris VII Mercenary League", ["TaurianGuard"] = "Taurian Guard", ["TheArcadians"] = "The Arcadians", ["TheKrushers"] = "The Krushers", ["ThermoPolice"] = "Thermo Police", ["ToothOfYmir"] = "Tooth of Ymir", ["TortugaFusiliers"] = "Tortuga Fusiliers", ["VanguardLegion"] = "Vanguard Legion", ["VLegioRipariensis"] = "V Legio Ripariensis", ["WarriorHouseImarra"] = "Warrior House Imarra", ["WinfieldsRegiment"] = "Winfield's Regiment", ["WoBProtectorateMilitia"] = "WoB Protectorate Militia", ["Betrayers"] = "Arano Betrayers", ["AuriganDirectorate"] = "Aurigan Directorate", ["AuriganMercenaries"] = "Darius", ["AuriganPirates"] = "Pirates", ["AuriganRestoration"] = "Aurigan Restoration (Arano)", ["Davion"] = "Federated Suns (Davion)", ["GrayDeathLegion"] = "Gray Death Legion", ["KellHounds"] = "Kell Hounds", ["Kurita"] = "Draconis Combine (Kurita)", ["Liao"] = "Capellan Confederation (Liao)", ["Locals"] = "Planetary Government", ["MagistracyCentrella"] = "Magistracy of Centrella", ["MagistracyOfCanopus"] = "Magistracy of Canopus", ["MajestyMetals"] = "Majesty Metals & Manufacturing", ["Marik"] = "Free Worlds League (Marik)", ["MercenaryReviewBoard"] = "Mercenary Review Board", ["Nautilus"] = "Nautilus Base Defenses", ["NoFaction"] = "Abandoned", ["SelfEmployed"] = "Darius", ["Steiner"] = "Lyran Commonwealth (Steiner)", ["TaurianConcordat"] = "Taurian Concordat" } p.spamFactionsToParents = { ClanWolf = "ClanWolf", ["ClanWolf"] = "ClanWolf", ["CWEpsilonGalaxy"] = "ClanWolf", ["ClanNovaCat"] = "ClanNovaCat", ["CNCOmicronGalaxy"] = "ClanNovaCat", ["ClanJadeFalcon"] = "ClanJadeFalcon", ["CJFIotaGalaxy"] = "ClanJadeFalcon", ["ClanGhostBear"] = "ClanGhostBear", ["CGBThetaGalaxy"] = "ClanGhostBear", ["WordOfBlake"] = "WordOfBlake", ["40thShadowDivision"] = "WordOfBlake", ["9thDivisionWoB"] = "WordOfBlake", ["WoBProtectorateMilitia"] = "WordOfBlake", ["Liao"] = "Liao", ["DeathCommandos"] = "Liao", ["1stMcCarronsArmoredCavalry"] = "Liao", ["WarriorHouseImarra"] = "Liao", ["6thConfederationReserveCavalry"] = "Liao", ["Kurita"] = "Kurita", ["1stSwordOfLight"] = "Kurita", ["3rdNightStalkers"] = "Kurita", ["2ndLegionOfVega"] = "Kurita", ["Davion"] = "Davion", ["DavionAssaultGuards"] = "Davion", ["2ndCrucisLancers"] = "Davion", ["1stKitteryBorderers"] = "Davion", ["10thLyranGuards"] = "Davion", ["Steiner"] = "Steiner", ["6thLyranGuards"] = "Steiner", ["5thDonegalGuards"] = "Steiner", ["15thLyranRegulars"] = "Steiner", ["11thAvalonHussars"] = "Steiner", ["Marik"] = "Marik", ["1stKnightsOfTheInnerSphere"] = "Marik", ["2ndFreeWorldsGuards"] = "Marik", ["30thMarikMilitia"] = "Marik", ["Comstar"] = "Comstar", ["2ndArmyVMu"] = "Comstar", ["11thArmyVEta"] = "Comstar", ["7thArmyVIota"] = "Comstar", ["Rasalhague"] = "Rasalhague", ["1stTyr"] = "Rasalhague", ["2ndFreemen"] = "Rasalhague", ["4thKavalleri"] = "Rasalhague", ["TaurianConcordat"] = "TaurianConcordat", ["TaurianGuard"] = "TaurianConcordat", ["PleiadesHussars"] = "TaurianConcordat", ["3rdTaurianLancers"] = "TaurianConcordat", ["MagistracyOfCanopus"] = "MagistracyOfCanopus", ["RaventhirsIronHand"] = "MagistracyOfCanopus", ["2ndCanopianFusiliers"] = "MagistracyOfCanopus", ["MagistracyCavaliers"] = "MagistracyOfCanopus", ["Outworld"] = "Outworld", ["1stAllianceAirWing"] = "Outworld", ["3rdAllianceAirWing"] = "Outworld", ["4thAllianceAirWing"] = "Outworld", ["Marian"] = "Marian", ["ILegioMartiaVictrix"] = "Marian", ["VLegioRipariensis"] = "Marian", ["CohorsMorituri"] = "Marian", ["BroadswordLegion"] = 'Mercenaries', ["BurrsBlackCobras"] = 'Mercenaries', ["51stDarkPanzerJaegers"] = 'Mercenaries', ["FistOfMokal"] = 'Mercenaries', ["HsienHotheads"] = 'Mercenaries', ["SimonsonsCutthroats"] = 'Mercenaries', ["AlwaysFaithful"] = 'Mercenaries', ["LangendorfLancers"] = 'Mercenaries', ["LethalInjection"] = 'Mercenaries', ["OlsonsRangers"] = 'Mercenaries', ["TheArcadians"] = 'Mercenaries', ["BlueStarIrregulars"] = 'Mercenaries', ["12thVeganRangers"] = 'Mercenaries', ["Dioscuri"] = 'Mercenaries', ["FederatedFreemen"] = 'Mercenaries', ["HarlocksWarriors"] = 'Mercenaries', ["ScreamingEagles"] = 'Mercenaries', ["SmithsonsChineseBandits"] = 'Mercenaries', ["VanguardLegion"] = 'Mercenaries', ["AvantisAngels"] = 'Mercenaries', ["KellHounds"] = 'Mercenaries', ["KnightsOfStCameron"] = 'Mercenaries', ["MobileFire"] = 'Mercenaries', ["SnordsIrregulars"] = 'Mercenaries', ["CamachosCaballeros"] = 'Mercenaries', ["GreenburgsGodzillas"] = 'Mercenaries', ["NarhalsRaiders"] = 'Mercenaries', ["NorthwindHighlanders"] = 'Mercenaries', ["Wolfs_Dragoons"] = 'Mercenaries', ["BarrettsFusiliers"] = 'Mercenaries', ["Blackhearts"] = 'Mercenaries', ["TheKrushers"] = 'Mercenaries', ["RomanovsCrusaders"] = 'Mercenaries', ["BannockburnsBandits"] = 'Mercenaries', ["CleanKill"] = 'Mercenaries', ["LoneStarRegiment"] = 'Mercenaries', ["LongwoodsBluecoats"] = 'Mercenaries', ["CaesarsCohorts"] = 'Mercenaries', ["CanopianHighlanders"] = 'Mercenaries', ["DismalDisinherited"] = 'Mercenaries', ["Dragonslayers"] = 'Mercenaries', ["HarcourtsDestructors"] = 'Mercenaries', ["RamiliesRaiders"] = 'Mercenaries', ["ThermoPolice"] = 'Mercenaries', ["BronsonsHorde"] = 'Mercenaries', ["BullardsArmoredCavalry"] = 'Mercenaries', ["QuintsOlympianGroundpounders"] = 'Mercenaries', ["GraysGhosts"] = 'Mercenaries', ["BlackOutlaws"] = 'Mercenaries', ["21stCentauriLancers"] = 'Mercenaries', ["RubinskysLightHorse"] = 'Mercenaries', ["KhorsakovsCossacks"] = 'Mercenaries', ["EridaniLightHorse"] = 'Mercenaries', ["IrukjandiCompany"] = 'Mercenaries', ["AntianLanciarii"] = 'Mercenaries', ["BlackCaravel"] = 'Mercenaries', ["KnightsOfCaerbannog"] = 'Mercenaries', ["WinfieldsRegiment"] = 'Mercenaries', ["ToothOfYmir"] = 'Mercenaries', ["JacobsJuggernauts"] = 'Mercenaries', ["LindonsBattalion"] = 'Mercenaries', ["GrimDetermination"] = 'Mercenaries', ["SolarisVIIMercLeague"] = 'Mercenaries', ["BandOfTheDamned"] = 'Mercenaries', ["DeathsConsorts"] = 'Mercenaries', ["MorrisonsExtractors"] = 'Mercenaries', ["NewBeltPirates"] = 'Mercenaries', ["TortugaFusiliers"] = 'Mercenaries', ["ShenSeTian"] = 'Mercenaries' } 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) -- some mechs share the same name but have different tonnages and therefore -- different pages to be linked to local function MakeMechLink(name, variant, tonnage) if (name == "Blackjack" and tonnage ~= "45") or (name == "Centurion" and tonnage ~= "50") or (name == "Corsair" and tonnage ~= "95") or (name == "Stalker" and tonnage ~= "85") or (name == "Mad Cat MK II" and tonnage ~= "90") then return string.format('[[%s_(%sT)#%s|%s (%sT) %s]]', name, tonnage, variant, name, tonnage, variant) elseif string.find(variant, "ZEU-X", 1, true) then return string.format('[[Zeus_X#%s|Zeus X %s]]', variant, variant) else return string.format('[[%s#%s|%s %s]]', name, variant, name, variant) end end -- when querying for mechs, set the limit to 2000. this is arbitrarily high -- (larger than the total number of mechs). without this, factions with lots -- of mechs would not show all of them. local factionMechData = mw.ext.cargo.query( 'Mech,Chassis','Chassis.Name=Name,Chassis.VariantName=VariantName,Chassis.Tonnage=Tonnage', { join = 'Mech.ChassisID=Chassis.Id', where=where, limit=2000 } ) 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(MakeMechLink(mech.Name, mech.VariantName, tostring(mech.Tonnage))) end return mechsList end function p.mechFactions(frame) local tpl_args = getArgs(frame, {parentFirst=true}) variant = tpl_args[1] local mech = mechs.mech.byVariant(variant) if mech == nil then return mw.html.create('div').wikitext("''Mech not found''") end local spamDict = {} local tags = {} local factionList = mw.html.create('ul') local collapsibleTagAttributes = { class = 'mw-collapsible mw-collapsed' } local collapsibleContentTagAttributes = { class = 'mw-collapsible-content' } for _, tag in ipairs(mech.tags) do if p.factionIdsToNames[tag] ~= nil then if spamDict[tag] == nil then spamDict[tag] = {} end table.insert(spamDict[tag], p.spamFactionsToParents[tag] or tag) end end -- create and then sort a list of the keys so we can put them into the html in the right order. Use the raw names so we don't get all the unlinked names going at the top. local factionIdSortedKeys = {} local n = 0 for tempId, _ in pairs(spamDict) do n = n + 1 factionIdSortedKeys[n] = tempId end local function sortByNamesFromIds(first, second) if p.factionIdsToNames[first] or "a" == p.factionIdsToNames[second] or "b" then return false else return p.factionIdsToNames[first] or "a" < p.factionIdsToNames[second] or "b" end end table.sort(factionIdSortedKeys, sortByNamesFromIds) -- for _, factionId in ipairs(factionIdSortedKeys) do -- if table.getn(spamDict[factionId]) == 1 and factionId == spamDict[factionId][1] then if p.factionTags[factionId] ~= nil then factionList:tag('li'):wikitext(p.factionTags[factionId]) elseif p.factionIdsToNames[factionId] ~= nil then factionList:tag('li'):wikitext(p.factionIdsToNames[factionId]) end -- else factionList:tag('li'):tag('div'):attr(collapsibleTagAttributes) if p.factionIdsToNames[factionId] ~= nil then factionList:wikitext(p.factionIdsToNames[factionId]) end factionList:tag('div'):attr(collapsibleContentTagAttributes):tag('ul') -- for __, subFactionId in ipairs(spamDict[factionId]) do factionList:tag('li'):wikitext(p.factionIdsToNames[factionId]) end factionList:done():done() end end return factionList end return p