Difference between revisions of "Module:Equipment"

From BTAWiki
Jump to navigation Jump to search
Line 16: Line 16:
  
  
--[===[
+
-- local where = string.format('MechInventory.ComponentDefID HOLDS "%s"', equipment)
  local where = string.format('MechInventory.ComponentDefID HOLDS "%s"', equipment)
 
  
 
   -- when querying for mechs, set the limit to 2000. this is arbitrarily high
 
   -- 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
 
   -- (larger than the total number of mechs). without this, factions with lots
 
   -- of mechs would not show all of them.
 
   -- of mechs would not show all of them.
  local equipmentMechData = mw.ext.cargo.query(
+
--  local equipmentMechData = mw.ext.cargo.query(
    'Mech,Chassis','Chassis.Name=Name,Chassis.VariantName=VariantName',
+
--    'Mech,Chassis','Chassis.Name=Name,Chassis.VariantName=VariantName',
    { join = 'Mech.ChassisID=Chassis.Id', where=where, limit=2000 }
+
--    { join = 'Mech.ChassisID=Chassis.Id', where=where, limit=2000 }
  )
+
--  )
 +
 
 +
--  local equipList = mw.html.create('ul')
 +
--  equipList:cssText('column-count: 3;-moz-column-count: 3;-webkit-column-count: 3')
 +
--  for _, mech in ipairs(equipmentMechData) do
 +
--    equipList:tag('li'):wikitext(string.format(
 +
--      '[[%s#%s|%s %s]]', mech['Name'], mech['VariantName'],
 +
--      mech['Name'], mech['VariantName']
 +
--    ))
 +
--  end
 +
--  return equipList
  
  local equipList = mw.html.create('ul')
 
  equipList:cssText('column-count: 3;-moz-column-count: 3;-webkit-column-count: 3')
 
  for _, mech in ipairs(equipmentMechData) do
 
    equipList:tag('li'):wikitext(string.format(
 
      '[[%s#%s|%s %s]]', mech['Name'], mech['VariantName'],
 
      mech['Name'], mech['VariantName']
 
    ))
 
  end
 
  return equipList
 
--]===]
 
 
end
 
end
  

Revision as of 11:49, 7 December 2021

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

-- Module:Equipment is my attempt to create a list of mechs that use a particular 
-- bit of equipment with the idea being you can see what mechs to hunt for particular bits of gear.

local p = {}

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


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

  local equipment = tpl_args[1]

  return mw.html.create('div').wikitext("''Hello World''")


--  local where = string.format('MechInventory.ComponentDefID HOLDS "%s"', equipment)

  -- 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 equipmentMechData = mw.ext.cargo.query(
--    'Mech,Chassis','Chassis.Name=Name,Chassis.VariantName=VariantName',
--    { join = 'Mech.ChassisID=Chassis.Id', where=where, limit=2000 }
--  )

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

end

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

  local mech = mechs.mech_inventory.componentDefID(gearpiece)

  if mech == nil then
    return mw.html.create('div').wikitext("''Mech not found''")
  end

  local equip = {}

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

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

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

return p